Example usage for org.bouncycastle.asn1.cmp PKIConfirmContent toASN1Primitive

List of usage examples for org.bouncycastle.asn1.cmp PKIConfirmContent toASN1Primitive

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.cmp PKIConfirmContent toASN1Primitive.

Prototype

public ASN1Primitive toASN1Primitive() 

Source Link

Document

 PKIConfirmContent ::= NULL 

Usage

From source file:org.ejbca.core.protocol.cmp.CmpTestCase.java

License:Open Source License

protected static void checkCmpPKIConfirmMessage(X500Name userDN, Certificate cacert, byte[] retMsg)
        throws IOException {
    ///* www . j a  v a 2s  . co  m*/
    // Parse response message
    //
    PKIMessage respObject = null;
    ASN1InputStream asn1InputStream = new ASN1InputStream(new ByteArrayInputStream(retMsg));
    try {
        respObject = PKIMessage.getInstance(asn1InputStream.readObject());
    } finally {
        asn1InputStream.close();
    }
    assertNotNull(respObject);
    PKIHeader header = respObject.getHeader();
    assertEquals(header.getSender().getTagNo(), 4);

    X509Principal responseDN = new X509Principal(header.getSender().getName().toString());
    X509Principal expectedDN = new X509Principal(
            ((X509Certificate) cacert).getSubjectDN().getName().toString());
    assertEquals(expectedDN.getName(), responseDN.getName());

    responseDN = new X509Principal(header.getRecipient().getName().toString());
    expectedDN = new X509Principal(userDN);
    assertEquals(expectedDN.getName(), responseDN.getName());

    PKIBody body = respObject.getBody();
    int tag = body.getType();
    assertEquals(19, tag);
    PKIConfirmContent n = (PKIConfirmContent) body.getContent();
    assertNotNull(n);
    assertEquals(DERNull.INSTANCE, n.toASN1Primitive());
}

From source file:org.ejbca.ui.cmpclient.commands.ConfirmationRequestCommand.java

License:Open Source License

@Override
public CommandResult handleCMPResponse(byte[] response, ParameterContainer parameters) throws Exception {
    PKIMessage respObject = null;// w  w w. j a v a 2s  . c  om
    ASN1InputStream asn1InputStream = new ASN1InputStream(new ByteArrayInputStream(response));
    try {
        respObject = PKIMessage.getInstance(asn1InputStream.readObject());
    } finally {
        asn1InputStream.close();
    }
    if (respObject == null) {
        log.error("ERROR. Cannot construct the response object");
        return CommandResult.FUNCTIONAL_FAILURE;
    }

    PKIBody body = respObject.getBody();
    int tag = body.getType();
    if (tag == 19) {
        log.info("Recieved CmpConfirmResponse");
    } else {
        log.error("Error: CmpConfirmResponse should be recieved. Instead, received response with tag " + tag);
    }
    PKIConfirmContent n = (PKIConfirmContent) body.getContent();

    if (n.toASN1Primitive().equals(DERNull.INSTANCE)) {
        log.info("CmpConfirmResponse contains DERNull as expected.");
        return CommandResult.SUCCESS;
    } else {
        log.error("Error: CmpConfirmResponse should contain DERNull. It did not.");
    }
    return CommandResult.FUNCTIONAL_FAILURE;
}