Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions lib/src/ssh_key_pair.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,20 @@ class OpenSSHKeyPairs {

final key = Uint8List.view(kdfHash.buffer, 0, cipher.keySize);
final iv = Uint8List.view(kdfHash.buffer, cipher.keySize, cipher.ivSize);
final decryptCipher = cipher.createCipher(key, iv, forEncryption: false);
return decryptCipher.processAll(blob);

try {
if (cipher.isAead) {
final decryptCipher = cipher.createAEADCipher(key, iv,
forEncryption: false) as AEADCipher;
return decryptCipher.processAll(blob);
} else {
final decryptCipher =
cipher.createCipher(key, iv, forEncryption: false);
return decryptCipher.processAll(blob);
}
} catch (e) {
throw SSHKeyDecryptError('Failed to decrypt private key', e);
}
}

@override
Expand Down
3 changes: 2 additions & 1 deletion lib/src/ssh_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,8 @@ class SSHTransport {
/// initialized in both directions.
bool get hasIntegrityProtection {
final usingAeadLocal = _localAeadKey != null || _localChaChaEncKey != null;
final usingAeadRemote = _remoteAeadKey != null || _remoteChaChaEncKey != null;
final usingAeadRemote =
_remoteAeadKey != null || _remoteChaChaEncKey != null;
if (usingAeadLocal && usingAeadRemote) return true;
return _localMac != null && _remoteMac != null;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/src/utils/cipher_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ extension BlockCipherX on BlockCipher {
}
}

extension AEADCipherX on AEADCipher {
Uint8List processAll(Uint8List data) {
final cipher = this as dynamic;
return cipher.process(data) as Uint8List;
}
}

extension MacX on Mac {
void updateAll(Uint8List data) {
update(data, 0, data.length);
Expand Down
Loading