Search in sources :

Example 41 with ASN1Null

use of com.unboundid.asn1.ASN1Null in project openkeystore by cyberphone.

the class PKCS7Signer method sign.

private byte[] sign(byte[] message, boolean detached) throws IOException, GeneralSecurityException {
    ArrayList<BaseASN1Object> cert_path = new ArrayList<>();
    for (X509Certificate c : certificatePath) {
        cert_path.add(ASN1Util.x509Certificate(c));
    }
    BaseASN1Object signer_cert = cert_path.get(0);
    int i = ParseUtil.isContext(signer_cert.get(new int[] { 0, 0 }), 0) ? 1 : 0;
    BaseASN1Object sign_info = signer_cert.get(new int[] { 0, i + 2 });
    BaseASN1Object cert_ref = signer_cert.get(new int[] { 0, i });
    String digest_oid = signer_implem.getAlgorithm().getDigestAlgorithm().getOid();
    String encryption_oid = AsymEncryptionAlgorithms.RSA_ES_PKCS_1_5.getOid();
    byte[] signed_data = signer_implem.signData(message);
    BaseASN1Object r = ASN1Util.oidValue(PKCS7_SIGNED_DATA, new CompositeContextSpecific(0, new ASN1Sequence(new BaseASN1Object[] { new ASN1Integer(1), ASN1Util.oidValueSet(digest_oid, new ASN1Null()), detached ? new ASN1Sequence((BaseASN1Object) new ASN1ObjectID(PKCS7_DATA)) : (BaseASN1Object) ASN1Util.oidValue(PKCS7_DATA, new CompositeContextSpecific(0, new ASN1OctetString(message))), new CompositeContextSpecific(0, cert_path), new ASN1Set(new ASN1Sequence(new BaseASN1Object[] { new ASN1Integer(1), new ASN1Sequence(new BaseASN1Object[] { sign_info, cert_ref }), ASN1Util.oidNull(digest_oid), ASN1Util.oidNull(encryption_oid), new ASN1OctetString(signed_data) })) })));
    return r.encode();
}
Also used : ASN1OctetString(org.webpki.asn1.ASN1OctetString) BaseASN1Object(org.webpki.asn1.BaseASN1Object) CompositeContextSpecific(org.webpki.asn1.CompositeContextSpecific) ArrayList(java.util.ArrayList) ASN1OctetString(org.webpki.asn1.ASN1OctetString) ASN1Integer(org.webpki.asn1.ASN1Integer) X509Certificate(java.security.cert.X509Certificate) ASN1Sequence(org.webpki.asn1.ASN1Sequence) ASN1Set(org.webpki.asn1.ASN1Set) ASN1ObjectID(org.webpki.asn1.ASN1ObjectID) ASN1Null(org.webpki.asn1.ASN1Null)

Example 42 with ASN1Null

use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.

the class DebugTestCase method testDebugASN1Write2EnabledAll.

/**
 * Tests the second {@code debugASN1Write} method with the debugger enabled
 * and a debug type set of all types.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDebugASN1Write2EnabledAll() throws Exception {
    Debug.setEnabled(true);
    testLogHandler.resetMessageCount();
    assertTrue(Debug.debugEnabled(DebugType.ASN1));
    Debug.debugASN1Write(Level.FINEST, new ASN1Null());
    assertTrue(testLogHandler.getMessageCount() >= 1);
}
Also used : ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 43 with ASN1Null

use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.

the class DebugTestCase method testDebugASN1Read2EnabledOnlyASN1.

/**
 * Tests the second {@code debugASN1Read} method with the debugger enabled
 * and a debug type set that includes only the ASN.1 type.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDebugASN1Read2EnabledOnlyASN1() throws Exception {
    Debug.setEnabled(true, EnumSet.of(DebugType.ASN1));
    testLogHandler.resetMessageCount();
    assertTrue(Debug.debugEnabled(DebugType.ASN1));
    Debug.debugASN1Read(Level.FINEST, new ASN1Null());
    assertTrue(testLogHandler.getMessageCount() >= 1);
}
Also used : ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 44 with ASN1Null

use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.

the class DebugTestCase method testDebugASN1Write1EnabledAll.

/**
 * Tests the first {@code debugASN1Write} method with the debugger enabled
 * and a debug type set of all types.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDebugASN1Write1EnabledAll() throws Exception {
    Debug.setEnabled(true);
    testLogHandler.resetMessageCount();
    assertTrue(Debug.debugEnabled(DebugType.ASN1));
    Debug.debugASN1Write(new ASN1Null());
    assertTrue(testLogHandler.getMessageCount() >= 1);
}
Also used : ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Example 45 with ASN1Null

use of com.unboundid.asn1.ASN1Null in project ldapsdk by pingidentity.

the class DebugTestCase method testDebugASN1Write2EnabledIncludeASN1.

/**
 * Tests the second {@code debugASN1Write} method with the debugger enabled
 * and a debug type set that includes the ASN.1 type among others.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDebugASN1Write2EnabledIncludeASN1() throws Exception {
    Debug.setEnabled(true, EnumSet.of(DebugType.ASN1, DebugType.OTHER));
    testLogHandler.resetMessageCount();
    assertTrue(Debug.debugEnabled(DebugType.ASN1));
    Debug.debugASN1Write(Level.FINEST, new ASN1Null());
    assertTrue(testLogHandler.getMessageCount() >= 1);
}
Also used : ASN1Null(com.unboundid.asn1.ASN1Null) Test(org.testng.annotations.Test)

Aggregations

ASN1Null (com.unboundid.asn1.ASN1Null)69 Test (org.testng.annotations.Test)65 ASN1BitString (com.unboundid.asn1.ASN1BitString)36 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)33 DN (com.unboundid.ldap.sdk.DN)33 OID (com.unboundid.util.OID)32 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)28 ASN1ObjectIdentifier (com.unboundid.asn1.ASN1ObjectIdentifier)23 ASN1Integer (com.unboundid.asn1.ASN1Integer)21 ASN1Element (com.unboundid.asn1.ASN1Element)20 ASN1BigInteger (com.unboundid.asn1.ASN1BigInteger)15 ASN1GeneralizedTime (com.unboundid.asn1.ASN1GeneralizedTime)9 ASN1UTCTime (com.unboundid.asn1.ASN1UTCTime)6 ArrayList (java.util.ArrayList)6 ASN1Null (com.github.zhenwei.core.asn1.ASN1Null)5 Date (java.util.Date)5 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)3 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)3 AlgorithmParameters (java.security.AlgorithmParameters)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3