more X509x tests added

pull/23/head
Jacob Barthelmeh 2019-04-16 14:48:12 -06:00
parent 755f9fec53
commit c9c31b08e1
2 changed files with 49 additions and 10 deletions

View File

@ -1 +0,0 @@
../../../../../../../examples/

View File

@ -54,6 +54,7 @@ import org.junit.Test;
import com.wolfssl.WolfSSLException; import com.wolfssl.WolfSSLException;
import com.wolfssl.provider.jsse.WolfSSLProvider; import com.wolfssl.provider.jsse.WolfSSLProvider;
import com.wolfssl.provider.jsse.WolfSSLX509; import com.wolfssl.provider.jsse.WolfSSLX509;
import com.wolfssl.provider.jsse.WolfSSLX509X;
public class WolfSSLX509Test { public class WolfSSLX509Test {
private static WolfSSLTestFactory tf; private static WolfSSLTestFactory tf;
@ -106,15 +107,15 @@ public class WolfSSLX509Test {
der = tf.getCert("ca"); der = tf.getCert("ca");
ca = new WolfSSLX509(der); ca = new WolfSSLX509(der);
try { try {
WolfSSLX509X x509x = new WolfSSLX509X(x509.getEncoded());
PublicKey pkey = ca.getPublicKey(); PublicKey pkey = ca.getPublicKey();
x509.verify(pkey); x509.verify(pkey);
x509x.verify(pkey);
} catch (InvalidKeyException | NoSuchProviderException | } catch (InvalidKeyException | NoSuchProviderException |
SignatureException e) { SignatureException | javax.security.cert.CertificateException e) {
error("\t\t... failed"); error("\t\t... failed");
fail("certificae not valid"); fail("certificae not valid");
} }
} catch (KeyStoreException | WolfSSLException | NoSuchAlgorithmException | } catch (KeyStoreException | WolfSSLException | NoSuchAlgorithmException |
CertificateException | IOException e) { CertificateException | IOException e) {
error("\t\t... failed"); error("\t\t... failed");
@ -143,9 +144,6 @@ public class WolfSSLX509Test {
try { try {
x509 = new WolfSSLX509(tf.googleCACert); x509 = new WolfSSLX509(tf.googleCACert);
// CertificateFactory cf = CertificateFactory.getInstance("X.509");
// x509 = (X509Certificate) cf.generateCertificate(new FileInputStream(tf.googleCACert));
keyUsage = x509.getKeyUsage(); keyUsage = x509.getKeyUsage();
if (keyUsage.length != expected.length) { if (keyUsage.length != expected.length) {
@ -201,6 +199,12 @@ public class WolfSSLX509Test {
error("\t... failed"); error("\t... failed");
fail("unexpected sig alg OID found"); fail("unexpected sig alg OID found");
} }
x509X = new WolfSSLX509X(x509.getEncoded());
if (!x509X.getSigAlgOID().equals("1.2.840.113549.1.1.5")) {
error("\t... failed");
fail("unexpected sig alg OID found");
}
} catch (Exception ex) { } catch (Exception ex) {
error("\t... failed"); error("\t... failed");
fail("unexpected exception found"); fail("unexpected exception found");
@ -208,6 +212,22 @@ public class WolfSSLX509Test {
pass("\t\t... passed"); pass("\t\t... passed");
} }
@Test
public void testX509XValidity() {
WolfSSLX509X x509;
System.out.print("\tTesting X509X validity");
try {
x509 = new WolfSSLX509X(tf.googleCACert);
x509.checkValidity();
x509.checkValidity(new Date());
} catch (WolfSSLException | javax.security.cert.CertificateExpiredException |
javax.security.cert.CertificateNotYetValidException e) {
error("\t\t... failed");
fail("failed date validity test");
}
pass("\t\t... passed");
}
@Test @Test
public void testTBS() { public void testTBS() {
@ -250,6 +270,7 @@ public class WolfSSLX509Test {
KeyStore store; KeyStore store;
InputStream stream; InputStream stream;
WolfSSLX509 ca; WolfSSLX509 ca;
WolfSSLX509X cax;
PublicKey pkey; PublicKey pkey;
byte[] key; byte[] key;
@ -261,6 +282,13 @@ public class WolfSSLX509Test {
store.load(stream, tf.jksPass); store.load(stream, tf.jksPass);
stream.close(); stream.close();
ca = new WolfSSLX509(store.getCertificate("ca").getEncoded()); ca = new WolfSSLX509(store.getCertificate("ca").getEncoded());
cax = new WolfSSLX509X(ca.getEncoded());
pkey = cax.getPublicKey();
if (pkey == null) {
error("\t\t... failed");
fail("failed to get public key");
}
pkey = ca.getPublicKey(); pkey = ca.getPublicKey();
if (!pkey.getFormat().equals("X.509")) { if (!pkey.getFormat().equals("X.509")) {
@ -295,6 +323,7 @@ public class WolfSSLX509Test {
KeyStore store; KeyStore store;
InputStream stream; InputStream stream;
WolfSSLX509 server, ca; WolfSSLX509 server, ca;
WolfSSLX509X serverx;
Provider[] p; Provider[] p;
Provider sigProvider = null; Provider sigProvider = null;
@ -322,8 +351,11 @@ public class WolfSSLX509Test {
ca = new WolfSSLX509(store.getCertificate("ca").getEncoded()); ca = new WolfSSLX509(store.getCertificate("ca").getEncoded());
try { try {
serverx = new WolfSSLX509X(server.getEncoded());
server.verify(ca.getPublicKey(), sigProvider); server.verify(ca.getPublicKey(), sigProvider);
} catch (InvalidKeyException | SignatureException e) { serverx.verify(ca.getPublicKey(), sigProvider.getName());
} catch (InvalidKeyException | SignatureException |
NoSuchProviderException | javax.security.cert.CertificateException e) {
error("\t... failed"); error("\t... failed");
fail("failed to verify certificate"); fail("failed to verify certificate");
} }
@ -487,6 +519,14 @@ public class WolfSSLX509Test {
/* @TODO not supported */ /* @TODO not supported */
} }
try {
peer.getSigAlgParams();
error("\t\t... failed: A test case for getSigAlgParams is needed");
fail("getSigAlgParams implemented without test case");
} catch (Exception ex) {
/* @TODO not supported */
}
} catch (SSLPeerUnverifiedException | WolfSSLException | } catch (SSLPeerUnverifiedException | WolfSSLException |
CertificateEncodingException | CertificateEncodingException |
javax.security.cert.CertificateEncodingException e) { javax.security.cert.CertificateEncodingException e) {