Search in sources :

Example 51 with IqPacket

use of eu.siacs.conversations.xmpp.stanzas.IqPacket 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 52 with IqPacket

use of eu.siacs.conversations.xmpp.stanzas.IqPacket in project Conversations by siacs.

the class IqGenerator method generateCreateAccountWithCaptcha.

public IqPacket generateCreateAccountWithCaptcha(Account account, String id, Data data) {
    final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
    register.setFrom(account.getJid().toBareJid());
    register.setTo(account.getServer());
    register.setId(id);
    Element query = register.query("jabber:iq:register");
    if (data != null) {
        query.addChild(data);
    }
    return register;
}
Also used : Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 53 with IqPacket

use of eu.siacs.conversations.xmpp.stanzas.IqPacket in project Conversations by siacs.

the class IqGenerator method generateGetBlockList.

public IqPacket generateGetBlockList() {
    final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
    iq.addChild("blocklist", Namespace.BLOCKING);
    return iq;
}
Also used : IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 54 with IqPacket

use of eu.siacs.conversations.xmpp.stanzas.IqPacket in project Conversations by siacs.

the class IqGenerator method retrieveVerificationForDevice.

public IqPacket retrieveVerificationForDevice(final Jid to, final int deviceid) {
    final IqPacket packet = retrieve(AxolotlService.PEP_VERIFICATION + ":" + deviceid, null);
    packet.setTo(to);
    return packet;
}
Also used : IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 55 with IqPacket

use of eu.siacs.conversations.xmpp.stanzas.IqPacket in project Conversations by siacs.

the class IqGenerator method changeAffiliation.

public IqPacket changeAffiliation(Conversation conference, List<Jid> jids, String affiliation) {
    IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    packet.setTo(conference.getJid().toBareJid());
    packet.setFrom(conference.getAccount().getJid());
    Element query = packet.query("http://jabber.org/protocol/muc#admin");
    for (Jid jid : jids) {
        Element item = query.addChild("item");
        item.setAttribute("jid", jid.toString());
        item.setAttribute("affiliation", affiliation);
    }
    return packet;
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)78 Element (eu.siacs.conversations.xml.Element)43 Account (eu.siacs.conversations.entities.Account)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)14 Data (eu.siacs.conversations.xmpp.forms.Data)6 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)6 ArrayList (java.util.ArrayList)6 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)4 HashSet (java.util.HashSet)4 InvalidKeyException (org.whispersystems.libaxolotl.InvalidKeyException)4 PreKeyBundle (org.whispersystems.libaxolotl.state.PreKeyBundle)4 Pair (android.util.Pair)3 Conversation (eu.siacs.conversations.entities.Conversation)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 InvalidKeyIdException (org.whispersystems.libaxolotl.InvalidKeyIdException)3 Bundle (android.os.Bundle)2 Bookmark (eu.siacs.conversations.entities.Bookmark)2 Contact (eu.siacs.conversations.entities.Contact)2