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

The following examples show how to use sun.security.util.DerValue#tag_OctetString() . 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: P11Key.java    From openjdk-jdk9 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 2
Source File: P11Key.java    From jdk8u-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 3
Source File: P11Key.java    From jdk8u_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 4
Source File: ResponderId.java    From jdk8u_jdk 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 5
Source File: P11Key.java    From openjdk-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 6
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 7
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 8
Source File: P11Key.java    From jdk8u-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: 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: ResponderId.java    From dragonwell8_jdk 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 11
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 12
Source File: P11Key.java    From openjdk-jdk8u-backup 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 13
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 14
Source File: P11Key.java    From openjdk-jdk8u 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: ResponderId.java    From openjdk-jdk8u 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 16
Source File: P11Key.java    From jdk8u60 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 17
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 18
Source File: ResponderId.java    From TencentKona-8 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 19
Source File: P11Key.java    From dragonwell8_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 20
Source File: OCSPNonceExtensionTests.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Map.Entry<Boolean, String> runTest() {
    Boolean pass = Boolean.FALSE;
    String message = null;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        Extension nonceByDer = new sun.security.x509.Extension(
                new DerValue(OCSP_NONCE_DER));

        // Verify overall encoded extension structure
        nonceByDer.encode(baos);
        verifyExtStructure(baos.toByteArray());

        // Verify the name, elements, and data conform to
        // expected values for this specific object.
        boolean crit = nonceByDer.isCritical();
        String oid = nonceByDer.getId();
        DerValue nonceData = new DerValue(nonceByDer.getValue());

        if (!crit) {
            message = "Extension lacks expected criticality setting";
        } else if (!oid.equals(OCSP_NONCE_OID)) {
            message = "Incorrect OID (Got " + oid + ", Expected " +
                    OCSP_NONCE_OID + ")";
        } else if (nonceData.getTag() != DerValue.tag_OctetString) {
            message = "Incorrect nonce data tag type (Got " +
                    String.format("0x%02X", nonceData.getTag()) +
                    ", Expected 0x04)";
        } else if (nonceData.getOctetString().length != 48) {
            message = "Incorrect nonce byte length (Got " +
                    nonceData.getOctetString().length +
                    ", Expected 48)";
        } else {
            pass = Boolean.TRUE;
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
        message = e.getClass().getName();
    }

    return new AbstractMap.SimpleEntry<>(pass, message);
}