Search in sources :

Example 51 with OID

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

Example 52 with OID

use of com.unboundid.util.OID 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());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) OID(com.unboundid.util.OID) ASN1ObjectIdentifier(com.unboundid.asn1.ASN1ObjectIdentifier) ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 53 with OID

use of com.unboundid.util.OID in project ldapsdk by pingidentity.

the class PKCS8PrivateKeyTestCase method testMinimalElementsNotDecodeable.

/**
 * Tests a private key with a minimal set of elements that uses an
 * unrecognized algorithm.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testMinimalElementsNotDecodeable() throws Exception {
    PKCS8PrivateKey privateKey = new PKCS8PrivateKey(PKCS8PrivateKeyVersion.V2, new OID("1.2.3.4"), new ASN1Null(), new ASN1OctetString("encoded-private-key"), null, null, null);
    assertNotNull(privateKey.getPKCS8PrivateKeyBytes());
    privateKey = new PKCS8PrivateKey(privateKey.encode().encode());
    assertNotNull(privateKey.getVersion());
    assertEquals(privateKey.getVersion(), PKCS8PrivateKeyVersion.V2);
    assertNotNull(privateKey.getPrivateKeyAlgorithmOID());
    assertEquals(privateKey.getPrivateKeyAlgorithmOID(), new OID("1.2.3.4"));
    assertNull(privateKey.getPrivateKeyAlgorithmName());
    assertNotNull(privateKey.getPrivateKeyAlgorithmNameOrOID());
    assertEquals(privateKey.getPrivateKeyAlgorithmNameOrOID(), "1.2.3.4");
    assertNotNull(privateKey.getPrivateKeyAlgorithmParameters());
    assertNotNull(privateKey.getEncodedPrivateKey());
    assertEquals(privateKey.getEncodedPrivateKey().getValue(), new ASN1OctetString("encoded-private-key").getValue());
    assertNull(privateKey.getDecodedPrivateKey());
    assertNotNull(privateKey.toString());
    assertNotNull(privateKey.toPEM());
    assertFalse(privateKey.toPEM().isEmpty());
    assertNotNull(privateKey.toPEMString());
    assertNotNull(privateKey.getPKCS8PrivateKeyBytes());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) OID(com.unboundid.util.OID) ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 54 with OID

use of com.unboundid.util.OID in project ldapsdk by pingidentity.

the class PKCS8PrivateKeyTestCase method testDecodeMalformedPublicKey.

/**
 * Tests the behavior when trying to decode a byte array that represents a
 * sequence with a malformed public key.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { CertException.class })
public void testDecodeMalformedPublicKey() throws Exception {
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Integer(0), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), new ASN1OctetString("encoded-private-key"), new ASN1OctetString((byte) 0x81));
    new PKCS8PrivateKey(valueSequence.encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Integer(com.unboundid.asn1.ASN1Integer) OID(com.unboundid.util.OID) ASN1ObjectIdentifier(com.unboundid.asn1.ASN1ObjectIdentifier) ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 55 with OID

use of com.unboundid.util.OID in project ldapsdk by pingidentity.

the class PKCS8PrivateKeyTestCase method testEncodeWithInvalidAlgorithmIdentifierOID.

/**
 * Tests the behavior when trying to encode a private key with an algorithm
 * identifier that is not a valid OID.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { CertException.class })
public void testEncodeWithInvalidAlgorithmIdentifierOID() throws Exception {
    final PKCS8PrivateKey privateKey = new PKCS8PrivateKey(PKCS8PrivateKeyVersion.V2, new OID("1234.5678"), new ASN1Null(), new ASN1OctetString("encoded-private-key"), null, null, null);
    privateKey.encode();
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) OID(com.unboundid.util.OID) 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