opt: auto rm pwd in key page for safe

This commit is contained in:
lollipopkit
2023-02-21 17:12:01 +08:00
parent e423e56152
commit 2986f80f89
6 changed files with 26 additions and 24 deletions

View File

@@ -8,12 +8,22 @@ import '../../data/store/private_key.dart';
import '../../locator.dart';
/// Must put this func out of any Class.
///
/// Because of this function is called by [compute] in [ServerProvider.genClient].
///
/// https://stackoverflow.com/questions/51998995/invalid-arguments-illegal-argument-in-isolate-message-object-is-a-closure
List<SSHKeyPair> loadIndentity(String key) {
return SSHKeyPair.fromPem(key);
}
/// [args] : [key, pwd]
String decyptPem(List<String> args) {
/// skip when the key is not encrypted, or will throw exception
if (!SSHKeyPair.isEncryptedPem(args[0])) return args[0];
final sshKey = SSHKeyPair.fromPem(args[0], args[1]);
return sshKey.first.toPem();
}
Future<SSHClient> genClient(ServerPrivateInfo spi) async {
final socket = await SSHSocket.connect(
spi.ip,

View File

@@ -2,8 +2,8 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 224;
static const int build = 225;
static const String engine = "Flutter 3.7.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 9944297138 (9 days ago) • 2023-02-08 15:46:04 -0800\nEngine • revision 248290d6d5\nTools • Dart 2.19.2 • DevTools 2.20.1\n";
static const String buildAt = "2023-02-18 13:16:46.172437";
static const int modifications = 1;
static const String buildAt = "2023-02-18 13:22:17.786805";
static const int modifications = 3;
}

View File

@@ -72,8 +72,8 @@ void onError(Object obj, StackTrace stack) {
}
Future<void> main() async {
await initApp();
runInZone(() async {
await initApp();
runApp(
MultiProvider(
providers: [

View File

@@ -1,7 +1,6 @@
import 'dart:io';
import 'package:after_layout/after_layout.dart';
import 'package:dartssh2/dartssh2.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -9,6 +8,7 @@ import 'package:toolbox/core/extension/numx.dart';
import 'package:toolbox/core/utils/misc.dart';
import 'package:toolbox/data/res/misc.dart';
import '../../../core/utils/server.dart';
import '../../../core/utils/ui.dart';
import '../../../data/model/server/private_key_info.dart';
import '../../../data/provider/private_key.dart';
@@ -158,7 +158,7 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
),
);
});
final info = PrivateKeyInfo(name, key, pwd);
final info = PrivateKeyInfo(name, key, '');
bool haveErr = false;
try {
info.privateKey = await compute(decyptPem, [key, pwd]);
@@ -197,11 +197,3 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
}
}
}
/// [args] : [key, pwd]
String decyptPem(List<String> args) {
/// skip when the key is not encrypted, or will throw exception
if (!SSHKeyPair.isEncryptedPem(args[0])) return args[0];
final sshKey = SSHKeyPair.fromPem(args[0], args[1]);
return sshKey.first.toPem();
}