Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing SSHClient on onAuthenticated callback and Environment Variables feature #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/src/ssh_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef SSHUserInfoRequestHandler = FutureOr<List<String>?> Function(
/// https://datatracker.ietf.org/doc/html/rfc4252#section-5.4
typedef SSHUserauthBannerHandler = void Function(String banner);

typedef SSHAuthenticatedHandler = void Function();
typedef SSHAuthenticatedHandler = void Function(SSHClient);

typedef SSHRemoteConnectionFilter = bool Function(String host, int port);

Expand Down Expand Up @@ -125,6 +125,8 @@ class SSHClient {
/// method. Set this to null to disable automatic keep-alive messages.
final Duration? keepAliveInterval;

final Map<String, String> environmentVariables;

/// Function called when additional host keys are received. This is an OpenSSH
/// extension. May not be called if the server does not support the extension.
// final SSHHostKeysHandler? onHostKeys;
Expand All @@ -151,6 +153,7 @@ class SSHClient {
this.onUserauthBanner,
this.onAuthenticated,
this.keepAliveInterval = const Duration(seconds: 10),
this.environmentVariables = const {},
}) {
_transport = SSHTransport(
socket,
Expand Down Expand Up @@ -559,7 +562,7 @@ class SSHClient {
printTrace?.call('<- $socket: SSH_Message_Userauth_Success');
printDebug?.call('SSHClient._handleUserauthSuccess');
_authenticated.complete();
onAuthenticated?.call();
onAuthenticated?.call(this);
_keepAlive?.start();
}

Expand Down Expand Up @@ -951,12 +954,20 @@ class SSHClient {
throw SSHStateError('Unexpected channel confirmation');
}

return _acceptChannel(
final channelController = _acceptChannel(
localChannelId: localChannelId,
remoteChannelId: reply.senderChannel,
remoteInitialWindowSize: reply.initialWindowSize,
remoteMaximumPacketSize: reply.maximumPacketSize,
);

// Sending environment variables
for (final environmentVariable in environmentVariables.entries) {
channelController.sendEnv(
environmentVariable.key, environmentVariable.value);
}

return channelController;
}

SSHChannelController _acceptChannel({
Expand Down