Guest User

Untitled

a guest
Dec 13th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. private void createSSLContext(Certificate certificate, XMPPTCPConnectionConfiguration.Builder builder) throws KeyStoreException,
  2. NoSuchAlgorithmException, KeyManagementException, UnrecoverableKeyException, CertificateException, IOException {
  3. KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
  4. trustStore.load(null, null);
  5. trustStore.setCertificateEntry("ca", certificate);
  6. TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  7. tmf.init(trustStore);
  8.  
  9. SSLContext sslContext = SSLContext.getInstance(TLSUtils.TLS);
  10. sslContext.init(null, tmf.getTrustManagers(), null);
  11. builder.setCustomSSLContext(sslContext);
  12. builder.setSocketFactory(sslContext.getSocketFactory());
  13. }
Add Comment
Please, Sign In to add comment