Search in sources :

Example 1 with IdentityKey

use of org.whispersystems.libaxolotl.IdentityKey in project Conversations by siacs.

the class IqParser method bundle.

public PreKeyBundle bundle(final IqPacket bundle) {
    Element bundleItem = getItem(bundle);
    if (bundleItem == null) {
        return null;
    }
    final Element bundleElement = bundleItem.findChild("bundle");
    if (bundleElement == null) {
        return null;
    }
    ECPublicKey signedPreKeyPublic = signedPreKeyPublic(bundleElement);
    Integer signedPreKeyId = signedPreKeyId(bundleElement);
    byte[] signedPreKeySignature = signedPreKeySignature(bundleElement);
    IdentityKey identityKey = identityKey(bundleElement);
    if (signedPreKeyId == null || signedPreKeyPublic == null || identityKey == null) {
        return null;
    }
    return new PreKeyBundle(0, 0, 0, null, signedPreKeyId, signedPreKeyPublic, signedPreKeySignature, identityKey);
}
Also used : PreKeyBundle(org.whispersystems.libaxolotl.state.PreKeyBundle) IdentityKey(org.whispersystems.libaxolotl.IdentityKey) ECPublicKey(org.whispersystems.libaxolotl.ecc.ECPublicKey) Element(eu.siacs.conversations.xml.Element)

Example 2 with IdentityKey

use of org.whispersystems.libaxolotl.IdentityKey in project Conversations by siacs.

the class DatabaseBackend method loadIdentityKeys.

public Set<IdentityKey> loadIdentityKeys(Account account, String name, FingerprintStatus status) {
    Set<IdentityKey> identityKeys = new HashSet<>();
    Cursor cursor = getIdentityKeyCursor(account, name, false);
    while (cursor.moveToNext()) {
        if (status != null && !FingerprintStatus.fromCursor(cursor).equals(status)) {
            continue;
        }
        try {
            String key = cursor.getString(cursor.getColumnIndex(SQLiteAxolotlStore.KEY));
            if (key != null) {
                identityKeys.add(new IdentityKey(Base64.decode(key, Base64.DEFAULT), 0));
            } else {
                Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Missing key (possibly preverified) in database for account" + account.getJid().toBareJid() + ", address: " + name);
            }
        } catch (InvalidKeyException e) {
            Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Encountered invalid IdentityKey in database for account" + account.getJid().toBareJid() + ", address: " + name);
        }
    }
    cursor.close();
    return identityKeys;
}
Also used : IdentityKey(org.whispersystems.libaxolotl.IdentityKey) Cursor(android.database.Cursor) InvalidKeyException(org.whispersystems.libaxolotl.InvalidKeyException) HashSet(java.util.HashSet)

Example 3 with IdentityKey

use of org.whispersystems.libaxolotl.IdentityKey in project Conversations by siacs.

the class IqParser method identityKey.

public IdentityKey identityKey(final Element bundle) {
    IdentityKey identityKey = null;
    final Element identityKeyElement = bundle.findChild("identityKey");
    if (identityKeyElement == null) {
        return null;
    }
    try {
        identityKey = new IdentityKey(Base64.decode(identityKeyElement.getContent(), Base64.DEFAULT), 0);
    } catch (Throwable e) {
        Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Invalid identityKey in PEP: " + e.getMessage());
    }
    return identityKey;
}
Also used : IdentityKey(org.whispersystems.libaxolotl.IdentityKey) Element(eu.siacs.conversations.xml.Element)

Example 4 with IdentityKey

use of org.whispersystems.libaxolotl.IdentityKey in project Conversations by siacs.

the class AxolotlService method verifySessionWithPEP.

private void verifySessionWithPEP(final XmppAxolotlSession session) {
    Log.d(Config.LOGTAG, "trying to verify fresh session (" + session.getRemoteAddress().getName() + ") with pep");
    final AxolotlAddress address = session.getRemoteAddress();
    final IdentityKey identityKey = session.getIdentityKey();
    try {
        IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveVerificationForDevice(Jid.fromString(address.getName()), address.getDeviceId());
        mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                Pair<X509Certificate[], byte[]> verification = mXmppConnectionService.getIqParser().verification(packet);
                if (verification != null) {
                    try {
                        Signature verifier = Signature.getInstance("sha256WithRSA");
                        verifier.initVerify(verification.first[0]);
                        verifier.update(identityKey.serialize());
                        if (verifier.verify(verification.second)) {
                            try {
                                mXmppConnectionService.getMemorizingTrustManager().getNonInteractive().checkClientTrusted(verification.first, "RSA");
                                String fingerprint = session.getFingerprint();
                                Log.d(Config.LOGTAG, "verified session with x.509 signature. fingerprint was: " + fingerprint);
                                setFingerprintTrust(fingerprint, FingerprintStatus.createActiveVerified(true));
                                axolotlStore.setFingerprintCertificate(fingerprint, verification.first[0]);
                                fetchStatusMap.put(address, FetchStatus.SUCCESS_VERIFIED);
                                Bundle information = CryptoHelper.extractCertificateInformation(verification.first[0]);
                                try {
                                    final String cn = information.getString("subject_cn");
                                    final Jid jid = Jid.fromString(address.getName());
                                    Log.d(Config.LOGTAG, "setting common name for " + jid + " to " + cn);
                                    account.getRoster().getContact(jid).setCommonName(cn);
                                } catch (final InvalidJidException ignored) {
                                //ignored
                                }
                                finishBuildingSessionsFromPEP(address);
                                return;
                            } catch (Exception e) {
                                Log.d(Config.LOGTAG, "could not verify certificate");
                            }
                        }
                    } catch (Exception e) {
                        Log.d(Config.LOGTAG, "error during verification " + e.getMessage());
                    }
                } else {
                    Log.d(Config.LOGTAG, "no verification found");
                }
                fetchStatusMap.put(address, FetchStatus.SUCCESS);
                finishBuildingSessionsFromPEP(address);
            }
        });
    } catch (InvalidJidException e) {
        fetchStatusMap.put(address, FetchStatus.SUCCESS);
        finishBuildingSessionsFromPEP(address);
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) IdentityKey(org.whispersystems.libaxolotl.IdentityKey) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Jid(eu.siacs.conversations.xmpp.jid.Jid) Bundle(android.os.Bundle) PreKeyBundle(org.whispersystems.libaxolotl.state.PreKeyBundle) AxolotlAddress(org.whispersystems.libaxolotl.AxolotlAddress) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) X509Certificate(java.security.cert.X509Certificate) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) InvalidKeyException(org.whispersystems.libaxolotl.InvalidKeyException) InvalidKeyIdException(org.whispersystems.libaxolotl.InvalidKeyIdException) UntrustedIdentityException(org.whispersystems.libaxolotl.UntrustedIdentityException) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket) Signature(java.security.Signature) Pair(android.util.Pair) IdentityKeyPair(org.whispersystems.libaxolotl.IdentityKeyPair)

Example 5 with IdentityKey

use of org.whispersystems.libaxolotl.IdentityKey in project Conversations by siacs.

the class SQLiteAxolotlStore method generateIdentityKeyPair.

private static IdentityKeyPair generateIdentityKeyPair() {
    Log.i(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + "Generating axolotl IdentityKeyPair...");
    ECKeyPair identityKeyPairKeys = Curve.generateKeyPair();
    return new IdentityKeyPair(new IdentityKey(identityKeyPairKeys.getPublicKey()), identityKeyPairKeys.getPrivateKey());
}
Also used : IdentityKey(org.whispersystems.libaxolotl.IdentityKey) ECKeyPair(org.whispersystems.libaxolotl.ecc.ECKeyPair) IdentityKeyPair(org.whispersystems.libaxolotl.IdentityKeyPair)

Aggregations

IdentityKey (org.whispersystems.libaxolotl.IdentityKey)9 InvalidKeyException (org.whispersystems.libaxolotl.InvalidKeyException)4 Jid (eu.siacs.conversations.xmpp.jid.Jid)3 InvalidKeyIdException (org.whispersystems.libaxolotl.InvalidKeyIdException)3 UntrustedIdentityException (org.whispersystems.libaxolotl.UntrustedIdentityException)3 PreKeyBundle (org.whispersystems.libaxolotl.state.PreKeyBundle)3 Bundle (android.os.Bundle)2 Account (eu.siacs.conversations.entities.Account)2 Element (eu.siacs.conversations.xml.Element)2 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)2 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)2 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)2 Signature (java.security.Signature)2 X509Certificate (java.security.cert.X509Certificate)2 HashSet (java.util.HashSet)2 AxolotlAddress (org.whispersystems.libaxolotl.AxolotlAddress)2 IdentityKeyPair (org.whispersystems.libaxolotl.IdentityKeyPair)2 Cursor (android.database.Cursor)1 Nullable (android.support.annotation.Nullable)1 Pair (android.util.Pair)1