Search in sources :

Example 6 with OID

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);
}
Also used : OID(com.unboundid.util.OID) Test(org.testng.annotations.Test)

Example 7 with OID

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());
}
Also used : OID(com.unboundid.util.OID) Test(org.testng.annotations.Test)

Example 8 with OID

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();
}
Also used : DN(com.unboundid.ldap.sdk.DN) OID(com.unboundid.util.OID) ASN1BitString(com.unboundid.asn1.ASN1BitString) ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 9 with OID

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());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1UTCTime(com.unboundid.asn1.ASN1UTCTime) ASN1BigInteger(com.unboundid.asn1.ASN1BigInteger) DN(com.unboundid.ldap.sdk.DN) ASN1Integer(com.unboundid.asn1.ASN1Integer) OID(com.unboundid.util.OID) ASN1BitString(com.unboundid.asn1.ASN1BitString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1ObjectIdentifier(com.unboundid.asn1.ASN1ObjectIdentifier) ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 10 with OID

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());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1UTCTime(com.unboundid.asn1.ASN1UTCTime) DN(com.unboundid.ldap.sdk.DN) 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)

Aggregations

OID (com.unboundid.util.OID)66 Test (org.testng.annotations.Test)53 ASN1BitString (com.unboundid.asn1.ASN1BitString)38 DN (com.unboundid.ldap.sdk.DN)38 ASN1Null (com.unboundid.asn1.ASN1Null)32 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)30 ASN1ObjectIdentifier (com.unboundid.asn1.ASN1ObjectIdentifier)25 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)23 ASN1Element (com.unboundid.asn1.ASN1Element)21 ASN1Integer (com.unboundid.asn1.ASN1Integer)18 ASN1BigInteger (com.unboundid.asn1.ASN1BigInteger)16 ASN1GeneralizedTime (com.unboundid.asn1.ASN1GeneralizedTime)9 NotNull (com.unboundid.util.NotNull)8 ArrayList (java.util.ArrayList)7 ASN1UTCTime (com.unboundid.asn1.ASN1UTCTime)6 Date (java.util.Date)6 ASN1Set (com.unboundid.asn1.ASN1Set)4 RDN (com.unboundid.ldap.sdk.RDN)4 File (java.io.File)4 KeyPair (java.security.KeyPair)4