use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeValidityNotSequence.
/**
* Tests the behavior when trying to decode a certificate with a validity
* element that cannot be parsed as a sequence.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeValidityNotSequence() 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 ASN1OctetString("not a valid sequence"), 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.4")), new ASN1Null()), new ASN1BitString(new boolean[1024]));
new X509Certificate(valueSequence.encode());
}
use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeVersionNotInteger.
/**
* Tests the behavior when trying to decode a certificate with a version that
* cannot be parsed as an integer.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeVersionNotInteger() 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 ASN1BigInteger(12435L), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), X509Certificate.encodeName(new DN("CN=issuer")), new ASN1Sequence(new ASN1UTCTime(notBefore), new ASN1UTCTime(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.4")), new ASN1Null()), new ASN1BitString(new boolean[1024]));
new X509Certificate(valueSequence.encode());
}
use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.
the class PKCS10CertificateSigningRequestTestCase method testCSRWithECKeyMalformedNamedCurve.
/**
* Tests a valid PKCS#10 certificate signing request with an EC public key
* and a malformed named curve.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testCSRWithECKeyMalformedNamedCurve() throws Exception {
final EllipticCurvePublicKey publicKey = new EllipticCurvePublicKey(BigInteger.valueOf(1234567890L), BigInteger.valueOf(9876543210L));
final ArrayList<ObjectPair<OID, ASN1Set>> nonExtensionAttributes = new ArrayList<>(2);
nonExtensionAttributes.add(new ObjectPair<>(new OID("1.2.3.4"), new ASN1Set()));
nonExtensionAttributes.add(new ObjectPair<>(new OID("1.2.3.5"), new ASN1Set()));
PKCS10CertificateSigningRequest csr = new PKCS10CertificateSigningRequest(PKCS10CertificateSigningRequestVersion.V1, SignatureAlgorithmIdentifier.SHA_256_WITH_ECDSA.getOID(), new ASN1Null(), new ASN1BitString(new boolean[2048]), new DN("CN=ldap.example.com,O=Example Corporation,C=US"), PublicKeyAlgorithmIdentifier.EC.getOID(), new ASN1OctetString(), publicKey.encode(), publicKey, nonExtensionAttributes, new SubjectKeyIdentifierExtension(false, new ASN1OctetString("keyIdentifier")), new SubjectAlternativeNameExtension(false, new GeneralNamesBuilder().addDNSName("ldap.example.com").build()));
assertNotNull(csr.toString());
assertNotNull(csr.toPEM());
assertFalse(csr.toPEM().isEmpty());
assertNotNull(csr.toPEMString());
}
use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.
the class PKCS8PrivateKeyTestCase method testDecodedEllipticCurvePrivateKeyWithoutNamedCurveParameter.
/**
* Tests the behavior with a private key created with a decoded elliptic curve
* private key but without a named curve OID as the algorithm parameters.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDecodedEllipticCurvePrivateKeyWithoutNamedCurveParameter() throws Exception {
final EllipticCurvePrivateKey ecPrivateKey = new EllipticCurvePrivateKey(1, new byte[32], NamedCurve.SECP256R1.getOID(), new ASN1BitString(new boolean[256]));
final PKCS8PrivateKey privateKey = new PKCS8PrivateKey(PKCS8PrivateKeyVersion.V1, PublicKeyAlgorithmIdentifier.EC.getOID(), new ASN1Null(), ecPrivateKey.encode(), ecPrivateKey, null, null);
assertNotNull(privateKey.toString());
assertNotNull(privateKey.toPEM());
assertFalse(privateKey.toPEM().isEmpty());
assertNotNull(privateKey.toPEMString());
assertNotNull(privateKey.getPKCS8PrivateKeyBytes());
}
use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.
the class PKCS8PrivateKeyTestCase method testDecodeVersionNotInteger.
/**
* Tests the behavior when trying to decode a byte array that represents a
* sequence with an version element that cannot be parsed as an integer.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeVersionNotInteger() throws Exception {
final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1OctetString(), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), new ASN1OctetString("encoded-private-key"));
new PKCS8PrivateKey(valueSequence.encode());
}
Aggregations