-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #563 from atsign-foundation/windows_support_2
feat: client side Windows support
- Loading branch information
Showing
17 changed files
with
151 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/noports_core/lib/src/common/openssh_binary_path.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'dart:io'; | ||
|
||
const String _windowsOpensshPath = r'C:\Windows\System32\OpenSSH\ssh.exe'; | ||
const String _unixOpensshPath = '/usr/bin/ssh'; | ||
|
||
String get opensshBinaryPath => | ||
Platform.isWindows ? _windowsOpensshPath : _unixOpensshPath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 1 addition & 64 deletions
65
...np/util/sshnp_initial_tunnel_handler.dart → ...er/sshnp_dart_initial_tunnel_handler.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...ts_core/lib/src/sshnp/util/sshnp_initial_tunnel_handler/sshnp_initial_tunnel_handler.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'dart:async'; | ||
import 'package:meta/meta.dart'; | ||
|
||
mixin SshnpInitialTunnelHandler<T> { | ||
@protected | ||
Future<T> startInitialTunnel({required String identifier}); | ||
} |
82 changes: 82 additions & 0 deletions
82
...lib/src/sshnp/util/sshnp_initial_tunnel_handler/sshnp_openssh_initial_tunnel_handler.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:noports_core/src/common/openssh_binary_path.dart'; | ||
import 'package:noports_core/sshnp_foundation.dart'; | ||
|
||
mixin SshnpOpensshInitialTunnelHandler on SshnpCore | ||
implements SshnpInitialTunnelHandler<Process?> { | ||
@override | ||
Future<Process?> startInitialTunnel({required String identifier}) async { | ||
Process? process; | ||
// If we are starting an initial tunnel, it should be to sshrvd, | ||
// so it is safe to assume that sshrvdChannel is not null here | ||
String argsString = '$remoteUsername@${sshrvdChannel!.host}' | ||
' -p ${sshrvdChannel!.sshrvdPort}' | ||
' -i $identifier' | ||
' -L $localPort:localhost:${params.remoteSshdPort}' | ||
' -o LogLevel=VERBOSE' | ||
' -t -t' | ||
' -o StrictHostKeyChecking=accept-new' | ||
' -o IdentitiesOnly=yes' | ||
' -o BatchMode=yes' | ||
' -o ExitOnForwardFailure=yes' | ||
' -n' | ||
' -f' // fork after authentication - this is important | ||
; | ||
if (params.addForwardsToTunnel) { | ||
argsString += ' ${params.localSshOptions.join(' ')}'; | ||
} | ||
argsString += ' sleep 15'; | ||
|
||
List<String> args = argsString.split(' '); | ||
|
||
logger.info('$sessionId | Executing $opensshBinaryPath ${args.join(' ')}'); | ||
|
||
// Because of the options we are using, we can wait for this process | ||
// to complete, because it will exit with exitCode 0 once it has connected | ||
// successfully | ||
final soutBuf = StringBuffer(); | ||
final serrBuf = StringBuffer(); | ||
try { | ||
if (Platform.isWindows) { | ||
// We have to do special stuff on Windows because -f doesn't fork | ||
// properly in the Windows OpenSSH client: | ||
// This incantation opens the initial tunnel in a separate powershell | ||
// window. It's not necessary (and currently not possible) to capture | ||
// the process since there is a physical window the user can close to | ||
// end the session | ||
unawaited(Process.start( | ||
'powershell.exe', | ||
[ | ||
'-command', | ||
opensshBinaryPath, | ||
...args, | ||
], | ||
runInShell: true, | ||
mode: ProcessStartMode.detachedWithStdio, | ||
)); | ||
// Delay to allow the detached session to pick up the keys | ||
await Future.delayed(Duration(seconds: 3)); | ||
} else { | ||
process = await Process.start(opensshBinaryPath, args); | ||
process.stdout.transform(Utf8Decoder()).listen((String s) { | ||
soutBuf.write(s); | ||
logger.info(' $sessionId | sshStdOut | $s'); | ||
}, onError: (e) {}); | ||
process.stderr.transform(Utf8Decoder()).listen((String s) { | ||
serrBuf.write(s); | ||
logger.info(' $sessionId | sshStdErr | $s'); | ||
}, onError: (e) {}); | ||
await process.exitCode.timeout(Duration(seconds: 10)); | ||
} | ||
} on TimeoutException catch (e) { | ||
throw SshnpError( | ||
'SSHNP failed to start the initial tunnel', | ||
error: e, | ||
); | ||
} | ||
return process; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.