Skip to content

Commit 40948ea

Browse files
authored
Merge pull request #123 from alexander-irion/master
Add parameter disableHostkeyVerification
2 parents c390a36 + cd3bc77 commit 40948ea

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

lib/src/ssh_channel.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,12 @@ class SSHChannelController {
297297
if (_done.isCompleted) return;
298298
if (_hasSentClose) return;
299299
_hasSentClose = true;
300-
sendMessage(SSH_Message_Channel_Close(recipientChannel: remoteId));
300+
301+
try {
302+
sendMessage(SSH_Message_Channel_Close(recipientChannel: remoteId));
303+
} catch (e) {
304+
printDebug?.call('SSHChannelController._sendCloseIfNeeded - error: $e');
305+
}
301306
}
302307

303308
void _sendRequestSuccess() {

lib/src/ssh_client.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class SSHClient {
130130
/// extension. May not be called if the server does not support the extension.
131131
// final SSHHostKeysHandler? onHostKeys;
132132

133+
/// Allow to disable hostkey verification, which can be slow in debug mode.
134+
final bool disableHostkeyVerification;
135+
133136
/// A [Future] that completes when the transport is closed, or when an error
134137
/// occurs. After this [Future] completes, [isClosed] will be true and no more
135138
/// data can be sent or received.
@@ -152,6 +155,7 @@ class SSHClient {
152155
this.onUserauthBanner,
153156
this.onAuthenticated,
154157
this.keepAliveInterval = const Duration(seconds: 10),
158+
this.disableHostkeyVerification = false,
155159
}) {
156160
_transport = SSHTransport(
157161
socket,
@@ -162,6 +166,7 @@ class SSHClient {
162166
onVerifyHostKey: onVerifyHostKey,
163167
onReady: _handleTransportReady,
164168
onPacket: _handlePacket,
169+
disableHostkeyVerification: disableHostkeyVerification,
165170
);
166171

167172
_transport.done.then(
@@ -476,7 +481,12 @@ class SSHClient {
476481
);
477482
}
478483
_keepAlive?.stop();
479-
_closeChannels();
484+
485+
try {
486+
_closeChannels();
487+
} catch (e) {
488+
printDebug?.call("SSHClient::_handleTransportClosed - error: $e");
489+
}
480490
}
481491

482492
void _handlePacket(Uint8List payload) {

lib/src/ssh_transport.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class SSHTransport {
7272
/// Function called when a packet is received.
7373
final SSHPacketHandler? onPacket;
7474

75+
final bool disableHostkeyVerification;
76+
7577
/// A [Future] that completes when the transport is closed, or when an error
7678
/// occurs. After this [Future] completes, [isClosed] will be true and no
7779
/// more data can be sent or received.
@@ -94,6 +96,7 @@ class SSHTransport {
9496
this.onVerifyHostKey,
9597
this.onReady,
9698
this.onPacket,
99+
this.disableHostkeyVerification = false,
97100
}) {
98101
_initSocket();
99102
_startHandshake();
@@ -803,12 +806,14 @@ class SSHTransport {
803806
sharedSecret: sharedSecret,
804807
);
805808

806-
final verified = _verifyHostkey(
807-
keyBytes: hostkey,
808-
signatureBytes: hostSignature,
809-
exchangeHash: exchangeHash,
810-
);
811-
if (!verified) throw SSHHostkeyError('Signature verification failed');
809+
if (!disableHostkeyVerification) {
810+
final verified = _verifyHostkey(
811+
keyBytes: hostkey,
812+
signatureBytes: hostSignature,
813+
exchangeHash: exchangeHash,
814+
);
815+
if (!verified) throw SSHHostkeyError('Signature verification failed');
816+
}
812817

813818
_exchangeHash = exchangeHash;
814819
_sessionId ??= exchangeHash;

0 commit comments

Comments
 (0)