Example usage for org.bouncycastle.cert CertIOException CertIOException

List of usage examples for org.bouncycastle.cert CertIOException CertIOException

Introduction

In this page you can find the example usage for org.bouncycastle.cert CertIOException CertIOException.

Prototype

public CertIOException(String msg) 

Source Link

Usage

From source file:org.wso2.carbon.certificate.mgt.core.impl.CertificateGeneratorNegativeTests.java

License:Open Source License

@Test(description = "This test case tests behaviour when a certificate IO error occurs", expectedExceptions = KeystoreException.class)
public void negativeTestGenerateCertificateFromCSR() throws Exception {
    CertificateGenerator generator = new CertificateGenerator();
    //Prepare mock objects
    X509v3CertificateBuilder mock = Mockito.mock(X509v3CertificateBuilder.class);
    Mockito.when(mock.addExtension(Matchers.any(ASN1ObjectIdentifier.class), Matchers.anyBoolean(),
            Matchers.any(ASN1Encodable.class))).thenThrow(new CertIOException("CERTIO"));
    PowerMockito.whenNew(X509v3CertificateBuilder.class).withAnyArguments().thenReturn(mock);
    //prepare input parameters
    CSRGenerator csrGeneration = new CSRGenerator();
    KeyStoreReader keyStoreReader = new KeyStoreReader();
    KeyPair keyPair = csrGeneration.generateKeyPair("RSA", 1024);
    byte[] csrData = csrGeneration.generateCSR("SHA256WithRSA", keyPair);
    PKCS10CertificationRequest certificationRequest;
    PrivateKey privateKeyCA = keyStoreReader.getCAPrivateKey();
    X509Certificate certCA = (X509Certificate) keyStoreReader.getCACertificate();
    certificationRequest = new PKCS10CertificationRequest(csrData);
    generator.generateCertificateFromCSR(privateKeyCA, certificationRequest,
            certCA.getIssuerX500Principal().getName());

}