Skip to content

Commit

Permalink
add tls support to packetgen
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven committed Mar 31, 2022
1 parent 0d22de2 commit 66a6203
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion examples/config/advanced/packetgen-tcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ jobs:
type: net
args:
protocol: "tcp"
address: "localhost:1234"
address: "google.com:443"
tls_config:
InsecureSkipVerify: true # this is not snake case because I decode it straight into tls config
packet:
application:
type: raw
Expand Down
21 changes: 17 additions & 4 deletions src/core/packetgen/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package packetgen

import (
"crypto/tls"
"fmt"
"net"
"time"
Expand Down Expand Up @@ -93,10 +94,11 @@ func (conn rawConn) Write(packet Packet) (n int, err error) {
}

type netConnConfig struct {
Protocol string
Address string
ProxyURLs string `mapstructure:"proxy_urls"`
Timeout time.Duration
Protocol string
Address string
Timeout time.Duration
ProxyURLs string `mapstructure:"proxy_urls"`
TLSClientConfig *tls.Config `mapstructure:"tls_config"`
}

type netConn struct {
Expand All @@ -106,6 +108,17 @@ type netConn struct {
func openNetConn(c netConnConfig) (*netConn, error) {
conn, err := utils.GetProxyFunc(c.ProxyURLs, c.Timeout)(c.Protocol, c.Address)

if c.TLSClientConfig != nil {
tlsConn := tls.Client(conn, c.TLSClientConfig)
if err := tlsConn.Handshake(); err != nil {
tlsConn.Close()

return nil, err
}

return &netConn{Conn: tlsConn}, err
}

return &netConn{Conn: conn}, err
}

Expand Down

0 comments on commit 66a6203

Please sign in to comment.