Results 1 to 5 of 5
  1. #1

    using a Self Signed SSL on Android Client

    When trying to connect to our client's LS server, we receive the error described in this android dev document:
    http://developer.android.com/trainin...CommonProblems

    We are attempting to solve it using their proposed solution- registering the cert in the applications custom TrustManager.
    This example is also from the dev doc referenced above:

    Code:
    // Load CAs from an InputStream
    // (could be from a resource or ByteArrayInputStream or ...)
    CertificateFactory cf =CertificateFactory.getInstance("X.509");
    
    InputStream caInput =newBufferedInputStream(newFileInputStream("local.cer"));
    Certificate ca;
    try{
        ca = cf.generateCertificate(caInput);
        System.out.println("ca="+((X509Certificate) ca).getSubjectDN());
    }finally{
        caInput.close();
    }
    
    // Create a KeyStore containing our trusted CAs
    String keyStoreType =KeyStore.getDefaultType();
    KeyStore keyStore =KeyStore.getInstance(keyStoreType);
    keyStore.load(null,null);
    keyStore.setCertificateEntry("ca", ca);
    
    // Create a TrustManager that trusts the CAs in our KeyStore
    String tmfAlgorithm =TrustManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory tmf =TrustManagerFactory.getInstance(tmfAlgorithm);
    tmf.init(keyStore);
    
    // Create an SSLContext that uses our TrustManager
    SSLContext context =SSLContext.getInstance("TLS");
    context.init(null, tmf.getTrustManagers(),null);
    
    Uaually the SSLContext is provided to a UriConnection...

    Code:
    // Tell the URLConnection to use a SocketFactory from our SSLContext
    URL url =new URL("https://certs.cac.washington.edu/CAtest/");
    HttpsURLConnection urlConnection =
        (HttpsURLConnection)url.openConnection();
    urlConnection.setSSLSocketFactory(context.getSocketFactory());
    How do we get android's LSClient to use this SSLContext which is aware of our self signed cert? Or, is there a way to get our application to use some sort of globally provided HttpsURLConnection?

  2. #2
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    541
    Hi Patrick,

    Have you tried to change the default factory for ordinary sockets before calling the openConnection() method of Lightstreamer library?

    Code:
    Socket.setSocketImplFactory(context.getSocketFactory());

  3. #3
    This looks close to what I need, but context.getSocketFactory() is an instance of javax.net.ssl.SSLSocketFactory, and Socket.setSocketImplFactory() expects a java.net.SocketImplFactory. I cannot cast them.

    Any idea what I am missing?

  4. #4
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    541
    Ok sorry, please can you try something like this:

    Code:
    HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());

  5. #5
    That's what I'm looking for. Thank you for the assistance.

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 12:54 AM.