Skip to content

Commit 3d1392a

Browse files
committed
decoy-reg: move decoy-specific keys to registrar
1 parent cdfbdbc commit 3d1392a

File tree

2 files changed

+51
-54
lines changed

2 files changed

+51
-54
lines changed

pkg/registrars/decoy-registrar/decoy-registrar.go

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@ import (
1111
pb "github.com/refraction-networking/conjure/proto"
1212
tls "github.com/refraction-networking/utls"
1313

14-
// td imports assets/RegError/generateHTTPRequestBeginning
14+
// td imports assets, RegError, generateHTTPRequestBeginning
1515
td "github.com/refraction-networking/gotapdance/tapdance"
1616

1717
"github.com/sirupsen/logrus"
1818
)
1919

20-
/**
21-
* TODO: enable logging
22-
*/
23-
2420
// timeout for sending TD request and getting a response
2521
const deadlineConnectTDStationMin = 11175
2622
const deadlineConnectTDStationMax = 14231
@@ -57,30 +53,9 @@ type DecoyRegistrar struct {
5753
// Fields taken from ConjureReg struct
5854
m sync.Mutex
5955
stats *pb.SessionStats
60-
}
61-
62-
// CurrentClientLibraryVersion returns the current client library version used
63-
// for feature compatibility support between client and server. Currently I
64-
// don't intend to connect this to the library tag version in any way.
65-
//
66-
// When adding new client versions comment out older versions and add new
67-
// version below with a description of the reason for the new version.
68-
func currentClientLibraryVersion() uint32 {
69-
// Support for randomizing destination port for phantom connection
70-
// https://github.com/refraction-networking/gotapdance/pull/108
71-
return 3
72-
73-
// // Selection algorithm update - Oct 27, 2022 -- Phantom selection version rework again to use
74-
// // hkdf for actual uniform distribution across phantom subnets.
75-
// // https://github.com/refraction-networking/conjure/pull/145
76-
// return 2
77-
78-
// // Initial inclusion of client version - added due to update in phantom
79-
// // selection algorithm that is not backwards compatible to older clients.
80-
// return 1
81-
82-
// // No client version indicates any client before this change.
83-
// return 0
56+
// add Width, sharedKeys necessary stuff (2nd line in struct except ConjureSeed)
57+
// Keys
58+
FspKey, FspIv, VspKey, VspIv, NewMasterSecret []byte
8459
}
8560

8661
func (r *DecoyRegistrar) setTCPToDecoy(tcprtt *uint32) {
@@ -120,24 +95,6 @@ func (r *DecoyRegistrar) getTcpToDecoy() uint32 {
12095
return 0
12196
}
12297

123-
func generateFlags(cjSession *td.ConjureSession) *pb.RegistrationFlags {
124-
flags := &pb.RegistrationFlags{}
125-
mask := default_flags
126-
if cjSession.UseProxyHeader {
127-
mask |= tdFlagProxyHeader
128-
}
129-
130-
uploadOnly := mask&tdFlagUploadOnly == tdFlagUploadOnly
131-
proxy := mask&tdFlagProxyHeader == tdFlagProxyHeader
132-
til := mask&tdFlagUseTIL == tdFlagUseTIL
133-
134-
flags.UploadOnly = &uploadOnly
135-
flags.ProxyHeader = &proxy
136-
flags.Use_TIL = &til
137-
138-
return flags
139-
}
140-
14198
func (r DecoyRegistrar) createTLSConn(dialConn net.Conn, address string, hostname string, deadline time.Time) (*tls.UConn, error) {
14299
var err error
143100
//[reference] TLS to Decoy
@@ -171,8 +128,6 @@ func (r DecoyRegistrar) createTLSConn(dialConn net.Conn, address string, hostnam
171128
return tlsConn, nil
172129
}
173130

174-
// Register -> Send -> createRequest -> generateVSP -> generateClientToStation
175-
176131
func (r *DecoyRegistrar) createRequest(tlsConn *tls.UConn, decoy *pb.TLSDecoySpec, cjSession *td.ConjureSession) ([]byte, error) {
177132
//[reference] generate and encrypt variable size payload
178133
vsp, err := generateVSP(cjSession)
@@ -182,14 +137,14 @@ func (r *DecoyRegistrar) createRequest(tlsConn *tls.UConn, decoy *pb.TLSDecoySpe
182137
if len(vsp) > int(^uint16(0)) {
183138
return nil, fmt.Errorf("Variable-Size Payload exceeds %v", ^uint16(0))
184139
}
185-
encryptedVsp, err := aesGcmEncrypt(vsp, cjSession.Keys.VspKey, cjSession.Keys.VspIv)
140+
encryptedVsp, err := aesGcmEncrypt(vsp, r.VspKey, r.VspIv)
186141
if err != nil {
187142
return nil, err
188143
}
189144

190145
//[reference] generate and encrypt fixed size payload
191146
fsp := generateFSP(uint16(len(encryptedVsp)))
192-
encryptedFsp, err := aesGcmEncrypt(fsp, cjSession.Keys.FspKey, cjSession.Keys.FspIv)
147+
encryptedFsp, err := aesGcmEncrypt(fsp, r.FspKey, r.FspIv)
193148
if err != nil {
194149
return nil, err
195150
}
@@ -277,7 +232,6 @@ func (r DecoyRegistrar) Register(cjSession *td.ConjureSession, ctx context.Conte
277232
}
278233

279234
// randomized sleeping here to break the intraflow signal
280-
// TODO: is this okay?
281235
toSleep := r.GetRandomDuration(3000, 212, 3449)
282236
logger.Debugf("Successfully sent registrations, sleeping for: %v", toSleep)
283237
lib.SleepWithContext(ctx, toSleep)
@@ -336,7 +290,7 @@ func (r *DecoyRegistrar) Send(ctx context.Context, cjSession *td.ConjureSession,
336290
//[reference] Write reg into conn
337291
_, err = tlsConn.Write(httpRequest)
338292
if err != nil {
339-
// // This will not get printed because it is executed in a goroutine.
293+
// This will not get printed because it is executed in a goroutine.
340294
// Logger().Errorf("%v - %v Could not send Conjure registration request, error: %v", decoy.GetHostname(), decoy.GetIpAddrStr(), err.Error())
341295
tlsConn.Close()
342296
msg := fmt.Sprintf("%v - %v Write: %v", decoy.GetHostname(), decoy.GetIpAddrStr(), err.Error())

pkg/registrars/decoy-registrar/utils.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,34 @@ func readAndClose(c net.Conn, readDeadline time.Duration) {
174174
c.Close()
175175
}
176176

177+
// CurrentClientLibraryVersion returns the current client library version used
178+
// for feature compatibility support between client and server. Currently I
179+
// don't intend to connect this to the library tag version in any way.
180+
//
181+
// When adding new client versions comment out older versions and add new
182+
// version below with a description of the reason for the new version.
183+
func currentClientLibraryVersion() uint32 {
184+
// Support for randomizing destination port for phantom connection
185+
// https://github.com/refraction-networking/gotapdance/pull/108
186+
return 3
187+
188+
// // Selection algorithm update - Oct 27, 2022 -- Phantom selection version rework again to use
189+
// // hkdf for actual uniform distribution across phantom subnets.
190+
// // https://github.com/refraction-networking/conjure/pull/145
191+
// return 2
192+
193+
// // Initial inclusion of client version - added due to update in phantom
194+
// // selection algorithm that is not backwards compatible to older clients.
195+
// return 1
196+
197+
// // No client version indicates any client before this change.
198+
// return 0
199+
}
200+
177201
// Below are functions adapted from tapdance/conjure.go that originally had receiver of
178202
// type *ConjureReg. For now, we can pass the *ConjureSession to work with and avoid any
179-
// receiver, but eventually we may want to change the receiver type to *ConjureSession.
203+
// receiver, but eventually we may want to change the receiver type to *ConjureSession,
204+
// or use type alias to another name so we can define functions with that receiver here.
180205

181206
func getPbTransportParams(cjSession *td.ConjureSession) (*anypb.Any, error) {
182207
var m proto.Message
@@ -247,3 +272,21 @@ func generateClientToStation(cjSession *td.ConjureSession) (*pb.ClientToStation,
247272

248273
return initProto, nil
249274
}
275+
276+
func generateFlags(cjSession *td.ConjureSession) *pb.RegistrationFlags {
277+
flags := &pb.RegistrationFlags{}
278+
mask := default_flags
279+
if cjSession.UseProxyHeader {
280+
mask |= tdFlagProxyHeader
281+
}
282+
283+
uploadOnly := mask&tdFlagUploadOnly == tdFlagUploadOnly
284+
proxy := mask&tdFlagProxyHeader == tdFlagProxyHeader
285+
til := mask&tdFlagUseTIL == tdFlagUseTIL
286+
287+
flags.UploadOnly = &uploadOnly
288+
flags.ProxyHeader = &proxy
289+
flags.Use_TIL = &til
290+
291+
return flags
292+
}

0 commit comments

Comments
 (0)