Search in sources :

Example 31 with DerInputStream

use of sun.security.util.DerInputStream in project jdk8u_jdk by JetBrains.

the class DSAPublicKey method parseKeyBits.

protected void parseKeyBits() throws InvalidKeyException {
    try {
        DerInputStream in = new DerInputStream(getKey().toByteArray());
        y = in.getBigInteger();
    } catch (IOException e) {
        throw new InvalidKeyException("Invalid key: y value\n" + e.getMessage());
    }
}
Also used : DerInputStream(sun.security.util.DerInputStream) InvalidKeyException(java.security.InvalidKeyException)

Example 32 with DerInputStream

use of sun.security.util.DerInputStream in project jdk8u_jdk by JetBrains.

the class GSSNameElement method export.

public byte[] export() throws GSSException {
    byte[] nameVal = cStub.exportName(pName);
    // Need to strip off the mech Oid portion of the exported
    // bytes since GSSNameImpl class will subsequently add it.
    int pos = 0;
    if ((nameVal[pos++] != 0x04) || (nameVal[pos++] != 0x01))
        throw new GSSException(GSSException.BAD_NAME);
    int mechOidLen = (((0xFF & nameVal[pos++]) << 8) | (0xFF & nameVal[pos++]));
    ObjectIdentifier temp = null;
    try {
        DerInputStream din = new DerInputStream(nameVal, pos, mechOidLen);
        temp = new ObjectIdentifier(din);
    } catch (IOException e) {
        throw new GSSExceptionImpl(GSSException.BAD_NAME, e);
    }
    Oid mech2 = new Oid(temp.toString());
    assert (mech2.equals(getMechanism()));
    pos += mechOidLen;
    int mechPortionLen = (((0xFF & nameVal[pos++]) << 24) | ((0xFF & nameVal[pos++]) << 16) | ((0xFF & nameVal[pos++]) << 8) | (0xFF & nameVal[pos++]));
    if (mechPortionLen < 0) {
        throw new GSSException(GSSException.BAD_NAME);
    }
    byte[] mechPortion = new byte[mechPortionLen];
    System.arraycopy(nameVal, pos, mechPortion, 0, mechPortionLen);
    return mechPortion;
}
Also used : DerInputStream(sun.security.util.DerInputStream) IOException(java.io.IOException) GSSExceptionImpl(sun.security.jgss.GSSExceptionImpl) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 33 with DerInputStream

use of sun.security.util.DerInputStream 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)

Example 34 with DerInputStream

use of sun.security.util.DerInputStream in project jdk8u_jdk by JetBrains.

the class BigInteger0 method main.

public static void main(String[] args) throws Exception {
    try {
        DerInputStream derin = new DerInputStream(INT_LEN0);
        BigInteger bi = derin.getBigInteger();
        throw new Exception("Succeeded parsing invalid zero length value");
    } catch (IOException e) {
        System.out.println("OK, zero length value rejected.");
    }
    DerInputStream derin = new DerInputStream(INT0);
    BigInteger bi = derin.getBigInteger();
    if (bi.equals(BigInteger.ZERO) == false) {
        throw new Exception("Failed to parse Integer 0");
    }
}
Also used : BigInteger(java.math.BigInteger) DerInputStream(sun.security.util.DerInputStream)

Example 35 with DerInputStream

use of sun.security.util.DerInputStream in project jdk8u_jdk by JetBrains.

the class DomainComponentEncoding method testDN.

private static void testDN(String dn) throws Exception {
    X500Principal p = new X500Principal(dn);
    byte[] encoded = p.getEncoded();
    // name is a sequence of RDN's
    DerInputStream dis = new DerInputStream(encoded);
    DerValue[] nameseq = dis.getSequence(3);
    boolean passed = false;
    for (int i = 0; i < nameseq.length; i++) {
        // each RDN is a set of AttributeTypeAndValue
        DerInputStream is = new DerInputStream(nameseq[i].toByteArray());
        DerValue[] ava = is.getSet(3);
        for (int j = 0; j < ava.length; j++) {
            ObjectIdentifier oid = ava[j].data.getOID();
            if (oid.equals(X500Name.DOMAIN_COMPONENT_OID)) {
                DerValue value = ava[j].data.getDerValue();
                if (value.getTag() == DerValue.tag_IA5String) {
                    passed = true;
                    break;
                } else {
                    throw new SecurityException("Test failed, expected DOMAIN_COMPONENT tag '" + DerValue.tag_IA5String + "', got '" + value.getTag() + "'");
                }
            }
        }
        if (passed) {
            break;
        }
    }
    if (passed) {
        System.out.println("Test passed");
    } else {
        throw new SecurityException("Test failed");
    }
}
Also used : DerValue(sun.security.util.DerValue) X500Principal(javax.security.auth.x500.X500Principal) DerInputStream(sun.security.util.DerInputStream) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Aggregations

DerInputStream (sun.security.util.DerInputStream)40 DerValue (sun.security.util.DerValue)17 IOException (java.io.IOException)12 ObjectIdentifier (sun.security.util.ObjectIdentifier)11 X509CertSelector (java.security.cert.X509CertSelector)6 BigInteger (java.math.BigInteger)5 X509Certificate (java.security.cert.X509Certificate)5 CertificateException (java.security.cert.CertificateException)4 CertificateFactory (java.security.cert.CertificateFactory)4 X500Principal (javax.security.auth.x500.X500Principal)4 SocketException (java.net.SocketException)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 UnrecoverableEntryException (java.security.UnrecoverableEntryException)3 UnrecoverableKeyException (java.security.UnrecoverableKeyException)3 DestroyFailedException (javax.security.auth.DestroyFailedException)3 AlgorithmParameters (java.security.AlgorithmParameters)2 InvalidKeyException (java.security.InvalidKeyException)2 KeyFactory (java.security.KeyFactory)2 Date (java.util.Date)2