public EACCertificateBuilder( CertificationAuthorityReference certificationAuthorityReference, PublicKeyDataObject publicKey, CertificateHolderReference certificateHolderReference, CertificateHolderAuthorization certificateHolderAuthorization, PackedDate certificateEffectiveDate, PackedDate certificateExpirationDate) { this.certificationAuthorityReference = certificationAuthorityReference; this.publicKey = publicKey; this.certificateHolderReference = certificateHolderReference; this.certificateHolderAuthorization = certificateHolderAuthorization; this.certificateEffectiveDate = certificateEffectiveDate; this.certificateExpirationDate = certificateExpirationDate; }
public void testGenerateEC() throws Exception { ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("prime256v1"); KeyPair kp = generateECKeyPair(ecSpec); JcaEACSignerBuilder signerBuilder = new JcaEACSignerBuilder().setProvider(BC); EACSigner signer = signerBuilder.build("SHA256withECDSA", kp.getPrivate()); int role = CertificateHolderAuthorization.CVCA; int rights = CertificateHolderAuthorization.RADG3 | CertificateHolderAuthorization.RADG4; EACCertificateBuilder certBuilder = new EACCertificateBuilder( new CertificationAuthorityReference("AU", "BC TEST", "12345"), new JcaPublicKeyConverter().getPublicKeyDataObject(signer.getUsageIdentifier(), kp.getPublic()), new CertificateHolderReference("AU", "BC TEST", "12345"), new CertificateHolderAuthorization(EACObjectIdentifiers.id_EAC_ePassport, role | rights), new PackedDate("110101"), new PackedDate("120101")); EACCertificateHolder certHolder = certBuilder.build(signer); EACSignatureVerifier verifier = new JcaEACSignatureVerifierBuilder().build(certHolder.getPublicKeyDataObject().getUsage(), kp.getPublic()); if (!certHolder.isSignatureValid(verifier)) { fail("first signature test failed"); } PublicKey pubKey = new JcaPublicKeyConverter().setProvider(BC).getKey(certHolder.getPublicKeyDataObject()); verifier = new JcaEACSignatureVerifierBuilder().build(certHolder.getPublicKeyDataObject().getUsage(), pubKey); if (!certHolder.isSignatureValid(verifier)) { fail("first signature test failed"); } }
public void testGenerateRSA() throws Exception { KeyPair kp = generateRSAKeyPair(); JcaEACSignerBuilder signerBuilder = new JcaEACSignerBuilder().setProvider(BC); EACSigner signer = signerBuilder.build("SHA256withRSA", kp.getPrivate()); int role = CertificateHolderAuthorization.CVCA; int rights = CertificateHolderAuthorization.RADG3 | CertificateHolderAuthorization.RADG4; EACCertificateBuilder certBuilder = new EACCertificateBuilder( new CertificationAuthorityReference("AU", "BC TEST", "12345"), new JcaPublicKeyConverter().getPublicKeyDataObject(signer.getUsageIdentifier(), kp.getPublic()), new CertificateHolderReference("AU", "BC TEST", "12345"), new CertificateHolderAuthorization(EACObjectIdentifiers.id_EAC_ePassport, role | rights), new PackedDate("110101"), new PackedDate("120101")); EACCertificateHolder certHolder = certBuilder.build(signer); EACSignatureVerifier verifier = new JcaEACSignatureVerifierBuilder().build(certHolder.getPublicKeyDataObject().getUsage(), kp.getPublic()); if (!certHolder.isSignatureValid(verifier)) { fail("first signature test failed"); } PublicKey pubKey = new JcaPublicKeyConverter().setProvider(BC).getKey(certHolder.getPublicKeyDataObject()); verifier = new JcaEACSignatureVerifierBuilder().build(certHolder.getPublicKeyDataObject().getUsage(), pubKey); if (!certHolder.isSignatureValid(verifier)) { fail("first signature test failed"); } }