Example usage for android.net SSLCertificateSocketFactory getDefault

List of usage examples for android.net SSLCertificateSocketFactory getDefault

Introduction

In this page you can find the example usage for android.net SSLCertificateSocketFactory getDefault.

Prototype

public static SSLSocketFactory getDefault(int handshakeTimeoutMillis, SSLSessionCache cache) 

Source Link

Document

Returns a new socket factory instance with an optional handshake timeout and SSL session cache.

Usage

From source file:Main.java

/**
 * Returns a {@link javax.net.ssl.SSLSocketFactory}.
 * Optionally bypass all SSL certificate checks.
 *
 * @param insecure if true, bypass all SSL certificate checks
 *//*from   ww w .  j  a  va 2s .c o  m*/
public synchronized static SSLCertificateSocketFactory getSSLSocketFactory(boolean insecure) {
    if (insecure) {
        if (sInsecureFactory == null) {
            sInsecureFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getInsecure(0, null);
        }
        return sInsecureFactory;
    } else {
        if (sSecureFactory == null) {
            sSecureFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(0, null);
        }
        return sSecureFactory;
    }
}

From source file:org.mariotaku.twidere.util.net.HostResolvedSSLSocketFactory.java

public HostResolvedSSLSocketFactory(HostAddressResolver resolver, boolean ignoreError) {
    if (ignoreError) {
        defaultFactory = SSLCertificateSocketFactory.getInsecure(0, null);
    } else {//from  w w w . j  ava 2s .c o  m
        defaultFactory = SSLCertificateSocketFactory.getDefault(0, null);
    }
    this.resolver = resolver;
}

From source file:net.sileht.lullaby.Utils.java

public static void setSSLCheck(Boolean insecure) {
    if (insecure) {
        HttpsURLConnection.setDefaultSSLSocketFactory(SSLCertificateSocketFactory.getInsecure(-1, null));
        HttpsURLConnection.setDefaultHostnameVerifier(
                org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    } else {//from ww w.  j  a  va  2s. co m
        HttpsURLConnection.setDefaultSSLSocketFactory(SSLCertificateSocketFactory.getDefault(-1, null));
        HttpsURLConnection.setDefaultHostnameVerifier(
                org.apache.http.conn.ssl.SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    }
}

From source file:com.android.emailcommon.utility.SSLUtils.java

/**
 * Returns a {@link javax.net.ssl.SSLSocketFactory}.
 * Optionally bypass all SSL certificate checks.
 *
 * @param insecure if true, bypass all SSL certificate checks
 */// www  .  j  a  v a2s. c o  m
public synchronized static SSLCertificateSocketFactory getSSLSocketFactory(Context context, HostAuth hostAuth,
        boolean insecure) {
    if (insecure) {
        SSLCertificateSocketFactory insecureFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory
                .getInsecure(0, null);
        insecureFactory.setTrustManagers(
                new TrustManager[] { new SameCertificateCheckingTrustManager(context, hostAuth) });
        return insecureFactory;
    } else {
        if (sSecureFactory == null) {
            sSecureFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(0, null);
        }
        return sSecureFactory;
    }
}

From source file:org.tigase.messenger.phone.pro.service.XMPPService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.i("XMPPService", "Service started");

    getApplication().registerActivityLifecycleCallbacks(mActivityCallbacks);

    this.ownPresenceStanzaFactory = new OwnPresenceFactoryImpl();
    this.dbHelper = DatabaseHelper.getInstance(this);
    this.connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    this.dataRemover = new DataRemover(this.dbHelper);

    SSLSessionCache sslSessionCache = new SSLSessionCache(this);
    this.sslSocketFactory = SSLCertificateSocketFactory.getDefault(0, sslSessionCache);

    this.rosterProvider = new RosterProviderExt(this, dbHelper, new RosterProviderExt.Listener() {
        @Override//from ww w  .j  a  v  a  2  s  .c  o  m
        public void onChange(Long rosterItemId) {
            Uri uri = rosterItemId != null ? ContentUris.withAppendedId(RosterProvider.ROSTER_URI, rosterItemId)
                    : RosterProvider.ROSTER_URI;

            Log.i(TAG, "Content change: " + uri);
            getApplicationContext().getContentResolver().notifyChange(uri, null);

        }
    }, "roster_version");
    rosterProvider.resetStatus();

    this.mobileModeFeature = new MobileModeFeature(this);

    this.presenceHandler = new PresenceHandler(this);
    this.messageHandler = new MessageHandler(this);
    this.chatProvider = new org.tigase.messenger.jaxmpp.android.chat.ChatProvider(this, dbHelper,
            new org.tigase.messenger.jaxmpp.android.chat.ChatProvider.Listener() {
                @Override
                public void onChange(Long chatId) {
                    Uri uri = chatId != null ? ContentUris.withAppendedId(ChatProvider.OPEN_CHATS_URI, chatId)
                            : ChatProvider.OPEN_CHATS_URI;
                    getApplicationContext().getContentResolver().notifyChange(uri, null);
                }
            });
    chatProvider.resetRoomState(CPresence.OFFLINE);
    this.mucHandler = new MucHandler();
    this.capsCache = new CapabilitiesDBCache(dbHelper);

    IntentFilter screenStateReceiverFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    screenStateReceiverFilter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(screenStateReceiver, screenStateReceiverFilter);

    registerReceiver(presenceChangedReceiver, new IntentFilter(CLIENT_PRESENCE_CHANGED_ACTION));

    registerReceiver(connReceiver, new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"));

    multiJaxmpp.addHandler(
            StreamManagementModule.StreamManagementFailedHandler.StreamManagementFailedEvent.class,
            new StreamManagementModule.StreamManagementFailedHandler() {
                @Override
                public void onStreamManagementFailed(final SessionObject sessionObject,
                        XMPPException.ErrorCondition condition) {
                    if (condition != null && condition.getElementName().equals("item-not-found")) {
                        XMPPService.this.rosterProvider.resetStatus(sessionObject);
                    }
                }
            });
    multiJaxmpp.addHandler(DiscoveryModule.ServerFeaturesReceivedHandler.ServerFeaturesReceivedEvent.class,
            streamHandler);
    multiJaxmpp.addHandler(JaxmppCore.LoggedInHandler.LoggedInEvent.class, jaxmppConnectedHandler);
    multiJaxmpp.addHandler(JaxmppCore.LoggedOutHandler.LoggedOutEvent.class, jaxmppDisconnectedHandler);
    // multiJaxmpp.addHandler(SocketConnector.ErrorHandler.ErrorEvent.class,
    // );
    //
    // this.connectorListener = new Connector.ErrorHandler() {
    //
    // @Override
    // public void onError(SessionObject sessionObject, StreamError
    // condition, Throwable caught) throws JaxmppException {
    // AbstractSocketXmppSessionLogic.this.processConnectorErrors(condition,
    // caught);
    // }
    // };
    multiJaxmpp.addHandler(PresenceModule.ContactAvailableHandler.ContactAvailableEvent.class, presenceHandler);
    multiJaxmpp.addHandler(PresenceModule.ContactUnavailableHandler.ContactUnavailableEvent.class,
            presenceHandler);
    multiJaxmpp.addHandler(PresenceModule.ContactChangedPresenceHandler.ContactChangedPresenceEvent.class,
            presenceHandler);
    multiJaxmpp.addHandler(PresenceModule.SubscribeRequestHandler.SubscribeRequestEvent.class,
            subscribeHandler);

    multiJaxmpp.addHandler(MessageModule.MessageReceivedHandler.MessageReceivedEvent.class, messageHandler);
    multiJaxmpp.addHandler(MessageCarbonsModule.CarbonReceivedHandler.CarbonReceivedEvent.class,
            messageHandler);
    multiJaxmpp.addHandler(ChatStateExtension.ChatStateChangedHandler.ChatStateChangedEvent.class,
            messageHandler);
    multiJaxmpp.addHandler(AuthModule.AuthFailedHandler.AuthFailedEvent.class,
            new AuthModule.AuthFailedHandler() {

                @Override
                public void onAuthFailed(SessionObject sessionObject, SaslModule.SaslError error)
                        throws JaxmppException {
                    processAuthenticationError((Jaxmpp) multiJaxmpp.get(sessionObject));
                }
            });

    multiJaxmpp.addHandler(MucModule.MucMessageReceivedHandler.MucMessageReceivedEvent.class, mucHandler);
    multiJaxmpp.addHandler(MucModule.MessageErrorHandler.MessageErrorEvent.class, mucHandler);
    multiJaxmpp.addHandler(MucModule.YouJoinedHandler.YouJoinedEvent.class, mucHandler);
    multiJaxmpp.addHandler(MucModule.StateChangeHandler.StateChangeEvent.class, mucHandler);
    multiJaxmpp.addHandler(MucModule.PresenceErrorHandler.PresenceErrorEvent.class, mucHandler);

    IntentFilter filterAccountModifyReceiver = new IntentFilter();
    filterAccountModifyReceiver.addAction(LoginActivity.ACCOUNT_MODIFIED_MSG);
    filterAccountModifyReceiver.addAction(AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION);
    registerReceiver(accountModifyReceiver, filterAccountModifyReceiver);

    startKeepAlive();

    updateJaxmppInstances();
    // connectAllJaxmpp();
}