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());
}
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());
}
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());
}
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);
}
}
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);
}
Aggregations