java.security.CryptoPrimitive Java Examples

The following examples show how to use java.security.CryptoPrimitive. 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: EllipticCurvesExtension.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static EllipticCurvesExtension createExtension(
            AlgorithmConstraints constraints) {

    ArrayList<Integer> idList = new ArrayList<>(supportedCurveIds.length);
    for (int curveId : supportedCurveIds) {
        if (constraints.permits(
                EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
                            "EC", idToParams.get(curveId))) {
            idList.add(curveId);
        }
    }

    if (!idList.isEmpty()) {
        int[] ids = new int[idList.size()];
        int i = 0;
        for (Integer id : idList) {
            ids[i++] = id;
        }

        return new EllipticCurvesExtension(ids);
    }

    return null;
}
 
Example #2
Source File: SSLAlgorithmConstraints.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean permits(Set<CryptoPrimitive> primitives, Key key) {

    boolean permitted = true;

    if (peerAlgConstraints != null) {
        permitted = peerAlgConstraints.permits(primitives, key);
    }

    if (permitted && userAlgConstraints != null) {
        permitted = userAlgConstraints.permits(primitives, key);
    }

    if (permitted) {
        permitted = tlsDisabledAlgConstraints.permits(primitives, key);
    }

    if (permitted && enabledX509DisabledAlgConstraints) {
        permitted = x509DisabledAlgConstraints.permits(primitives, key);
    }

    return permitted;
}
 
Example #3
Source File: EllipticCurvesExtension.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static EllipticCurvesExtension createExtension(
            AlgorithmConstraints constraints) {

    ArrayList<Integer> idList = new ArrayList<>(supportedCurveIds.length);
    for (int curveId : supportedCurveIds) {
        if (constraints.permits(
                EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
                            "EC", idToParams.get(curveId))) {
            idList.add(curveId);
        }
    }

    if (!idList.isEmpty()) {
        int[] ids = new int[idList.size()];
        int i = 0;
        for (Integer id : idList) {
            ids[i++] = id;
        }

        return new EllipticCurvesExtension(ids);
    }

    return null;
}
 
Example #4
Source File: DisabledAlgorithmConstraints.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkConstraints(Set<CryptoPrimitive> primitives,
        String algorithm, Key key, AlgorithmParameters parameters) {

    // check the key parameter, it cannot be null.
    if (key == null) {
        throw new IllegalArgumentException("The key cannot be null");
    }

    // check the signature algorithm with parameters
    if (algorithm != null && algorithm.length() != 0) {
        if (!permits(primitives, algorithm, parameters)) {
            return false;
        }
    }

    // check the key algorithm
    if (!permits(primitives, key.getAlgorithm(), null)) {
        return false;
    }

    // check the key constraints
    return algorithmConstraints.permits(key);
}
 
Example #5
Source File: EllipticCurvesExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static EllipticCurvesExtension createExtension(
            AlgorithmConstraints constraints) {

    ArrayList<Integer> idList = new ArrayList<>(supportedCurveIds.length);
    for (int curveId : supportedCurveIds) {
        if (constraints.permits(
                EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
                            "EC", idToParams.get(curveId))) {
            idList.add(curveId);
        }
    }

    if (!idList.isEmpty()) {
        int[] ids = new int[idList.size()];
        int i = 0;
        for (Integer id : idList) {
            ids[i++] = id;
        }

        return new EllipticCurvesExtension(ids);
    }

    return null;
}
 
Example #6
Source File: DisabledAlgorithmConstraints.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void checkConstraints(Set<CryptoPrimitive> primitives,
        CertConstraintParameters cp) throws CertPathValidatorException {

    X509Certificate cert = cp.getCertificate();
    String algorithm = cert.getSigAlgName();

    // Check signature algorithm is not disabled
    if (!permits(primitives, algorithm, null)) {
        throw new CertPathValidatorException(
                "Algorithm constraints check failed on disabled "+
                        "signature algorithm: " + algorithm,
                null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }

    // Check key algorithm is not disabled
    if (!permits(primitives, cert.getPublicKey().getAlgorithm(), null)) {
        throw new CertPathValidatorException(
                "Algorithm constraints check failed on disabled "+
                        "public key algorithm: " + algorithm,
                null, null, -1, BasicReason.ALGORITHM_CONSTRAINED);
    }

    // Check the certificate and key constraints
    algorithmConstraints.permits(cp);

}
 
Example #7
Source File: ECDHClientKeyExchange.java    From openjsse with GNU General Public License v2.0 6 votes vote down vote up
static void checkConstraints(AlgorithmConstraints constraints,
        ECPublicKey publicKey,
        byte[] encodedPoint) throws SSLHandshakeException {

    try {
        ECParameterSpec params = publicKey.getParams();
        ECPoint point =
                JsseJce.decodePoint(encodedPoint, params.getCurve());
        ECPublicKeySpec spec = new ECPublicKeySpec(point, params);

        KeyFactory kf = JsseJce.getKeyFactory("EC");
        ECPublicKey peerPublicKey =
                (ECPublicKey)kf.generatePublic(spec);

        // check constraints of ECPublicKey
        if (!constraints.permits(
                EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
                peerPublicKey)) {
            throw new SSLHandshakeException(
                "ECPublicKey does not comply to algorithm constraints");
        }
    } catch (GeneralSecurityException | java.io.IOException e) {
        throw (SSLHandshakeException) new SSLHandshakeException(
                "Could not generate ECPublicKey").initCause(e);
    }
}
 
Example #8
Source File: SSLAlgorithmConstraints.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean permits(Set<CryptoPrimitive> primitives, Key key) {

    boolean permitted = true;

    if (peerAlgConstraints != null) {
        permitted = peerAlgConstraints.permits(primitives, key);
    }

    if (permitted && userAlgConstraints != null) {
        permitted = userAlgConstraints.permits(primitives, key);
    }

    if (permitted) {
        permitted = tlsDisabledAlgConstraints.permits(primitives, key);
    }

    if (permitted && enabledX509DisabledAlgConstraints) {
        permitted = x509DisabledAlgConstraints.permits(primitives, key);
    }

    return permitted;
}
 
Example #9
Source File: SSLAlgorithmConstraints.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean permits(Set<CryptoPrimitive> primitives, Key key) {

    boolean permitted = true;

    if (peerAlgConstraints != null) {
        permitted = peerAlgConstraints.permits(primitives, key);
    }

    if (permitted && userAlgConstraints != null) {
        permitted = userAlgConstraints.permits(primitives, key);
    }

    if (permitted) {
        permitted = tlsDisabledAlgConstraints.permits(primitives, key);
    }

    if (permitted && enabledX509DisabledAlgConstraints) {
        permitted = x509DisabledAlgConstraints.permits(primitives, key);
    }

    return permitted;
}
 
Example #10
Source File: DisabledAlgorithmConstraints.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkConstraints(Set<CryptoPrimitive> primitives,
        String algorithm, Key key, AlgorithmParameters parameters) {

    // check the key parameter, it cannot be null.
    if (key == null) {
        throw new IllegalArgumentException("The key cannot be null");
    }

    // check the signature algorithm
    if (algorithm != null && algorithm.length() != 0) {
        if (!permits(primitives, algorithm, parameters)) {
            return false;
        }
    }

    // check the key algorithm
    if (!permits(primitives, key.getAlgorithm(), null)) {
        return false;
    }

    // check the key constraints
    return algorithmConstraints.permits(key);
}
 
Example #11
Source File: ECDHKeyExchange.java    From openjsse with GNU General Public License v2.0 6 votes vote down vote up
void checkConstraints(AlgorithmConstraints constraints,
        byte[] encodedPoint) throws SSLHandshakeException {
    try {

        ECParameterSpec params = publicKey.getParams();
        ECPoint point =
                JsseJce.decodePoint(encodedPoint, params.getCurve());
        ECPublicKeySpec spec = new ECPublicKeySpec(point, params);

        KeyFactory kf = JsseJce.getKeyFactory("EC");
        ECPublicKey pubKey = (ECPublicKey)kf.generatePublic(spec);

        // check constraints of ECPublicKey
        if (!constraints.permits(
                EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), pubKey)) {
            throw new SSLHandshakeException(
                "ECPublicKey does not comply to algorithm constraints");
        }
    } catch (GeneralSecurityException | java.io.IOException e) {
        throw (SSLHandshakeException) new SSLHandshakeException(
                "Could not generate ECPublicKey").initCause(e);
    }
}
 
Example #12
Source File: DisabledAlgorithmConstraints.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public final boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, AlgorithmParameters parameters) {
    if (primitives == null || primitives.isEmpty()) {
        throw new IllegalArgumentException("The primitives cannot be null" +
                " or empty.");
    }

    if (!checkAlgorithm(disabledAlgorithms, algorithm, decomposer)) {
        return false;
    }

    if (parameters != null) {
        return algorithmConstraints.permits(algorithm, parameters);
    }

    return true;
}
 
Example #13
Source File: DisabledAlgorithmConstraints.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkConstraints(Set<CryptoPrimitive> primitives,
        String algorithm, Key key, AlgorithmParameters parameters) {

    // check the key parameter, it cannot be null.
    if (key == null) {
        throw new IllegalArgumentException("The key cannot be null");
    }

    // check the signature algorithm with parameters
    if (algorithm != null && algorithm.length() != 0) {
        if (!permits(primitives, algorithm, parameters)) {
            return false;
        }
    }

    // check the key algorithm
    if (!permits(primitives, key.getAlgorithm(), null)) {
        return false;
    }

    // check the key constraints
    return algorithmConstraints.permits(key);
}
 
Example #14
Source File: SupportedGroupsExtension.java    From openjsse with GNU General Public License v2.0 6 votes vote down vote up
static NamedGroup getPreferredGroup(
        ProtocolVersion negotiatedProtocol,
        AlgorithmConstraints constraints, NamedGroupType type) {
    for (NamedGroup namedGroup : supportedNamedGroups) {
        if ((namedGroup.type == type) &&
                namedGroup.isAvailable(negotiatedProtocol) &&
                constraints.permits(
                        EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
                        namedGroup.algorithm,
                        namedGroupParams.get(namedGroup))) {
            return namedGroup;
        }
    }

    return null;
}
 
Example #15
Source File: SupportedGroupsExtension.java    From openjsse with GNU General Public License v2.0 6 votes vote down vote up
static NamedGroup getPreferredGroup(
        ProtocolVersion negotiatedProtocol,
        AlgorithmConstraints constraints, NamedGroupType type,
        List<NamedGroup> requestedNamedGroups) {
    for (NamedGroup namedGroup : requestedNamedGroups) {
        if ((namedGroup.type == type) &&
                namedGroup.isAvailable(negotiatedProtocol) &&
                isSupported(namedGroup) &&
                constraints.permits(
                        EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
                        namedGroup.algorithm,
                        namedGroupParams.get(namedGroup))) {
            return namedGroup;
        }
    }

    return null;
}
 
Example #16
Source File: EllipticCurvesExtension.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static EllipticCurvesExtension createExtension(
            AlgorithmConstraints constraints) {

    ArrayList<Integer> idList = new ArrayList<>(supportedCurveIds.length);
    for (int curveId : supportedCurveIds) {
        if (constraints.permits(
                EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
                            "EC", idToParams.get(curveId))) {
            idList.add(curveId);
        }
    }

    if (!idList.isEmpty()) {
        int[] ids = new int[idList.size()];
        int i = 0;
        for (Integer id : idList) {
            ids[i++] = id;
        }

        return new EllipticCurvesExtension(ids);
    }

    return null;
}
 
Example #17
Source File: EllipticCurvesExtension.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static int getPreferredCurve(int[] curves,
            AlgorithmConstraints constraints) {
    for (int curveId : curves) {
        if (isSupported(curveId) && constraints.permits(
                EnumSet.of(CryptoPrimitive.KEY_AGREEMENT),
                            "EC", idToParams.get(curveId))) {
            return curveId;
        }
    }

    return -1;
}
 
Example #18
Source File: DisabledAlgorithmConstraints.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, Key key, AlgorithmParameters parameters) {

    if (algorithm == null || algorithm.length() == 0) {
        throw new IllegalArgumentException("No algorithm name specified");
    }

    return checkConstraints(primitives, algorithm, key, parameters);
}
 
Example #19
Source File: SSLAlgorithmConstraints.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, AlgorithmParameters parameters) {

    boolean permitted = true;

    if (peerAlgConstraints != null) {
        permitted = peerAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted && userAlgConstraints != null) {
        permitted = userAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted) {
        permitted = tlsDisabledAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted && enabledX509DisabledAlgConstraints) {
        permitted = x509DisabledAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    return permitted;
}
 
Example #20
Source File: DisabledAlgorithmConstraints.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, AlgorithmParameters parameters) {
    if (!checkAlgorithm(disabledAlgorithms, algorithm, decomposer)) {
        return false;
    }

    if (parameters != null) {
        return algorithmConstraints.permits(algorithm, parameters);
    }

    return true;
}
 
Example #21
Source File: SSLAlgorithmConstraints.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
final public boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, Key key, AlgorithmParameters parameters) {

    if (algorithm == null || algorithm.length() == 0) {
        throw new IllegalArgumentException(
                "No algorithm name specified");
    }

    return permits(primitives, algorithm, parameters);
}
 
Example #22
Source File: LegacyAlgorithmConstraints.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public final boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, Key key, AlgorithmParameters parameters) {
    if (primitives == null || primitives.isEmpty()) {
        throw new IllegalArgumentException("The primitives cannot be null" +
                " or empty.");
    }
    return checkAlgorithm(legacyAlgorithms, algorithm, decomposer);
}
 
Example #23
Source File: SSLAlgorithmConstraints.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, AlgorithmParameters parameters) {

    boolean permitted = true;

    if (peerAlgConstraints != null) {
        permitted = peerAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted && userAlgConstraints != null) {
        permitted = userAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted) {
        permitted = tlsDisabledAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted && enabledX509DisabledAlgConstraints) {
        permitted = x509DisabledAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    return permitted;
}
 
Example #24
Source File: SSLAlgorithmConstraints.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, AlgorithmParameters parameters) {

    if (algorithm == null || algorithm.length() == 0) {
        throw new IllegalArgumentException(
                "No algorithm name specified");
    }

    if (primitives == null || primitives.isEmpty()) {
        throw new IllegalArgumentException(
                "No cryptographic primitive specified");
    }

    if (supportedAlgorithms == null ||
                supportedAlgorithms.length == 0) {
        return false;
    }

    // trim the MGF part: <digest>with<encryption>and<mgf>
    int position = algorithm.indexOf("and");
    if (position > 0) {
        algorithm = algorithm.substring(0, position);
    }

    for (String supportedAlgorithm : supportedAlgorithms) {
        if (algorithm.equalsIgnoreCase(supportedAlgorithm)) {
            return true;
        }
    }

    return false;
}
 
Example #25
Source File: SSLAlgorithmConstraints.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, Key key, AlgorithmParameters parameters) {

    boolean permitted = true;

    if (peerAlgConstraints != null) {
        permitted = peerAlgConstraints.permits(
                                primitives, algorithm, key, parameters);
    }

    if (permitted && userAlgConstraints != null) {
        permitted = userAlgConstraints.permits(
                                primitives, algorithm, key, parameters);
    }

    if (permitted) {
        permitted = tlsDisabledAlgConstraints.permits(
                                primitives, algorithm, key, parameters);
    }

    if (permitted && enabledX509DisabledAlgConstraints) {
        permitted = x509DisabledAlgConstraints.permits(
                                primitives, algorithm, key, parameters);
    }

    return permitted;
}
 
Example #26
Source File: SSLAlgorithmConstraints.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, AlgorithmParameters parameters) {

    boolean permitted = true;

    if (peerAlgConstraints != null) {
        permitted = peerAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted && userAlgConstraints != null) {
        permitted = userAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted) {
        permitted = tlsDisabledAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted && enabledX509DisabledAlgConstraints) {
        permitted = x509DisabledAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    return permitted;
}
 
Example #27
Source File: SSLAlgorithmConstraints.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, AlgorithmParameters parameters) {

    boolean permitted = true;

    if (peerAlgConstraints != null) {
        permitted = peerAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted && userAlgConstraints != null) {
        permitted = userAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted) {
        permitted = tlsDisabledAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    if (permitted && enabledX509DisabledAlgConstraints) {
        permitted = x509DisabledAlgConstraints.permits(
                                primitives, algorithm, parameters);
    }

    return permitted;
}
 
Example #28
Source File: SSLAlgorithmConstraints.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, Key key, AlgorithmParameters parameters) {

    boolean permitted = true;

    if (peerSpecifiedConstraints != null) {
        permitted = peerSpecifiedConstraints.permits(
                                primitives, algorithm, key, parameters);
    }

    if (permitted && userSpecifiedConstraints != null) {
        permitted = userSpecifiedConstraints.permits(
                                primitives, algorithm, key, parameters);
    }

    if (permitted) {
        permitted = tlsDisabledAlgConstraints.permits(
                                primitives, algorithm, key, parameters);
    }

    if (permitted && enabledX509DisabledAlgConstraints) {
        permitted = x509DisabledAlgConstraints.permits(
                                primitives, algorithm, key, parameters);
    }

    return permitted;
}
 
Example #29
Source File: SSLAlgorithmConstraints.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
final public boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, Key key, AlgorithmParameters parameters) {

    if (algorithm == null || algorithm.length() == 0) {
        throw new IllegalArgumentException(
                "No algorithm name specified");
    }

    return permits(primitives, algorithm, parameters);
}
 
Example #30
Source File: DisabledAlgorithmConstraints.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final boolean permits(Set<CryptoPrimitive> primitives,
        String algorithm, AlgorithmParameters parameters) {
    if (!checkAlgorithm(disabledAlgorithms, algorithm, decomposer)) {
        return false;
    }

    if (parameters != null) {
        return algorithmConstraints.permits(algorithm, parameters);
    }

    return true;
}