Skip to content

Commit f356d6f

Browse files
authored
Port Randomization (#156)
* update station-to-detector for port randomization * merge master for removal of time package * add a test for Session lookup. Hashmap up to 10m seems to work fine * intermediate pust * process udp and tcp pacets in detetor - tests failing * passing existing tests for proto and dst dependent map keys * better test, cargo format * tracking udp vs tcp and adding transport params to transports * update transports to implement port selection interfaces * tests passing, but no new tests confirming behavior yet * add tests for simple port selection using mock * add tests for reg ingest corner cases * use selected phantom port for liveness tests * detector always matches on dst port update tests and formatiing checks * add randomization for bidirectional registration processor, add client transport types, simplify transport interface(s) * no need to fix typo in this PR * update name in protobuf * revisit station -> detecor pipeline on the station side * lints and protobuf changes * update github actions to minumum 1.18 golang version * prelim fixes from unidirectional tests on dev box * clean up cj-reg logging so I can find real reg errors * forgot to parse transport params in bidirectional regprocessor * github action fixes and tun interface iptables rules for udp * fmt fixes anf github action error
1 parent ed03a1f commit f356d6f

39 files changed

+9987
-4341
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ jobs:
3636
sudo apt-get install protobuf-compiler gcc curl git wget software-properties-common -y -q
3737
sudo apt-get install libzmq3-dev libssl-dev pkg-config libgmp3-dev -y -q
3838
sudo add-apt-repository universe
39-
wget https://packages.ntop.org/apt-stable/20.04/all/apt-ntop-stable.deb
40-
sudo apt install ./apt-ntop-stable.deb
39+
wget https://packages.ntop.org/apt/20.04/all/apt-ntop.deb
40+
sudo apt install ./apt-ntop.deb
4141
sudo apt-get update
4242
sudo apt-get install pfring
4343
echo "Apt dependencies installed"

.github/workflows/golang.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
go-version: [1.16.x, 1.17.x, 1.18.x, stable]
16+
go-version: [1.18.x, 1.19.x, stable]
1717

1818
runs-on: ubuntu-latest
1919
steps:

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ chrono = "0.4.23"
2525
pnet = "0.31.0"
2626
arrayref = "0.3.2"
2727
log = "0.3.6"
28-
rand = "0.4.2"
28+
rand = "0.8.5"
2929
errno = "0.2.3"
3030
tuntap = { git = "https://github.com/ewust/tuntap.rs" }
3131
ipnetwork = "^0.14.0"

application/lib/conjure.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ func generateObfs4Keys(rand io.Reader) (Obfs4Keys, error) {
4545
}
4646

4747
type ConjureSharedKeys struct {
48-
SharedSecret []byte
49-
FspKey, FspIv, VspKey, VspIv, MasterSecret, DarkDecoySeed []byte
50-
Obfs4Keys Obfs4Keys
48+
SharedSecret []byte
49+
FspKey, FspIv, VspKey, VspIv, MasterSecret, ConjureSeed []byte
50+
Obfs4Keys Obfs4Keys
5151
}
5252

5353
func GenSharedKeys(sharedSecret []byte, tt pb.TransportType) (ConjureSharedKeys, error) {
5454
tdHkdf := hkdf.New(sha256.New, sharedSecret, []byte("conjureconjureconjureconjure"), nil)
5555
keys := ConjureSharedKeys{
56-
SharedSecret: sharedSecret,
57-
FspKey: make([]byte, 16),
58-
FspIv: make([]byte, 12),
59-
VspKey: make([]byte, 16),
60-
VspIv: make([]byte, 12),
61-
MasterSecret: make([]byte, 48),
62-
DarkDecoySeed: make([]byte, 16),
56+
SharedSecret: sharedSecret,
57+
FspKey: make([]byte, 16),
58+
FspIv: make([]byte, 12),
59+
VspKey: make([]byte, 16),
60+
VspIv: make([]byte, 12),
61+
MasterSecret: make([]byte, 48),
62+
ConjureSeed: make([]byte, 16),
6363
}
6464

6565
if _, err := tdHkdf.Read(keys.FspKey); err != nil {
@@ -77,7 +77,7 @@ func GenSharedKeys(sharedSecret []byte, tt pb.TransportType) (ConjureSharedKeys,
7777
if _, err := tdHkdf.Read(keys.MasterSecret); err != nil {
7878
return keys, err
7979
}
80-
if _, err := tdHkdf.Read(keys.DarkDecoySeed); err != nil {
80+
if _, err := tdHkdf.Read(keys.ConjureSeed); err != nil {
8181
return keys, err
8282
}
8383

application/lib/phantom_selector.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ const (
2020
phantomHkdfMinVersion uint = 2
2121
)
2222

23+
var (
24+
// ErrLegacyAddrSelectBug indicates that we have hit a corner case in a legacy address selection
25+
// algorithm that causes phantom address selection to fail.
26+
ErrLegacyAddrSelectBug = errors.New("no valid addresses specified")
27+
// ErrMissingAddrs indicates that no subnets were provided with addresses to select from. This
28+
// is only valid for phantomHkdfMinVersion and newer.
29+
ErrMissingAddrs = errors.New("no valid addresses specified to select")
30+
)
31+
2332
// getSubnetsVarint - return EITHER all subnet strings as one composite array if
2433
// we are selecting unweighted, or return the array associated with the (seed)
2534
// selected array of subnet strings based on the associated weights
@@ -276,7 +285,7 @@ func selectPhantomImplVarint(seed []byte, subnets []*net.IPNet) (net.IP, error)
276285

277286
// If the total number of addresses is 0 something has gone wrong
278287
if addressTotal.Cmp(big.NewInt(0)) <= 0 {
279-
return nil, fmt.Errorf("no valid addresses specified")
288+
return nil, ErrLegacyAddrSelectBug
280289
}
281290

282291
// Pick a value using the seed in the range of between 0 and the total
@@ -345,7 +354,7 @@ func selectPhantomImplV0(seed []byte, subnets []*net.IPNet) (net.IP, error) {
345354
}
346355

347356
if addressTotal.Cmp(big.NewInt(0)) <= 0 {
348-
return nil, fmt.Errorf("no valid addresses specified")
357+
return nil, ErrLegacyAddrSelectBug
349358
}
350359

351360
id := &big.Int{}
@@ -365,7 +374,7 @@ func selectPhantomImplV0(seed []byte, subnets []*net.IPNet) (net.IP, error) {
365374
}
366375
}
367376
if result == nil {
368-
return nil, errors.New("let's rewrite the phantom address selector")
377+
return nil, ErrLegacyAddrSelectBug
369378
}
370379
return result, nil
371380
}
@@ -479,7 +488,7 @@ func selectPhantomImplHkdf(seed []byte, subnets []*net.IPNet) (net.IP, error) {
479488

480489
// If the total number of addresses is 0 something has gone wrong
481490
if addressTotal.Cmp(big.NewInt(0)) <= 0 {
482-
return nil, fmt.Errorf("no valid addresses specified")
491+
return nil, ErrMissingAddrs
483492
}
484493

485494
// Pick a value using the seed in the range of between 0 and the total

0 commit comments

Comments
 (0)