Example usage for org.bouncycastle.asn1 DEREnumerated getValue

List of usage examples for org.bouncycastle.asn1 DEREnumerated getValue

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 DEREnumerated getValue.

Prototype

public BigInteger getValue() 

Source Link

Usage

From source file:chapter7.X509CRLExample.java

/**
 *
 * @param args//from www. j av a 2s.co m
 * @throws java.lang.Exception
 */
public static void main(String[] args) throws Exception {
    //1.- Create CA keys and certificate
    KeyPair caPair = Utils.generateRSAKeyPair();
    X509Certificate caCert = Utils.generateRootCert(caPair);
    BigInteger revokedSerialNumber = BigInteger.valueOf(2);

    //2.- Create a CRL revoking certificate number 2
    final X509CRL crl = createCRL(caCert, caPair.getPrivate(), revokedSerialNumber);

    //3.- Verify the CRL
    crl.verify(caCert.getPublicKey(), CryptoDefs.Provider.BC.getName());

    //4.- Check if the CRL revokes certificate number 2
    final X509CRLEntry entry = crl.getRevokedCertificate(revokedSerialNumber);

    System.out.println("Revocation details:");
    System.out.println("  Certificate number: " + entry.getSerialNumber());
    System.out.println("  Issuer            : " + crl.getIssuerX500Principal());

    if (entry.hasExtensions() == true) {
        byte[] ext = entry.getExtensionValue(X509Extensions.ReasonCode.getId());

        if (ext != null) {
            DEREnumerated reasonCode = (DEREnumerated) X509ExtensionUtil.fromExtensionValue(ext);

            System.out.println("  Reason Code      : " + reasonCode.getValue());
        }
    }
}

From source file:io.aos.crypto.spl07.X509CRLExample.java

License:Apache License

public static void main(String... args) throws Exception {
    // create CA keys and certificate
    KeyPair caPair = Utils.generateRSAKeyPair();
    X509Certificate caCert = Utils.generateRootCert(caPair);
    BigInteger revokedSerialNumber = BigInteger.valueOf(2);

    // create a CRL revoking certificate number 2
    X509CRL crl = createCRL(caCert, caPair.getPrivate(), revokedSerialNumber);

    // verify the CRL
    crl.verify(caCert.getPublicKey(), "BC");

    // check if the CRL revokes certificate number 2
    X509CRLEntry entry = crl.getRevokedCertificate(revokedSerialNumber);
    System.out.println("Revocation Details:");
    System.out.println("  Certificate number: " + entry.getSerialNumber());
    System.out.println("  Issuer            : " + crl.getIssuerX500Principal());

    if (entry.hasExtensions()) {
        byte[] ext = entry.getExtensionValue(X509Extensions.ReasonCode.getId());

        if (ext != null) {
            DEREnumerated reasonCode = (DEREnumerated) X509ExtensionUtil.fromExtensionValue(ext);

            System.out.println("  Reason Code       : " + reasonCode.getValue());
        }//from  w  w w.  ja va 2  s. c  o  m
    }
}

From source file:mitm.common.security.crl.X509CRLEntryInspector.java

License:Open Source License

/**
 * Returns the reason code, null of this extension does not exist.
 *//*from  ww  w  .  ja v  a2  s  .co m*/
public static Integer getReasonCode(X509CRLEntry crlEntry) throws IOException {
    Integer code = null;

    DEREnumerated reasonCode = DEREnumerated
            .getInstance(ASN1Utils.getExtensionValue(crlEntry, X509Extension.reasonCode.getId()));

    if (reasonCode != null) {
        code = reasonCode.getValue().intValue();
    }

    return code;
}

From source file:org.opensc.pkcs15.asn1.basic.PinType.java

License:Apache License

public PinType(DEREnumerated e) {

    if (e.getValue().intValue() < 0 || e.getValue().intValue() > iso9564_1)
        throw new IllegalArgumentException("Invalid PinType enum value [" + e.getValue() + "]");

    this.value = e.getValue().intValue();
}

From source file:org.signserver.validationservice.server.ValidationUtils.java

License:Open Source License

public static int getReasonCodeFromCRLEntry(X509CRLEntry crlEntry) throws IOException {
    // retrieve reason
    byte[] reasonBytes = crlEntry.getExtensionValue(X509Extension.reasonCode.getId());
    if (reasonBytes == null) {
        // if null then unspecified (RFC 3280)
        return CRLReason.unspecified;
    }/*  w w w.  jav  a 2s .c  om*/

    DEREnumerated reasonCode = (DEREnumerated) X509ExtensionUtil.fromExtensionValue(reasonBytes);

    return reasonCode.getValue().intValue();
}