mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-26 16:46:51 +08:00
SSH Private Key: Try formats supported by ssh_key
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:crypton/crypton.dart';
|
||||
import 'package:isolate/isolate_runner.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:ssh_key/ssh_key.dart' as ssh_key;
|
||||
|
||||
import 'package:crypton/crypton.dart';
|
||||
import 'package:gitjournal/error_reporting.dart';
|
||||
import 'package:gitjournal/ssh/binary_length_value.dart';
|
||||
import 'package:gitjournal/utils/logger.dart';
|
||||
@ -25,22 +25,32 @@ class RsaKeyPair {
|
||||
this.publicKey = RSAPublicKey(key.modulus, key.exponent);
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
print(e);
|
||||
}
|
||||
|
||||
if (publicKey == null) {
|
||||
try {
|
||||
this.publicKey = RSAPublicKey.fromString(publicKey);
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
var key = ssh_key.privateKeyDecode(privateKey);
|
||||
if (key is ssh_key.RSAPrivateKeyWithInfo) {
|
||||
this.privateKey =
|
||||
RSAPrivateKey(key.modulus, key.exponent, key.p, key.q);
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
|
||||
if (privateKey == null) {
|
||||
try {
|
||||
this.privateKey = RSAPrivateKey.fromPEM(privateKey);
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +58,7 @@ class RsaKeyPair {
|
||||
try {
|
||||
this.privateKey = RSAPrivateKey.fromString(privateKey);
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ AEQwc1bG+Z/Gc1Fd8DncgxyhKSQzLsfWroTnIn8wsnmhPJtaZWNuT5BJa8GhnzX0
|
||||
expect(pair.publicKeyString(), publicKeySingleLine);
|
||||
});
|
||||
|
||||
/*
|
||||
var privateOpenSshKey = '''-----BEGIN OPENSSH PRIVATE KEY-----
|
||||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
|
||||
NhAAAAAwEAAQAAAYEAnSgRJuxDPuTAyUQoGTF+tmA/7kT3FPg5DtM4RbcinIteCbkUWOoA
|
||||
@ -128,5 +127,22 @@ gsiY5pDTPJqEiGrO4wwz0Hj5Pn9cFl2l3zN1/HUSzNszuyIvZflI7HHWcguYXH9E
|
||||
FaG9LapMZjfIj7QTmJCqRpeOaSjoQx0a2Rtcgv7uo4haC502mYMcbhxllJWY4g0/
|
||||
0Shlq/1WGhnWLu8x+570q3eE9kF11Rpq95lSTdfP3RRPa43403Ld
|
||||
-----END RSA PRIVATE KEY-----''';
|
||||
*/
|
||||
|
||||
test('Should read privateOpenSshKey', () async {
|
||||
var pair = RsaKeyPair.fromStrings(
|
||||
publicKey: '',
|
||||
privateKey: privateOpenSshKey,
|
||||
);
|
||||
|
||||
expect(pair.privateKeyString().isNotEmpty, true);
|
||||
});
|
||||
|
||||
test('Should read privateRsaKey', () async {
|
||||
var pair = RsaKeyPair.fromStrings(
|
||||
publicKey: '',
|
||||
privateKey: privateRsaKey,
|
||||
);
|
||||
|
||||
expect(pair.privateKeyString().isNotEmpty, true);
|
||||
}, skip: true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user