diff options
-rw-r--r-- | jessie-tests/run-tests.sh | 50 | ||||
-rw-r--r-- | jessie-tests/testAlert.java | 54 | ||||
-rw-r--r-- | jessie-tests/testCertificate.java | 71 | ||||
-rw-r--r-- | jessie-tests/testCertificateRequest.java | 61 | ||||
-rw-r--r-- | jessie-tests/testCipherSuiteList.java | 36 | ||||
-rw-r--r-- | jessie-tests/testClientHello.java | 107 | ||||
-rw-r--r-- | jessie-tests/testCompressionMethodList.java | 42 | ||||
-rw-r--r-- | jessie-tests/testHelloRequest.java | 35 | ||||
-rw-r--r-- | jessie-tests/testRecord.java | 66 | ||||
-rw-r--r-- | jessie-tests/testServerDHParams.java | 53 | ||||
-rw-r--r-- | jessie-tests/testServerHello.java | 73 | ||||
-rw-r--r-- | jessie-tests/testServerKeyExchange.java | 69 | ||||
-rw-r--r-- | jessie-tests/testServerRSAParams.java | 48 | ||||
-rw-r--r-- | jessie-tests/testSignature.java | 45 |
14 files changed, 810 insertions, 0 deletions
diff --git a/jessie-tests/run-tests.sh b/jessie-tests/run-tests.sh new file mode 100644 index 000000000..397d2ab77 --- /dev/null +++ b/jessie-tests/run-tests.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +test -z "$JAVAC" && export JAVAC=jikes +test -z "$JAVA" && export JAVA=jamvm +test -z "$JAVA_OPTIONS" && export JAVA_OPTIONS= +test -z "$CLASSPATH" && export CLASSPATH=. + +tests="testAlert testCertificate testCertificateRequest \ + testCipherSuiteList testClientHello testCompressionMethodList \ + testHelloRequest testRecord testServerDHParams \ + testServerHello testServerKeyExchange testServerRSAParams \ + testSignature" + +rm -rf test-classes +mkdir test-classes +${JAVAC} -cp $CLASSPATH -d test-classes *.java || exit 1 + +ntests=0 +fails=0 +rm -rf check.log check.err +echo -n "Jessie check run at " | tee check.err > check.log +date | tee -a check.err >> check.log +for test in $tests +do + echo $test + echo ---- $test ---- >> check.log + echo ---- $test ---- >> check.err + if `(${JAVA} ${JAVA_OPTIONS} -cp ${CLASSPATH}:test-classes $test 2>> check.err || echo FAIL: $test) | tee -a check.log | grep -q ^FAIL > /dev/null` + then + echo FAIL: $test + let 'fails = fails + 1' + fi + let 'ntests = ntests + 1' +done + +if test ${fails} -eq 1 +then + echo $ntests tests, $fails failure + echo ---- $ntests tests, $fails failure ---- >> check.err +else + echo $ntests tests, $fails failures + echo ---- $ntests tests, $fails failures ---- >> check.err +fi +echo -n "Jessie check done at " | tee -a check.err >> check.log +date | tee -a check.err >> check.log + +if test ${fails} -gt 0 + then + exit 1 +fi diff --git a/jessie-tests/testAlert.java b/jessie-tests/testAlert.java new file mode 100644 index 000000000..ba063a713 --- /dev/null +++ b/jessie-tests/testAlert.java @@ -0,0 +1,54 @@ + + +import gnu.javax.net.ssl.provider.Alert; +import java.nio.ByteBuffer; + +class testAlert +{ + public static void main (String[] argv) + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + Alert a1 = new Alert (ByteBuffer.allocate (2)); + + a1.setLevel (Alert.Level.WARNING); + System.out.println ("PASS: setLevel()"); + a1.setDescription (Alert.Description.UNEXPECTED_MESSAGE); + System.out.println ("PASS: setDescription()"); + + Alert a2 = new Alert (ByteBuffer.allocate (2)); + + a2.setLevel (Alert.Level.WARNING); + System.out.println ("PASS: setLevel()"); + a2.setDescription (Alert.Description.UNEXPECTED_MESSAGE); + System.out.println ("PASS: setDescription()"); + + if (a1.equals (a2)) + System.out.println ("PASS: equals()"); + else + System.out.println ("FAIL: equals()"); + + if (a1.level () == Alert.Level.WARNING) + System.out.println ("PASS: level"); + else + System.out.println ("FAIL: level"); + + if (a1.description () == Alert.Description.UNEXPECTED_MESSAGE) + System.out.println ("PASS: description"); + else + System.out.println ("FAIL: description"); + + System.err.println (a1); + } +} diff --git a/jessie-tests/testCertificate.java b/jessie-tests/testCertificate.java new file mode 100644 index 000000000..dcc64d119 --- /dev/null +++ b/jessie-tests/testCertificate.java @@ -0,0 +1,71 @@ + + +import gnu.javax.net.ssl.provider.Certificate; +import gnu.javax.net.ssl.provider.Handshake; + +import java.io.ByteArrayInputStream; +import java.nio.ByteBuffer; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.Collections; +import java.util.List; + +class testCertificate +{ + static final byte[] test_cert = + ("-----BEGIN CERTIFICATE-----\n" + + "MIICFTCCAX6gAwIBAgIBATANBgkqhkiG9w0BAQQFADBVMRswGQYDVQQKExJBcGFj\n" + + "aGUgSFRUUCBTZXJ2ZXIxIjAgBgNVBAsTGUZvciB0ZXN0aW5nIHB1cnBvc2VzIG9u\n" + + "bHkxEjAQBgNVBAMTCWxvY2FsaG9zdDAeFw0wNDA0MTMwMzM1NTJaFw0wNTA0MTMw\n" + + "MzM1NTJaMEwxGzAZBgNVBAoTEkFwYWNoZSBIVFRQIFNlcnZlcjEZMBcGA1UECxMQ\n" + + "VGVzdCBDZXJ0aWZpY2F0ZTESMBAGA1UEAxMJbG9jYWxob3N0MIGfMA0GCSqGSIb3\n" + + "DQEBAQUAA4GNADCBiQKBgQCxJUcMWt9GO59u46xY/gbp0sZP6v4nbnG64as6UF9c\n" + + "rlyKUaSToUoO0LtBT1MlZxAg+VgmrCz75clOFdzUJonj9aOMZZvkOHgVhUwuGOcO\n" + + "1gLYa+vjhaPdbfymo5ztEbBZBZ9GsasGPX6K58GmQaUQwUtdcgE/hhnhwN+gHPBm\n" + + "7wIDAQABMA0GCSqGSIb3DQEBBAUAA4GBADSEHkrDmCCdmtX8+9O4o4Uvb2UobeF+\n" + + "1GspRsWBMPHUDDF1ipEHxlNp0+M9hwTqFqQwBoJJ7Kfcqz+lXd61hS0GQZJdEkzp\n" + + "7578r/KhpXsT+fLKTBUgjrwOoHbohCqOWejV2j6lstA8P3U/vdAQuLTm0GiuIFcv\n" + + "riDVGJJzZ2b/\n" + + "-----END CERTIFICATE-----\n").getBytes (); + + public static void main (String[] argv) throws Throwable + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + final int alloc_len = 4096; + CertificateFactory factory = CertificateFactory.getInstance ("X.509"); + X509Certificate cert = (X509Certificate) + factory.generateCertificate (new ByteArrayInputStream (test_cert)); + ByteBuffer buffer = ByteBuffer.allocate (alloc_len); + Handshake handshake = new Handshake (buffer); + + handshake.setType (Handshake.Type.CERTIFICATE); + handshake.setLength (alloc_len - 4); + + Certificate _cert = (Certificate) handshake.body (); + _cert.setCertificates (Collections.singletonList (cert)); + System.err.println (_cert.certificates ()); + System.err.println (_cert); + handshake.setLength (_cert.length ()); + + Handshake handshake2 = new Handshake (buffer); + Certificate _cert2 = (Certificate) handshake2.body (); + List certs = _cert2.certificates (); + + if (cert.equals (certs.get (0))) + System.out.println ("PASS: equals()"); + else + System.out.println ("FAIL: equals()"); + } +} diff --git a/jessie-tests/testCertificateRequest.java b/jessie-tests/testCertificateRequest.java new file mode 100644 index 000000000..2c099faa4 --- /dev/null +++ b/jessie-tests/testCertificateRequest.java @@ -0,0 +1,61 @@ +import gnu.javax.net.ssl.provider.CertificateRequest; +import gnu.javax.net.ssl.provider.ClientCertificateTypeList; +import gnu.javax.net.ssl.provider.X500PrincipalList; + +import java.nio.ByteBuffer; +import javax.security.auth.x500.X500Principal; + +class testCertificateRequest +{ + public static void main (String[] argv) throws Throwable + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + ByteBuffer buffer = ByteBuffer.allocate (4096); + System.err.println ("create X500Principal..."); + X500Principal name = new X500Principal ("C=US,ST=MA,L=Boston,O=FSF,OU=Certificate Authority,CN=savannah.gnu.org"); + System.err.println (name); + CertificateRequest req = new CertificateRequest (buffer); + + System.err.println ("getting types..."); + ClientCertificateTypeList types = req.types (); + types.setSize (4); + System.err.println ("adding types..."); + types.put (0, CertificateRequest.ClientCertificateType.DSS_FIXED_DH); + types.put (1, CertificateRequest.ClientCertificateType.RSA_FIXED_DH); + types.put (2, CertificateRequest.ClientCertificateType.DSS_SIGN); + types.put (3, CertificateRequest.ClientCertificateType.RSA_SIGN); + + System.err.println ("getting names..."); + X500PrincipalList names = req.authorities (); + byte[] bytes = name.getEncoded (); + names.setSize (1, bytes.length); + System.err.println ("putting name..."); + names.put (0, bytes); + + System.err.println (req); + + CertificateRequest req2 = new CertificateRequest (buffer); + ClientCertificateTypeList types2 = req2.types (); + X500PrincipalList names2 = req2.authorities (); + if (types2.equals (types)) + System.out.println ("PASS: equals(types)"); + else + System.out.println ("FAIL: equals(types)"); + if (names2.equals (names)) + System.out.println ("PASS: equals(names)"); + else + System.out.println ("FAIL: equals(names)"); + } +} diff --git a/jessie-tests/testCipherSuiteList.java b/jessie-tests/testCipherSuiteList.java new file mode 100644 index 000000000..d083d7ba6 --- /dev/null +++ b/jessie-tests/testCipherSuiteList.java @@ -0,0 +1,36 @@ + + +import gnu.javax.net.ssl.provider.CipherSuite; +import gnu.javax.net.ssl.provider.CipherSuiteList; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.nio.ByteBuffer; + +class testCipherSuiteList +{ + public static void main (String[] argv) throws Exception + { + final int n = 8; + ByteBuffer buffer = ByteBuffer.allocate (n * 2 + 2); + CipherSuiteList list = new CipherSuiteList (buffer); + + list.setSize (n); + Field[] f = CipherSuite.class.getDeclaredFields (); + for (int i = 0, j = 0; i < f.length && j < n; i++) + { + if (CipherSuite.class.equals (f[i].getType ()) + && Modifier.isStatic (f[i].getModifiers ())) + list.put (j++, (CipherSuite) f[i].get (null)); + } + + System.err.println (list); + + CipherSuiteList list2 = new CipherSuiteList (buffer); + + if (list2.equals (list)) + System.out.println ("PASS: equals()"); + else + System.out.println ("FAIL: equals()"); + } +} diff --git a/jessie-tests/testClientHello.java b/jessie-tests/testClientHello.java new file mode 100644 index 000000000..d3c8ba802 --- /dev/null +++ b/jessie-tests/testClientHello.java @@ -0,0 +1,107 @@ + + +import gnu.javax.net.ssl.provider.CipherSuite; +import gnu.javax.net.ssl.provider.CipherSuiteList; +import gnu.javax.net.ssl.provider.ClientHello; +import gnu.javax.net.ssl.provider.CompressionMethod; +import gnu.javax.net.ssl.provider.CompressionMethodList; +import gnu.javax.net.ssl.provider.ProtocolVersion; +import gnu.javax.net.ssl.provider.Handshake; +import gnu.javax.net.ssl.provider.Random; + +import java.nio.ByteBuffer; +import java.util.Arrays; + +class testClientHello +{ + public static void main (String[] argv) + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + final int alloc_len = 4096; + ByteBuffer buffer = ByteBuffer.allocate (alloc_len); + Handshake handshake = new Handshake (buffer); + + handshake.setType (Handshake.Type.CLIENT_HELLO); + handshake.setLength (alloc_len - 4); + + ClientHello hello = null; + hello = (ClientHello) handshake.body (); + + byte[] sessionId = new byte[32]; + for (int i = 0; i < 32; i++) + sessionId[i] = (byte) i; + + hello.setVersion (ProtocolVersion.TLS_1); + hello.setSessionId (sessionId); + + Random random = hello.random (); + random.setGmtUnixTime (123456); + byte[] nonce = new byte [28]; + for (int i = 0; i < nonce.length; i++) + nonce[i] = (byte) i; + random.setRandomBytes (nonce); + + CipherSuiteList suites = hello.cipherSuites (); + suites.setSize (10); + suites.put (0, CipherSuite.TLS_NULL_WITH_NULL_NULL); + suites.put (1, CipherSuite.TLS_RSA_WITH_NULL_MD5); + suites.put (2, CipherSuite.TLS_RSA_WITH_NULL_SHA); + suites.put (3, CipherSuite.TLS_RSA_EXPORT_WITH_RC4_40_MD5); + suites.put (4, CipherSuite.TLS_RSA_WITH_RC4_128_MD5); + suites.put (5, CipherSuite.TLS_RSA_WITH_RC4_128_SHA); + suites.put (6, CipherSuite.TLS_RSA_EXPORT_WITH_DES40_CBC_SHA); + suites.put (7, CipherSuite.TLS_RSA_WITH_DES_CBC_SHA); + suites.put (8, CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA); + suites.put (9, CipherSuite.TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA); + + CompressionMethodList comps = hello.compressionMethods (); + comps.setSize (2); + comps.put (0, CompressionMethod.NULL); + comps.put (1, CompressionMethod.ZLIB); + + hello.setExtensionsLength (0); + handshake.setLength (hello.length ()); + + handshake = new Handshake (buffer); + + hello = (ClientHello) handshake.body (); + if (ProtocolVersion.TLS_1.equals (hello.version ())) + System.out.println ("PASS: protocolVersion ()"); + else + System.out.println ("FAIL: protocolVersion ()"); + + if (hello.random ().gmtUnixTime () == 123456) + System.out.println ("PASS: random ().gmtUnixTime ()"); + else + System.out.println ("FAIL: random ().gmtUnixTime ()"); + + if (Arrays.equals (nonce, hello.random ().randomBytes ())) + System.out.println ("PASS: random ().randomBytes ()"); + else + System.out.println ("FAIL: random ().randomBytes ()"); + + if (suites.equals (hello.cipherSuites ())) + System.out.println ("PASS: cipherSuites()"); + else + System.out.println ("FAIL: cipherSuites()"); + + if (comps.equals (hello.compressionMethods ())) + System.out.println ("PASS: compressionMethods()"); + else + System.out.println ("FAIL: compressionMethods()"); + + System.err.println (handshake); + } +} diff --git a/jessie-tests/testCompressionMethodList.java b/jessie-tests/testCompressionMethodList.java new file mode 100644 index 000000000..290d6b81b --- /dev/null +++ b/jessie-tests/testCompressionMethodList.java @@ -0,0 +1,42 @@ + + +import gnu.javax.net.ssl.provider.CompressionMethod; +import gnu.javax.net.ssl.provider.CompressionMethodList; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.nio.ByteBuffer; + +class testCompressionMethodList +{ + public static void main (String[] argv) + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: uncaught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + ByteBuffer buffer = ByteBuffer.allocate (3); + CompressionMethodList list = new CompressionMethodList (buffer); + + list.setSize (2); + list.put (0, CompressionMethod.NULL); + list.put (1, CompressionMethod.ZLIB); + + System.err.println (list); + + CompressionMethodList list2 = new CompressionMethodList (buffer); + if (list2.equals (list)) + System.out.println ("PASS: equals()"); + else + System.out.println ("FAIL: equals()"); + } +} diff --git a/jessie-tests/testHelloRequest.java b/jessie-tests/testHelloRequest.java new file mode 100644 index 000000000..bcbec5c3a --- /dev/null +++ b/jessie-tests/testHelloRequest.java @@ -0,0 +1,35 @@ + + +import gnu.javax.net.ssl.provider.Handshake; +import gnu.javax.net.ssl.provider.HelloRequest; + +import java.nio.ByteBuffer; + +class testHelloRequest +{ + public static void main (String[] argv) + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + ByteBuffer buffer = ByteBuffer.allocate (4); + Handshake handshake = new Handshake (buffer); + handshake.setType (Handshake.Type.HELLO_REQUEST); + handshake.setLength (0); + HelloRequest body = (HelloRequest) handshake.body (); + + System.out.println ("PASS: body"); + + System.err.println (handshake); + } +} diff --git a/jessie-tests/testRecord.java b/jessie-tests/testRecord.java new file mode 100644 index 000000000..da053f11b --- /dev/null +++ b/jessie-tests/testRecord.java @@ -0,0 +1,66 @@ + + +import gnu.javax.net.ssl.provider.ContentType; +import gnu.javax.net.ssl.provider.ProtocolVersion; +import gnu.javax.net.ssl.provider.Record; + +import java.nio.ByteBuffer; +import java.util.Arrays; + +class testRecord +{ + public static void main (final String[] argv) + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + ByteBuffer buf = ByteBuffer.allocate (42 + 5); + Record record = new Record (buf); + byte[] fragment = new byte[42]; + new java.util.Random (31337).nextBytes (fragment); + + record.setVersion (ProtocolVersion.TLS_1); + System.out.println ("PASS: setVersion"); + record.setContentType (ContentType.APPLICATION_DATA); + System.out.println ("PASS: setContentType"); + record.setLength (42); + System.out.println ("PASS: setLength"); + + record.fragment ().put (fragment); + System.out.println ("PASS: fragment ().put ()"); + + if (ProtocolVersion.TLS_1.equals (record.version ())) + System.out.println ("PASS: version()"); + else + System.out.println ("FAIL: version()"); + + if (ContentType.APPLICATION_DATA.equals (record.contentType ())) + System.out.println ("PASS: contentType()"); + else + System.out.println ("FAIL: contentType()"); + + if (record.length () == 42) + System.out.println ("PASS: length()"); + else + System.out.println ("FAIL: length()"); + + byte[] fragment2 = new byte[42]; + record.fragment ().get (fragment2); + if (Arrays.equals (fragment, fragment2)) + System.out.println ("PASS: fragment ().get ()"); + else + System.out.println ("FAIL: fragment ().get ()"); + + System.err.println (record); + } +} diff --git a/jessie-tests/testServerDHParams.java b/jessie-tests/testServerDHParams.java new file mode 100644 index 000000000..1a2ae1cec --- /dev/null +++ b/jessie-tests/testServerDHParams.java @@ -0,0 +1,53 @@ + + +import gnu.javax.net.ssl.provider.ServerDHParams; + +import java.math.BigInteger; +import java.nio.ByteBuffer; + +class testServerDHParams +{ + public static void main (String[] argv) throws Throwable + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + BigInteger p = new BigInteger ("1234567890abcdef1234567890abcdef1234567890abcdef", 16); + BigInteger g = BigInteger.valueOf (2); + BigInteger y = new BigInteger ("fedcba0987654321fedcba0987654321fedcba0987654321", 16); + ByteBuffer buffer = ByteBuffer.allocate (1024); + + ServerDHParams params = new ServerDHParams (buffer); + + params.setP (p); + params.setG (g); + params.setY (y); + + if (params.p ().equals (p)) + System.out.println ("PASS: p"); + else + System.out.println ("FAIL: " + p + " != " + params.p ()); + + if (params.g ().equals (g)) + System.out.println ("PASS: g"); + else + System.out.println ("FAIL: " + g + " != " + params.g ()); + + if (params.y ().equals (y)) + System.out.println ("PASS: y"); + else + System.out.println ("FAIL: " + y + " != " + params.y ()); + + System.err.println (params); + } +} diff --git a/jessie-tests/testServerHello.java b/jessie-tests/testServerHello.java new file mode 100644 index 000000000..04471767c --- /dev/null +++ b/jessie-tests/testServerHello.java @@ -0,0 +1,73 @@ + +import gnu.javax.net.ssl.provider.CipherSuite; +import gnu.javax.net.ssl.provider.CompressionMethod; +import gnu.javax.net.ssl.provider.Handshake; +import gnu.javax.net.ssl.provider.ProtocolVersion; +import gnu.javax.net.ssl.provider.Random; +import gnu.javax.net.ssl.provider.ServerHello; + +import java.nio.ByteBuffer; +import java.util.Arrays; + +class testServerHello +{ + public static void main (String[] argv) + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + final int alloc_len = 4096; + ByteBuffer buffer = ByteBuffer.allocate (alloc_len); + Handshake handshake = new Handshake (buffer); + + handshake.setType (Handshake.Type.SERVER_HELLO); + handshake.setLength (alloc_len - 4); + + ServerHello hello = (ServerHello) handshake.body (); + + hello.setVersion (ProtocolVersion.TLS_1); + Random random = hello.random (); + random.setGmtUnixTime (123456); + byte[] nonce = new byte[28]; + for (int i = 0; i < nonce.length; i++) + nonce[i] = (byte) i; + random.setRandomBytes (nonce); + byte[] sessionId = new byte[32]; + for (int i = 0; i < sessionId.length; i++) + sessionId[i] = (byte) i; + hello.setSessionId (sessionId); + hello.setCipherSuite (CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA); + hello.setCompressionMethod (CompressionMethod.ZLIB); + hello.setExtensionsLength (0); + + handshake.setLength (hello.length ()); + System.err.println (handshake); + + handshake = new Handshake (buffer); + hello = (ServerHello) handshake.body (); + if (Arrays.equals (sessionId, hello.sessionId ())) + System.out.println ("PASS: sessionId"); + else + System.out.println ("FAIL: sessionId"); + + if (hello.cipherSuite () == CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA) + System.out.println ("PASS: cipherSuite"); + else + System.out.println ("FAIL: cipherSuite"); + + if (hello.compressionMethod () == CompressionMethod.ZLIB) + System.out.println ("PASS: compressionMethod"); + else + System.out.println ("FAIL: compressionMethod"); + } +} diff --git a/jessie-tests/testServerKeyExchange.java b/jessie-tests/testServerKeyExchange.java new file mode 100644 index 000000000..32dd46215 --- /dev/null +++ b/jessie-tests/testServerKeyExchange.java @@ -0,0 +1,69 @@ +import gnu.javax.net.ssl.provider.CipherSuite; +import gnu.javax.net.ssl.provider.Handshake; +import gnu.javax.net.ssl.provider.ServerKeyExchange; +import gnu.javax.net.ssl.provider.ServerRSAParams; +import gnu.javax.net.ssl.provider.Signature; + +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.util.Arrays; + +class testServerKeyExchange +{ + public static void main (String[] argv) + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + ByteBuffer buffer = ByteBuffer.allocate (1024); + Handshake handshake = new Handshake (buffer, CipherSuite.SSL_RSA_WITH_NULL_MD5); + + handshake.setType (Handshake.Type.SERVER_KEY_EXCHANGE); + handshake.setLength (1019); + + ServerKeyExchange kex = (ServerKeyExchange) handshake.body (); + ServerRSAParams params = (ServerRSAParams) kex.params (); + BigInteger modulus = new BigInteger ("FEEDFACEDEADBEEFCAFEBABE00000001", 16); + BigInteger exponent = BigInteger.valueOf (2); + params.setModulus (modulus); + params.setExponent (exponent); + + Signature sig = kex.signature (); + byte[] sigbuf = new byte[256]; + for (int i = 0; i < sigbuf.length; i++) + sigbuf[i] = (byte) i; + sig.setSignature (sigbuf); + + handshake.setLength (kex.length ()); + + handshake = new Handshake (buffer, CipherSuite.SSL_RSA_WITH_NULL_MD5); + kex = (ServerKeyExchange) handshake.body (); + params = (ServerRSAParams) kex.params (); + sig = kex.signature (); + + if (params.modulus ().equals (modulus)) + System.out.println ("PASS: modulus"); + else + System.out.println ("FAIL: modulus " + modulus + " != " + params.modulus ()); + + if (params.exponent ().equals (exponent)) + System.out.println ("PASS: exponent"); + else + System.out.println ("FAIL: exponent " + exponent + " != " + params.exponent ()); + + if (Arrays.equals (sigbuf, sig.signature ())) + System.out.println ("PASS: signature"); + else + System.out.println ("FAIL: signature"); + } +}
\ No newline at end of file diff --git a/jessie-tests/testServerRSAParams.java b/jessie-tests/testServerRSAParams.java new file mode 100644 index 000000000..6a2860700 --- /dev/null +++ b/jessie-tests/testServerRSAParams.java @@ -0,0 +1,48 @@ + + +import gnu.javax.net.ssl.provider.ServerRSAParams; + +import java.math.BigInteger; +import java.nio.ByteBuffer; + +class testServerRSAParams +{ + public static void main (String[] argv) throws Throwable + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + x.printStackTrace (); + } + } + + static void check () throws Exception + { + BigInteger modulus = new BigInteger ("1234567890abcdef1234567890abcdef1234567890abcdef", 16); + BigInteger exponent = BigInteger.valueOf (0xff); + ByteBuffer buffer = ByteBuffer.allocate (1024); + + ServerRSAParams params = new ServerRSAParams (buffer); + + params.setModulus (modulus); + params.setExponent (exponent); + + params = new ServerRSAParams (buffer); + + if (params.modulus ().equals (modulus)) + System.out.println ("PASS: modulus"); + else + System.out.println ("FAIL: " + modulus + " != " + params.modulus ()); + + if (params.exponent ().equals (exponent)) + System.out.println ("PASS: exponent"); + else + System.out.println ("FAIL: " + exponent + " != " + params.exponent ()); + + System.err.println (params); + } +} diff --git a/jessie-tests/testSignature.java b/jessie-tests/testSignature.java new file mode 100644 index 000000000..69fd3d680 --- /dev/null +++ b/jessie-tests/testSignature.java @@ -0,0 +1,45 @@ +import gnu.javax.net.ssl.provider.Signature; +import gnu.javax.net.ssl.provider.SignatureAlgorithm; + +import java.nio.ByteBuffer; +import java.util.Arrays; + +class testSignature +{ + public static void main (String[] argv) + { + try + { + check (); + } + catch (Exception x) + { + System.out.println ("FAIL: caught exception " + x); + } + } + + static void check () throws Exception + { + ByteBuffer buffer = ByteBuffer.allocate (1024); + Signature sig = new Signature (buffer, SignatureAlgorithm.RSA); + byte[] sigbuf = new byte[256]; + for (int i = 0; i < sigbuf.length; i++) + sigbuf[i] = (byte) i; + + sig.setSignature (sigbuf); + + sig = new Signature (buffer, SignatureAlgorithm.RSA); + + if (sig.length () == 258) + System.out.println ("PASS: length"); + else + System.out.println ("FAIL: length (" + sig.length () + ")"); + + if (Arrays.equals (sigbuf, sig.signature ())) + System.out.println ("PASS: signature"); + else + System.out.println ("FAIL: signature"); + + System.err.println (sig); + } +}
\ No newline at end of file |