Search in sources :

Example 36 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class XmppConnectionManager method getConnectedMainConnectionFor.

private AbstractXMPPConnection getConnectedMainConnectionFor(AccountNum accountNum) throws SmackException, IOException, XMPPException, InterruptedException, KeyManagementException, NoSuchAlgorithmException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    String middlefix;
    String accountUsername;
    String accountPassword;
    switch(accountNum) {
        case One:
            accountUsername = sinttestConfiguration.accountOneUsername;
            accountPassword = sinttestConfiguration.accountOnePassword;
            middlefix = "one";
            break;
        case Two:
            accountUsername = sinttestConfiguration.accountTwoUsername;
            accountPassword = sinttestConfiguration.accountTwoPassword;
            middlefix = "two";
            break;
        case Three:
            accountUsername = sinttestConfiguration.accountThreeUsername;
            accountPassword = sinttestConfiguration.accountThreePassword;
            middlefix = "three";
            break;
        default:
            throw new IllegalStateException();
    }
    // Note that it is perfectly fine for account(Username|Password) to be 'null' at this point.
    final String finalAccountUsername = StringUtils.isNullOrEmpty(accountUsername) ? USERNAME_PREFIX + '-' + middlefix + '-' + testRunId : accountUsername;
    final String finalAccountPassword = StringUtils.isNullOrEmpty(accountPassword) ? StringUtils.insecureRandomString(16) : accountPassword;
    if (sinttestConfiguration.isAccountRegistrationPossible()) {
        registerAccount(finalAccountUsername, finalAccountPassword);
    }
    AbstractXMPPConnection mainConnection = defaultConnectionDescriptor.construct(sinttestConfiguration, builder -> {
        try {
            builder.setUsernameAndPassword(finalAccountUsername, finalAccountPassword).setResource(middlefix + '-' + testRunId);
        } catch (XmppStringprepException e) {
            throw new IllegalArgumentException(e);
        }
    });
    connections.put(mainConnection, defaultConnectionDescriptor);
    mainConnection.connect();
    mainConnection.login();
    return mainConnection;
}
Also used : XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Example 37 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class SmackIntegrationTestXmppConnectionManagerTest method simpleXmppConnectionDescriptorTest.

@Test
public void simpleXmppConnectionDescriptorTest() throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, KeyManagementException, NoSuchAlgorithmException, XmppStringprepException, InstantiationException {
    XmppConnectionDescriptor<ModularXmppClientToServerConnection, ModularXmppClientToServerConnectionConfiguration, ModularXmppClientToServerConnectionConfiguration.Builder> descriptor = XmppConnectionDescriptor.buildWith(ModularXmppClientToServerConnection.class, ModularXmppClientToServerConnectionConfiguration.class, ModularXmppClientToServerConnectionConfiguration.Builder.class).applyExtraConfguration(b -> b.removeAllModules().addModule(XmppTcpTransportModuleDescriptor.class)).build();
    Configuration sinttestConfiguration = Configuration.builder().setService("example.org").build();
    ModularXmppClientToServerConnection connection = descriptor.construct(sinttestConfiguration);
    assertEquals("example.org", connection.getXMPPServiceDomain().toString());
}
Also used : Test(org.junit.jupiter.api.Test) XmppTcpTransportModuleDescriptor(org.jivesoftware.smack.tcp.XmppTcpTransportModuleDescriptor) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) ModularXmppClientToServerConnectionConfiguration(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) KeyManagementException(java.security.KeyManagementException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ModularXmppClientToServerConnection(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection) ModularXmppClientToServerConnectionConfiguration(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration) ModularXmppClientToServerConnectionConfiguration(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration) ModularXmppClientToServerConnection(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection) Test(org.junit.jupiter.api.Test)

Example 38 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class RTPBridge method getPublicIP.

/**
 * Get Public Address from the Server.
 *
 * @param xmppConnection TODO javadoc me please
 * @return public IP String or null if not found
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 */
public static String getPublicIP(XMPPConnection xmppConnection) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
    if (!xmppConnection.isConnected()) {
        return null;
    }
    RTPBridge rtpPacket = new RTPBridge(RTPBridge.BridgeAction.publicip);
    DomainBareJid jid;
    try {
        jid = JidCreate.domainBareFrom(RTPBridge.NAME + "." + xmppConnection.getXMPPServiceDomain());
    } catch (XmppStringprepException e) {
        throw new AssertionError(e);
    }
    rtpPacket.setTo(jid);
    rtpPacket.setType(Type.set);
    // LOGGER.debug("Relayed to: " + candidate.getIp() + ":" + candidate.getPort());
    RTPBridge response = xmppConnection.sendIqRequestAndWaitForResponse(rtpPacket);
    if (response == null)
        return null;
    if (response.getIp() == null || response.getIp().equals(""))
        return null;
    Enumeration<NetworkInterface> ifaces = null;
    try {
        ifaces = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
    while (ifaces != null && ifaces.hasMoreElements()) {
        NetworkInterface iface = ifaces.nextElement();
        Enumeration<InetAddress> iaddresses = iface.getInetAddresses();
        while (iaddresses.hasMoreElements()) {
            InetAddress iaddress = iaddresses.nextElement();
            if (!iaddress.isLoopbackAddress())
                if (iaddress.getHostAddress().indexOf(response.getIp()) >= 0)
                    return null;
        }
    }
    return response.getIp();
}
Also used : SocketException(java.net.SocketException) NetworkInterface(java.net.NetworkInterface) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) DomainBareJid(org.jxmpp.jid.DomainBareJid) InetAddress(java.net.InetAddress)

Example 39 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class STUN method getSTUNServer.

/**
 * Get a new STUN Server Address and port from the server.
 * If a error occurs or the server don't support STUN Service, null is returned.
 *
 * @param connection TODO javadoc me please
 * @return the STUN server address
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 */
public static STUN getSTUNServer(XMPPConnection connection) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException {
    if (!connection.isConnected()) {
        return null;
    }
    STUN stunPacket = new STUN();
    DomainBareJid jid;
    try {
        jid = JidCreate.domainBareFrom(DOMAIN + "." + connection.getXMPPServiceDomain());
    } catch (XmppStringprepException e) {
        throw new AssertionError(e);
    }
    stunPacket.setTo(jid);
    STUN response = connection.sendIqRequestAndWaitForResponse(stunPacket);
    return response;
}
Also used : XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 40 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Smack by igniterealtime.

the class SignalOmemoStoreConnector method loadSession.

@Override
public SessionRecord loadSession(SignalProtocolAddress signalProtocolAddress) {
    OmemoDevice device;
    try {
        device = asOmemoDevice(signalProtocolAddress);
    } catch (XmppStringprepException e) {
        throw new AssertionError(e);
    }
    SessionRecord record;
    try {
        record = omemoStore.loadRawSession(getOurDevice(), device);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    if (record != null) {
        return record;
    } else {
        return new SessionRecord();
    }
}
Also used : OmemoDevice(org.jivesoftware.smackx.omemo.internal.OmemoDevice) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) IOException(java.io.IOException) SessionRecord(org.whispersystems.libsignal.state.SessionRecord)

Aggregations

XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)76 DomainBareJid (org.jxmpp.jid.DomainBareJid)20 SmackException (org.jivesoftware.smack.SmackException)18 Jid (org.jxmpp.jid.Jid)18 EntityBareJid (org.jxmpp.jid.EntityBareJid)16 AccountJid (com.xabber.android.data.entity.AccountJid)12 XMPPException (org.jivesoftware.smack.XMPPException)12 UserJid (com.xabber.android.data.entity.UserJid)11 BareJid (org.jxmpp.jid.BareJid)9 Resourcepart (org.jxmpp.jid.parts.Resourcepart)9 ArrayList (java.util.ArrayList)8 Localpart (org.jxmpp.jid.parts.Localpart)8 Cursor (android.database.Cursor)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 HashMap (java.util.HashMap)5 SwingWorker (org.jivesoftware.spark.util.SwingWorker)5 IOException (java.io.IOException)4 KeyManagementException (java.security.KeyManagementException)4 NetworkException (com.xabber.android.data.NetworkException)3 InetAddress (java.net.InetAddress)3