Hi

I'm running a webserver on the android. Now it's time to get HTTPS
running. I've created a BKS keystor and placed it under res/raw. Now I
want to create an SSL socket using this certificate. But it failes
when it comes to get the keymanagers from the KeyManagerFactory. I
only get an empty list of KeyManagers.

I think the problem is the same at this Discussion (but no answer
yet):
http://groups.google.com/group/android-developers/browse_thread/thread/27d82082e0a0b0f0/4d1ecd76964a086c?show_docid=4d1ecd76964a086c
(I'll spread the answer if I can find it.)

Does anybody know how to setup an SSL server socket on an Android?

Here's my code snipped:
---------------------------

        protected static ServerSocketFactory createSSLSocketFactory(Context
context, InputStream keyStoreData, char[] passPhrase) throws
IOException {

                KeyManagerFactory kmf;
                KeyStore keyStore;
                ServerSocketFactory socketFactory;

                try {

                        // default type: BKS
                        keyStore = KeyStore.getInstance 
(KeyStore.getDefaultType());
                        keyStore.load(keyStoreData,passPhrase);
                        keyStoreData.close();

                        // default algorithm: X509
                        kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                        kmf.init(keyStore, passPhrase);
                        KeyManager[] keyManagers = kmf.getKeyManagers();

                        SSLContext sc = SSLContext.getInstance("TLS");
                        TrustManagerFactory tmf = 
TrustManagerFactory.getInstance("X509");
                        tmf.init(keyStore);
                        sc.init(keyManagers, tmf.getTrustManagers(), new
java.security.SecureRandom());

                        socketFactory = sc.getServerSocketFactory();
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new IOException(e.getMessage());
                }
                return socketFactory;
        }
----------

Here is the content of the kmf object (KeyManagerFactory) after
initialization from keystore data resource. Maybe initialization
failed / the keystore data is not correct?

----------

kmf     KeyManagerFactory
        algorithm       "X509"
        provider        JSSEProvider
        spiImpl KeyManagerFactoryImpl
                keyStore        KeyStore
                        implSpi JDKKeyStore
                                random  SecureRandom
                                table   Hashtable
                                        entrySet        null
                                        keySet  null
                                        modCount        1
                                        size    1
                                        table   Hashtable$HashtableEntry[4]
                                                [0]     null
                                                [1]     null
                                                [2]     null
                                                [3]     Hashtable$HashtableEntry
                                                        hash    51
                                                        key     " (id=...)"
                                                        next    null
                                                        value   
JDKKeyStore$StoreEntry
                                                                alias   "0"
                                                                certChain       
null
                                                                date    Date
                                                                obj     
X509CertificateObject
                                                                        c       
X509CertificateStructure
                                                                        
encodedOut      null
                                                                        pkcs12  
OrderedTable
                                                                                
key0    null
                                                                                
key1    null
                                                                                
key2    null
                                                                                
key3    null
                                                                                
rest    null
                                                                                
size    0
                                                                                
value0  null
                                                                                
value1  null
                                                                                
value2  null
                                                                                
value3  null
                                                                        type    
"X.509"
                                                                this$0  
JDKKeyStore
                                                                type    1
                                        threshold       3
                                        values  null
                        isInit  true
                        provider        BouncyCastleProvider
                        type    "BKS"
                pwd

----------

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to