Skip to content

Commit

Permalink
tests: add https request scripts(golang).
Browse files Browse the repository at this point in the history
Signed-off-by: CFC4N <[email protected]>
  • Loading branch information
cfc4n committed Apr 26, 2023
1 parent 1064ff3 commit 786f1c0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
7 changes: 0 additions & 7 deletions cli/cmd/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"ecapture/pkg/util/kernel"
"ecapture/user/config"
"ecapture/user/module"
"errors"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -136,12 +135,6 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {
err = conf.Check()

if err != nil {
// ErrorGoBINNotSET is a special error, we should not print it.
if errors.Is(err, config.ErrorGoBINNotSET) {
logger.Printf("%s\tmodule [disabled].", mod.Name())
continue
}

logger.Printf("%s\tmodule initialization failed. [skip it]. error:%+v", mod.Name(), err)
continue
}
Expand Down
40 changes: 40 additions & 0 deletions tests/golang_https.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"crypto/tls"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
)

func main() {

b, e := GetHttp("https://github.com")
if e == nil {
fmt.Printf("response body: %s\n\n", b)
} else {
fmt.Printf("error :%v", e)
}
}

func GetHttp(url string) (body []byte, err error) {
f, err := os.OpenFile(filepath.Join(os.TempDir(), "ecapture_go_master_secret.log"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
panic(err)
}
defer f.Close()
c := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true, KeyLogWriter: f},
}}
resp, e := c.Get(url)
if e != nil {
return nil, e
}

defer resp.Body.Close()
body, err = io.ReadAll(resp.Body)
return body, err
}
4 changes: 2 additions & 2 deletions user/config/config_gotls.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

var (
ErrorGoBINNotSET = errors.New("GO binary not set")
ErrorGoBINNotFound = errors.New("GO binary not found")
)

// GoTLSConfig represents configuration for Go SSL probe
Expand All @@ -39,7 +39,7 @@ func NewGoTLSConfig() *GoTLSConfig {

func (c *GoTLSConfig) Check() error {
if c.Path == "" {
return ErrorGoBINNotSET
return ErrorGoBINNotFound
}

if c.Ifname == "" || len(c.Ifname) == 0 {
Expand Down

0 comments on commit 786f1c0

Please sign in to comment.