harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r992263 - in /harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main: java/org/apache/harmony/xnet/provider/jsse/ native/jsse/shared/
Date Fri, 03 Sep 2010 10:53:58 GMT
Author: odeakin
Date: Fri Sep  3 10:53:58 2010
New Revision: 992263

URL: http://svn.apache.org/viewvc?rev=992263&view=rev
Log:
Implement getLocalCertificates(), getLocalPrincipal() and getProtocol() on SSLSessionImpl.

Modified:
    harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java
    harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java
    harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java
    harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java
    harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSession.c

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java?rev=992263&r1=992262&r2=992263&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java
Fri Sep  3 10:53:58 2010
@@ -88,9 +88,9 @@ public class ClientHandshakeImpl extends
         } else if (parameters.getEnableSessionCreation()){    
             isResuming = false;
             session = new SSLSessionImpl(parameters.getSecureRandom());
-            session.protocol = ProtocolVersion.getLatestVersion(parameters
+            /*session.protocol = ProtocolVersion.getLatestVersion(parameters
                     .getEnabledProtocols());
-            recordProtocol.setVersion(session.protocol.version);
+            recordProtocol.setVersion(session.protocol.version);*/
         } else {
             fatalAlert(AlertProtocol.HANDSHAKE_FAILURE, "SSL Session may not be created ");
         }
@@ -105,9 +105,9 @@ public class ClientHandshakeImpl extends
         if (parameters.getEnableSessionCreation()){    
             isResuming = false;
             session = new SSLSessionImpl(parameters.getSecureRandom());
-            session.protocol = ProtocolVersion.getLatestVersion(parameters
+            /*session.protocol = ProtocolVersion.getLatestVersion(parameters
                     .getEnabledProtocols());
-            recordProtocol.setVersion(session.protocol.version);
+            recordProtocol.setVersion(session.protocol.version);*/
             startSession();
         } else {
             status = NOT_HANDSHAKING;
@@ -125,8 +125,8 @@ public class ClientHandshakeImpl extends
         } else {
             //cipher_suites = parameters.getEnabledCipherSuites();
         }
-        clientHello = new ClientHello(parameters.getSecureRandom(),
-                session.protocol.version, session.id, cipher_suites);
+        /*clientHello = new ClientHello(parameters.getSecureRandom(),
+                session.protocol.version, session.id, cipher_suites);*/
         session.clientRandom = clientHello.random;
         send(clientHello);
         status = NEED_UNWRAP;
@@ -224,9 +224,9 @@ public class ClientHandshakeImpl extends
                             isResuming = false;
                         } else if (!Arrays.equals(serverHello.session_id, clientHello.session_id))
{
                             isResuming = false;
-                        } else if (!session.protocol.equals(servProt)) {
+                        /*} else if (!session.protocol.equals(servProt)) {
                             fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
-                                    "Bad server hello protocol version");               
            
+                                    "Bad server hello protocol version");               
            */
                         } else if (!session.cipherSuite
                                 .equals(serverHello.cipher_suite)) {
                             fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
@@ -238,8 +238,8 @@ public class ClientHandshakeImpl extends
                             computerReferenceVerifyDataSSLv3(SSLv3Constants.server);
                         }
                     }
-                    session.protocol = servProt;
-                    recordProtocol.setVersion(session.protocol.version);
+                    //session.protocol = servProt;
+                    //recordProtocol.setVersion(session.protocol.version);
                     session.cipherSuite = serverHello.cipher_suite;
                     session.id = serverHello.session_id.clone();
                     session.serverRandom = serverHello.random;

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java?rev=992263&r1=992262&r2=992263&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParameters.java
Fri Sep  3 10:53:58 2010
@@ -46,12 +46,14 @@ import javax.net.ssl.X509TrustManager;
 public class SSLParameters {
 
     // default source of authentication keys
-    private static X509KeyManager defaultKeyManager;
+    private X509KeyManager defaultKeyManager;
     // default source of authentication trust decisions
-    private static X509TrustManager defaultTrustManager;
+    private X509TrustManager defaultTrustManager;
     // default SSL parameters
     private static SSLParameters defaultParameters;
 
+    private X509Certificate[] certChain;
+
     // client session context contains the set of reusable
     // client-side SSL sessions
     private SSLSessionContextImpl clientSessionContext;
@@ -219,10 +221,10 @@ public class SSLParameters {
         byte[] privateKeyDER = null;
 
         if (alias != null) {
-            X509Certificate[] certs = keyManager.getCertificateChain(alias);
-            if (certs.length != 0) {
+            certChain = keyManager.getCertificateChain(alias);
+            if (certChain.length != 0) {
                 try {
-                    keyCertDER = certs[0].getEncoded();
+                    keyCertDER = certChain[0].getEncoded();
                 } catch (CertificateEncodingException e) {
                     //TODO how to handle exceptions?
                     System.out.println("threw exception");
@@ -277,6 +279,13 @@ public class SSLParameters {
     }
 
     /**
+     * @return certificate chain
+     */
+    protected X509Certificate[] getCertificateChain() {
+        return certChain;
+    }
+
+    /**
      * @return secure random
      */
     protected SecureRandom getSecureRandom() {
@@ -467,6 +476,7 @@ public class SSLParameters {
         parameters.serverSessionContext = serverSessionContext;
         parameters.keyManager = keyManager;
         parameters.trustManager = trustManager;
+        if (certChain != null) parameters.certChain = certChain.clone();
         parameters.secureRandom = secureRandom;
 
         parameters.enabledProtocols = enabledProtocols;

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java?rev=992263&r1=992262&r2=992263&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java
Fri Sep  3 10:53:58 2010
@@ -134,7 +134,7 @@ public class SSLSessionImpl implements S
     /**
      * Protocol used in the session
      */
-    ProtocolVersion protocol;
+    String protocol;
 
     /**
      * CipherSuite used in the session
@@ -254,7 +254,13 @@ public class SSLSessionImpl implements S
             id = new byte[0];
         } else {
             SSL_SESSION = initialiseSession(SSL);
-            cipherName = getCipherNameImpl(SSL);
+
+            // Get back the cipher name with protocol prefixed
+            // Expected to be in the format "<protocol>:<cipher_name>"
+            String[] tokens = getCipherNameImpl(SSL).split(":");
+            protocol = tokens[0];
+            cipherName = tokens[1];
+
             creationTime = getCreationTimeImpl(SSL_SESSION);
 
             id = new byte[32];
@@ -267,6 +273,7 @@ public class SSLSessionImpl implements S
         }
 
         lastAccessedTime = creationTime;
+        localCertificates = parms.getCertificateChain();
     }
 
     public int getApplicationBufferSize() {
@@ -289,12 +296,10 @@ public class SSLSessionImpl implements S
         return lastAccessedTime;
     }
 
-    // TODO: implement
     public Certificate[] getLocalCertificates() {
         return localCertificates;
     }
     
-    // TODO: implement
     public Principal getLocalPrincipal() {
         if (localCertificates != null && localCertificates.length > 0) {
             return localCertificates[0].getSubjectX500Principal();
@@ -350,9 +355,8 @@ public class SSLSessionImpl implements S
         return peerCertificates[0].getSubjectX500Principal();
     }
 
-    // TODO: implement
     public String getProtocol() {
-        return protocol.name;
+        return protocol;
     }
 
     // TODO: implement

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java?rev=992263&r1=992262&r2=992263&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java
Fri Sep  3 10:53:58 2010
@@ -431,7 +431,7 @@ public class ServerHandshakeImpl extends
         }
 
         recordProtocol.setVersion(clientHello.client_version);
-        session.protocol = ProtocolVersion.getByVersion(clientHello.client_version);
+        //session.protocol = ProtocolVersion.getByVersion(clientHello.client_version);
         session.clientRandom = clientHello.random;
         
         // create server hello message

Modified: harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSession.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSession.c?rev=992263&r1=992262&r2=992263&view=diff
==============================================================================
--- harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSession.c
(original)
+++ harmony/enhanced/java/branches/omd/classlib/modules/x-net/src/main/native/jsse/shared/sslSession.c
Fri Sep  3 10:53:58 2010
@@ -45,26 +45,35 @@ char* getSpecName(const char *cipherName
 JNIEXPORT jstring JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSessionImpl_getCipherNameImpl
   (JNIEnv *env, jobject object, jlong jssl) {
     SSL *ssl = jlong2addr(SSL, jssl);
-    const SSL_CIPHER *cipher;
     const char *cipherName = SSL_get_cipher(ssl);
     char *protocol = SSL_get_cipher_version(ssl);
     char *specName = NULL;
+    char *finalName;
 
     if (!strcmp(protocol, "TLSv1/SSLv3")) {
         // We're in either TLS or SSLv3, now find the spec name
         specName = getSpecName(cipherName, getTLSv1OpenSSLNames(), getTLSv1SpecNames(), TLSv1_CIPHER_COUNT);
-        if (!specName) {
+        if (specName) {
+            protocol = "TLSv1";
+        } else {
             // Not in the TLS list, now search the SSL list
             // TODO: Lists are likely to be the same - can this case ever occur?
             specName = getSpecName(cipherName, getSSLv3OpenSSLNames(), getSSLv3SpecNames(),
SSLv3_CIPHER_COUNT);
+            protocol = "SSLv3";
         }
     } else {
-        // SSLv2 case
+        // SSLv2 case - protocol will already be "SSLv2", so no need to set it
         specName = getSpecName(cipherName, getSSLv2OpenSSLNames(), getSSLv2SpecNames(), SSLv2_CIPHER_COUNT);
     }
 
-    cipher = SSL_get_current_cipher(ssl);
-    return (*env)->NewStringUTF(env, specName);
+    // finalName is "protocol:specName\0"
+    // protocol length is always 5, so allocate strlen(specName) + 5 + 1 for the colon +
1 for the terminator
+    finalName = malloc(strlen(specName)+7);
+    strcpy(finalName, protocol);
+    strcat(finalName, ":");
+    strcat(finalName, specName);
+
+    return (*env)->NewStringUTF(env, finalName);
 }
 
 JNIEXPORT jlong JNICALL Java_org_apache_harmony_xnet_provider_jsse_SSLSessionImpl_getCreationTimeImpl



Mime
View raw message