Quantcast
Viewing all articles
Browse latest Browse all 12000

Re: How can I use SecurityMode.enabled? (aSmack 4.0.0)

This is how I did it:

publicclass ContextService {     publicstatic SSLContext createContext() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {        KeyStore trustStore;        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {            trustStore = KeyStore.getInstance("AndroidCAStore");        }else{            trustStore = KeyStore.getInstance("BKS");        }         TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());        trustManagerFactory.init(trustStore);        SSLContext sslContext = SSLContext.getInstance("TLS");        sslContext.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());        return sslContext;    }}

 

ConnectionConfiguration configuration = new ConnectionConfiguration(ExtraConstants.MSG_HOST, PORT, ExtraConstants.SERVICE);
configuration.setSecurityMode(SecurityMode.required);
configuration.setCustomSSLContext(ContextService.createContext());

I have a certificate that is signed by GoDaddy so it's a valid one, no need to use a self signed.

Hope that helps, I'm not 100% sure if that's the right way to do it, but after a lot of research it seems to be.


Viewing all articles
Browse latest Browse all 12000

Trending Articles