Skip to content

Commit 7a87db8

Browse files
authored
Merge pull request #2005 from atsign-foundation/fix-ops-216
feat: twin keys for control socket and data sockets
2 parents a0ae7af + c08383b commit 7a87db8

File tree

18 files changed

+605
-261
lines changed

18 files changed

+605
-261
lines changed

packages/dart/noports_core/lib/src/common/features.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ enum DaemonFeature {
3131

3232
/// Understands [RelayAuthMode.escr]
3333
supportsRamEscr('1.4.0'),
34+
35+
/// Separate keys & IVs for client-to-server and server-to-client
36+
twinKeys('1.5.0'),
3437
;
3538

3639
/// The version of the NoPorts control protocol which introduced this feature.
@@ -75,6 +78,8 @@ extension FeatureDescription on DaemonFeature {
7578
return 'handle heartbeat messages being send over the control channel';
7679
case DaemonFeature.supportsRamEscr:
7780
return 'support the \'ESCR\' relay auth mode';
81+
case DaemonFeature.twinKeys:
82+
return 'support separate keys for each direction';
7883
}
7984
}
8085
}

packages/dart/noports_core/lib/src/common/types.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ typedef SrvGenerator<T> = Srv<T> Function(
77
bool? bindLocalPort,
88
String? localHost,
99
required RelayAuthenticator? relayAuthenticator,
10-
String? sessionAESKeyString,
11-
String? sessionIVString,
10+
String? aesC2D,
11+
String? ivC2D,
12+
String? aesD2C,
13+
String? ivD2C,
1214
bool multi,
1315
bool detached,
1416
Duration timeout,

packages/dart/noports_core/lib/src/npt/npt.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ class _NptImpl extends NptBase
256256
var msg = 'Sending session request to the device daemon';
257257
logger.info(msg);
258258
sendProgress(msg);
259+
if (sshnpdChannel.twinKeys) {
260+
logger.info('Session will use twinned keys');
261+
}
259262

260263
/// Send an ssh request to sshnpd
261264
await notify(
@@ -282,6 +285,7 @@ class _NptImpl extends NptBase
282285
requestedPort: params.remotePort,
283286
requestedHost: params.remoteHost,
284287
timeout: params.timeout,
288+
twinKeys: sshnpdChannel.twinKeys,
285289
).toJson()),
286290
checkForFinalDeliveryStatus: false,
287291
waitForFinalDeliveryStatus: false,
@@ -331,8 +335,10 @@ class _NptImpl extends NptBase
331335

332336
await _srvdChannel.runSrv(
333337
localRvPort: localRvPort,
334-
sessionAESKeyString: sshnpdChannel.sessionAESKeyString,
335-
sessionIVString: sshnpdChannel.sessionIVString,
338+
aesC2D: sshnpdChannel.aesC2D,
339+
ivC2D: sshnpdChannel.ivC2D,
340+
aesD2C: sshnpdChannel.aesD2C,
341+
ivD2C: sshnpdChannel.ivD2C,
336342
multi: true,
337343
detached: true,
338344
timeout: params.timeout,
@@ -356,8 +362,10 @@ class _NptImpl extends NptBase
356362

357363
SocketConnector sc = await _srvdChannel.runSrv(
358364
localRvPort: localRvPort,
359-
sessionAESKeyString: sshnpdChannel.sessionAESKeyString,
360-
sessionIVString: sshnpdChannel.sessionIVString,
365+
aesC2D: sshnpdChannel.aesC2D,
366+
ivC2D: sshnpdChannel.ivC2D,
367+
aesD2C: sshnpdChannel.aesD2C,
368+
ivD2C: sshnpdChannel.ivD2C,
361369
multi: true,
362370
detached: false,
363371
timeout: params.timeout,

packages/dart/noports_core/lib/src/srv/srv.dart

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ abstract class Srv<T> {
2727

2828
abstract final RelayAuthenticator? relayAuthenticator;
2929

30-
/// The AES key for encryption / decryption of the rv traffic
31-
abstract final String? sessionAESKeyString;
30+
/// The AES key for Client-to-Daemon encryption in a single-socket
31+
/// session, or on the control channel for a multi-socket session
32+
abstract final String? aesC2D;
3233

33-
/// The IV to use with the [sessionAESKeyString]
34-
abstract final String? sessionIVString;
34+
/// The IV to use with the [aesC2D]
35+
abstract final String? ivC2D;
36+
37+
/// The AES key for Daemon-to-Client encryption in a single-socket
38+
/// session, or on the control channel for a multi-socket session
39+
abstract final String? aesD2C;
40+
41+
/// The IV to use with the [aesD2C]
42+
abstract final String? ivD2C;
3543

3644
/// Whether to bind a local port or not
3745
abstract final bool? bindLocalPort;
@@ -60,8 +68,10 @@ abstract class Srv<T> {
6068
bool? bindLocalPort,
6169
String? rvdAuthString,
6270
required RelayAuthenticator? relayAuthenticator,
63-
String? sessionAESKeyString,
64-
String? sessionIVString,
71+
String? aesC2D,
72+
String? ivC2D,
73+
String? aesD2C,
74+
String? ivD2C,
6575
bool multi = false,
6676
bool detached = false,
6777
Duration timeout = DefaultArgs.srvTimeout,
@@ -74,8 +84,10 @@ abstract class Srv<T> {
7484
localHost: localHost,
7585
bindLocalPort: bindLocalPort,
7686
relayAuthenticator: relayAuthenticator,
77-
sessionAESKeyString: sessionAESKeyString,
78-
sessionIVString: sessionIVString,
87+
aesC2D: aesC2D,
88+
ivC2D: ivC2D,
89+
aesD2C: aesD2C,
90+
ivD2C: ivD2C,
7991
multi: multi,
8092
timeout: timeout,
8193
controlChannelHeartbeat: controlChannelHeartbeat,
@@ -90,8 +102,10 @@ abstract class Srv<T> {
90102
String? localHost,
91103
String? rvdAuthString,
92104
required RelayAuthenticator? relayAuthenticator,
93-
String? sessionAESKeyString,
94-
String? sessionIVString,
105+
String? aesC2D,
106+
String? ivC2D,
107+
String? aesD2C,
108+
String? ivD2C,
95109
bool multi = false,
96110
bool detached = false,
97111
Duration timeout = DefaultArgs.srvTimeout,
@@ -104,8 +118,10 @@ abstract class Srv<T> {
104118
localHost: localHost,
105119
bindLocalPort: bindLocalPort!,
106120
relayAuthenticator: relayAuthenticator,
107-
sessionAESKeyString: sessionAESKeyString,
108-
sessionIVString: sessionIVString,
121+
aesC2D: aesC2D,
122+
ivC2D: ivC2D,
123+
aesD2C: aesD2C,
124+
ivD2C: ivD2C,
109125
multi: multi,
110126
detached: detached,
111127
timeout: timeout,
@@ -121,8 +137,10 @@ abstract class Srv<T> {
121137
String? localHost,
122138
String? rvdAuthString,
123139
required RelayAuthenticator? relayAuthenticator,
124-
String? sessionAESKeyString,
125-
String? sessionIVString,
140+
String? aesC2D,
141+
String? ivC2D,
142+
String? aesD2C,
143+
String? ivD2C,
126144
bool multi = false,
127145
bool detached = false,
128146
Duration timeout = DefaultArgs.srvTimeout,
@@ -132,8 +150,10 @@ abstract class Srv<T> {
132150
streamingHost,
133151
streamingPort,
134152
relayAuthenticator: relayAuthenticator,
135-
sessionAESKeyString: sessionAESKeyString,
136-
sessionIVString: sessionIVString,
153+
aesC2D: aesC2D,
154+
ivC2D: ivC2D,
155+
aesD2C: aesD2C,
156+
ivD2C: ivD2C,
137157
multi: multi,
138158
timeout: timeout,
139159
controlChannelHeartbeat: controlChannelHeartbeat,

0 commit comments

Comments
 (0)