Search in sources :

Example 36 with ASN1GeneralizedTime

use of com.unboundid.asn1.ASN1GeneralizedTime in project ldapsdk by pingidentity.

the class X509CertificateTestCase method testDecodeMalformedIssuerUniqueID.

/**
 * Tests the behavior when trying to decode a certificate with a malformed
 * issuer unique ID.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { CertException.class })
public void testDecodeMalformedIssuerUniqueID() throws Exception {
    final long notBefore = System.currentTimeMillis();
    final long notAfter = notBefore + (365L * 24L * 60L * 60L * 1000L);
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Sequence(new ASN1Element((byte) 0xA0, new ASN1Integer(2).encode()), new ASN1BigInteger(12435L), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), X509Certificate.encodeName(new DN("CN=issuer")), new ASN1Sequence(new ASN1GeneralizedTime(notBefore), new ASN1GeneralizedTime(notAfter)), X509Certificate.encodeName(new DN("CN=ldap.example.com")), new ASN1Sequence(new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.5")), new ASN1Null()), new ASN1BitString(new boolean[1024])), new ASN1Element((byte) 0x81)), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), new ASN1BitString(new boolean[1024]));
    new X509Certificate(valueSequence.encode());
}
Also used : ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1BigInteger(com.unboundid.asn1.ASN1BigInteger) DN(com.unboundid.ldap.sdk.DN) ASN1GeneralizedTime(com.unboundid.asn1.ASN1GeneralizedTime) ASN1Integer(com.unboundid.asn1.ASN1Integer) OID(com.unboundid.util.OID) ASN1ObjectIdentifier(com.unboundid.asn1.ASN1ObjectIdentifier) ASN1BitString(com.unboundid.asn1.ASN1BitString) ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 37 with ASN1GeneralizedTime

use of com.unboundid.asn1.ASN1GeneralizedTime in project ldapsdk by pingidentity.

the class X509CertificateTestCase method testDecodeMalformedExtension.

/**
 * Tests the behavior when trying to decode a certificate with a malformed
 * subject unique ID.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { CertException.class })
public void testDecodeMalformedExtension() throws Exception {
    final long notBefore = System.currentTimeMillis();
    final long notAfter = notBefore + (365L * 24L * 60L * 60L * 1000L);
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Sequence(new ASN1Element((byte) 0xA0, new ASN1Integer(2).encode()), new ASN1BigInteger(12435L), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), X509Certificate.encodeName(new DN("CN=issuer")), new ASN1Sequence(new ASN1GeneralizedTime(notBefore), new ASN1GeneralizedTime(notAfter)), X509Certificate.encodeName(new DN("CN=ldap.example.com")), new ASN1Sequence(new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.5")), new ASN1Null()), new ASN1BitString(new boolean[1024])), new ASN1Element((byte) 0xA3)), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), new ASN1BitString(new boolean[1024]));
    new X509Certificate(valueSequence.encode());
}
Also used : ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1BigInteger(com.unboundid.asn1.ASN1BigInteger) DN(com.unboundid.ldap.sdk.DN) ASN1GeneralizedTime(com.unboundid.asn1.ASN1GeneralizedTime) ASN1Integer(com.unboundid.asn1.ASN1Integer) OID(com.unboundid.util.OID) ASN1ObjectIdentifier(com.unboundid.asn1.ASN1ObjectIdentifier) ASN1BitString(com.unboundid.asn1.ASN1BitString) ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 38 with ASN1GeneralizedTime

use of com.unboundid.asn1.ASN1GeneralizedTime in project ldapsdk by pingidentity.

the class X509CertificateTestCase method testDecodeMalformedSignatureBitString.

/**
 * Tests the behavior when trying to decode a certificate with a malformed
 * signature bit string.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { CertException.class })
public void testDecodeMalformedSignatureBitString() throws Exception {
    final long notBefore = System.currentTimeMillis();
    final long notAfter = notBefore + (365L * 24L * 60L * 60L * 1000L);
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Sequence(new ASN1Element((byte) 0xA0, new ASN1Integer(2).encode()), new ASN1BigInteger(12435L), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), X509Certificate.encodeName(new DN("CN=issuer")), new ASN1Sequence(new ASN1GeneralizedTime(notBefore), new ASN1GeneralizedTime(notAfter)), X509Certificate.encodeName(new DN("CN=ldap.example.com")), new ASN1Sequence(new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.5")), new ASN1Null()), new ASN1BitString(new boolean[1024]))), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.5")), new ASN1Null()), new ASN1BitString(new boolean[1024]));
    new X509Certificate(valueSequence.encode());
}
Also used : ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1BigInteger(com.unboundid.asn1.ASN1BigInteger) DN(com.unboundid.ldap.sdk.DN) ASN1GeneralizedTime(com.unboundid.asn1.ASN1GeneralizedTime) ASN1Integer(com.unboundid.asn1.ASN1Integer) OID(com.unboundid.util.OID) ASN1ObjectIdentifier(com.unboundid.asn1.ASN1ObjectIdentifier) ASN1BitString(com.unboundid.asn1.ASN1BitString) ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 39 with ASN1GeneralizedTime

use of com.unboundid.asn1.ASN1GeneralizedTime in project attestation by TokenScript.

the class Attestation method getPrehash.

/**
 * Construct the DER encoded byte array to be signed. Returns null if the Attestation object is
 * not valid
 */
public byte[] getPrehash(boolean blockchainFriendlyEncoding) {
    if (!checkValidity()) {
        logger.error("Attestation is not valid");
        return null;
    }
    ASN1EncodableVector res = new ASN1EncodableVector();
    res.add(new DERTaggedObject(true, 0, this.version));
    res.add(this.serialNumber);
    res.add(this.signingAlgorithm);
    res.add(this.issuer == null ? new DERSequence() : this.issuer);
    if (this.notValidAfter != null && this.notValidBefore != null) {
        ASN1EncodableVector date = new ASN1EncodableVector();
        date.add(new ASN1GeneralizedTime(this.notValidBefore));
        if (blockchainFriendlyEncoding) {
            date.add(new ASN1Integer(this.notValidBefore.getTime()));
        }
        date.add(new ASN1GeneralizedTime(this.notValidAfter));
        if (blockchainFriendlyEncoding) {
            date.add(new ASN1Integer(this.notValidAfter.getTime()));
        }
        res.add(new DERSequence(date));
    } else {
        res.add(DERNull.INSTANCE);
    }
    res.add(this.subject == null ? new DERSequence() : this.subject);
    res.add(this.subjectPublicKeyInfo == null ? DERNull.INSTANCE : this.subjectPublicKeyInfo);
    if (this.smartcontracts != null) {
        res.add(this.smartcontracts);
    }
    // The validity check ensure that only one of "extensions" and "dataObject" is set
    if (this.extensions != null) {
        res.add(new DERTaggedObject(true, 3, this.extensions));
    }
    if (this.dataObject != null) {
        res.add(new DERTaggedObject(true, 4, this.dataObject));
    }
    try {
        return new DERSequence(res).getEncoded();
    } catch (IOException e) {
        throw ExceptionUtil.makeRuntimeException(logger, "Could not encode asn1", e);
    }
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1GeneralizedTime(org.bouncycastle.asn1.ASN1GeneralizedTime) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) IOException(java.io.IOException)

Example 40 with ASN1GeneralizedTime

use of com.unboundid.asn1.ASN1GeneralizedTime in project attestation by TokenScript.

the class Cheque method makeCheque.

private ASN1Sequence makeCheque(byte[] commitment, long amount, long notValidBefore, long notValidAfter) {
    ASN1EncodableVector cheque = new ASN1EncodableVector();
    cheque.add(new ASN1Integer(amount));
    ASN1GeneralizedTime notValidBeforeEnc = new ASN1GeneralizedTime(new Date(notValidBefore));
    ASN1GeneralizedTime notValidAfterEnc = new ASN1GeneralizedTime(new Date(notValidAfter));
    ASN1Sequence validityEnc = new DERSequence(new ASN1Encodable[] { notValidBeforeEnc, notValidAfterEnc });
    cheque.add(validityEnc);
    cheque.add(new DEROctetString(commitment));
    return new DERSequence(cheque);
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1GeneralizedTime(org.bouncycastle.asn1.ASN1GeneralizedTime) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) Date(java.util.Date) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Aggregations

ASN1GeneralizedTime (org.bouncycastle.asn1.ASN1GeneralizedTime)24 ASN1GeneralizedTime (com.unboundid.asn1.ASN1GeneralizedTime)10 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)10 IOException (java.io.IOException)10 Date (java.util.Date)10 ASN1BigInteger (com.unboundid.asn1.ASN1BigInteger)9 ASN1BitString (com.unboundid.asn1.ASN1BitString)9 ASN1Element (com.unboundid.asn1.ASN1Element)9 ASN1Integer (com.unboundid.asn1.ASN1Integer)9 ASN1Null (com.unboundid.asn1.ASN1Null)9 ASN1ObjectIdentifier (com.unboundid.asn1.ASN1ObjectIdentifier)9 DN (com.unboundid.ldap.sdk.DN)9 OID (com.unboundid.util.OID)9 Test (org.testng.annotations.Test)9 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)7 DEROctetString (org.bouncycastle.asn1.DEROctetString)7 ASN1GeneralizedTime (com.github.zhenwei.core.asn1.ASN1GeneralizedTime)6 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)6 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5