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());
}
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());
}
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());
}
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()));
}
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;
}
}
Aggregations