Search in sources :

Example 6 with PKCS10Attribute

use of sun.security.pkcs10.PKCS10Attribute in project jdk8u_jdk by JetBrains.

the class PKCS10AttributeReader method main.

public static void main(String[] args) throws Exception {
    // Decode base64 encoded DER file
    byte[] pkcs10Bytes = Base64.getMimeDecoder().decode(ATTRIBS.getBytes());
    HashMap<ObjectIdentifier, Object> RequestStander = new HashMap() {

        {
            put(PKCS9Attribute.CHALLENGE_PASSWORD_OID, "GuessWhoAmI");
            put(PKCS9Attribute.SIGNING_TIME_OID, new Date(861720610000L));
            put(PKCS9Attribute.CONTENT_TYPE_OID, new ObjectIdentifier("1.9.50.51.52"));
        }
    };
    int invalidNum = 0;
    PKCS10Attributes resp = new PKCS10Attributes(new DerInputStream(pkcs10Bytes));
    Enumeration eReq = resp.getElements();
    int numOfAttrs = 0;
    while (eReq.hasMoreElements()) {
        numOfAttrs++;
        PKCS10Attribute attr = (PKCS10Attribute) eReq.nextElement();
        if (RequestStander.containsKey(attr.getAttributeId())) {
            if (RequestStander.get(attr.getAttributeId()).equals(attr.getAttributeValue())) {
                System.out.println(attr.getAttributeId() + " " + attr.getAttributeValue());
            } else {
                invalidNum++;
                System.out.println("< " + attr.getAttributeId() + " " + attr.getAttributeValue());
                System.out.println("< " + attr.getAttributeId() + " " + RequestStander.get(attr.getAttributeId()));
            }
        } else {
            invalidNum++;
            System.out.println("No" + attr.getAttributeId() + "in Certificate Request list");
        }
    }
    if (numOfAttrs != RequestStander.size()) {
        invalidNum++;
        System.out.println("Incorrect number of attributes.");
    }
    System.out.println();
    if (invalidNum > 0) {
        throw new RuntimeException("Attributes Compared with Stander :" + " Failed");
    }
    System.out.println("Attributes Compared with Stander: Pass");
}
Also used : PKCS10Attribute(sun.security.pkcs10.PKCS10Attribute) Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) PKCS10Attributes(sun.security.pkcs10.PKCS10Attributes) DerInputStream(sun.security.util.DerInputStream) Date(java.util.Date) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Aggregations

PKCS10Attribute (sun.security.pkcs10.PKCS10Attribute)6 PKCS10 (sun.security.pkcs10.PKCS10)4 PrivateKey (java.security.PrivateKey)3 Signature (java.security.Signature)3 ObjectIdentifier (sun.security.util.ObjectIdentifier)3 PublicKey (java.security.PublicKey)2 Certificate (java.security.cert.Certificate)2 X509Certificate (java.security.cert.X509Certificate)2 PKCS10Attributes (sun.security.pkcs10.PKCS10Attributes)2 Key (java.security.Key)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableEntryException (java.security.UnrecoverableEntryException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertStoreException (java.security.cert.CertStoreException)1 CertificateException (java.security.cert.CertificateException)1 MessageFormat (java.text.MessageFormat)1 Date (java.util.Date)1