Java Code Examples for org.jivesoftware.smack.SmackException#NoResponseException

The following examples show how to use org.jivesoftware.smack.SmackException#NoResponseException . 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
/**
 * Create an OmemoMessage.
 *
 * @param managerGuard initialized OmemoManager
 * @param contactsDevices set of recipient devices
 * @param message message we want to send
 * @return encrypted OmemoMessage
 *
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws UndecidedOmemoIdentityException if the list of recipient devices contains an undecided device.
 * @throws CryptoFailedException if we are lacking some cryptographic algorithms
 * @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.
 */
OmemoMessage.Sent createOmemoMessage(OmemoManager.LoggedInOmemoManager managerGuard,
                                     Set<OmemoDevice> contactsDevices,
                                     String message)
        throws InterruptedException, UndecidedOmemoIdentityException, CryptoFailedException,
        SmackException.NotConnectedException, SmackException.NoResponseException, IOException {

    byte[] key, iv;
    iv = OmemoMessageBuilder.generateIv();

    try {
        key = OmemoMessageBuilder.generateKey(KEYTYPE, KEYLENGTH);
    } catch (NoSuchAlgorithmException e) {
        throw new CryptoFailedException(e);
    }

    return encrypt(managerGuard, contactsDevices, key, iv, message);
}
 
Example 2
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 3
Source File: Client.java    From desktopclient-java with GNU General Public License v3.0 6 votes vote down vote up
public boolean removeFromRoster(JID jid) {
    if (!this.isConnected()) {
        LOGGER.info("not connected");
        return false;
    }
    Roster roster = Roster.getInstanceFor(mConn);
    RosterEntry entry = roster.getEntry(jid.toBareSmack());
    if (entry == null) {
        LOGGER.info("can't find roster entry for jid: "+jid);
        return true;
    }
    try {
        // blocking
        roster.removeEntry(entry);
    } catch (SmackException.NotLoggedInException |
            SmackException.NoResponseException |
            XMPPException.XMPPErrorException |
            SmackException.NotConnectedException |
            InterruptedException ex) {
        LOGGER.log(Level.WARNING, "can't remove contact from roster", ex);
        return false;
    }
    return true;
}
 
Example 4
Source File: OmemoManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Get the fingerprint of a contacts device.
 *
 * @param device contacts OmemoDevice
 * @return fingerprint of the given OMEMO device.
 *
 * @throws CannotEstablishOmemoSessionException if we have no session yet, and are unable to create one.
 * @throws SmackException.NotLoggedInException if the XMPP connection is not authenticated.
 * @throws CorruptedOmemoKeyException if the copy of the fingerprint we have is corrupted.
 * @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 IOException if an I/O error occurred.
 */
public synchronized OmemoFingerprint getFingerprint(OmemoDevice device)
        throws CannotEstablishOmemoSessionException, SmackException.NotLoggedInException,
        CorruptedOmemoKeyException, SmackException.NotConnectedException, InterruptedException,
        SmackException.NoResponseException, IOException {
    if (getOwnJid() == null) {
        throw new SmackException.NotLoggedInException();
    }

    if (device.equals(getOwnDevice())) {
        return getOwnFingerprint();
    }

    return getOmemoService().getOmemoStoreBackend()
            .getFingerprintAndMaybeBuildSession(new LoggedInOmemoManager(this), device);
}
 
Example 5
Source File: HttpFileUploadManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Discover upload service.
 *
 * Called automatically when connection is authenticated.
 *
 * Note that this is a synchronous call -- Smack must wait for the server response.
 *
 * @return true if upload service was discovered

 * @throws XMPPException.XMPPErrorException if there was an XMPP error returned.
 * @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.
 */
public boolean discoverUploadService() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException,
        InterruptedException, SmackException.NoResponseException {
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection());
    List<DiscoverInfo> servicesDiscoverInfo = sdm
            .findServicesDiscoverInfo(NAMESPACE, true, true);

    if (servicesDiscoverInfo.isEmpty()) {
        servicesDiscoverInfo = sdm.findServicesDiscoverInfo(NAMESPACE_0_2, true, true);
        if (servicesDiscoverInfo.isEmpty()) {
            return false;
        }
    }

    DiscoverInfo discoverInfo = servicesDiscoverInfo.get(0);

    defaultUploadService = uploadServiceFrom(discoverInfo);
    return true;
}
 
Example 6
Source File: RosterManager.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
public void removeContact(User user)
        throws SmackException.NotLoggedInException, InterruptedException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NoResponseException, XmppStringprepException {
    String jidString = XMPPUtils.fromUserNameToJID(user.getLogin());
    removeContact(jidString);
}
 
Example 7
Source File: JingleUtil.java    From Smack with Apache License 2.0 5 votes vote down vote up
public IQ sendSessionTerminateCancel(FullJid recipient,
                              String sessionId)
        throws InterruptedException, XMPPException.XMPPErrorException,
        SmackException.NotConnectedException, SmackException.NoResponseException {

    Jingle jingle = createSessionTerminateCancel(recipient, sessionId);
    return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
 
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: RoomManager.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
public void removeFromMUCLight(User user, String chatJID) {
    MultiUserChatLightManager multiUserChatLightManager = XMPPSession.getInstance().getMUCLightManager();
    try {
        MultiUserChatLight mucLight = multiUserChatLightManager.getMultiUserChatLight(JidCreate.from(chatJID).asEntityBareJidIfPossible());

        Jid jid = JidCreate.from(XMPPUtils.fromUserNameToJID(user.getLogin()));

        HashMap<Jid, MUCLightAffiliation> affiliations = new HashMap<>();
        affiliations.put(jid, MUCLightAffiliation.none);

        mucLight.changeAffiliations(affiliations);
    } catch (XmppStringprepException | InterruptedException | SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException.XMPPErrorException e) {
        e.printStackTrace();
    }
}
 
Example 10
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 11
Source File: OXSecretKeyBackupIntegrationTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
@SmackIntegrationTest
public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException,
        NoSuchProviderException, IOException, InterruptedException, PubSubException.NotALeafNodeException,
        SmackException.NoResponseException, SmackException.NotConnectedException, XMPPException.XMPPErrorException,
        SmackException.NotLoggedInException, SmackException.FeatureNotSupportedException,
        MissingUserIdOnKeyException, NoBackupFoundException, InvalidBackupCodeException, PGPException,
        MissingOpenPgpKeyException {

    OpenPgpStore beforeStore = new FileBasedOpenPgpStore(beforePath);
    beforeStore.setKeyRingProtector(new UnprotectedKeysProtector());
    PainlessOpenPgpProvider beforeProvider = new PainlessOpenPgpProvider(beforeStore);
    openPgpManager = OpenPgpManager.getInstanceFor(aliceConnection);
    openPgpManager.setOpenPgpProvider(beforeProvider);

    OpenPgpSelf self = openPgpManager.getOpenPgpSelf();

    assertNull(self.getSigningKeyFingerprint());

    OpenPgpV4Fingerprint keyFingerprint = openPgpManager.generateAndImportKeyPair(alice);
    assertEquals(keyFingerprint, self.getSigningKeyFingerprint());

    assertTrue(self.getSecretKeys().contains(keyFingerprint.getKeyId()));

    PGPSecretKeyRing beforeSec = beforeStore.getSecretKeyRing(alice, keyFingerprint);
    assertNotNull(beforeSec);

    PGPPublicKeyRing beforePub = beforeStore.getPublicKeyRing(alice, keyFingerprint);
    assertNotNull(beforePub);

    openPgpManager.backupSecretKeyToServer(new DisplayBackupCodeCallback() {
        @Override
        public void displayBackupCode(String backupCode) {
            OXSecretKeyBackupIntegrationTest.this.backupCode = backupCode;
        }
    }, new SecretKeyBackupSelectionCallback() {
        @Override
        public Set<OpenPgpV4Fingerprint> selectKeysToBackup(Set<OpenPgpV4Fingerprint> availableSecretKeys) {
            return availableSecretKeys;
        }
    });

    FileBasedOpenPgpStore afterStore = new FileBasedOpenPgpStore(afterPath);
    afterStore.setKeyRingProtector(new UnprotectedKeysProtector());
    PainlessOpenPgpProvider afterProvider = new PainlessOpenPgpProvider(afterStore);
    openPgpManager.setOpenPgpProvider(afterProvider);

    OpenPgpV4Fingerprint fingerprint = openPgpManager.restoreSecretKeyServerBackup(new AskForBackupCodeCallback() {
        @Override
        public String askForBackupCode() {
            return backupCode;
        }
    });

    assertEquals(keyFingerprint, fingerprint);

    assertTrue(self.getSecretKeys().contains(keyFingerprint.getKeyId()));

    assertEquals(keyFingerprint, self.getSigningKeyFingerprint());

    PGPSecretKeyRing afterSec = afterStore.getSecretKeyRing(alice, keyFingerprint);
    assertNotNull(afterSec);
    assertTrue(Arrays.equals(beforeSec.getEncoded(), afterSec.getEncoded()));

    PGPPublicKeyRing afterPub = afterStore.getPublicKeyRing(alice, keyFingerprint);
    assertNotNull(afterPub);
    assertTrue(Arrays.equals(beforePub.getEncoded(), afterPub.getEncoded()));
}
 
Example 12
Source File: AbstractTwoUsersOmemoIntegrationTest.java    From Smack with Apache License 2.0 4 votes vote down vote up
public AbstractTwoUsersOmemoIntegrationTest(SmackIntegrationTestEnvironment environment)
        throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
        SmackException.NoResponseException, TestNotPossibleException {
    super(environment);
}
 
Example 13
Source File: XMPPSession.java    From mangosta-android with Apache License 2.0 4 votes vote down vote up
public void unblockContacts(List<Jid> jids)
        throws XMPPException.XMPPErrorException, SmackException.NotConnectedException,
        InterruptedException, SmackException.NoResponseException {
    getBlockingCommandManager().unblockContacts(jids);
}
 
Example 14
Source File: XMPPSession.java    From mangosta-android with Apache License 2.0 4 votes vote down vote up
public void blockContacts(List<Jid> jids)
        throws XMPPException.XMPPErrorException, SmackException.NotConnectedException,
        InterruptedException, SmackException.NoResponseException {
    getBlockingCommandManager().blockContacts(jids);
}
 
Example 15
Source File: MoodManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
public void setMood(Mood mood)
        throws InterruptedException, SmackException.NotLoggedInException, SmackException.NoResponseException,
        SmackException.NotConnectedException, XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException {
    setMood(mood, null, null);
}
 
Example 16
Source File: FallbackIndicationManager.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Determine, whether or not a user supports Fallback Indications.
 *
 * @param jid BareJid of the user.
 * @return 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 userSupportsFallbackIndications(EntityBareJid jid)
        throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
        SmackException.NoResponseException {
    return ServiceDiscoveryManager.getInstanceFor(connection())
            .supportsFeature(jid, FallbackIndicationElement.NAMESPACE);
}
 
Example 17
Source File: OmemoManager.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Returns true, if the Server supports PEP.
 *
 * @param connection XMPPConnection
 * @param server domainBareJid of the server to test
 * @return true if server supports pep
 *
 * @throws XMPPException.XMPPErrorException if there was an XMPP error returned.
 * @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.
 */
public static boolean serverSupportsOmemo(XMPPConnection connection, DomainBareJid server)
        throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
        SmackException.NoResponseException {
    return ServiceDiscoveryManager.getInstanceFor(connection)
            .discoverInfo(server).containsFeature(PubSub.NAMESPACE);
}
 
Example 18
Source File: OmemoService.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Create an OMEMO KeyTransportElement.
 *
 * @see <a href="https://xmpp.org/extensions/xep-0384.html#usecases-keysend">XEP-0384: Sending a key</a>.
 *
 * @param managerGuard Initialized OmemoManager.
 * @param contactsDevices set of recipient devices.
 * @param key AES-Key to be transported.
 * @param iv initialization vector to be used with the key.
 *
 * @return a new key transport element
 *
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws UndecidedOmemoIdentityException if the list of recipients contains an undecided device
 * @throws CryptoFailedException if we are lacking some cryptographic algorithms
 * @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.
 */
OmemoMessage.Sent createKeyTransportElement(OmemoManager.LoggedInOmemoManager managerGuard,
                                            Set<OmemoDevice> contactsDevices,
                                            byte[] key,
                                            byte[] iv)
        throws InterruptedException, UndecidedOmemoIdentityException, CryptoFailedException,
        SmackException.NotConnectedException, SmackException.NoResponseException, IOException {
    return encrypt(managerGuard, contactsDevices, key, iv, null);
}
 
Example 19
Source File: OXSecretKeyBackupIntegrationTest.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * This integration test tests the basic secret key backup and restore functionality as described
 * in XEP-0373 §5.
 *
 * In order to simulate two different devices, we are using two {@link FileBasedOpenPgpStore} implementations
 * which point to different directories.
 *
 * First, Alice generates a fresh OpenPGP key pair.
 *
 * She then creates a backup of the key in her private PEP node.
 *
 * Now the {@link OpenPgpStore} implementation is replaced by another instance to simulate a different device.
 *
 * Then the secret key backup is restored from PubSub and the imported secret key is compared to the one in
 * the original store.
 *
 * Afterwards the private PEP node is deleted from PubSub and the storage directories are emptied.
 *
 * @see <a href="https://xmpp.org/extensions/xep-0373.html#synchro-pep">
 *     XEP-0373 §5: Synchronizing the Secret Key with a Private PEP Node</a>
 * @param environment TODO javadoc me please
 * @throws XMPPException.XMPPErrorException if there was an XMPP error returned.
 * @throws TestNotPossibleException if the test is not possible.
 * @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.
 */
public OXSecretKeyBackupIntegrationTest(SmackIntegrationTestEnvironment environment)
        throws XMPPException.XMPPErrorException, TestNotPossibleException, SmackException.NotConnectedException,
        InterruptedException, SmackException.NoResponseException {
    super(environment);
    if (!OpenPgpManager.serverSupportsSecretKeyBackups(aliceConnection)) {
        throw new TestNotPossibleException("Server does not support the 'whitelist' PubSub access model.");
    }
}
 
Example 20
Source File: OXInstantMessagingManager.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Determine, whether a contact announces support for XEP-0374: OpenPGP for XMPP: Instant Messaging.
 *
 * @param contact {@link OpenPgpContact} in question.
 * @return true if contact announces support, otherwise false.
 *
 * @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 boolean contactSupportsOxInstantMessaging(OpenPgpContact contact)
        throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException,
        SmackException.NoResponseException {
    return contactSupportsOxInstantMessaging(contact.getJid());
}