diff --git a/app/src/main/java/org/kontalk/client/NumberValidator.java b/app/src/main/java/org/kontalk/client/NumberValidator.java index d8b760bc4..e12be91fa 100644 --- a/app/src/main/java/org/kontalk/client/NumberValidator.java +++ b/app/src/main/java/org/kontalk/client/NumberValidator.java @@ -414,7 +414,16 @@ private void initConnection() throws XMPPException, SmackException, if (!mConnector.isConnected() || mConnector.isServerDirty()) { mConnector.setListener(this); - mConnector.connectOnce(mKey != null ? mKey.copy(mBridgeCert) : null); + PersonalKey key = null; + if (mImportedPrivateKey != null && mImportedPublicKey != null) { + PGPKeyPairRing ring = PGPKeyPairRing.load(mImportedPrivateKey, mImportedPublicKey); + key = PersonalKey.load(ring.secretKey, ring.publicKey, mPassphrase, mBridgeCert); + } + else if (mKey != null) { + key = mKey.copy(mBridgeCert); + } + + mConnector.connectOnce(key); } } diff --git a/app/src/main/java/org/kontalk/crypto/PersonalKey.java b/app/src/main/java/org/kontalk/crypto/PersonalKey.java index 3de6cc67f..19ecf8d02 100644 --- a/app/src/main/java/org/kontalk/crypto/PersonalKey.java +++ b/app/src/main/java/org/kontalk/crypto/PersonalKey.java @@ -286,6 +286,17 @@ public static PersonalKey load(byte[] privateKeyData, byte[] publicKeyData, Stri return load(secRing, pubRing, passphrase, bridgeCert); } + /** Creates a {@link PersonalKey} from private and public key byte buffers. */ + public static PersonalKey load(byte[] privateKeyData, byte[] publicKeyData, String passphrase, X509Certificate bridgeCert) + throws PGPException, IOException, CertificateException, NoSuchProviderException { + + KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator(); + PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, fpr); + PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, fpr); + + return load(secRing, pubRing, passphrase, bridgeCert); + } + @SuppressWarnings("unchecked") public static PersonalKey load(PGPSecretKeyRing secRing, PGPPublicKeyRing pubRing, String passphrase, X509Certificate bridgeCert) throws PGPException, IOException, CertificateException, NoSuchProviderException {