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.
This commit is contained in:
Vishesh Handa
2021-06-19 00:59:08 +02:00
parent 2f59196596
commit 17c9413efb
3 changed files with 38 additions and 6 deletions

View File

@ -25,10 +25,11 @@ class SshKey {
final bool useDartKeyGen = false; final bool useDartKeyGen = false;
Future<SshKey?> generateSSHKeys({required String comment}) async { Future<SshKey?> generateSSHKeys({required String comment}) async {
if (useDartKeyGen) { if (Platform.isAndroid || Platform.isIOS) {
//return generateSSHKeysDart(comment: comment); return generateSSHKeysNative(comment: comment);
} else {} } else {
return generateSSHKeysNative(comment: comment); return generateSSHKeysKeygen(comment: comment);
}
} }
/* /*
@ -80,6 +81,37 @@ Future<SshKey?> generateSSHKeysNative({required String comment}) async {
return null; return null;
} }
Future<SshKey?> 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<SshKey> generateSSHEccKeys({required String comment}) async { Future<SshKey> generateSSHEccKeys({required String comment}) async {
print("Generating KeyPair ..."); print("Generating KeyPair ...");
var stopwatch = Stopwatch()..start(); var stopwatch = Stopwatch()..start();

View File

@ -3,7 +3,7 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>com.apple.security.app-sandbox</key> <key>com.apple.security.app-sandbox</key>
<true/> <false/>
<key>com.apple.security.cs.allow-jit</key> <key>com.apple.security.cs.allow-jit</key>
<true/> <true/>
<key>com.apple.security.network.server</key> <key>com.apple.security.network.server</key>

View File

@ -3,6 +3,6 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>com.apple.security.app-sandbox</key> <key>com.apple.security.app-sandbox</key>
<true/> <false/>
</dict> </dict>
</plist> </plist>