use of com.unboundid.util.OID in project ldapsdk by pingidentity.
the class SubjectKeyIdentifierExtensionTestCase method testExtensionValueNotOctetString.
/**
* Tests the behavior with an extension whose value cannot be parsed as an
* ASN.1 octet string.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testExtensionValueNotOctetString() throws Exception {
final X509CertificateExtension genericExtension = new X509CertificateExtension(new OID("2.5.29.14"), false, StaticUtils.NO_BYTES);
new SubjectKeyIdentifierExtension(genericExtension);
}
use of com.unboundid.util.OID in project ldapsdk by pingidentity.
the class X509CertificateExtensionTestCase method testCriticalWithPrintableValue.
/**
* Tests the behavior with a critical extension and a printable value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testCriticalWithPrintableValue() throws Exception {
X509CertificateExtension extension = new X509CertificateExtension(new OID("1.2.3.4"), true, "foo".getBytes("UTF-8"));
extension = new X509CertificateExtension(extension);
assertNotNull(extension.getOID());
assertEquals(extension.getOID().toString(), "1.2.3.4");
assertTrue(extension.isCritical());
assertNotNull(extension.getValue());
assertEquals(extension.getValue(), "foo".getBytes("UTF-8"));
assertNotNull(extension.encode());
assertNotNull(extension.getExtensionName());
assertEquals(extension.getExtensionName(), "1.2.3.4");
assertNotNull(extension.toString());
}
use of com.unboundid.util.OID in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testEncodeCertificateWithInvalidOID.
/**
* Tests the behavior when trying to encode a certificate that includes a
* malformed OID.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testEncodeCertificateWithInvalidOID() throws Exception {
final long notBefore = System.currentTimeMillis();
final long notAfter = notBefore + (365L * 24L * 60L * 60L * 1000L);
final X509Certificate c = new X509Certificate(X509CertificateVersion.V1, BigInteger.valueOf(123456789L), new OID("1234.5678"), new ASN1Null(), new ASN1BitString(new boolean[1235]), new DN("CN=Issuer,O=Example Corp,C=US"), notBefore, notAfter, new DN("CN=ldap.example.com,O=Example Corp,C=US"), new OID("1.2.3.5"), new ASN1Null(), new ASN1BitString(new boolean[123]), null, null, null);
c.encode();
}
use of com.unboundid.util.OID in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeValidityMalformedNotBefore.
/**
* Tests the behavior when trying to decode a certificate with a validity
* sequence whose first element is neither a UTCTime nor a GeneralizedTime.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeValidityMalformedNotBefore() 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 ASN1OctetString("malformed 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.util.OID in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeSerialNumberNotInteger.
/**
* Tests the behavior when trying to decode a certificate with a serial number
* that cannot be parsed as an integer.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeSerialNumberNotInteger() 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 ASN1OctetString(), 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());
}
Aggregations