diff --git a/lib/core/utils/server.dart b/lib/core/utils/server.dart index 70d48490..2d5283a7 100644 --- a/lib/core/utils/server.dart +++ b/lib/core/utils/server.dart @@ -504,20 +504,37 @@ Future ensureKnownHostKey( var cache = _loadKnownHostFingerprints(); final hops = resolveMergedJumpChain(spi); - for (final hop in hops) { + + // Check each hop's host key, routing through preceding hops + for (var i = 0; i < hops.length; i++) { + final hop = hops[i]; + // Preceding hops needed to reach this hop + final precedingHops = i > 0 ? hops.sublist(0, i) : null; + final precedingKeys = precedingHops?.map((h) => + h.keyId != null ? getPrivateKey(h.keyId!) : null + ).toList(); + cache = await _ensureKnownHostKeyForSingle( hop, cache: cache, timeout: timeout, onKeyboardInteractive: onKeyboardInteractive, + jumpChain: precedingHops, + jumpPrivateKeys: precedingKeys, ); } + // Check the target's host key, routing through all hops + final allKeys = hops.isNotEmpty + ? hops.map((h) => h.keyId != null ? getPrivateKey(h.keyId!) : null).toList() + : null; await _ensureKnownHostKeyForSingle( spi, cache: cache, timeout: timeout, onKeyboardInteractive: onKeyboardInteractive, + jumpChain: hops.isNotEmpty ? hops : null, + jumpPrivateKeys: allKeys, ); } @@ -526,6 +543,8 @@ Future> _ensureKnownHostKeyForSingle( required Map cache, Duration timeout = const Duration(seconds: 5), SSHUserInfoRequestHandler? onKeyboardInteractive, + List? jumpChain, + List? jumpPrivateKeys, }) async { if (_hasKnownHostFingerprintForSpi(spi, cache)) { return cache; @@ -536,6 +555,8 @@ Future> _ensureKnownHostKeyForSingle( timeout: timeout, onKeyboardInteractive: onKeyboardInteractive, knownHostFingerprints: cache, + jumpChain: jumpChain, + jumpPrivateKeys: jumpPrivateKeys, ); try { diff --git a/lib/data/model/sftp/worker.dart b/lib/data/model/sftp/worker.dart index 49ff885b..56466a38 100644 --- a/lib/data/model/sftp/worker.dart +++ b/lib/data/model/sftp/worker.dart @@ -7,7 +7,6 @@ import 'package:dartssh2/dartssh2.dart'; import 'package:easy_isolate/easy_isolate.dart'; import 'package:fl_lib/fl_lib.dart'; import 'package:server_box/core/utils/server.dart'; -import 'package:server_box/data/model/app/error.dart'; import 'package:server_box/data/model/server/server_private_info.dart'; import 'package:server_box/data/res/store.dart';