X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fxwt%2FTinySSL.java;h=d036d3378d22049da920bd2e6ef5727192b4695d;hb=f66bd0f26410e548d31db8421ddd6c8c0750f54c;hp=516fee6f649a065b4dceca5c09bcc704e58be260;hpb=d48bd6e50ee09d1649a7680d7943510d274b5c91;p=org.ibex.core.git diff --git a/src/org/xwt/TinySSL.java b/src/org/xwt/TinySSL.java index 516fee6..d036d33 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