mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 01:02:14 +08:00
Go back to generating the ssh keys via openssl
Instead of our custom dart code. Fixes #351 Fixes #353
This commit is contained in:
@ -147,6 +147,11 @@ static FlutterMethodChannel* gitChannel = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if ([@"generateSSHKeys" isEqualToString:method]) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[self handleMethodCallAsync:call result:result];
|
||||
});
|
||||
}
|
||||
else {
|
||||
NSLog(@"Not Implemented");
|
||||
result(FlutterMethodNotImplemented);
|
||||
@ -314,6 +319,32 @@ bool handleError(FlutterResult result, int err) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if ([@"generateSSHKeys" isEqualToString:method]) {
|
||||
NSString *comment = arguments[@"comment"];
|
||||
NSString *privateKeyPath = arguments[@"privateKeyPath"];
|
||||
NSString *publicKeyPath = arguments[@"publicKeyPath"];
|
||||
|
||||
if (comment == nil || [comment length] == 0) {
|
||||
NSLog(@"generateSSHKeys: Using default comment");
|
||||
comment = @"Generated on iOS";
|
||||
}
|
||||
if (privateKeyPath == nil || [privateKeyPath length] == 0) {
|
||||
result([FlutterError errorWithCode:@"InvalidParams"
|
||||
message:@"Invalid privateKeyPath" details:nil]);
|
||||
return;
|
||||
}
|
||||
if (publicKeyPath == nil || [publicKeyPath length] == 0) {
|
||||
result([FlutterError errorWithCode:@"InvalidParams"
|
||||
message:@"Invalid publicKeyPath" details:nil]);
|
||||
return;
|
||||
}
|
||||
|
||||
int err = gj_generate_ssh_keys([privateKeyPath UTF8String], [publicKeyPath UTF8String], [comment UTF8String]);
|
||||
if (!handleError(result, err)) {
|
||||
result(@YES);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)app
|
||||
|
@ -1,7 +1,11 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'package:gitjournal/ssh/rsa_key_pair.dart';
|
||||
import 'package:gitjournal/utils/logger.dart';
|
||||
import 'package:git_bindings/git_bindings.dart' as gb;
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
class SshKey {
|
||||
final String publicKey;
|
||||
@ -15,7 +19,17 @@ class SshKey {
|
||||
});
|
||||
}
|
||||
|
||||
final bool useDartKeyGen = false;
|
||||
|
||||
Future<SshKey> generateSSHKeys({@required String comment}) async {
|
||||
if (useDartKeyGen) {
|
||||
return generateSSHKeysDart(comment: comment);
|
||||
} else {
|
||||
return generateSSHKeysNative(comment: comment);
|
||||
}
|
||||
}
|
||||
|
||||
Future<SshKey> generateSSHKeysDart({@required String comment}) async {
|
||||
try {
|
||||
var stopwatch = Stopwatch()..start();
|
||||
var keyPair = await RsaKeyPair.generateAsync();
|
||||
@ -26,8 +40,37 @@ Future<SshKey> generateSSHKeys({@required String comment}) async {
|
||||
privateKey: keyPair.privateKeyString(),
|
||||
password: "",
|
||||
);
|
||||
} catch (e) {
|
||||
Log.e(e);
|
||||
} catch (e, st) {
|
||||
Log.e("generateSSHKeysDart", ex: e, stacktrace: st);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<SshKey> generateSSHKeysNative({@required String comment}) async {
|
||||
try {
|
||||
var stopwatch = Stopwatch()..start();
|
||||
var dir = await Directory.systemTemp.createTemp('keys');
|
||||
var publicKeyPath = p.join(dir.path, 'id_rsa.pub');
|
||||
var privateKeyPath = p.join(dir.path, 'id_rsa');
|
||||
|
||||
await gb.generateSSHKeys(
|
||||
publicKeyPath: publicKeyPath,
|
||||
privateKeyPath: privateKeyPath,
|
||||
comment: comment,
|
||||
);
|
||||
Log.i("Generating KeyPair took: ${stopwatch.elapsed}");
|
||||
|
||||
var all = dir.listSync().map((e) => e.path).toList();
|
||||
Log.d("Keys Dir: $all");
|
||||
|
||||
return SshKey(
|
||||
publicKey: await File(publicKeyPath).readAsString(),
|
||||
privateKey: await File(privateKeyPath).readAsString(),
|
||||
password: "",
|
||||
);
|
||||
} catch (e, st) {
|
||||
Log.e("generateSSHKeysNative", ex: e, stacktrace: st);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -479,7 +479,7 @@ packages:
|
||||
description:
|
||||
path: "."
|
||||
ref: HEAD
|
||||
resolved-ref: "277eeda053b3ebc778c801b39a805b265d44e10f"
|
||||
resolved-ref: "89c587037dd4d9d9270b09b51df40e537d7263c5"
|
||||
url: "https://github.com/GitJournal/git_bindings.git"
|
||||
source: git
|
||||
version: "0.0.18"
|
||||
|
Reference in New Issue
Block a user