Search in sources :

Example 31 with ASN1Integer

use of org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.

the class DraftBeheraLDAPPasswordPolicy10ResponseControlTestCase method testDecodeControlAllTypes.

/**
 * Tests the {@code decodeControl} method with a valid set of information
 * with all element types.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDecodeControlAllTypes() throws Exception {
    ASN1Element[] valueElements = { new ASN1Element((byte) 0xA0, new ASN1Integer((byte) 0x80, 12345).encode()), new ASN1Enumerated((byte) 0x81, 0) };
    ASN1OctetString value = new ASN1OctetString(new ASN1Sequence(valueElements).encode());
    DraftBeheraLDAPPasswordPolicy10ResponseControl c = new DraftBeheraLDAPPasswordPolicy10ResponseControl().decodeControl("1.3.6.1.4.1.42.2.27.8.5.1", false, value);
    assertNotNull(c.getWarningType());
    assertEquals(c.getWarningType(), DraftBeheraLDAPPasswordPolicy10WarningType.TIME_BEFORE_EXPIRATION);
    assertEquals(c.getWarningValue(), 12345);
    assertNotNull(c.getErrorType());
    assertEquals(c.getErrorType(), DraftBeheraLDAPPasswordPolicy10ErrorType.PASSWORD_EXPIRED);
    assertNotNull(c.getControlName());
    assertNotNull(c.toString());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1Integer(com.unboundid.asn1.ASN1Integer) Test(org.testng.annotations.Test)

Example 32 with ASN1Integer

use of org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.

the class DraftBeheraLDAPPasswordPolicy10ResponseControlTestCase method testDecodeControlValueSequenceTooManyElements.

/**
 * Tests the {@code decodeControl} method with a value sequence with too many
 * elements.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testDecodeControlValueSequenceTooManyElements() throws Exception {
    ASN1Element[] valueElements = { new ASN1Element((byte) 0xA0, new ASN1Integer((byte) 0x80, 12345).encode()), new ASN1Enumerated((byte) 0x81, 0), new ASN1Integer(0) };
    ASN1OctetString value = new ASN1OctetString(new ASN1Sequence(valueElements).encode());
    new DraftBeheraLDAPPasswordPolicy10ResponseControl().decodeControl("1.3.6.1.4.1.42.2.27.8.5.1", false, value);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ASN1Integer(com.unboundid.asn1.ASN1Integer) Test(org.testng.annotations.Test)

Example 33 with ASN1Integer

use of org.webpki.asn1.ASN1Integer in project ldapsdk by pingidentity.

the class CryptoHelperTestCase method testInferKeyStoreTypeSequenceFirstElementIntegerUnexpectedValue.

/**
 * Tests the behavior for the {@code inferKeyStoreType} method with a file
 * that contains an empty ASN.1 sequence in which the first element is an
 * integer with a value that is not 3 (the expected value for a PKCS #12 key
 * store).
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testInferKeyStoreTypeSequenceFirstElementIntegerUnexpectedValue() throws Exception {
    final File f = createTempFile();
    assertTrue(f.delete());
    try (FileOutputStream fos = new FileOutputStream(f)) {
        new ASN1Sequence(new ASN1Integer(0)).writeTo(fos);
    }
    try {
        CryptoHelper.inferKeyStoreType(f);
        fail("Expected an exception from inferKeyStoreType with a file " + "containing an ASN.1 sequence in which the first element is an " + "integer with a value that is not 3");
    } catch (final KeyStoreException e) {
    // This was expected.
    }
}
Also used : ASN1Sequence(com.unboundid.asn1.ASN1Sequence) FileOutputStream(java.io.FileOutputStream) ASN1Integer(com.unboundid.asn1.ASN1Integer) KeyStoreException(java.security.KeyStoreException) File(java.io.File) Test(org.testng.annotations.Test)

Example 34 with ASN1Integer

use of org.webpki.asn1.ASN1Integer in project OpenUnison by TremoloSecurity.

the class X509ExtensionParsingUtil method getInt.

/**
 * Extracts an {@code int} from an {@link ASN1Encodable}.
 * @throws CertificateParsingException
 */
public static int getInt(ASN1Encodable asn1Encodable) throws CertificateParsingException {
    if (asn1Encodable == null || !(asn1Encodable instanceof ASN1Integer)) {
        throw new CertificateParsingException("Expected INTEGER type.");
    }
    ASN1Integer asn1Integer = (ASN1Integer) asn1Encodable;
    BigInteger bigInt = asn1Integer.getPositiveValue();
    if (bigInt.bitLength() > MAX_INT_BITS) {
        throw new CertificateParsingException("INTEGER too big");
    }
    return bigInt.intValue();
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) BigInteger(java.math.BigInteger) ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Example 35 with ASN1Integer

use of org.webpki.asn1.ASN1Integer in project OpenUnison by TremoloSecurity.

the class X509ExtensionParsingUtil method getLong.

/**
 * Extracts an {@code long} from an {@link ASN1Encodable}.
 * @throws CertificateParsingException
 */
public static long getLong(ASN1Encodable asn1Encodable) throws CertificateParsingException {
    if (asn1Encodable == null || !(asn1Encodable instanceof ASN1Integer)) {
        throw new CertificateParsingException("Expected INTEGER type.");
    }
    ASN1Integer asn1Integer = (ASN1Integer) asn1Encodable;
    BigInteger bigInt = asn1Integer.getPositiveValue();
    if (bigInt.bitLength() > MAX_LONG_BITS) {
        throw new CertificateParsingException("INTEGER too big");
    }
    return bigInt.longValue();
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) BigInteger(java.math.BigInteger) ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Aggregations

ASN1Integer (org.bouncycastle.asn1.ASN1Integer)213 ASN1Integer (com.unboundid.asn1.ASN1Integer)96 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)94 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)91 IOException (java.io.IOException)89 DERSequence (org.bouncycastle.asn1.DERSequence)89 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)86 BigInteger (java.math.BigInteger)86 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)80 ASN1Element (com.unboundid.asn1.ASN1Element)69 Test (org.testng.annotations.Test)63 ArrayList (java.util.ArrayList)50 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)49 DERSequence (com.github.zhenwei.core.asn1.DERSequence)47 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)47 DEROctetString (org.bouncycastle.asn1.DEROctetString)38 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)35 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)28 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)27 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)27