/** * Accept all TLS certificates. * <p> * <b>Warning:</b> Use with care. This method make the Connection use {@link AcceptAllTrustManager} and essentially * <b>invalidates all security guarantees provided by TLS</b>. Only use this method if you understand the * implications. * </p> * * @param builder a connection configuration builder. * @param <B> Type of the ConnectionConfiguration builder. * @throws NoSuchAlgorithmException * @throws KeyManagementException * @return the given builder. */ public static <B extends ConnectionConfiguration.Builder<B,?>> B acceptAllCertificates(B builder) throws NoSuchAlgorithmException, KeyManagementException { SSLContext context = SSLContext.getInstance(TLS); context.init(null, new TrustManager[] { new AcceptAllTrustManager() }, new SecureRandom()); builder.setCustomSSLContext(context); return builder; }
/** * Perform authentication using SASL EXTERNAL. Your XMPP service must support this * authentication mechanism. This method also calls {@link #addEnabledSaslMechanism(String)} with "EXTERNAL" as * argument. It also calls {@link #allowEmptyOrNullUsernames()} and {@link #setSecurityMode(ConnectionConfiguration.SecurityMode)} to * {@link SecurityMode#required}. * * @param sslContext custom SSLContext to be used. * @return a reference to this builder. */ public B performSaslExternalAuthentication(SSLContext sslContext) { if (!SASLAuthentication.isSaslMechanismRegistered(SASLMechanism.EXTERNAL)) { throw new IllegalArgumentException("SASL " + SASLMechanism.EXTERNAL + " is not registered"); } setCustomSSLContext(sslContext); throwIfEnabledSaslMechanismsSet(); allowEmptyOrNullUsernames(); setSecurityMode(SecurityMode.required); addEnabledSaslMechanism(SASLMechanism.EXTERNAL); saslMechanismsSealed = true; return getThis(); }
/** * Accept all TLS certificates. * <p> * <b>Warning:</b> Use with care. This method make the Connection use {@link AcceptAllTrustManager} and essentially * <b>invalidates all security guarantees provided by TLS</b>. Only use this method if you understand the * implications. * </p> * * @param builder a connection configuration builder. * @param <B> Type of the ConnectionConfiguration builder. * @throws NoSuchAlgorithmException * @throws KeyManagementException * @return the given builder. */ public static <B extends ConnectionConfiguration.Builder<B,?>> B acceptAllCertificates(B builder) throws NoSuchAlgorithmException, KeyManagementException { SSLContext context = SSLContext.getInstance(TLS); context.init(null, new TrustManager[] { new AcceptAllTrustManager() }, new SecureRandom()); builder.setCustomSSLContext(context); return builder; }
/** * Perform authentication using SASL EXTERNAL. Your XMPP service must support this * authentication mechanism. This method also calls {@link #addEnabledSaslMechanism(String)} with "EXTERNAL" as * argument. It also calls {@link #allowEmptyOrNullUsernames()} and {@link #setSecurityMode(ConnectionConfiguration.SecurityMode)} to * {@link SecurityMode#required}. * * @param sslContext custom SSLContext to be used. * @return a reference to this builder. */ public B performSaslExternalAuthentication(SSLContext sslContext) { if (!SASLAuthentication.isSaslMechanismRegistered(SASLMechanism.EXTERNAL)) { throw new IllegalArgumentException("SASL " + SASLMechanism.EXTERNAL + " is not registered"); } setCustomSSLContext(sslContext); throwIfEnabledSaslMechanismsSet(); allowEmptyOrNullUsernames(); setSecurityMode(SecurityMode.required); addEnabledSaslMechanism(SASLMechanism.EXTERNAL); saslMechanismsSealed = true; return getThis(); }