mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
feat: keyboard-interactive auth (#349)
This commit is contained in:
20
lib/core/utils/auth.dart
Normal file
20
lib/core/utils/auth.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/extension/context/dialog.dart';
|
||||
import 'package:toolbox/data/model/server/server_private_info.dart';
|
||||
import 'package:toolbox/data/res/provider.dart';
|
||||
|
||||
abstract final class KeybordInteractive {
|
||||
static FutureOr<List<String>?> defaultHandle(
|
||||
ServerPrivateInfo spi, {
|
||||
BuildContext? ctx,
|
||||
}) async {
|
||||
try {
|
||||
final res = await (ctx ?? Pros.app.ctx)?.showPwdDialog(title: spi.id);
|
||||
return res == null ? null : [res];
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,9 @@ Future<SSHClient> genClient(
|
||||
///
|
||||
/// Must pass this param when use multi-thread and key login
|
||||
ServerPrivateInfo? jumpSpi,
|
||||
|
||||
/// Handle keyboard-interactive authentication
|
||||
FutureOr<List<String>?> Function(SSHUserInfoRequest)? onKeyboardInteractive,
|
||||
}) async {
|
||||
onStatus?.call(GenSSHClientStatus.socket);
|
||||
|
||||
@@ -109,6 +112,9 @@ Future<SSHClient> genClient(
|
||||
socket,
|
||||
username: spi.user,
|
||||
onPasswordRequest: () => spi.pwd,
|
||||
onUserInfoRequest: onKeyboardInteractive,
|
||||
printDebug: debugPrint,
|
||||
printTrace: debugPrint,
|
||||
);
|
||||
}
|
||||
privateKey ??= getPrivateKey(keyId);
|
||||
@@ -119,5 +125,8 @@ Future<SSHClient> genClient(
|
||||
username: spi.user,
|
||||
// Must use [compute] here, instead of [Computer.shared.start]
|
||||
identities: await compute(loadIndentity, privateKey),
|
||||
onUserInfoRequest: onKeyboardInteractive,
|
||||
printDebug: debugPrint,
|
||||
printTrace: debugPrint,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user