X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FTinySSL.java;h=637e41c7d15064f7ce8f1e90fa42fba172261f9d;hb=937a064e3217ad35dff63cabf16f5df67dfa0954;hp=41e83a15ab433a2b97cb2386c97314b363144bcb;hpb=2df69a25b28946ac1c45dbd819facaa7fe14f6e1;p=org.ibex.core.git diff --git a/src/org/xwt/TinySSL.java b/src/org/xwt/TinySSL.java index 41e83a1..637e41c 100644 --- a/src/org/xwt/TinySSL.java +++ b/src/org/xwt/TinySSL.java @@ -112,6 +112,7 @@ public class TinySSL extends Socket { public static class SSLException extends IOException { public SSLException(String s) { super(s); } } static SubjectPublicKeyInfo[] trusted_CA_public_keys; + static String[] trusted_CA_public_key_identifiers; public static byte[] pad1 = new byte[48]; public static byte[] pad2 = new byte[48]; public static byte[] pad1_sha = new byte[40]; @@ -137,8 +138,8 @@ public class TinySSL extends Socket { public X509CertificateStructure server_cert = null; - public SSLOutputStream os; - public SSLInputStream is; + public SSLOutputStream os = null; + public SSLInputStream is = null; String hostname; @@ -148,15 +149,20 @@ public class TinySSL extends Socket { /** true iff we're using SSL_RSA_EXPORT_WITH_RC4_40_MD5 */ boolean export = false; - public InputStream getInputStream() { return is; } - public OutputStream getOutputStream() { return os; } + public InputStream getInputStream() throws IOException { return is != null ? is : super.getInputStream(); } + public OutputStream getOutputStream() throws IOException { return os != null ? os : super.getOutputStream(); } - public TinySSL(String host, int port) throws IOException { + public TinySSL(String host, int port) throws IOException { this(host, port, true); } + public TinySSL(String host, int port, boolean negotiateImmediately) throws IOException { super(host, port); hostname = host; + if (negotiateImmediately) negotiate(); + } + + /** negotiates the SSL connection */ + public void negotiate() throws IOException { os = new SSLOutputStream(super.getOutputStream()); is = new SSLInputStream(super.getInputStream()); - os.writeClientHello(); is.readServerHandshakes(); os.sendClientHandshakes(); @@ -381,7 +387,7 @@ public class TinySSL extends Socket { Log.log(this, "server cert (name, validity dates) checks out okay"); } else if (!isSignedBy(last_cert, this_cert.getSubjectPublicKeyInfo())) - throw new SSLException("certificate chain discontinuity"); + throw new SSLException("the server sent a broken chain of certificates"); last_cert = this_cert; i += certlen + 3; @@ -390,13 +396,27 @@ public class TinySSL extends Socket { if (Log.on) Log.log(this, " Certificate (" + numcerts + " certificates)"); boolean good = false; + + // pass 1 -- only check CA's whose subject is a partial match + String subject = this_cert.getSubject().toString(); for(int i=0; i