Java Code Examples for org.jivesoftware.smack.XMPPException#XMPPErrorException

The following examples show how to use org.jivesoftware.smack.XMPPException#XMPPErrorException . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OmemoService.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve a users OMEMO bundle.
 *
 * @param connection authenticated XMPP connection.
 * @param contactsDevice device of which we want to retrieve the bundle.
 * @return OmemoBundle of the device or null, if it doesn't exist.
 *
 * @throws SmackException.NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws SmackException.NoResponseException if there was no response from the remote entity.
 * @throws XMPPException.XMPPErrorException if there was an XMPP error returned.
 * @throws PubSubException.NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node.
 * @throws PubSubException.NotAPubSubNodeException if a involved node is not a PubSub node.
 */
private static OmemoBundleElement fetchBundle(XMPPConnection connection,
                                              OmemoDevice contactsDevice)
        throws SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException,
        XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException,
        PubSubException.NotAPubSubNodeException {

    PubSubManager pm = PubSubManager.getInstanceFor(connection, contactsDevice.getJid());
    LeafNode node = pm.getLeafNode(contactsDevice.getBundleNodeName());

    if (node == null) {
        return null;
    }

    List<PayloadItem<OmemoBundleElement>> bundleItems = node.getItems();
    if (bundleItems.isEmpty()) {
        return null;
    }

    return bundleItems.get(bundleItems.size() - 1).getPayload();
}
 
Example 2
Source File: XmppConnection.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
private void queryArchive (EntityBareJid jid) throws XMPPException.XMPPErrorException, SmackException.NotLoggedInException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {

            /**
            MamManager mucMamManager = MamManager.getInstanceFor(mConnection, jid);
            MamManager.MamQueryArgs.Builder args = new MamManager.MamQueryArgs.Builder();
            args.setResultPageSizeTo(20);

            MamManager.MamQuery result = mucMamManager.queryArchive(args.build());

            if (result != null && result.getMessageCount() > 0) {
                for (org.jivesoftware.smack.packet.Message msg : result.getMessages())
                {
                    Log.w(TAG, "retreived archive message: " + msg);
                }
            }**/
        }
 
Example 3
Source File: AbstractOpenPgpIntegrationTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
protected AbstractOpenPgpIntegrationTest(SmackIntegrationTestEnvironment environment)
        throws XMPPException.XMPPErrorException, TestNotPossibleException, SmackException.NotConnectedException,
        InterruptedException, SmackException.NoResponseException {
    super(environment);

    throwIfPubSubNotSupported(conOne);
    throwIfPubSubNotSupported(conTwo);
    throwIfPubSubNotSupported(conThree);

    this.aliceConnection = conOne;
    this.bobConnection = conTwo;
    this.chloeConnection = conThree;

    this.alice = aliceConnection.getUser().asBareJid();
    this.bob = bobConnection.getUser().asBareJid();
    this.chloe = chloeConnection.getUser().asBareJid();

    this.alicePepManager = PepManager.getInstanceFor(aliceConnection);
    this.bobPepManager = PepManager.getInstanceFor(bobConnection);
    this.chloePepManager = PepManager.getInstanceFor(chloeConnection);

    OpenPgpPubSubUtil.deletePubkeysListNode(alicePepManager);
    OpenPgpPubSubUtil.deletePubkeysListNode(bobPepManager);
    OpenPgpPubSubUtil.deletePubkeysListNode(chloePepManager);
}
 
Example 4
Source File: AbstractOmemoIntegrationTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
public AbstractOmemoIntegrationTest(SmackIntegrationTestEnvironment environment) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, TestNotPossibleException {
    super(environment);

    // Test for server support
    if (!OmemoManager.serverSupportsOmemo(connection, connection.getXMPPServiceDomain())) {
        throw new TestNotPossibleException("Server does not support OMEMO (PubSub)");
    }

    // Check for OmemoService
    if (!OmemoService.isServiceRegistered()) {
        throw new TestNotPossibleException("No OmemoService registered.");
    }

    OmemoConfiguration.setCompleteSessionWithEmptyMessage(true);
    OmemoConfiguration.setRepairBrokenSessionsWithPrekeyMessages(true);
}
 
Example 5
Source File: OmemoManagerSetupHelper.java    From Smack with Apache License 2.0 6 votes vote down vote up
public static void trustAllIdentities(OmemoManager alice, OmemoManager bob)
        throws InterruptedException, SmackException.NotConnectedException, SmackException.NotLoggedInException,
        SmackException.NoResponseException, CannotEstablishOmemoSessionException, CorruptedOmemoKeyException,
        XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException, IOException {
    Roster roster = Roster.getInstanceFor(alice.getConnection());

    if (alice.getOwnJid() != bob.getOwnJid() &&
            (!roster.iAmSubscribedTo(bob.getOwnJid()) || !roster.isSubscribedToMyPresence(bob.getOwnJid()))) {
        throw new IllegalStateException("Before trusting identities of a user, we must be subscribed to one another.");
    }

    alice.requestDeviceListUpdateFor(bob.getOwnJid());
    HashMap<OmemoDevice, OmemoFingerprint> fingerprints = alice.getActiveFingerprints(bob.getOwnJid());

    for (OmemoDevice device : fingerprints.keySet()) {
        OmemoFingerprint fingerprint = fingerprints.get(device);
        alice.trustOmemoIdentity(device, fingerprint);
    }
}
 
Example 6
Source File: RoomManager.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
private void getSubject(Chat chatRoom) {
    try {
        MultiUserChatLight multiUserChatLight = XMPPSession.getInstance().getMUCLightManager().getMultiUserChatLight(JidCreate.from(chatRoom.getJid()).asEntityBareJidIfPossible());
        MUCLightRoomConfiguration configuration = multiUserChatLight.getConfiguration();
        chatRoom.setSubject(configuration.getSubject());
    } catch (XmppStringprepException | SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: RoomManager.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
public List<String> loadMUCLightMembers(String roomJid) throws XmppStringprepException, SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
    MultiUserChatLightManager multiUserChatLightManager = MultiUserChatLightManager.getInstanceFor(XMPPSession.getInstance().getXMPPConnection());
    MultiUserChatLight multiUserChatLight = multiUserChatLightManager.getMultiUserChatLight(JidCreate.from(roomJid).asEntityBareJidIfPossible());

    HashMap<Jid, MUCLightAffiliation> occupants = multiUserChatLight.getAffiliations();
    List<String> jids = new ArrayList<>();

    for (Map.Entry<Jid, MUCLightAffiliation> pair : occupants.entrySet()) {
        Jid jid = pair.getKey();
        if (jid != null) {
            jids.add(jid.toString());
        }
    }
    return jids;
}
 
Example 8
Source File: JingleIBBTransportSession.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Override
public void initiateOutgoingSession(JingleTransportInitiationCallback callback) {
    LOGGER.log(Level.INFO, "Initiate Jingle InBandBytestream session.");

    BytestreamSession session;
    try {
        session = InBandBytestreamManager.getByteStreamManager(jingleSession.getConnection())
                .establishSession(jingleSession.getRemote(), theirProposal.getSessionId());
        callback.onSessionInitiated(session);
    } catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
        callback.onException(e);
    }
}
 
Example 9
Source File: JingleUtil.java    From Smack with Apache License 2.0 5 votes vote down vote up
public IQ sendSessionTerminateAlternativeSession(FullJid recipient, String sessionId, String altSessionId)
        throws InterruptedException, XMPPException.XMPPErrorException,
        SmackException.NotConnectedException, SmackException.NoResponseException {

    Jingle jingle = createSessionTerminateAlternativeSession(recipient, sessionId, altSessionId);
    return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
 
Example 10
Source File: OpenPgpPubSubUtil.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Publish the users OpenPGP public key to the public key node if necessary.
 * Also announce the key to other users by updating the metadata node.
 *
 * @see <a href="https://xmpp.org/extensions/xep-0373.html#annoucning-pubkey">XEP-0373 §4.1</a>
 *
 * @param pepManager The PEP manager.
 * @param pubkeyElement {@link PubkeyElement} containing the public key
 * @param fingerprint fingerprint of the public key
 *
 * @throws InterruptedException if the thread gets interrupted.
 * @throws PubSubException.NotALeafNodeException if either the metadata node or the public key node is not a
 *                                               {@link LeafNode}.
 * @throws XMPPException.XMPPErrorException in case of an XMPP protocol error.
 * @throws SmackException.NotConnectedException if we are not connected.
 * @throws SmackException.NoResponseException if the server doesn't respond.
 */
public static void publishPublicKey(PepManager pepManager, PubkeyElement pubkeyElement, OpenPgpV4Fingerprint fingerprint)
        throws InterruptedException, PubSubException.NotALeafNodeException,
        XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {

    String keyNodeName = PEP_NODE_PUBLIC_KEY(fingerprint);
    PubSubManager pm = pepManager.getPepPubSubManager();

    // Check if key available at data node
    // If not, publish key to data node
    LeafNode keyNode = pm.getOrCreateLeafNode(keyNodeName);
    changeAccessModelIfNecessary(keyNode, AccessModel.open);
    List<Item> items = keyNode.getItems(1);
    if (items.isEmpty()) {
        LOGGER.log(Level.FINE, "Node " + keyNodeName + " is empty. Publish.");
        keyNode.publish(new PayloadItem<>(pubkeyElement));
    } else {
        LOGGER.log(Level.FINE, "Node " + keyNodeName + " already contains key. Skip.");
    }

    // Fetch IDs from metadata node
    LeafNode metadataNode = pm.getOrCreateLeafNode(PEP_NODE_PUBLIC_KEYS);
    changeAccessModelIfNecessary(metadataNode, AccessModel.open);
    List<PayloadItem<PublicKeysListElement>> metadataItems = metadataNode.getItems(1);

    PublicKeysListElement.Builder builder = PublicKeysListElement.builder();
    if (!metadataItems.isEmpty() && metadataItems.get(0).getPayload() != null) {
        // Add old entries back to list.
        PublicKeysListElement publishedList = metadataItems.get(0).getPayload();
        for (PublicKeysListElement.PubkeyMetadataElement meta : publishedList.getMetadata().values()) {
            builder.addMetadata(meta);
        }
    }
    builder.addMetadata(new PublicKeysListElement.PubkeyMetadataElement(fingerprint, new Date()));

    // Publish IDs to metadata node
    metadataNode.publish(new PayloadItem<>(builder.build()));
}
 
Example 11
Source File: OpenPgpManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Upload the encrypted secret key to a private PEP node.
 *
 * @see <a href="https://xmpp.org/extensions/xep-0373.html#synchro-pep">XEP-0373 §5</a>
 *
 * @param displayCodeCallback callback, which will receive the backup password used to encrypt the secret key.
 * @param selectKeyCallback callback, which will receive the users choice of which keys will be backed up.
 * @throws InterruptedException if the thread is interrupted.
 * @throws PubSubException.NotALeafNodeException if the private node is not a {@link LeafNode}.
 * @throws XMPPException.XMPPErrorException in case of an XMPP protocol error.
 * @throws SmackException.NotConnectedException if we are not connected.
 * @throws SmackException.NoResponseException if the server doesn't respond.
 * @throws SmackException.NotLoggedInException if we are not logged in.
 * @throws IOException IO is dangerous.
 * @throws SmackException.FeatureNotSupportedException if the server doesn't support the PubSub whitelist access model.
 * @throws PGPException PGP is brittle
 * @throws MissingOpenPgpKeyException in case we have no OpenPGP key pair to back up.
 */
public void backupSecretKeyToServer(DisplayBackupCodeCallback displayCodeCallback,
                                    SecretKeyBackupSelectionCallback selectKeyCallback)
        throws InterruptedException, PubSubException.NotALeafNodeException,
        XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException,
        SmackException.NotLoggedInException, IOException,
        SmackException.FeatureNotSupportedException, PGPException, MissingOpenPgpKeyException {
    throwIfNoProviderSet();
    throwIfNotAuthenticated();

    BareJid ownJid = connection().getUser().asBareJid();

    String backupCode = SecretKeyBackupHelper.generateBackupPassword();

    PGPSecretKeyRingCollection secretKeyRings = provider.getStore().getSecretKeysOf(ownJid);

    Set<OpenPgpV4Fingerprint> availableKeyPairs = new HashSet<>();
    for (PGPSecretKeyRing ring : secretKeyRings) {
        availableKeyPairs.add(new OpenPgpV4Fingerprint(ring));
    }

    Set<OpenPgpV4Fingerprint> selectedKeyPairs = selectKeyCallback.selectKeysToBackup(availableKeyPairs);

    SecretkeyElement secretKey = SecretKeyBackupHelper.createSecretkeyElement(provider, ownJid, selectedKeyPairs, backupCode);

    OpenPgpPubSubUtil.depositSecretKey(connection(), secretKey);
    displayCodeCallback.displayBackupCode(backupCode);
}
 
Example 12
Source File: OmemoManagerSetupHelper.java    From Smack with Apache License 2.0 5 votes vote down vote up
public static void cleanUpRoster(OmemoManager omemoManager) {
    Roster roster = Roster.getInstanceFor(omemoManager.getConnection());
    for (RosterEntry r : roster.getEntries()) {
        try {
            roster.removeEntry(r);
        } catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException |
                XMPPException.XMPPErrorException | SmackException.NotLoggedInException e) {
            // Silent
        }
    }
}
 
Example 13
Source File: JingleUtil.java    From Smack with Apache License 2.0 4 votes vote down vote up
public IQ sendSessionTerminateUnsupportedTransports(FullJid recipient, String sessionId)
        throws InterruptedException, XMPPException.XMPPErrorException,
        SmackException.NotConnectedException, SmackException.NoResponseException {
    Jingle jingle = createSessionTerminateUnsupportedTransports(recipient, sessionId);
    return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
 
Example 14
Source File: SessionRenegotiationIntegrationTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
public SessionRenegotiationIntegrationTest(SmackIntegrationTestEnvironment environment)
        throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
        SmackException.NoResponseException, TestNotPossibleException {
    super(environment);
}
 
Example 15
Source File: FallbackIndicationManager.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Determine, whether or not the server supports Fallback Indications.
 *
 * @return server side feature support
 *
 * @throws XMPPException.XMPPErrorException if a protocol level error happens
 * @throws SmackException.NotConnectedException if the connection is not connected
 * @throws InterruptedException if the thread is being interrupted
 * @throws SmackException.NoResponseException if the server doesn't send a response in time
 */
public boolean serverSupportsFallbackIndications()
        throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
        SmackException.NoResponseException {
    return ServiceDiscoveryManager.getInstanceFor(connection())
            .serverSupportsFeature(FallbackIndicationElement.NAMESPACE);
}
 
Example 16
Source File: OpenPgpPubSubUtil.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Query the access model of {@code node}. If it is different from {@code accessModel}, change the access model
 * of the node to {@code accessModel}.
 *
 * @see <a href="https://xmpp.org/extensions/xep-0060.html#accessmodels">XEP-0060 §4.5 - Node Access Models</a>
 *
 * @param node {@link LeafNode} whose PubSub access model we want to change
 * @param accessModel new access model.
 *
 * @throws XMPPException.XMPPErrorException in case of an XMPP protocol error.
 * @throws SmackException.NotConnectedException if we are not connected.
 * @throws InterruptedException if the thread is interrupted.
 * @throws SmackException.NoResponseException if the server doesn't respond.
 */
public static void changeAccessModelIfNecessary(LeafNode node, AccessModel accessModel)
        throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
        SmackException.NoResponseException {
    ConfigureForm current = node.getNodeConfiguration();
    if (current.getAccessModel() != accessModel) {
        FillableConfigureForm updateConfig = current.getFillableForm();
        updateConfig.setAccessModel(accessModel);
        node.sendConfigurationForm(updateConfig);
    }
}
 
Example 17
Source File: OpenPgpManager.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Delete the private {@link LeafNode} containing our secret key backup.
 *
 * @throws XMPPException.XMPPErrorException in case of an XMPP protocol error.
 * @throws SmackException.NotConnectedException if we are not connected.
 * @throws InterruptedException if the thread gets interrupted.
 * @throws SmackException.NoResponseException if the server doesn't respond.
 * @throws SmackException.NotLoggedInException if we are not logged in.
 */
public void deleteSecretKeyServerBackup()
        throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
        SmackException.NoResponseException, SmackException.NotLoggedInException {
    throwIfNotAuthenticated();
    OpenPgpPubSubUtil.deleteSecretKeyNode(pepManager);
}
 
Example 18
Source File: OmemoManager.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Request a deviceList update from contact contact.
 *
 * @param contact contact we want to obtain the deviceList from.
 *
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws PubSubException.NotALeafNodeException if a PubSub leaf node operation was attempted on a non-leaf node.
 * @throws XMPPException.XMPPErrorException if there was an XMPP error returned.
 * @throws SmackException.NotConnectedException if the XMPP connection is not connected.
 * @throws SmackException.NoResponseException if there was no response from the remote entity.
 * @throws IOException if an I/O error occurred.
 */
public synchronized void requestDeviceListUpdateFor(BareJid contact)
        throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException,
        SmackException.NotConnectedException, SmackException.NoResponseException, IOException {
    getOmemoService().refreshDeviceList(connection(), getOwnDevice(), contact);
}
 
Example 19
Source File: OpenPgpPubSubUtil.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Consult the public key metadata node and fetch a list of all of our published OpenPGP public keys.
 *
 * @see <a href="https://xmpp.org/extensions/xep-0373.html#discover-pubkey-list">
 *      XEP-0373 §4.3: Discovering Public Keys of a User</a>
 *
 * @param connection XMPP connection
 * @return content of our metadata node.
 *
 * @throws InterruptedException if the thread gets interrupted.
 * @throws XMPPException.XMPPErrorException in case of an XMPP protocol exception.
 * @throws PubSubException.NotAPubSubNodeException in case the queried entity is not a PubSub node
 * @throws PubSubException.NotALeafNodeException in case the queried node is not a {@link LeafNode}
 * @throws SmackException.NotConnectedException in case we are not connected
 * @throws SmackException.NoResponseException in case the server doesn't respond
 */
public static PublicKeysListElement fetchPubkeysList(XMPPConnection connection)
        throws InterruptedException, XMPPException.XMPPErrorException, PubSubException.NotAPubSubNodeException,
        PubSubException.NotALeafNodeException, SmackException.NotConnectedException, SmackException.NoResponseException {
    return fetchPubkeysList(connection, null);
}
 
Example 20
Source File: OXInstantMessagingIntegrationTest.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * This integration test tests basic OX message exchange.
 * In this scenario, Alice and Bob are strangers, as they do not have subscribed to one another.
 *
 * Alice (conOne) creates keys and publishes them to the server.
 * Bob (conTwo) creates keys and publishes them to the server.
 *
 * Alice then manually fetches Bobs metadata node and all announced keys.
 *
 * Alice trusts Bobs keys and vice versa (even though Bob does not have copies of Alice' keys yet).
 *
 * She proceeds to create an OX encrypted message, which is encrypted to Bob and herself and signed by her.
 *
 * She sends the message.
 *
 * Bob receives the message, which - due to missing keys - triggers him to update Alice' keys.
 *
 * After the update Bob proceeds to decrypt and verify the message.
 *
 * After the test, the keys are deleted from local storage and from PubSub.
 *
 * @param environment test environment
 *
 * @throws XMPPException.XMPPErrorException if there was an XMPP error returned.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws SmackException.NotConnectedException if the XMPP connection is not connected.
 * @throws TestNotPossibleException if the test is not possible due to lacking server support for PEP.
 * @throws SmackException.NoResponseException if there was no response from the remote entity.
 */
public OXInstantMessagingIntegrationTest(SmackIntegrationTestEnvironment environment)
        throws XMPPException.XMPPErrorException, InterruptedException, SmackException.NotConnectedException,
        TestNotPossibleException, SmackException.NoResponseException {
    super(environment);
}