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

The following examples show how to use sun.security.util.DerValue#toByteArray() . 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: Oid.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an Oid object from its ASN.1 DER encoding.  This refers to
 * the full encoding including tag and length.  The structure and
 * encoding of Oids is defined in ISOIEC-8824 and ISOIEC-8825.  This
 * method is identical in functionality to its byte array counterpart.
 *
 * @param derOid stream containing the DER encoded oid
 * @exception GSSException may be thrown when the DER encoding does not
 *  follow the prescribed format.
 */
public Oid(InputStream derOid) throws GSSException {
    try {
        DerValue derVal = new DerValue(derOid);
        derEncoding = derVal.toByteArray();
        oid = derVal.getOID();
    } catch (IOException e) {
        throw new GSSException(GSSException.FAILURE,
                      "Improperly formatted ASN.1 DER encoding for Oid");
    }
}
 
Example 2
Source File: Oid.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an Oid object from its ASN.1 DER encoding.  This refers to
 * the full encoding including tag and length.  The structure and
 * encoding of Oids is defined in ISOIEC-8824 and ISOIEC-8825.  This
 * method is identical in functionality to its InputStream conterpart.
 *
 * @param data byte array containing the DER encoded oid
 * @exception GSSException may be thrown when the DER encoding does not
 *     follow the prescribed format.
 */
public Oid(byte [] data) throws GSSException {
    try {
        DerValue derVal = new DerValue(data);
        derEncoding = derVal.toByteArray();
        oid = derVal.getOID();
    } catch (IOException e) {
        throw new GSSException(GSSException.FAILURE,
                      "Improperly formatted ASN.1 DER encoding for Oid");
    }
}
 
Example 3
Source File: ResponderId.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the responderKeyId data member into its DER-encoded form
 *
 * @return the DER encoding for a responder ID byKey option, including
 *      explicit context-specific tagging.
 *
 * @throws IOException if any encoding error occurs
 */
private byte[] keyIdToBytes() throws IOException {
    // Place the KeyIdentifier bytes into an OCTET STRING
    DerValue inner = new DerValue(DerValue.tag_OctetString,
            responderKeyId.getIdentifier());

    // Mark the OCTET STRING-wrapped KeyIdentifier bytes
    // as EXPLICIT CONTEXT 2
    DerValue outer = new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
            true, (byte)Type.BY_KEY.value()), inner.toByteArray());

    return outer.toByteArray();
}
 
Example 4
Source File: Oid.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an Oid object from its ASN.1 DER encoding.  This refers to
 * the full encoding including tag and length.  The structure and
 * encoding of Oids is defined in ISOIEC-8824 and ISOIEC-8825.  This
 * method is identical in functionality to its byte array counterpart.
 *
 * @param derOid stream containing the DER encoded oid
 * @exception GSSException may be thrown when the DER encoding does not
 *  follow the prescribed format.
 */
public Oid(InputStream derOid) throws GSSException {
    try {
        DerValue derVal = new DerValue(derOid);
        derEncoding = derVal.toByteArray();
        oid = derVal.getOID();
    } catch (IOException e) {
        throw new GSSException(GSSException.FAILURE,
                      "Improperly formatted ASN.1 DER encoding for Oid");
    }
}
 
Example 5
Source File: Oid.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an Oid object from its ASN.1 DER encoding.  This refers to
 * the full encoding including tag and length.  The structure and
 * encoding of Oids is defined in ISOIEC-8824 and ISOIEC-8825.  This
 * method is identical in functionality to its byte array counterpart.
 *
 * @param derOid stream containing the DER encoded oid
 * @exception GSSException may be thrown when the DER encoding does not
 *  follow the prescribed format.
 */
public Oid(InputStream derOid) throws GSSException {
    try {
        DerValue derVal = new DerValue(derOid);
        derEncoding = derVal.toByteArray();
        oid = derVal.getOID();
    } catch (IOException e) {
        throw new GSSException(GSSException.FAILURE,
                      "Improperly formatted ASN.1 DER encoding for Oid");
    }
}
 
Example 6
Source File: Oid.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an Oid object from its ASN.1 DER encoding.  This refers to
 * the full encoding including tag and length.  The structure and
 * encoding of Oids is defined in ISOIEC-8824 and ISOIEC-8825.  This
 * method is identical in functionality to its byte array counterpart.
 *
 * @param derOid stream containing the DER encoded oid
 * @exception GSSException may be thrown when the DER encoding does not
 *  follow the prescribed format.
 */
public Oid(InputStream derOid) throws GSSException {
    try {
        DerValue derVal = new DerValue(derOid);
        derEncoding = derVal.toByteArray();
        oid = derVal.getOID();
    } catch (IOException e) {
        throw new GSSException(GSSException.FAILURE,
                      "Improperly formatted ASN.1 DER encoding for Oid");
    }
}
 
Example 7
Source File: Oid.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an Oid object from its ASN.1 DER encoding.  This refers to
 * the full encoding including tag and length.  The structure and
 * encoding of Oids is defined in ISOIEC-8824 and ISOIEC-8825.  This
 * method is identical in functionality to its InputStream conterpart.
 *
 * @param data byte array containing the DER encoded oid
 * @exception GSSException may be thrown when the DER encoding does not
 *     follow the prescribed format.
 */
public Oid(byte [] data) throws GSSException {
    try {
        DerValue derVal = new DerValue(data);
        derEncoding = derVal.toByteArray();
        oid = derVal.getOID();
    } catch (IOException e) {
        throw new GSSException(GSSException.FAILURE,
                      "Improperly formatted ASN.1 DER encoding for Oid");
    }
}
 
Example 8
Source File: NativeGSSContext.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private byte[] retrieveToken(InputStream is, int mechTokenLen)
    throws GSSException {
    try {
        byte[] result = null;
        if (mechTokenLen != -1) {
            // Need to add back the GSS header for a complete GSS token
            SunNativeProvider.debug("Precomputed mechToken length: " +
                                     mechTokenLen);
            GSSHeader gssHeader = new GSSHeader
                (new ObjectIdentifier(cStub.getMech().toString()),
                 mechTokenLen);
            ByteArrayOutputStream baos = new ByteArrayOutputStream(600);

            byte[] mechToken = new byte[mechTokenLen];
            int len = is.read(mechToken);
            assert(mechTokenLen == len);
            gssHeader.encode(baos);
            baos.write(mechToken);
            result = baos.toByteArray();
        } else {
            // Must be unparsed GSS token or SPNEGO's NegTokenTarg token
            assert(mechTokenLen == -1);
            DerValue dv = new DerValue(is);
            result = dv.toByteArray();
        }
        SunNativeProvider.debug("Complete Token length: " +
                                result.length);
        return result;
    } catch (IOException ioe) {
        throw new GSSExceptionImpl(GSSException.FAILURE, ioe);
    }
}
 
Example 9
Source File: ResponderId.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert the responderKeyId data member into its DER-encoded form
 *
 * @return the DER encoding for a responder ID byKey option, including
 *      explicit context-specific tagging.
 *
 * @throws IOException if any encoding error occurs
 */
private byte[] keyIdToBytes() throws IOException {
    // Place the KeyIdentifier bytes into an OCTET STRING
    DerValue inner = new DerValue(DerValue.tag_OctetString,
            responderKeyId.getIdentifier());

    // Mark the OCTET STRING-wrapped KeyIdentifier bytes
    // as EXPLICIT CONTEXT 2
    DerValue outer = new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
            true, (byte)Type.BY_KEY.value()), inner.toByteArray());

    return outer.toByteArray();
}
 
Example 10
Source File: Oid.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an Oid object from its ASN.1 DER encoding.  This refers to
 * the full encoding including tag and length.  The structure and
 * encoding of Oids is defined in ISOIEC-8824 and ISOIEC-8825.  This
 * method is identical in functionality to its byte array counterpart.
 *
 * @param derOid stream containing the DER encoded oid
 * @exception GSSException may be thrown when the DER encoding does not
 *  follow the prescribed format.
 */
public Oid(InputStream derOid) throws GSSException {
    try {
        DerValue derVal = new DerValue(derOid);
        derEncoding = derVal.toByteArray();
        oid = derVal.getOID();
    } catch (IOException e) {
        throw new GSSException(GSSException.FAILURE,
                      "Improperly formatted ASN.1 DER encoding for Oid");
    }
}
 
Example 11
Source File: Oid.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an Oid object from its ASN.1 DER encoding.  This refers to
 * the full encoding including tag and length.  The structure and
 * encoding of Oids is defined in ISOIEC-8824 and ISOIEC-8825.  This
 * method is identical in functionality to its InputStream conterpart.
 *
 * @param data byte array containing the DER encoded oid
 * @exception GSSException may be thrown when the DER encoding does not
 *     follow the prescribed format.
 */
public Oid(byte [] data) throws GSSException {
    try {
        DerValue derVal = new DerValue(data);
        derEncoding = derVal.toByteArray();
        oid = derVal.getOID();
    } catch (IOException e) {
        throw new GSSException(GSSException.FAILURE,
                      "Improperly formatted ASN.1 DER encoding for Oid");
    }
}
 
Example 12
Source File: NativeGSSContext.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private byte[] retrieveToken(InputStream is, int mechTokenLen)
    throws GSSException {
    try {
        byte[] result = null;
        if (mechTokenLen != -1) {
            // Need to add back the GSS header for a complete GSS token
            SunNativeProvider.debug("Precomputed mechToken length: " +
                                     mechTokenLen);
            GSSHeader gssHeader = new GSSHeader
                (new ObjectIdentifier(cStub.getMech().toString()),
                 mechTokenLen);
            ByteArrayOutputStream baos = new ByteArrayOutputStream(600);

            byte[] mechToken = new byte[mechTokenLen];
            int len = is.read(mechToken);
            assert(mechTokenLen == len);
            gssHeader.encode(baos);
            baos.write(mechToken);
            result = baos.toByteArray();
        } else {
            // Must be unparsed GSS token or SPNEGO's NegTokenTarg token
            assert(mechTokenLen == -1);
            DerValue dv = new DerValue(is);
            result = dv.toByteArray();
        }
        SunNativeProvider.debug("Complete Token length: " +
                                result.length);
        return result;
    } catch (IOException ioe) {
        throw new GSSExceptionImpl(GSSException.FAILURE, ioe);
    }
}
 
Example 13
Source File: PKCS9Attributes.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Decode this set of PKCS9 attributes from the contents of its
 * DER encoding. Ignores unsupported attributes when directed.
 *
 * @param in
 * the contents of the DER encoding of the attribute set.
 *
 * @exception IOException
 * on i/o error, encoding syntax error, unacceptable or
 * unsupported attribute, or duplicate attribute.
 */
private byte[] decode(DerInputStream in) throws IOException {

    DerValue val = in.getDerValue();

    // save the DER encoding with its proper tag byte.
    byte[] derEncoding = val.toByteArray();
    derEncoding[0] = DerValue.tag_SetOf;

    DerInputStream derIn = new DerInputStream(derEncoding);
    DerValue[] derVals = derIn.getSet(3,true);

    PKCS9Attribute attrib;
    ObjectIdentifier oid;
    boolean reuseEncoding = true;

    for (int i=0; i < derVals.length; i++) {

        try {
            attrib = new PKCS9Attribute(derVals[i]);

        } catch (ParsingException e) {
            if (ignoreUnsupportedAttributes) {
                reuseEncoding = false; // cannot reuse supplied DER encoding
                continue; // skip
            } else {
                throw e;
            }
        }
        oid = attrib.getOID();

        if (attributes.get(oid) != null)
            throw new IOException("Duplicate PKCS9 attribute: " + oid);

        if (permittedAttributes != null &&
            !permittedAttributes.containsKey(oid))
            throw new IOException("Attribute " + oid +
                                  " not permitted in this attribute set");

        attributes.put(oid, attrib);
    }
    return reuseEncoding ? derEncoding : generateDerEncoding();
}
 
Example 14
Source File: PKCS9Attributes.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Decode this set of PKCS9 attributes from the contents of its
 * DER encoding. Ignores unsupported attributes when directed.
 *
 * @param in
 * the contents of the DER encoding of the attribute set.
 *
 * @exception IOException
 * on i/o error, encoding syntax error, unacceptable or
 * unsupported attribute, or duplicate attribute.
 */
private byte[] decode(DerInputStream in) throws IOException {

    DerValue val = in.getDerValue();

    // save the DER encoding with its proper tag byte.
    byte[] derEncoding = val.toByteArray();
    derEncoding[0] = DerValue.tag_SetOf;

    DerInputStream derIn = new DerInputStream(derEncoding);
    DerValue[] derVals = derIn.getSet(3,true);

    PKCS9Attribute attrib;
    ObjectIdentifier oid;
    boolean reuseEncoding = true;

    for (int i=0; i < derVals.length; i++) {

        try {
            attrib = new PKCS9Attribute(derVals[i]);

        } catch (ParsingException e) {
            if (ignoreUnsupportedAttributes) {
                reuseEncoding = false; // cannot reuse supplied DER encoding
                continue; // skip
            } else {
                throw e;
            }
        }
        oid = attrib.getOID();

        if (attributes.get(oid) != null)
            throw new IOException("Duplicate PKCS9 attribute: " + oid);

        if (permittedAttributes != null &&
            !permittedAttributes.containsKey(oid))
            throw new IOException("Attribute " + oid +
                                  " not permitted in this attribute set");

        attributes.put(oid, attrib);
    }
    return reuseEncoding ? derEncoding : generateDerEncoding();
}
 
Example 15
Source File: PKCS9Attributes.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Decode this set of PKCS9 attributes from the contents of its
 * DER encoding. Ignores unsupported attributes when directed.
 *
 * @param in
 * the contents of the DER encoding of the attribute set.
 *
 * @exception IOException
 * on i/o error, encoding syntax error, unacceptable or
 * unsupported attribute, or duplicate attribute.
 */
private byte[] decode(DerInputStream in) throws IOException {

    DerValue val = in.getDerValue();

    // save the DER encoding with its proper tag byte.
    byte[] derEncoding = val.toByteArray();
    derEncoding[0] = DerValue.tag_SetOf;

    DerInputStream derIn = new DerInputStream(derEncoding);
    DerValue[] derVals = derIn.getSet(3,true);

    PKCS9Attribute attrib;
    ObjectIdentifier oid;
    boolean reuseEncoding = true;

    for (int i=0; i < derVals.length; i++) {

        try {
            attrib = new PKCS9Attribute(derVals[i]);

        } catch (ParsingException e) {
            if (ignoreUnsupportedAttributes) {
                reuseEncoding = false; // cannot reuse supplied DER encoding
                continue; // skip
            } else {
                throw e;
            }
        }
        oid = attrib.getOID();

        if (attributes.get(oid) != null)
            throw new IOException("Duplicate PKCS9 attribute: " + oid);

        if (permittedAttributes != null &&
            !permittedAttributes.containsKey(oid))
            throw new IOException("Attribute " + oid +
                                  " not permitted in this attribute set");

        attributes.put(oid, attrib);
    }
    return reuseEncoding ? derEncoding : generateDerEncoding();
}
 
Example 16
Source File: ResponderId.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Convert the responderName data member into its DER-encoded form
 *
 * @return the DER encoding for a responder ID byName option, including
 *      explicit context-specific tagging.
 *
 * @throws IOException if any encoding error occurs
 */
private byte[] principalToBytes() throws IOException {
    DerValue dv = new DerValue(DerValue.createTag(DerValue.TAG_CONTEXT,
            true, (byte)Type.BY_NAME.value()),
            responderName.getEncoded());
    return dv.toByteArray();
}
 
Example 17
Source File: X400Address.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create the X400Address object from the passed encoded Der value.
 *
 * @param derValue the encoded DER X400Address.
 * @exception IOException on error.
 */
public X400Address(DerValue derValue) throws IOException {
    nameValue = derValue.toByteArray();
}
 
Example 18
Source File: X400Address.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create the X400Address object from the passed encoded Der value.
 *
 * @param derValue the encoded DER X400Address.
 * @exception IOException on error.
 */
public X400Address(DerValue derValue) throws IOException {
    nameValue = derValue.toByteArray();
}
 
Example 19
Source File: X400Address.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create the X400Address object from the passed encoded Der value.
 *
 * @param derValue the encoded DER X400Address.
 * @exception IOException on error.
 */
public X400Address(DerValue derValue) throws IOException {
    nameValue = derValue.toByteArray();
}
 
Example 20
Source File: X400Address.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create the X400Address object from the passed encoded Der value.
 *
 * @param derValue the encoded DER X400Address.
 * @exception IOException on error.
 */
public X400Address(DerValue derValue) throws IOException {
    nameValue = derValue.toByteArray();
}