Search in sources :

Example 81 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class X509CertificateTestCase method testDecodeMalformedSubjectUniqueID.

/**
 * 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 testDecodeMalformedSubjectUniqueID() 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) 0x82)), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), new ASN1BitString(new boolean[1024]));
    new X509Certificate(valueSequence.encode());
}
Also used : ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1BigInteger(com.unboundid.asn1.ASN1BigInteger) DN(com.unboundid.ldap.sdk.DN) ASN1GeneralizedTime(com.unboundid.asn1.ASN1GeneralizedTime) 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)

Example 82 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class X509CertificateTestCase method testDecodeValidityMalformedNotAfter.

/**
 * Tests the behavior when trying to decode a certificate with a validity
 * sequence whose second element is neither a UTCTime nor a GeneralizedTime.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { CertException.class })
public void testDecodeValidityMalformedNotAfter() 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 ASN1OctetString("malformed 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) ASN1BigInteger(com.unboundid.asn1.ASN1BigInteger) DN(com.unboundid.ldap.sdk.DN) ASN1GeneralizedTime(com.unboundid.asn1.ASN1GeneralizedTime) 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 83 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class PKCS8PrivateKeyTestCase method testDecodeInvalidAlgorithmIdentifier.

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

Example 84 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class RSAPrivateKeyTestCase method testDecodeKeyInvalidVersion.

/**
 * Tests the behavior when trying to decode a private key with an invalid
 * version.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { CertException.class })
public void testDecodeKeyInvalidVersion() throws Exception {
    final ASN1Sequence pkSequence = new ASN1Sequence(new ASN1Integer(123), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE), new ASN1BigInteger(BigInteger.ONE));
    new RSAPrivateKey(new ASN1OctetString(pkSequence.encode()));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1BigInteger(com.unboundid.asn1.ASN1BigInteger) ASN1Integer(com.unboundid.asn1.ASN1Integer) Test(org.testng.annotations.Test)

Example 85 with ASN1Sequence

use of com.github.zhenwei.core.asn1.ASN1Sequence in project ldapsdk by pingidentity.

the class MatchedValuesFilter method encode.

/**
 * Encodes this matched values filter for use in the matched values control.
 *
 * @return  The ASN.1 element containing the encoded representation of this
 *          matched values filter.
 */
@NotNull()
public ASN1Element encode() {
    switch(matchType) {
        case MATCH_TYPE_EQUALITY:
        case MATCH_TYPE_GREATER_OR_EQUAL:
        case MATCH_TYPE_LESS_OR_EQUAL:
        case MATCH_TYPE_APPROXIMATE:
            ASN1Element[] elements = { new ASN1OctetString(attributeType), assertionValue };
            return new ASN1Sequence(matchType, elements);
        case MATCH_TYPE_SUBSTRINGS:
            final ArrayList<ASN1Element> subElements = new ArrayList<>(3);
            if (subInitialValue != null) {
                subElements.add(subInitialValue);
            }
            if (subAnyValues.length > 0) {
                subElements.addAll(Arrays.asList(subAnyValues));
            }
            if (subFinalValue != null) {
                subElements.add(subFinalValue);
            }
            elements = new ASN1Element[] { new ASN1OctetString(attributeType), new ASN1Sequence(subElements) };
            return new ASN1Sequence(matchType, elements);
        case MATCH_TYPE_PRESENT:
            return new ASN1OctetString(matchType, attributeType);
        case MATCH_TYPE_EXTENSIBLE:
            final ArrayList<ASN1Element> extElements = new ArrayList<>(3);
            if (attributeType != null) {
                extElements.add(new ASN1OctetString(EXTENSIBLE_TYPE_ATTRIBUTE_NAME, attributeType));
            }
            if (matchingRuleID != null) {
                extElements.add(new ASN1OctetString(EXTENSIBLE_TYPE_MATCHING_RULE_ID, matchingRuleID));
            }
            extElements.add(assertionValue);
            return new ASN1Sequence(matchType, extElements);
        default:
            // This should never happen.
            return null;
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) NotNull(com.unboundid.util.NotNull)

Aggregations

ASN1Sequence (com.unboundid.asn1.ASN1Sequence)455 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)397 Test (org.testng.annotations.Test)311 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)297 ASN1Element (com.unboundid.asn1.ASN1Element)231 ArrayList (java.util.ArrayList)184 IOException (java.io.IOException)141 NotNull (com.unboundid.util.NotNull)116 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)95 ASN1Integer (com.unboundid.asn1.ASN1Integer)94 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)85 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)76 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)73 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)69 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)64 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)57 Enumeration (java.util.Enumeration)54 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)53 X509Certificate (java.security.cert.X509Certificate)53 BigInteger (java.math.BigInteger)50