Skip to content

Commit

Permalink
feat: address review comments
Browse files Browse the repository at this point in the history
- in ping response, daemon says whether or not it accepts public keys from the client
- added abbreviations in SshnpArg for the new flags
- corrected some code comments and added to others
  • Loading branch information
gkc committed Jan 18, 2024
1 parent 47429c8 commit a2e5b44
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/dart/noports_core/lib/src/common/features.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/// Features which can be supported by the NoPorts Daemon
enum DaemonFeatures {
/// daemon will accept public keys sent by clients (i.e. daemon has been
/// started with the `--sshpublickey` or `-s` flag)
acceptsPublicKeys,

/// authenticate when connecting to the Socket Rendezvous (sr)
srAuth,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ class SshnpArg {
);
static const authenticateClientToRvdArg = SshnpArg(
name: 'authenticate-client-to-rvd',
abbr: 'a',
help: 'When false, client will not authenticate itself to rvd',
defaultsTo: DefaultArgs.authenticateClientToRvd,
format: ArgFormat.flag,
Expand All @@ -360,6 +361,7 @@ class SshnpArg {
);
static const authenticateDeviceToRvdArg = SshnpArg(
name: 'authenticate-device-to-rvd',
abbr: 'A',
help: 'When false, device will not authenticate to the socket rendezvous',
defaultsTo: DefaultArgs.authenticateDeviceToRvd,
format: ArgFormat.flag,
Expand All @@ -368,6 +370,7 @@ class SshnpArg {
);
static const encryptRvdTrafficArg = SshnpArg(
name: 'encrypt-rvd-traffic',
abbr: 'E',
help: 'When true, traffic via the socket rendezvous is encrypted,'
' in addition to whatever encryption the traffic already has'
' (e.g. an ssh session)',
Expand All @@ -378,6 +381,7 @@ class SshnpArg {
);
static const discoverDaemonFeaturesArg = SshnpArg(
name: 'discover-daemon-features',
abbr: 'F',
help: 'When this flag is set, this client starts by pinging the daemon to'
' discover what features it supports, and exits if this client has '
' requested use of a feature which the daemon does not support.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ abstract class SshnpdChannel with AsyncInitialization, AtClientBindings {
@protected
Future<SshnpdAck> handleSshnpdPayload(AtNotification notification);

/// Wait until we've received an acknowledgement from the daemon.
/// Returns true if the daemon acknowledged our request.
/// Returns false if a timeout occurred.
/// Wait until we've received an acknowledgement from the daemon, or
/// have timed out while waiting.
Future<SshnpdAck> waitForDaemonResponse({int maxWaitMillis = 15000}) async {
// Timer to timeout after 10 Secs or after the Ack of connected/Errors
for (int counter = 1; counter <= 100; counter++) {
Expand Down
1 change: 1 addition & 0 deletions packages/dart/noports_core/lib/src/sshnpd/sshnpd_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class SshnpdImpl implements Sshnpd {
'supportedFeatures': {
DaemonFeatures.srAuth.name: true,
DaemonFeatures.srE2ee.name: true,
DaemonFeatures.acceptsPublicKeys.name: addSshPublicKeys,
},
};
unawaited(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ class SignatureAuthVerifier {
return atChops.verify(input);
}

/// We expect the authenticating client to send a JSON message with
/// this structure:
/// ```json
/// {
/// "signature":"&lt;signature&gt;",
/// "hashingAlgo":"&lt;algo&gt;",
/// "signingAlgo":"&lt;algo&gt;",
/// "payload":&lt;the data which was signed&gt;
/// }
/// ```
/// The signature is verified against [dataToVerify] and, although not
/// strictly necessary, the rvdNonce is also checked in what the client
/// send in the payload
Future<(bool, Stream<Uint8List>?)> authenticate(Socket socket) async {
Completer<(bool, Stream<Uint8List>?)> completer = Completer();
bool authenticated = false;
Expand All @@ -61,13 +74,6 @@ class SignatureAuthVerifier {
try {
final message = String.fromCharCodes(data);
logger.info('SignatureAuthVerifier $tag received data: $message');
// Expected message to be the JSON format with the below structure:
// {
// "signature":"<signature>",
// "hashingAlgo":"<algo>",
// "signingAlgo":"<algo>",
// "payload":{<the data which was signed>}
// }
var envelope = jsonDecode(message);

final hashingAlgo =
Expand Down

0 comments on commit a2e5b44

Please sign in to comment.