1 21 22 package net.sourceforge.jcetaglib.test; 23 24 import junit.framework.Assert; 25 import junit.framework.TestCase; 26 import net.sourceforge.jcetaglib.lib.X509Cert; 27 import org.bouncycastle.asn1.pkcs.CertificationRequestInfo; 28 import org.bouncycastle.jce.PKCS10CertificationRequest; 29 30 import java.math.BigInteger ; 31 import java.security.PrivateKey ; 32 import java.security.cert.X509CRL ; 33 import java.security.cert.X509Certificate ; 34 35 47 public class X509CertTest extends TestCase { 48 private String pkcs10request = 49 "-----BEGIN CERTIFICATE REQUEST-----\r\nMIIBmTCCAQICAQAwXTELMAkGA1UEBhMCQkUxDDAKBgNVBAoTA25ldDEUMBIGA1UECxMLc291cmNlZm9yZ2UxDDAKBgNVBAMTA2JvYjEcMBoGA1UEChMTYm9iQHNvdXJjZWZvcmdlLm5ldDCBnTANBgkqhkiG9w0BAQEFAAOBiwAwgYcCgYEAjgiky6GyOaM1Yg5yVn/3FFX9/oZ/dEh778sfUVl3/GIa3ZJ5V7D/LzoDQhe813oej3f1xHFl0sw8zLiin7h00NshpLfuD1YQR7+0hCkZ4eSMWPJjBttn4BHF1xIM5RuvLhSoEmEQmCH1NIlddla2Ho/K53Bi03KzwdhTnYuKEksCAREwDQYJKoZIhvcNAQEEBQADgYEAfsks77dYx5SRFro2fpffJJw6wZidfaOvIbxll+9oKEjyWMFofe4Ni4TjcUuQKrjHM82hPfITB7qoIR+1Phv8YDUJF9ERP/UJJ/rj+4C+1utF62qRwMJ8XJn1S4R7/vSRfVT2/CENTTIYCh7TBDU/8BHvAOgYTqf7Jw7i/u13UJ0=\r\n-----END CERTIFICATE REQUEST-----"; 50 51 56 57 public void testPCKS10Request() throws Exception { 58 PKCS10CertificationRequest cr = X509Cert.getPKCS10Request(pkcs10request); 59 60 CertificationRequestInfo reqinfo = cr.getCertificationRequestInfo(); 61 62 Assert.assertEquals("C=BE,O=net,OU=sourceforge,CN=bob,O=bob@sourceforge.net", reqinfo.getSubject().toString()); 63 } 64 65 70 public void testVerifyCertificate() throws Exception { 71 X509Certificate alicecert = X509Cert.getCertificateFromP12(RunTest.TEMPFOLDER + "alice.p12", "alice", new StringBuffer ("password")); 73 X509Certificate bobcert = X509Cert.getCertificateFromP12(RunTest.TEMPFOLDER + "bob.p12", "bob", new StringBuffer ("password")); 74 75 X509Certificate cacert = X509Cert.getCertificateFromP12(RunTest.TEMPFOLDER + "ca.p12", "ca", new StringBuffer ("password")); 77 PrivateKey caprivkey = X509Cert.getPrivateFromP12(RunTest.TEMPFOLDER + "ca.p12", "ca", new StringBuffer ("password")); 78 79 BigInteger [] certnumbers = new BigInteger [1]; 81 certnumbers[0] = bobcert.getSerialNumber(); 82 83 X509CRL crl = X509Cert.CreateCRL(certnumbers 84 , 1 85 , 24 86 , "MD5WithRSAEncryption" 87 , cacert 88 , caprivkey); 89 90 Assert.assertEquals("VERIFIED", X509Cert.verifyCertificate(alicecert, cacert, crl)); 91 Assert.assertEquals("REVOKED", X509Cert.verifyCertificate(bobcert, cacert, crl)); 92 93 } 94 } 95 | Popular Tags |