diff options
author | Brian Carlstrom <bdc@google.com> | 2010-05-18 13:45:26 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2010-05-18 14:37:31 -0700 |
commit | a653cca054f36de92bbef8498be3f0f01d9d6119 (patch) | |
tree | 0b96f909d808884abe4730b7d35533a7c2659d7b | |
parent | f58ed6726cd84346979261432130eb5d9ee48a3b (diff) | |
download | libcore-a653cca054f36de92bbef8498be3f0f01d9d6119.zip libcore-a653cca054f36de92bbef8498be3f0f01d9d6119.tar.gz libcore-a653cca054f36de92bbef8498be3f0f01d9d6119.tar.bz2 |
SSLSocketFactory.connect(Socket...) should allow port of -1
SSLSession.getPeerPort is supposed to return -1 when the port is
undefined so now we initialize it to that value.
luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java
Avoid creating InetAddress to store the OpenSSLSessionImplWrapper host
and port arguments since it was causing an exception on an port value
of -1 and was just used to go back to the original host and port when
creating the SSLSession, which is allowed to return a port value of -1.
luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
Remove last of KnownFailures for SSLSocketFactory
luni/src/test/java/javax/net/ssl/SSLSocketFactoryTest.java
Update classpath for newly seperated out junit jars
run-core-tests
Change-Id: I646a8f23c3d6ae01f1dd38e40bc9c32d436e6254
4 files changed, 20 insertions, 13 deletions
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java index b889e7d..14ccea2 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java @@ -51,7 +51,7 @@ public class OpenSSLSessionImpl implements SSLSession { private javax.security.cert.X509Certificate[] peerCertificateChain; protected int sslSessionNativePointer; private String peerHost; - private int peerPort; + private int peerPort = -1; private String cipherSuite; private String protocol; private AbstractSessionContext sessionContext; @@ -203,16 +203,22 @@ public class OpenSSLSessionImpl implements SSLSession { * not X509 certificate was used (i.e. Kerberos certificates) or the * peer could not be verified. */ - public javax.security.cert.X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException { + public javax.security.cert.X509Certificate[] getPeerCertificateChain() + throws SSLPeerUnverifiedException { if (peerCertificateChain == null) { try { - byte[][] bytes = NativeCrypto.SSL_SESSION_get_peer_cert_chain(sessionContext.sslCtxNativePointer, sslSessionNativePointer); - if (bytes == null) throw new SSLPeerUnverifiedException("No certificate available"); + byte[][] bytes + = NativeCrypto.SSL_SESSION_get_peer_cert_chain( + sessionContext.sslCtxNativePointer, sslSessionNativePointer); + if (bytes == null) { + throw new SSLPeerUnverifiedException("No certificate available"); + } peerCertificateChain = new javax.security.cert.X509Certificate[bytes.length]; for(int i = 0; i < bytes.length; i++) { - peerCertificateChain[i] = javax.security.cert.X509Certificate.getInstance(bytes[i]); + peerCertificateChain[i] + = javax.security.cert.X509Certificate.getInstance(bytes[i]); } return peerCertificateChain; diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java index a58d74e..61c1bdc 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java @@ -77,7 +77,8 @@ public class OpenSSLSocketImpl // BEGIN android-added private int handshakeTimeout = -1; // -1 = same as timeout; 0 = infinite // END android-added - private InetSocketAddress address; + private String wrappedHost; + private int wrappedPort; private static final AtomicInteger instanceCount = new AtomicInteger(0); @@ -170,7 +171,7 @@ public class OpenSSLSocketImpl /** * Constructor with 5 parameters: 1st is socket. Enhances an existing socket - * with SSL functionality. + * with SSL functionality. Invoked via OpenSSLSocketImplWrapper constructor. * * @throws IOException if network fails */ @@ -179,7 +180,8 @@ public class OpenSSLSocketImpl super(); this.socket = socket; this.timeout = socket.getSoTimeout(); - this.address = new InetSocketAddress(host, port); + this.wrappedHost = host; + this.wrappedPort = port; this.autoClose = autoClose; init(sslParameters); } @@ -411,13 +413,13 @@ public class OpenSSLSocketImpl } } - if (address == null) { + if (wrappedHost == null) { sslSession = new OpenSSLSessionImpl(sslSessionNativePointer, localCertificates, super.getInetAddress().getHostName(), super.getPort(), sessionContext); } else { sslSession = new OpenSSLSessionImpl(sslSessionNativePointer, localCertificates, - address.getHostName(), address.getPort(), + wrappedHost, wrappedPort, sessionContext); } // putSession will be done later in handshakeCompleted() callback diff --git a/luni/src/test/java/javax/net/ssl/SSLSocketFactoryTest.java b/luni/src/test/java/javax/net/ssl/SSLSocketFactoryTest.java index 15e2e71..92c4cb4 100644 --- a/luni/src/test/java/javax/net/ssl/SSLSocketFactoryTest.java +++ b/luni/src/test/java/javax/net/ssl/SSLSocketFactoryTest.java @@ -16,7 +16,6 @@ package javax.net.ssl; -import dalvik.annotation.KnownFailure; import java.net.Socket; import java.net.SocketException; import java.net.ServerSocket; @@ -78,7 +77,6 @@ public class SSLSocketFactoryTest extends TestCase { assertEquals(StandardNames.CIPHER_SUITES.size(), cipherSuites.length); } - @KnownFailure("Should not parse bogus port number -1 during createSocket") public void test_SSLSocketFactory_createSocket() throws Exception { try { SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault(); diff --git a/run-core-tests b/run-core-tests index 893b0d6..80570f8d 100755 --- a/run-core-tests +++ b/run-core-tests @@ -24,7 +24,8 @@ mkdir $tmp chmod 777 $tmp # Build the classpath by putting together the jar file for each module. -classpath="/system/framework/sqlite-jdbc.jar" # Bonus item for jdbc testing. +classpath="/system/framework/core-junit.jar:/system/framework/core-junitrunner.jar" +classpath="$classpath:/system/framework/sqlite-jdbc.jar" # Bonus item for jdbc testing. modules="dom json luni support xml" for module in $modules; do classpath="$classpath:/system/framework/core-tests-$module.jar" |