Skip to content

Commit dd5bf2b

Browse files
committed
key management and client version centralization
1 parent 783edd0 commit dd5bf2b

File tree

19 files changed

+408
-191
lines changed

19 files changed

+408
-191
lines changed

cmd/application/registration_with_transport_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"google.golang.org/protobuf/proto"
1818
)
1919

20-
func mockReceiveFromDetector() (*pb.ClientToStation, cj.ConjureSharedKeys) {
20+
func mockReceiveFromDetector() (*pb.ClientToStation, core.ConjureSharedKeys) {
2121
clientToStationBytes, _ := hex.DecodeString("109a04180ba2010e35322e34342e37332e363a343433b00100a2060100")
2222
sharedSecret, _ := hex.DecodeString("5414c734ad5dc53e6b56a7bb47ce695a14a3ef076a3d5ace9cbf3b4d12706b73")
2323

@@ -32,7 +32,7 @@ func mockReceiveFromDetector() (*pb.ClientToStation, cj.ConjureSharedKeys) {
3232
clientToStation.Flags = &pb.RegistrationFlags{Use_TIL: &t}
3333
clientToStation.ClientLibVersion = &v
3434

35-
conjureKeys, _ := cj.GenSharedKeys(uint(v), sharedSecret, 0)
35+
conjureKeys, _ := core.GenSharedKeys(uint(v), sharedSecret, 0)
3636

3737
return clientToStation, conjureKeys
3838
}

go.mod

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ module github.com/refraction-networking/conjure
22

33
go 1.18
44

5-
// replace gitlab.com/yawning/obfs4.git => github.com/jmwample/obfs4.git v0.0.0-20230113193642-07b111e6b208
6-
7-
replace gitlab.com/yawning/obfs4.git => github.com/jmwample/obfs4 v0.0.0-20230113193642-07b111e6b208
8-
95
require (
10-
git.torproject.org/pluggable-transports/goptlib.git v1.3.0
116
github.com/BurntSushi/toml v1.2.1
127
github.com/flynn/noise v1.0.0
138
github.com/go-redis/redis/v8 v8.11.5
@@ -18,19 +13,20 @@ require (
1813
github.com/pebbe/zmq4 v1.2.9
1914
github.com/pelletier/go-toml v1.9.5
2015
github.com/pion/stun v0.3.5
16+
github.com/refraction-networking/ed25519 v0.1.2
2117
github.com/refraction-networking/gotapdance v1.5.5
18+
github.com/refraction-networking/obfs4 v0.1.2
2219
github.com/refraction-networking/utls v1.2.0
2320
github.com/sirupsen/logrus v1.9.0
2421
github.com/stretchr/testify v1.8.1
25-
gitlab.com/yawning/obfs4.git v0.0.0-20230519154740-645026c2ada4
26-
golang.org/x/crypto v0.9.0
27-
golang.org/x/net v0.10.0
22+
gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.4.0
23+
golang.org/x/crypto v0.11.0
24+
golang.org/x/net v0.12.0
2825
google.golang.org/grpc v1.53.0
2926
google.golang.org/protobuf v1.31.0
3027
)
3128

3229
require (
33-
filippo.io/edwards25519 v1.0.0 // indirect
3430
github.com/andybalholm/brotli v1.0.4 // indirect
3531
github.com/cespare/xxhash/v2 v2.2.0 // indirect
3632
github.com/davecgh/go-spew v1.1.1 // indirect
@@ -41,8 +37,7 @@ require (
4137
github.com/oschwald/maxminddb-golang v1.10.0 // indirect
4238
github.com/pmezard/go-difflib v1.0.0 // indirect
4339
github.com/sergeyfrolov/bsbuffer v0.0.0-20180903213811-94e85abb8507 // indirect
44-
gitlab.com/yawning/edwards25519-extra.git v0.0.0-20220726154925-def713fd18e4 // indirect
45-
golang.org/x/sys v0.8.0 // indirect
46-
golang.org/x/text v0.9.0 // indirect
40+
golang.org/x/sys v0.10.0 // indirect
41+
golang.org/x/text v0.11.0 // indirect
4742
gopkg.in/yaml.v3 v3.0.1 // indirect
4843
)

go.sum

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
filippo.io/edwards25519 v1.0.0-rc.1.0.20210721174708-390f27c3be20/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
2-
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
3-
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
4-
git.torproject.org/pluggable-transports/goptlib.git v1.0.0/go.mod h1:YT4XMSkuEXbtqlydr9+OxqFAyspUv0Gr9qhM3B++o/Q=
5-
git.torproject.org/pluggable-transports/goptlib.git v1.3.0 h1:G+iuRUblCCC2xnO+0ag1/4+aaM98D5mjWP1M0v9s8a0=
6-
git.torproject.org/pluggable-transports/goptlib.git v1.3.0/go.mod h1:4PBMl1dg7/3vMWSoWb46eGWlrxkUyn/CAJmxhDLAlDs=
71
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
82
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
93
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
@@ -13,7 +7,6 @@ github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
137
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
148
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
159
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16-
github.com/dchest/siphash v1.2.1/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4=
1710
github.com/dchest/siphash v1.2.3 h1:QXwFc8cFOR2dSa/gE6o/HokBMWtLUaNDVd+22aKHeEA=
1811
github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc=
1912
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
@@ -32,8 +25,6 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
3225
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
3326
github.com/hashicorp/golang-lru v0.6.0 h1:uL2shRDx7RTrOrTCUZEGP/wJUFiUI8QT6E7z5o8jga4=
3427
github.com/hashicorp/golang-lru v0.6.0/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
35-
github.com/jmwample/obfs4 v0.0.0-20230113193642-07b111e6b208 h1:6nxlCjgsYnjYafKVqvElKbFL+95Kgg5YWT/GuXUNoD8=
36-
github.com/jmwample/obfs4 v0.0.0-20230113193642-07b111e6b208/go.mod h1:9GcM8QNU9/wXtEEH2q8bVOnPI7FtIF6VVLzZ1l6Hgf8=
3728
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
3829
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
3930
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
@@ -59,8 +50,12 @@ github.com/pion/stun v0.3.5/go.mod h1:gDMim+47EeEtfWogA37n6qXZS88L5V6LqFcf+DZA2U
5950
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
6051
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6152
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
53+
github.com/refraction-networking/ed25519 v0.1.2 h1:08kJZUkAlY7a7cZGosl1teGytV+QEoNxPO7NnRvAB+g=
54+
github.com/refraction-networking/ed25519 v0.1.2/go.mod h1:nxYLUAYt/hmNpAh64PNSQ/tQ9gTIB89wCaGKJlRtZ9I=
6255
github.com/refraction-networking/gotapdance v1.5.5 h1:PquRRNtBeMU9wToaYXelH+VTJYOFN5WmfNGu3L1M03I=
6356
github.com/refraction-networking/gotapdance v1.5.5/go.mod h1:kPt7e1vlkn67NPe1zmPQCpVOfLLHApegCY3/KtsMBCU=
57+
github.com/refraction-networking/obfs4 v0.1.2 h1:J842O4fGSkd2W8ogYj0KN6gqVVY+Cpqodw9qFGL7wVU=
58+
github.com/refraction-networking/obfs4 v0.1.2/go.mod h1:wAl/+gWiLsrcykJA3nKJHx89f5/gXGM8UKvty7+mvbM=
6459
github.com/refraction-networking/utls v1.2.0 h1:U5f8wkij2NVinfLuJdFP3gCMwIHs+EzvhxmYdXgiapo=
6560
github.com/refraction-networking/utls v1.2.0/go.mod h1:NPq+cVqzH7D1BeOkmOcb5O/8iVewAsiVt2x1/eO0hgQ=
6661
github.com/sergeyfrolov/bsbuffer v0.0.0-20180903213811-94e85abb8507 h1:ML7ZNtcln5UBo5Wv7RIv9Xg3Pr5VuRCWLFXEwda54Y4=
@@ -75,25 +70,22 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
7570
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
7671
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
7772
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
78-
gitlab.com/yawning/edwards25519-extra.git v0.0.0-20211229043746-2f91fcc9fbdb/go.mod h1:gvdJuZuO/tPZyhEV8K3Hmoxv/DWud5L4qEQxfYjEUTo=
79-
gitlab.com/yawning/edwards25519-extra.git v0.0.0-20220726154925-def713fd18e4 h1:LeXiZggivkDGgmkl7+r+m/2xj3rd+K/30/0obRKayAU=
80-
gitlab.com/yawning/edwards25519-extra.git v0.0.0-20220726154925-def713fd18e4/go.mod h1:gvdJuZuO/tPZyhEV8K3Hmoxv/DWud5L4qEQxfYjEUTo=
73+
gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.4.0 h1:Y7fHDMy11yyjM+YlHfcM3svaujdL+m5DqS444wbj8o4=
74+
gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.4.0/go.mod h1:70bhd4JKW/+1HLfm+TMrgHJsUHG4coelMWwiVEJ2gAg=
8175
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
82-
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
83-
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
84-
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
76+
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
77+
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
8578
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
86-
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
87-
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
79+
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
80+
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
8881
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
89-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9082
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
91-
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
92-
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
83+
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
84+
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9385
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
9486
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
95-
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
96-
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
87+
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
88+
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
9789
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
9890
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
9991
google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc=

pkg/core/core.go

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
11
package core
22

3-
import (
4-
"crypto/hmac"
5-
"crypto/sha256"
3+
const (
4+
// PhantomSelectionMinGeneration
5+
PhantomSelectionMinGeneration uint = 1
6+
7+
// PhantomHkdfMinVersion indicates the first version in which the Phantom selection was based on HKDF
8+
PhantomHkdfMinVersion uint = 2
9+
10+
// RandomizeDstPortMinVersion is the earliest client library version ID that supports destination port randomization
11+
RandomizeDstPortMinVersion uint = 3
12+
13+
// SharedKeysRefactorMinVersion
14+
SharedKeysRefactorMinVersion uint = 4
615
)
716

8-
// ConjureHMAC implements the hmak that can then be used for further hkdf key generation
9-
func ConjureHMAC(key []byte, str string) []byte {
10-
hash := hmac.New(sha256.New, key)
11-
hash.Write([]byte(str))
12-
return hash.Sum(nil)
17+
// CurrentClientLibraryVersion returns the current client library version used
18+
// for feature compatibility support between client and server. Currently I
19+
// don't intend to connect this to the library tag version in any way.
20+
//
21+
// When adding new client versions comment out older versions and add new
22+
// version below with a description of the reason for the new version.
23+
func CurrentClientLibraryVersion() uint32 {
24+
// Registration refactor extricates some (Decoy) registrar specific keys out of the shared
25+
// keys object, changing the keys that get generated based on client version.
26+
// https://github.com/refraction-networking/gotapdance/pull/131
27+
// https://github.com/refraction-networking/conjure/pull/202
28+
return 4
29+
30+
// // Support for randomizing destination port for phantom connection
31+
// // https://github.com/refraction-networking/gotapdance/pull/108
32+
// return 3
33+
34+
// // Selection algorithm update - Oct 27, 2022 -- Phantom selection version rework again to use
35+
// // hkdf for actual uniform distribution across phantom subnets.
36+
// // https://github.com/refraction-networking/conjure/pull/145
37+
// return 2
38+
39+
// // Initial inclusion of client version - added due to update in phantom
40+
// // selection algorithm that is not backwards compatible to older clients.
41+
// return 1
42+
43+
// // No client version indicates any client before this change.
44+
// return 0
1345
}

pkg/core/core_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package core
2+
3+
import (
4+
"bytes"
5+
"crypto/sha256"
6+
"io"
7+
"testing"
8+
9+
pb "github.com/refraction-networking/conjure/proto"
10+
11+
"golang.org/x/crypto/hkdf"
12+
)
13+
14+
func TestNewGenKeys(t *testing.T) {
15+
fakePubkey := [32]byte{0}
16+
17+
keys, _ := GenerateClientSharedKeys(fakePubkey)
18+
oldKeys, _ := generateClientSharedKeysOld(fakePubkey)
19+
20+
stationKeys, _ := GenSharedKeys(4, keys.SharedSecret, pb.TransportType_Null)
21+
stationKeysOld, _ := GenSharedKeys(3, oldKeys.SharedSecret, pb.TransportType_Null)
22+
23+
if !bytes.Equal(keys.ConjureSeed, stationKeys.ConjureSeed) {
24+
t.Fatalf("Version 4 station ConjureSeed does not match client: \nStation: %v\nClient: %v", stationKeys.ConjureSeed, keys.ConjureSeed)
25+
}
26+
27+
if !bytes.Equal(oldKeys.ConjureSeed, stationKeysOld.ConjureSeed) {
28+
t.Fatalf("Version 3 station ConjureSeed does not match client: \nStation: %v\nClient: %v", stationKeysOld.ConjureSeed, oldKeys.ConjureSeed)
29+
}
30+
}
31+
32+
// Below is for testing that SharedSecret and ConjureSeed match with old client version.
33+
type OldSharedKeys struct {
34+
SharedSecret, Representative []byte
35+
FspKey, FspIv, VspKey, VspIv, NewMasterSecret, ConjureSeed []byte
36+
reader io.Reader
37+
}
38+
39+
// oldConjureSharedKeys contains keys that the station is required to keep.
40+
type oldConjureSharedKeys struct {
41+
SharedSecret []byte
42+
FspKey, FspIv, VspKey, VspIv, MasterSecret, ConjureSeed []byte
43+
}
44+
45+
func generateClientSharedKeysOld(pubkey [32]byte) (*OldSharedKeys, error) {
46+
sharedSecret, representative, err := generateEligatorTransformedKey(pubkey[:])
47+
if err != nil {
48+
return nil, err
49+
}
50+
51+
tdHkdf := hkdf.New(sha256.New, sharedSecret, []byte("conjureconjureconjureconjure"), nil)
52+
keys := &OldSharedKeys{
53+
SharedSecret: sharedSecret,
54+
Representative: representative,
55+
FspKey: make([]byte, 16),
56+
FspIv: make([]byte, 12),
57+
VspKey: make([]byte, 16),
58+
VspIv: make([]byte, 12),
59+
NewMasterSecret: make([]byte, 48),
60+
ConjureSeed: make([]byte, 16),
61+
reader: tdHkdf,
62+
}
63+
64+
if _, err := tdHkdf.Read(keys.FspKey); err != nil {
65+
return keys, err
66+
}
67+
if _, err := tdHkdf.Read(keys.FspIv); err != nil {
68+
return keys, err
69+
}
70+
if _, err := tdHkdf.Read(keys.VspKey); err != nil {
71+
return keys, err
72+
}
73+
if _, err := tdHkdf.Read(keys.VspIv); err != nil {
74+
return keys, err
75+
}
76+
if _, err := tdHkdf.Read(keys.NewMasterSecret); err != nil {
77+
return keys, err
78+
}
79+
if _, err := tdHkdf.Read(keys.ConjureSeed); err != nil {
80+
return keys, err
81+
}
82+
return keys, err
83+
}

0 commit comments

Comments
 (0)