Example usage for org.bouncycastle.pkcs PKCS10CertificationRequest PKCS10CertificationRequest

List of usage examples for org.bouncycastle.pkcs PKCS10CertificationRequest PKCS10CertificationRequest

Introduction

In this page you can find the example usage for org.bouncycastle.pkcs PKCS10CertificationRequest PKCS10CertificationRequest.

Prototype

public PKCS10CertificationRequest(byte[] encoded) throws IOException 

Source Link

Document

Create a PKCS10CertificationRequestHolder from the passed in bytes.

Usage

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  w  ww .ja va  2 s. c om

    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:org.xipki.pki.ca.jscep.client.shell.EnrollCertCommandSupport.java

License:Open Source License

@Override
protected Object doExecute() throws Exception {
    Client client = getScepClient();/*  w  w  w. ja va2s .  c  om*/

    PKCS10CertificationRequest csr = new PKCS10CertificationRequest(IoUtil.read(csrFile));

    EnrollmentResponse resp = requestCertificate(client, csr, getIdentityKey(), getIdentityCert());
    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 enrolled certificate to file", new File(outputFile), cert.getEncoded());
    return null;
}

From source file:org.xipki.pki.scep.serveremulator.CaEmulator.java

License:Open Source License

private boolean verifyPopo(final CertificationRequest csr) {
    ParamUtil.requireNonNull("csr", csr);
    try {//from   ww w  . ja  v a 2 s. com
        PKCS10CertificationRequest p10Req = new PKCS10CertificationRequest(csr);
        SubjectPublicKeyInfo pkInfo = p10Req.getSubjectPublicKeyInfo();
        PublicKey pk = KeyUtil.generatePublicKey(pkInfo);

        ContentVerifierProvider cvp = getContentVerifierProvider(pk);
        return p10Req.isSignatureValid(cvp);
    } catch (InvalidKeyException | PKCSException | NoSuchAlgorithmException | InvalidKeySpecException ex) {
        LogUtil.error(LOG, ex, "could not validate POPO of CSR");
        return false;
    }
}

From source file:org.xipki.security.SignerUtil.java

License:Open Source License

public static boolean verifyPOP(final CertificationRequest p10Request) {
    PKCS10CertificationRequest p10Req = new PKCS10CertificationRequest(p10Request);
    return verifyPOP(p10Req);
}

From source file:ServiceCert.MsgAtoS.java

public PKCS10CertificationRequest getDataArrayOfcsr() {
    PKCS10CertificationRequest csr = null;
    try {//from  w  w  w. j ava  2  s  .  c  o m
        csr = new PKCS10CertificationRequest(dataArrayOfcsr);
    } catch (IOException ex) {
        System.err.println(ex.toString());
    }
    return csr;
}

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  w w  w .  ja  va2 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:Useful.InfoCSR.java

public PKCS10CertificationRequest getCsr() {
    try {/*from w w w.  j a va 2  s  .  c o  m*/
        return new PKCS10CertificationRequest(csr);
    } catch (IOException ex) {
        Logger.getLogger(InfoCSR.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}