From 17c9413efba4d5473fb069942a019d0cca976777 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sat, 19 Jun 2021 00:59:08 +0200 Subject: [PATCH] Use ssh-keygen to generate the ssh keys At some point I'll figure out how to do this with Dart only code, but till then lets just call the process. GitJournal can also no longer run in a sandbox as it needs to access the ssh-keygen executable. --- lib/ssh/keygen.dart | 40 +++++++++++++++++++++++--- macos/Runner/DebugProfile.entitlements | 2 +- macos/Runner/Release.entitlements | 2 +- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/lib/ssh/keygen.dart b/lib/ssh/keygen.dart index bb02adc4..9925e12c 100644 --- a/lib/ssh/keygen.dart +++ b/lib/ssh/keygen.dart @@ -25,10 +25,11 @@ class SshKey { final bool useDartKeyGen = false; Future generateSSHKeys({required String comment}) async { - if (useDartKeyGen) { - //return generateSSHKeysDart(comment: comment); - } else {} - return generateSSHKeysNative(comment: comment); + if (Platform.isAndroid || Platform.isIOS) { + return generateSSHKeysNative(comment: comment); + } else { + return generateSSHKeysKeygen(comment: comment); + } } /* @@ -80,6 +81,37 @@ Future generateSSHKeysNative({required String comment}) async { return null; } +Future generateSSHKeysKeygen({required String comment}) async { + var privateFile = p.join(Directory.systemTemp.path, 'id_rsa'); + + // ssh-keygen -f /tmp/r -t rsa -b 4096 -q -N "" -C 'happy' + var process = await Process.start('ssh-keygen', [ + '-f', + privateFile, + '-t', + 'rsa', + '-b', + '4096', + '-q', + '-N', + '', + '-C', + comment, + ]); + + var exitCode = await process.exitCode; + if (exitCode != 0) { + // FIXME: Give me an error! + return null; + } + + return SshKey( + publicKey: await File(privateFile + '.pub').readAsString(), + privateKey: await File(privateFile).readAsString(), + password: "", + ); +} + Future generateSSHEccKeys({required String comment}) async { print("Generating KeyPair ..."); var stopwatch = Stopwatch()..start(); diff --git a/macos/Runner/DebugProfile.entitlements b/macos/Runner/DebugProfile.entitlements index dddb8a30..9f56413f 100644 --- a/macos/Runner/DebugProfile.entitlements +++ b/macos/Runner/DebugProfile.entitlements @@ -3,7 +3,7 @@ com.apple.security.app-sandbox - + com.apple.security.cs.allow-jit com.apple.security.network.server diff --git a/macos/Runner/Release.entitlements b/macos/Runner/Release.entitlements index 852fa1a4..e89b7f32 100644 --- a/macos/Runner/Release.entitlements +++ b/macos/Runner/Release.entitlements @@ -3,6 +3,6 @@ com.apple.security.app-sandbox - +