List of usage examples for org.bouncycastle.pkcs PKCS10CertificationRequest getSubject
public X500Name getSubject()
From source file:org.xipki.pki.ca.jscep.client.shell.CertPollCmd.java
License:Open Source License
@Override protected Object doExecute() throws Exception { PKCS10CertificationRequest csr = new PKCS10CertificationRequest(IoUtil.read(csrFile)); Client client = getScepClient();/*from www .j av a2s . c o m*/ TransactionId transId = TransactionId.createTransactionId(CertificationRequestUtils.getPublicKey(csr), "SHA-1"); EnrollmentResponse resp = client.poll(getIdentityCert(), getIdentityKey(), new X500Principal(csr.getSubject().getEncoded()), transId); if (resp.isFailure()) { throw new CmdFailure("server returned 'failure'"); } if (resp.isPending()) { throw new CmdFailure("server returned 'pending'"); } X509Certificate cert = extractEeCerts(resp.getCertStore()); if (cert == null) { throw new Exception("received no certificate"); } saveVerbose("saved polled certificate to file", new File(outputFile), cert.getEncoded()); return null; }
From source file:test.integ.be.e_contract.mycarenet.certra.CertRAClientTest.java
License:Open Source License
@Test public void testGenerateCertificate() throws Exception { CertRASession certRASession = new CertRASession("info@e-contract.be", "0478/299492"); String ssin = CertRAClient.getSSIN(this.signCertificateChain.get(0)); X500NameBuilder nameBuilder = new X500NameBuilder(); nameBuilder.addRDN(X509ObjectIdentifiers.countryName, new DERPrintableString("BE")); nameBuilder.addRDN(X509ObjectIdentifiers.organization, new DERPrintableString("Federal Government")); nameBuilder.addRDN(X509ObjectIdentifiers.organizationalUnitName, new DERPrintableString("eHealth-platform Belgium")); nameBuilder.addRDN(X509ObjectIdentifiers.organizationalUnitName, new DERPrintableString("SSIN=" + ssin)); nameBuilder.addRDN(X509ObjectIdentifiers.commonName, new DERPrintableString("SSIN=" + ssin)); X500Name name = nameBuilder.build(); byte[] encodedCsr = certRASession.generateCSR(name); PKCS10CertificationRequest csr = new PKCS10CertificationRequest(encodedCsr); LOG.debug("CSR subject: " + csr.getSubject()); X500Name subjectName = csr.getSubject(); RDN[] rdns = subjectName.getRDNs();//from ww w . j a va 2 s .c o m for (RDN rdn : rdns) { LOG.debug("--------"); AttributeTypeAndValue[] attributes = rdn.getTypesAndValues(); for (AttributeTypeAndValue attribute : attributes) { LOG.debug(attribute.getType() + " = " + attribute.getValue()); LOG.debug("value type: " + attribute.getValue().getClass().getName()); } } }
From source file:Utils.CSRbuilder.java
public static X509Certificate createCertOfCSR(PKCS10CertificationRequest csr, KeyPair caKeys, X509Certificate caCert) { X509Certificate cert = null;/*from w w w . j a va2 s. c o m*/ try { BigInteger bigInt = new BigInteger(String.valueOf(System.currentTimeMillis())); Security.addProvider(new BouncyCastleProvider()); AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1withRSA"); AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId); AsymmetricKeyParameter parameterCa = PrivateKeyFactory.createKey(caKeys.getPrivate().getEncoded()); SubjectPublicKeyInfo keyInfo = csr.getSubjectPublicKeyInfo(); Calendar cal = Calendar.getInstance(); Date notbefore = cal.getTime(); cal.add(Calendar.YEAR, 2); // Define the validity of 2 years Date notafter = cal.getTime(); X509v3CertificateBuilder myCertificateGenerator = new X509v3CertificateBuilder( new X500Name(caCert.getSubjectDN().getName()), bigInt, notbefore, notafter, csr.getSubject(), keyInfo); ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(parameterCa); myCertificateGenerator.addExtension(X509Extension.basicConstraints, true, new BasicConstraints(false)); myCertificateGenerator.addExtension(X509Extension.authorityKeyIdentifier, false, new JcaX509ExtensionUtils().createAuthorityKeyIdentifier(caCert)); SubjectKeyIdentifier subjectKeyIdentifier = new JcaX509ExtensionUtils() .createSubjectKeyIdentifier(keyInfo); myCertificateGenerator.addExtension(X509Extension.subjectKeyIdentifier, false, subjectKeyIdentifier); KeyUsage keyUsage = new KeyUsage(KeyUsage.digitalSignature | KeyUsage.nonRepudiation | KeyUsage.keyEncipherment | KeyUsage.dataEncipherment | KeyUsage.digitalSignature); myCertificateGenerator.addExtension(X509Extension.keyUsage, true, keyUsage); X509CertificateHolder holder = myCertificateGenerator.build(sigGen); cert = (X509Certificate) java.security.cert.CertificateFactory.getInstance("X.509", "BC") .generateCertificate(new ByteArrayInputStream(holder.getEncoded())); } catch (Exception ex) { System.err.println("Probeleme de creartion de certificat pour le client a partir du csr: " + ex); } return cert; }