Search in sources :

Example 1 with OmemoMessage

use of org.jivesoftware.smackx.omemo.OmemoMessage in project Smack by igniterealtime.

the class OmemoClient method handleInput.

public void handleInput(String input) throws NotConnectedException, NotLoggedInException, InterruptedException, IOException {
    String[] com = input.split(" ", 3);
    switch(com[0]) {
        case "/omemo":
            if (com.length < 3) {
                print("Usage: /omemo <contact-jid> <message>");
                return;
            }
            BareJid recipient = JidCreate.bareFrom(com[1]);
            String body = com[2];
            MessageBuilder messageBuilder = connection.getStanzaFactory().buildMessageStanza();
            try {
                Message omemoMessage = omemoManager.encrypt(recipient, body).buildMessage(messageBuilder, recipient);
                connection.sendStanza(omemoMessage);
            } catch (UndecidedOmemoIdentityException e) {
                print("Undecided Identities!\n" + Arrays.toString(e.getUndecidedDevices().toArray()));
            } catch (CryptoFailedException | SmackException.NoResponseException e) {
                LOGGER.log(Level.SEVERE, "Unexpected Exception", e);
            }
            break;
        case "/trust":
            print("Trust");
            if (com.length != 2) {
                print("Usage: /trust <contact-jid>");
            }
            BareJid contact = JidCreate.bareFrom(com[1]);
            HashMap<OmemoDevice, OmemoFingerprint> devices;
            try {
                devices = omemoManager.getActiveFingerprints(contact);
            } catch (CorruptedOmemoKeyException | CannotEstablishOmemoSessionException | SmackException.NoResponseException e) {
                LOGGER.log(Level.SEVERE, "Unexpected Exception", e);
                return;
            }
            for (OmemoDevice d : devices.keySet()) {
                print("Trust (1) or distrust (2)?\n" + devices.get(d).blocksOf8Chars());
                if (Integer.parseInt(scanner.nextLine()) == 1) {
                    omemoManager.trustOmemoIdentity(d, devices.get(d));
                } else {
                    omemoManager.distrustOmemoIdentity(d, devices.get(d));
                }
            }
            print("Done.");
            break;
        case "/purge":
            try {
                omemoManager.purgeDeviceList();
                print("Purged.");
            } catch (XMPPException.XMPPErrorException | SmackException.NoResponseException | PubSubException.NotALeafNodeException e) {
                LOGGER.log(Level.SEVERE, "Unexpected Exception", e);
            }
    }
}
Also used : CryptoFailedException(org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException) UndecidedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException) OmemoMessage(org.jivesoftware.smackx.omemo.OmemoMessage) Message(org.jivesoftware.smack.packet.Message) OmemoDevice(org.jivesoftware.smackx.omemo.internal.OmemoDevice) EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) CorruptedOmemoKeyException(org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException) CannotEstablishOmemoSessionException(org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException) MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) OmemoFingerprint(org.jivesoftware.smackx.omemo.trust.OmemoFingerprint)

Aggregations

Message (org.jivesoftware.smack.packet.Message)1 MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)1 OmemoMessage (org.jivesoftware.smackx.omemo.OmemoMessage)1 CannotEstablishOmemoSessionException (org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException)1 CorruptedOmemoKeyException (org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException)1 CryptoFailedException (org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException)1 UndecidedOmemoIdentityException (org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException)1 OmemoDevice (org.jivesoftware.smackx.omemo.internal.OmemoDevice)1 OmemoFingerprint (org.jivesoftware.smackx.omemo.trust.OmemoFingerprint)1 BareJid (org.jxmpp.jid.BareJid)1 EntityBareJid (org.jxmpp.jid.EntityBareJid)1