@@ -2,9 +2,13 @@ package obfs4
22
33import (
44 "fmt"
5+ "io"
6+ "net"
57
8+ pt "git.torproject.org/pluggable-transports/goptlib.git"
69 "github.com/refraction-networking/conjure/application/transports"
710 pb "github.com/refraction-networking/gotapdance/protobuf"
11+ "gitlab.com/yawning/obfs4.git/transports/obfs4"
812
913 "google.golang.org/protobuf/proto"
1014)
@@ -14,6 +18,7 @@ import (
1418// the station side Transport struct has one instance to be re-used for all sessions.
1519type ClientTransport struct {
1620 Parameters * pb.GenericTransportParams
21+ keys Obfs4Keys
1722}
1823
1924// Name returns a string identifier for the Transport for logging
@@ -59,8 +64,39 @@ func (t *ClientTransport) GetDstPort(seed []byte, params any) (uint16, error) {
5964 return transports .PortSelectorRange (portRangeMin , portRangeMax , seed )
6065}
6166
62- // // Connect creates the connection to the phantom address negotiated in the registration phase of
63- // // Conjure connection establishment.
64- // func (*ClientTransport) Connect(ctx context.Context, reg *cj.ConjureReg) (net.Conn, error) {
65- // return nil, nil
66- // }
67+ // WrapConn creates the connection to the phantom address negotiated in the registration phase of
68+ // Conjure connection establishment.
69+ func (t ClientTransport ) WrapConn (conn net.Conn ) (net.Conn , error ) {
70+ obfsTransport := obfs4.Transport {}
71+ args := pt.Args {}
72+
73+ args .Add ("node-id" , t .keys .NodeID .Hex ())
74+ args .Add ("public-key" , t .keys .PublicKey .Hex ())
75+ args .Add ("iat-mode" , "1" )
76+
77+ c , err := obfsTransport .ClientFactory ("" )
78+ if err != nil {
79+ return nil , fmt .Errorf ("failed to create client factory" )
80+ }
81+
82+ parsedArgs , err := c .ParseArgs (& args )
83+ if err != nil {
84+ return nil , fmt .Errorf ("failed to parse obfs4 args" )
85+ }
86+
87+ d := func (network , address string ) (net.Conn , error ) {
88+ return conn , nil
89+ }
90+
91+ return c .Dial ("tcp" , "" , d , parsedArgs )
92+ }
93+
94+ func (t * ClientTransport ) PrepareKeys (pubkey [32 ]byte , sharedSecret []byte , dRand io.Reader ) error {
95+ // Generate shared keys
96+ var err error
97+ t .keys , err = generateObfs4Keys (dRand )
98+ if err != nil {
99+ return err
100+ }
101+ return nil
102+ }
0 commit comments