Search in sources :

Example 11 with CertRequest

use of org.bouncycastle.asn1.crmf.CertRequest in project athenz by yahoo.

the class CryptoTest method testX509CSRrequestWithPrivateKeyOnly.

@Test(dataProvider = "x500Principal")
public void testX509CSRrequestWithPrivateKeyOnly(String x500Principal, boolean badRequest) {
    PrivateKey privateKey = Crypto.loadPrivateKey(rsaPrivateKey);
    String certRequest = null;
    GeneralName otherName1 = new GeneralName(GeneralName.otherName, new DERIA5String("role1"));
    GeneralName otherName2 = new GeneralName(GeneralName.otherName, new DERIA5String("role2"));
    GeneralName[] sanArray = new GeneralName[] { otherName1, otherName2 };
    try {
        certRequest = Crypto.generateX509CSR(privateKey, x500Principal, sanArray);
    } catch (Exception e) {
        if (!badRequest) {
            fail("Should not have failed to create csr");
        }
    }
    if (!badRequest) {
        // Now validate the csr
        Crypto.getPKCS10CertRequest(certRequest);
    }
}
Also used : PrivateKey(java.security.PrivateKey) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERIA5String(org.bouncycastle.asn1.DERIA5String) GeneralName(org.bouncycastle.asn1.x509.GeneralName) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.testng.annotations.Test)

Aggregations

PKIMessage (org.bouncycastle.asn1.cmp.PKIMessage)4 CertRequest (org.bouncycastle.asn1.crmf.CertRequest)4 CertTemplateBuilder (org.bouncycastle.asn1.crmf.CertTemplateBuilder)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 HashMap (java.util.HashMap)3 DERIA5String (org.bouncycastle.asn1.DERIA5String)3 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)3 CertReqMsg (org.bouncycastle.asn1.crmf.CertReqMsg)3 CertTemplate (org.bouncycastle.asn1.crmf.CertTemplate)3 POPOSigningKey (org.bouncycastle.asn1.crmf.POPOSigningKey)3 ProofOfPossession (org.bouncycastle.asn1.crmf.ProofOfPossession)3 EnrollCertRequest (org.xipki.ca.client.api.dto.EnrollCertRequest)3 PrivateKey (java.security.PrivateKey)2 PublicKey (java.security.PublicKey)2 Date (java.util.Date)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)2 PKIBody (org.bouncycastle.asn1.cmp.PKIBody)2 AttributeTypeAndValue (org.bouncycastle.asn1.crmf.AttributeTypeAndValue)2 CertReqMessages (org.bouncycastle.asn1.crmf.CertReqMessages)2