use of com.unboundid.asn1.ASN1BitString in project ldapsdk by pingidentity.
the class EllipticCurvePrivateKeyTestCase method testAllElementsWithPublicKeyMultipleOfEightBits.
/**
* Tests a private key with all elements and a public key size that is a
* multiple of eight bits.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testAllElementsWithPublicKeyMultipleOfEightBits() throws Exception {
EllipticCurvePrivateKey privateKey = new EllipticCurvePrivateKey(1, new byte[32], NamedCurve.SECP256R1.getOID(), new ASN1BitString(new boolean[256]));
privateKey = new EllipticCurvePrivateKey(privateKey.encode());
assertEquals(privateKey.getVersion(), 1);
assertNotNull(privateKey.getPrivateKeyBytes());
assertEquals(privateKey.getPrivateKeyBytes(), new byte[32]);
assertNotNull(privateKey.getNamedCurveOID());
assertEquals(privateKey.getNamedCurveOID(), NamedCurve.SECP256R1.getOID());
assertNotNull(privateKey.getPublicKey());
assertNotNull(privateKey.toString());
}
use of com.unboundid.asn1.ASN1BitString in project ldapsdk by pingidentity.
the class EllipticCurvePrivateKeyTestCase method testAllElementsWithPublicKeyNotMultipleOfEightBits.
/**
* Tests a private key with all elements and a public key size that is not a
* multiple of eight bits.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testAllElementsWithPublicKeyNotMultipleOfEightBits() throws Exception {
EllipticCurvePrivateKey privateKey = new EllipticCurvePrivateKey(1, new byte[32], NamedCurve.SECP256R1.getOID(), new ASN1BitString(new boolean[25]));
privateKey = new EllipticCurvePrivateKey(privateKey.encode());
assertEquals(privateKey.getVersion(), 1);
assertNotNull(privateKey.getPrivateKeyBytes());
assertEquals(privateKey.getPrivateKeyBytes(), new byte[32]);
assertNotNull(privateKey.getNamedCurveOID());
assertEquals(privateKey.getNamedCurveOID(), NamedCurve.SECP256R1.getOID());
assertNotNull(privateKey.getPublicKey());
assertNotNull(privateKey.toString());
}
use of com.unboundid.asn1.ASN1BitString in project ldapsdk by pingidentity.
the class EllipticCurvePublicKeyTestCase method testDecodeCompressedKeyWithWrongFirstByte.
/**
* Tests the behavior when trying to decode a public key that is 33 bytes long
* but doesn't start with 0x02 or 0x03.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeCompressedKeyWithWrongFirstByte() throws Exception {
final byte[] keyBytes = new byte[33];
keyBytes[0] = (byte) 0xFF;
final ASN1BitString bitString = new ASN1BitString(ASN1BitString.getBitsForBytes(keyBytes));
new EllipticCurvePublicKey(bitString);
}
use of com.unboundid.asn1.ASN1BitString in project ldapsdk by pingidentity.
the class EllipticCurvePublicKeyTestCase method testDecodeUncompressedKeyWithWrongFirstByte.
/**
* Tests the behavior when trying to decode a public key that is 65 bytes long
* but doesn't start with 0x04.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeUncompressedKeyWithWrongFirstByte() throws Exception {
final byte[] keyBytes = new byte[65];
keyBytes[0] = (byte) 0xFF;
final ASN1BitString bitString = new ASN1BitString(ASN1BitString.getBitsForBytes(keyBytes));
new EllipticCurvePublicKey(bitString);
}
use of com.unboundid.asn1.ASN1BitString in project ldapsdk by pingidentity.
the class X509CertificateTestCase method testDecodeMalformedIssuerUniqueID.
/**
* Tests the behavior when trying to decode a certificate with a malformed
* issuer unique ID.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test(expectedExceptions = { CertException.class })
public void testDecodeMalformedIssuerUniqueID() 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) 0x81)), new ASN1Sequence(new ASN1ObjectIdentifier(new OID("1.2.3.4")), new ASN1Null()), new ASN1BitString(new boolean[1024]));
new X509Certificate(valueSequence.encode());
}
Aggregations