Java Code Examples for sun.security.util.DerValue#getTag()

The following examples show how to use sun.security.util.DerValue#getTag() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KerberosTime.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse (unmarshal) a kerberostime from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @param data the Der input stream value, which contains
 *             one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicates if this data field is optional
 * @return an instance of KerberosTime.
 *
 */
public static KerberosTime parse(
        DerInputStream data, byte explicitTag, boolean optional)
        throws Asn1Exception, IOException {
    if ((optional) && (((byte)data.peekByte() & (byte)0x1F)!= explicitTag))
        return null;
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    else {
        DerValue subDer = der.getData().getDerValue();
        Date temp = subDer.getGeneralizedTime();
        return new KerberosTime(temp.getTime(), 0);
    }
}
 
Example 2
Source File: KerberosTime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse (unmarshal) a kerberostime from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @param data the Der input stream value, which contains
 *             one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicates if this data field is optional
 * @return an instance of KerberosTime.
 *
 */
public static KerberosTime parse(
        DerInputStream data, byte explicitTag, boolean optional)
        throws Asn1Exception, IOException {
    if ((optional) && (((byte)data.peekByte() & (byte)0x1F)!= explicitTag))
        return null;
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    else {
        DerValue subDer = der.getData().getDerValue();
        Date temp = subDer.getGeneralizedTime();
        return new KerberosTime(temp.getTime(), 0);
    }
}
 
Example 3
Source File: KerberosTime.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse (unmarshal) a kerberostime from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @param data the Der input stream value, which contains
 *             one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicates if this data field is optional
 * @return an instance of KerberosTime.
 *
 */
public static KerberosTime parse(
        DerInputStream data, byte explicitTag, boolean optional)
        throws Asn1Exception, IOException {
    if ((optional) && (((byte)data.peekByte() & (byte)0x1F)!= explicitTag))
        return null;
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    else {
        DerValue subDer = der.getData().getDerValue();
        Date temp = subDer.getGeneralizedTime();
        return new KerberosTime(temp.getTime(), 0);
    }
}
 
Example 4
Source File: KerberosTime.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse (unmarshal) a kerberostime from a DER input stream.  This form
 * parsing might be used when expanding a value which is part of
 * a constructed sequence and uses explicitly tagged type.
 *
 * @exception Asn1Exception on error.
 * @param data the Der input stream value, which contains
 *             one or more marshaled value.
 * @param explicitTag tag number.
 * @param optional indicates if this data field is optional
 * @return an instance of KerberosTime.
 *
 */
public static KerberosTime parse(
        DerInputStream data, byte explicitTag, boolean optional)
        throws Asn1Exception, IOException {
    if ((optional) && (((byte)data.peekByte() & (byte)0x1F)!= explicitTag))
        return null;
    DerValue der = data.getDerValue();
    if (explicitTag != (der.getTag() & (byte)0x1F))  {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
    else {
        DerValue subDer = der.getData().getDerValue();
        Date temp = subDer.getGeneralizedTime();
        return new KerberosTime(temp.getTime(), 0);
    }
}
 
Example 5
Source File: PaPacOptions.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a PA-PAC-OPTIONS object from a DER encoding.
 * @param encoding the ASN.1 encoded input
 * @throws Asn1Exception if invalid DER
 * @throws IOException if there is an error reading the DER value
 */
public PaPacOptions(DerValue encoding) throws Asn1Exception, IOException {
    if (encoding.getTag() != DerValue.tag_Sequence) {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }

    DerValue der = encoding.getData().getDerValue();
    if ((der.getTag() & 0x1F) == 0x00) {
        flags = new KDCOptions(
                der.getData().getDerValue());
    } else {
        throw new Asn1Exception(Krb5.ASN1_BAD_ID);
    }
}
 
Example 6
Source File: P11Key.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void fetchValues() {
    token.ensureValid();
    if (w != null) {
        return;
    }
    CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
        new CK_ATTRIBUTE(CKA_EC_POINT),
        new CK_ATTRIBUTE(CKA_EC_PARAMS),
    };
    fetchAttributes(attributes);

    try {
        params = P11ECKeyFactory.decodeParameters
                    (attributes[1].getByteArray());
        byte[] ecKey = attributes[0].getByteArray();

        // Check whether the X9.63 encoding of an EC point is wrapped
        // in an ASN.1 OCTET STRING
        if (!token.config.getUseEcX963Encoding()) {
            DerValue wECPoint = new DerValue(ecKey);

            if (wECPoint.getTag() != DerValue.tag_OctetString) {
                throw new IOException("Could not DER decode EC point." +
                    " Unexpected tag: " + wECPoint.getTag());
            }
            w = P11ECKeyFactory.decodePoint
                (wECPoint.getDataBytes(), params.getCurve());

        } else {
            w = P11ECKeyFactory.decodePoint(ecKey, params.getCurve());
        }

    } catch (Exception e) {
        throw new RuntimeException("Could not parse key values", e);
    }
}
 
Example 7
Source File: EncryptedPrivateKeyInfo.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTag(DerValue val, byte tag, String valName)
    throws IOException {
    if (val.getTag() != tag) {
        throw new IOException("invalid key encoding - wrong tag for " +
                              valName);
    }
}
 
Example 8
Source File: P11Key.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void fetchValues() {
    token.ensureValid();
    if (w != null) {
        return;
    }
    CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
        new CK_ATTRIBUTE(CKA_EC_POINT),
        new CK_ATTRIBUTE(CKA_EC_PARAMS),
    };
    fetchAttributes(attributes);

    try {
        params = P11ECKeyFactory.decodeParameters
                    (attributes[1].getByteArray());
        byte[] ecKey = attributes[0].getByteArray();

        // Check whether the X9.63 encoding of an EC point is wrapped
        // in an ASN.1 OCTET STRING
        if (!token.config.getUseEcX963Encoding()) {
            DerValue wECPoint = new DerValue(ecKey);

            if (wECPoint.getTag() != DerValue.tag_OctetString) {
                throw new IOException("Could not DER decode EC point." +
                    " Unexpected tag: " + wECPoint.getTag());
            }
            w = P11ECKeyFactory.decodePoint
                (wECPoint.getDataBytes(), params.getCurve());

        } else {
            w = P11ECKeyFactory.decodePoint(ecKey, params.getCurve());
        }

    } catch (Exception e) {
        throw new RuntimeException("Could not parse key values", e);
    }
}
 
Example 9
Source File: EncryptedPrivateKeyInfo.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTag(DerValue val, byte tag, String valName)
    throws IOException {
    if (val.getTag() != tag) {
        throw new IOException("invalid key encoding - wrong tag for " +
                              valName);
    }
}
 
Example 10
Source File: EncryptedPrivateKeyInfo.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTag(DerValue val, byte tag, String valName)
    throws IOException {
    if (val.getTag() != tag) {
        throw new IOException("invalid key encoding - wrong tag for " +
                              valName);
    }
}
 
Example 11
Source File: EncryptedPrivateKeyInfo.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTag(DerValue val, byte tag, String valName)
    throws IOException {
    if (val.getTag() != tag) {
        throw new IOException("invalid key encoding - wrong tag for " +
                              valName);
    }
}
 
Example 12
Source File: EncryptedPrivateKeyInfo.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static void checkTag(DerValue val, byte tag, String valName)
    throws IOException {
    if (val.getTag() != tag) {
        throw new IOException("invalid key encoding - wrong tag for " +
                              valName);
    }
}
 
Example 13
Source File: P11Key.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void fetchValues() {
    token.ensureValid();
    if (w != null) {
        return;
    }
    CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
        new CK_ATTRIBUTE(CKA_EC_POINT),
        new CK_ATTRIBUTE(CKA_EC_PARAMS),
    };
    fetchAttributes(attributes);

    try {
        params = P11ECKeyFactory.decodeParameters
                    (attributes[1].getByteArray());
        byte[] ecKey = attributes[0].getByteArray();

        // Check whether the X9.63 encoding of an EC point is wrapped
        // in an ASN.1 OCTET STRING
        if (!token.config.getUseEcX963Encoding()) {
            DerValue wECPoint = new DerValue(ecKey);

            if (wECPoint.getTag() != DerValue.tag_OctetString) {
                throw new IOException("Could not DER decode EC point." +
                    " Unexpected tag: " + wECPoint.getTag());
            }
            w = P11ECKeyFactory.decodePoint
                (wECPoint.getDataBytes(), params.getCurve());

        } else {
            w = P11ECKeyFactory.decodePoint(ecKey, params.getCurve());
        }

    } catch (Exception e) {
        throw new RuntimeException("Could not parse key values", e);
    }
}
 
Example 14
Source File: P11Key.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void fetchValues() {
    token.ensureValid();
    if (w != null) {
        return;
    }
    CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
        new CK_ATTRIBUTE(CKA_EC_POINT),
        new CK_ATTRIBUTE(CKA_EC_PARAMS),
    };
    fetchAttributes(attributes);

    try {
        params = P11ECKeyFactory.decodeParameters
                    (attributes[1].getByteArray());
        byte[] ecKey = attributes[0].getByteArray();

        // Check whether the X9.63 encoding of an EC point is wrapped
        // in an ASN.1 OCTET STRING
        if (!token.config.getUseEcX963Encoding()) {
            DerValue wECPoint = new DerValue(ecKey);

            if (wECPoint.getTag() != DerValue.tag_OctetString) {
                throw new IOException("Could not DER decode EC point." +
                    " Unexpected tag: " + wECPoint.getTag());
            }
            w = P11ECKeyFactory.decodePoint
                (wECPoint.getDataBytes(), params.getCurve());

        } else {
            w = P11ECKeyFactory.decodePoint(ecKey, params.getCurve());
        }

    } catch (Exception e) {
        throw new RuntimeException("Could not parse key values", e);
    }
}
 
Example 15
Source File: EncryptedPrivateKeyInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTag(DerValue val, byte tag, String valName)
    throws IOException {
    if (val.getTag() != tag) {
        throw new IOException("invalid key encoding - wrong tag for " +
                              valName);
    }
}
 
Example 16
Source File: EncryptedPrivateKeyInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTag(DerValue val, byte tag, String valName)
    throws IOException {
    if (val.getTag() != tag) {
        throw new IOException("invalid key encoding - wrong tag for " +
                              valName);
    }
}
 
Example 17
Source File: DomainComponentEncoding.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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");
    }
}
 
Example 18
Source File: DomainComponentEncoding.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
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");
    }
}
 
Example 19
Source File: DomainComponentEncoding.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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");
    }
}
 
Example 20
Source File: DomainComponentEncoding.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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");
    }
}