From cb908f6da07c4ae81a79d5001e43cda4f735bc87 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Sat, 19 Jun 2021 12:33:40 +0200 Subject: [PATCH] Remove unused file I've given up generating the rsa key in dart. At some point I'll manage to use ECC, and that's about it. --- lib/ssh/keygen.dart | 2 - lib/ssh/rsa_key_pair.dart | 125 -------------------------------------- 2 files changed, 127 deletions(-) delete mode 100644 lib/ssh/rsa_key_pair.dart diff --git a/lib/ssh/keygen.dart b/lib/ssh/keygen.dart index 9925e12c..01d6fd64 100644 --- a/lib/ssh/keygen.dart +++ b/lib/ssh/keygen.dart @@ -8,8 +8,6 @@ import 'package:path/path.dart' as p; import 'package:gitjournal/ssh/binary_length_value.dart'; import 'package:gitjournal/utils/logger.dart'; -// import 'package:gitjournal/ssh/rsa_key_pair.dart'; - class SshKey { final String publicKey; final String privateKey; diff --git a/lib/ssh/rsa_key_pair.dart b/lib/ssh/rsa_key_pair.dart deleted file mode 100644 index 2baa0d69..00000000 --- a/lib/ssh/rsa_key_pair.dart +++ /dev/null @@ -1,125 +0,0 @@ -/* - -import 'dart:async'; -import 'dart:convert'; - -import 'package:crypton/crypton.dart'; -import 'package:meta/meta.dart'; - -import 'package:gitjournal/error_reporting.dart'; -import 'package:gitjournal/ssh/binary_length_value.dart'; -import 'package:gitjournal/utils/logger.dart'; - -class RsaKeyPair { - RSAPublicKey publicKey; - RSAPrivateKey privateKey; - - RsaKeyPair.fromStrings({ - @required String privateKey, - @required String publicKey, - }) { - publicKey = publicKey.trim(); - try { - var key = ssh_key.publicKeyDecode(publicKey); - if (key is ssh_key.RSAPublicKeyWithInfo) { - this.publicKey = RSAPublicKey(key.modulus, key.exponent); - } - } catch (e) { - print(e); - } - - if (publicKey == null) { - try { - this.publicKey = RSAPublicKey.fromString(publicKey); - } catch (e) { - 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) { - print(e); - } - } - - if (privateKey == null) { - try { - this.privateKey = RSAPrivateKey.fromString(privateKey); - } catch (e) { - print(e); - } - } - } - - RsaKeyPair.generate() { - var keyPair = RSAKeypair.fromRandom(keySize: 4096); - - publicKey = keyPair.publicKey; - privateKey = keyPair.privateKey; - } - - // Tries to encrypt and decrypt - bool isValid() { - if (publicKey == null || privateKey == null) { - return false; - } - var orig = 'word'; - var enc = publicKey.encrypt(orig); - var dec = privateKey.decrypt(enc); - - return orig == dec; - } - - // OpenSSH Public Key (single-line format) - String publicKeyString({String comment = ""}) { - var pk = publicKey.asPointyCastle; - - var data = BinaryLengthValue.encode([ - BinaryLengthValue.fromString("ssh-rsa"), - BinaryLengthValue.fromBigInt(pk.exponent), - BinaryLengthValue.fromBigInt(pk.modulus), - ]); - - if (comment.isNotEmpty) { - comment = comment.replaceAll('\r', ' '); - comment = comment.replaceAll('\n', ' '); - comment = ' $comment'; - } - - return 'ssh-rsa ${base64.encode(data)}$comment'; - } - - String privateKeyString() { - return privateKey.toPEM(); - } - - static Future generateAsync() async { - IsolateRunner iso = await IsolateRunner.spawn(); - try { - return await iso.run(_gen, null); - } catch (e) { - Log.e(e); - logException(e, StackTrace.current); - return null; - } finally { - iso.close(); - } - } -} - -FutureOr _gen(void _) async { - return RsaKeyPair.generate(); -} -*/