use of org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeMalformedSubjectDN.
/**
* Tests the behavior when trying to decode a certificate with a malformed
* subject DN.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeMalformedSubjectDN() 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)), new ASN1OctetString("malformed subject DN"), 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 org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeSignatureAlgorithmMismatch.
/**
* Tests the behavior when trying to decode a certificate with a mismatch in
* the signature algorithm between the TBSCertificate and Certificate
* sequences.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeSignatureAlgorithmMismatch() 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 ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), new ASN1OctetString());
new X509Certificate(valueSequence.encode());
}
use of org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeSignatureAlgorithmElementNotSequence.
/**
* Tests the behavior when trying to decode a certificate with a signature
* algorithm element that is not a valid sequence.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeSignatureAlgorithmElementNotSequence() 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 ASN1OctetString("not a valid sequence"), 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());
}
use of org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class EndTransactionExtendedResult method encodeValue.
/**
* Encodes the provided information into an appropriate value for this
* control.
*
* @param failedOpMessageID The message ID for the operation that failed,
* or {@code null} if there was no failure.
* @param opResponseControls A map containing the response controls for each
* operation, indexed by message ID. It may be
* {@code null} if there were no response
* controls.
*
* @return An ASN.1 octet string containing the encoded value for this
* control, or {@code null} if there should not be a value.
*/
@Nullable()
private static ASN1OctetString encodeValue(@Nullable final Integer failedOpMessageID, @Nullable final Map<Integer, Control[]> opResponseControls) {
if ((failedOpMessageID == null) && (opResponseControls == null)) {
return null;
}
final ArrayList<ASN1Element> elements = new ArrayList<>(2);
if (failedOpMessageID != null) {
elements.add(new ASN1Integer(failedOpMessageID));
}
if ((opResponseControls != null) && (!opResponseControls.isEmpty())) {
final ArrayList<ASN1Element> controlElements = new ArrayList<>(10);
for (final Map.Entry<Integer, Control[]> e : opResponseControls.entrySet()) {
final ASN1Element[] ctlElements = { new ASN1Integer(e.getKey()), Control.encodeControls(e.getValue()) };
controlElements.add(new ASN1Sequence(ctlElements));
}
elements.add(new ASN1Sequence(controlElements));
}
return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
use of org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.
the class EndTransactionExtendedResultTestCase method testConstructorControlsSequenceEmptyControls.
/**
* Tests the generic constructor with a value that is a sequence with an
* element containing a controls sequence that is a sequence with an invalid
* number of controls.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testConstructorControlsSequenceEmptyControls() throws Exception {
ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Sequence(new ASN1Sequence(new ASN1Integer(1), new ASN1Sequence())));
new EndTransactionExtendedResult(new ExtendedResult(1, ResultCode.SUCCESS, null, null, null, null, new ASN1OctetString(valueSequence.encode()), null));
}
Aggregations