Skip to content

Commit

Permalink
Fix import during registration (fix #352)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Mar 22, 2015
1 parent b63f60f commit a6e6e61
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/src/main/java/org/kontalk/client/NumberValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/org/kontalk/crypto/PersonalKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a6e6e61

Please sign in to comment.