java.security.AlgorithmConstraints Java Examples

The following examples show how to use java.security.AlgorithmConstraints. 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 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 #2
Source File: SSLAlgorithmConstraints.java    From openjsse with GNU General Public License v2.0 6 votes vote down vote up
private static AlgorithmConstraints getUserSpecifiedConstraints(
        SSLEngine engine) {
    if (engine != null) {
        // Note that the KeyManager or TrustManager implementation may be
        // not implemented in the same provider as SSLSocket/SSLEngine.
        // Please check the instance before casting to use SSLEngineImpl.
        if (engine instanceof SSLEngineImpl) {
            HandshakeContext hc =
                    ((SSLEngineImpl)engine).conContext.handshakeContext;
            if (hc != null) {
                return hc.sslConfig.userSpecifiedAlgorithmConstraints;
            }
        }

        return engine.getSSLParameters().getAlgorithmConstraints();
    }

    return null;
}
 
Example #3
Source File: SignatureAndHashAlgorithm.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static Collection<SignatureAndHashAlgorithm>
        getSupportedAlgorithms(AlgorithmConstraints constraints) {

    Collection<SignatureAndHashAlgorithm> supported = new ArrayList<>();
    synchronized (priorityMap) {
        for (SignatureAndHashAlgorithm sigAlg : priorityMap.values()) {
            if (sigAlg.priority <= SUPPORTED_ALG_PRIORITY_MAX_NUM &&
                    constraints.permits(SIGNATURE_PRIMITIVE_SET,
                            sigAlg.algorithm, null)) {
                supported.add(sigAlg);
            }
        }
    }

    return supported;
}
 
Example #4
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 #5
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 #6
Source File: SupportedEllipticCurvesExtension.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static SupportedEllipticCurvesExtension 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 SupportedEllipticCurvesExtension(ids);
    }

    return null;
}
 
Example #7
Source File: SSLSocketImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
SSLSocketImpl(SSLContextImpl context, boolean serverMode,
        CipherSuiteList suites, byte clientAuth,
        boolean sessionCreation, ProtocolList protocols,
        String identificationProtocol,
        AlgorithmConstraints algorithmConstraints,
        Collection<SNIMatcher> sniMatchers,
        boolean preferLocalCipherSuites) throws IOException {

    super();
    doClientAuth = clientAuth;
    enableSessionCreation = sessionCreation;
    this.identificationProtocol = identificationProtocol;
    this.algorithmConstraints = algorithmConstraints;
    this.sniMatchers = sniMatchers;
    this.preferLocalCipherSuites = preferLocalCipherSuites;
    init(context, serverMode);

    /*
     * Override what was picked out for us.
     */
    enabledCipherSuites = suites;
    enabledProtocols = protocols;
}
 
Example #8
Source File: AlgorithmChecker.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a new <code>AlgorithmChecker</code> with the
 * given <code>TrustAnchor</code> and <code>AlgorithmConstraints</code>.
 *
 * @param anchor the trust anchor selected to validate the target
 *     certificate
 * @param constraints the algorithm constraints (or null)
 *
 * @throws IllegalArgumentException if the <code>anchor</code> is null
 */
public AlgorithmChecker(TrustAnchor anchor,
        AlgorithmConstraints constraints) {

    if (anchor == null) {
        throw new IllegalArgumentException(
                    "The trust anchor cannot be null");
    }

    if (anchor.getTrustedCert() != null) {
        this.trustedPubKey = anchor.getTrustedCert().getPublicKey();
        // Check for anchor certificate restrictions
        trustedMatch = checkFingerprint(anchor.getTrustedCert());
        if (trustedMatch && debug != null) {
            debug.println("trustedMatch = true");
        }
    } else {
        this.trustedPubKey = anchor.getCAPublicKey();
    }

    this.prevPubKey = trustedPubKey;
    this.constraints = constraints;
}
 
Example #9
Source File: AlgorithmChecker.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a new <code>AlgorithmChecker</code> with the
 * given <code>TrustAnchor</code> and <code>AlgorithmConstraints</code>.
 *
 * @param anchor the trust anchor selected to validate the target
 *     certificate
 * @param constraints the algorithm constraints (or null)
 *
 * @throws IllegalArgumentException if the <code>anchor</code> is null
 */
public AlgorithmChecker(TrustAnchor anchor,
        AlgorithmConstraints constraints) {

    if (anchor == null) {
        throw new IllegalArgumentException(
                    "The trust anchor cannot be null");
    }

    if (anchor.getTrustedCert() != null) {
        this.trustedPubKey = anchor.getTrustedCert().getPublicKey();
    } else {
        this.trustedPubKey = anchor.getCAPublicKey();
    }

    this.prevPubKey = trustedPubKey;
    this.constraints = constraints;
}
 
Example #10
Source File: SSLAlgorithmConstraints.java    From openjsse with GNU General Public License v2.0 6 votes vote down vote up
private static AlgorithmConstraints getUserSpecifiedConstraints(
        SSLSocket socket) {
    if (socket != null) {
        // Note that the KeyManager or TrustManager implementation may be
        // not implemented in the same provider as SSLSocket/SSLEngine.
        // Please check the instance before casting to use SSLSocketImpl.
        if (socket instanceof SSLSocketImpl) {
            HandshakeContext hc =
                    ((SSLSocketImpl)socket).conContext.handshakeContext;
            if (hc != null) {
                return hc.sslConfig.userSpecifiedAlgorithmConstraints;
            }
        }

        return socket.getSSLParameters().getAlgorithmConstraints();
    }

    return null;
}
 
Example #11
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 #12
Source File: Validator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate the given certificate chain.
 *
 * @param chain the target certificate chain
 * @param otherCerts a Collection of additional X509Certificates that
 *        could be helpful for path building (or null)
 * @param constraints algorithm constraints for certification path
 *        processing
 * @param parameter an additional parameter with variant specific meaning.
 *        Currently, it is only defined for TLS_SERVER variant validators,
 *        where it must be non null and the name of the TLS key exchange
 *        algorithm being used (see JSSE X509TrustManager specification).
 *        In the future, it could be used to pass in a PKCS#7 object for
 *        code signing to check time stamps.
 * @return a non-empty chain that was used to validate the path. The
 *        end entity cert is at index 0, the trust anchor at index n-1.
 */
public final X509Certificate[] validate(X509Certificate[] chain,
            Collection<X509Certificate> otherCerts,
            AlgorithmConstraints constraints,
            Object parameter) throws CertificateException {
    chain = engineValidate(chain, otherCerts, constraints, parameter);

    // omit EE extension check if EE cert is also trust anchor
    if (chain.length > 1) {
        // EndEntityChecker does not need to check unresolved critical
        // extensions when validating with a TYPE_PKIX Validator.
        // A TYPE_PKIX Validator will already have run checks on all
        // certs' extensions, including checks by any PKIXCertPathCheckers
        // included in the PKIXParameters, so the extra checks would be
        // redundant.
        boolean checkUnresolvedCritExts =
                (type == TYPE_PKIX) ? false : true;
        endEntityChecker.check(chain, parameter,
                               checkUnresolvedCritExts);
    }

    return chain;
}
 
Example #13
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 #14
Source File: Validator.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate the given certificate chain.
 *
 * @param chain the target certificate chain
 * @param otherCerts a Collection of additional X509Certificates that
 *        could be helpful for path building (or null)
 * @param constraints algorithm constraints for certification path
 *        processing
 * @param parameter an additional parameter with variant specific meaning.
 *        Currently, it is only defined for TLS_SERVER variant validators,
 *        where it must be non null and the name of the TLS key exchange
 *        algorithm being used (see JSSE X509TrustManager specification).
 *        In the future, it could be used to pass in a PKCS#7 object for
 *        code signing to check time stamps.
 * @return a non-empty chain that was used to validate the path. The
 *        end entity cert is at index 0, the trust anchor at index n-1.
 */
public final X509Certificate[] validate(X509Certificate[] chain,
            Collection<X509Certificate> otherCerts,
            AlgorithmConstraints constraints,
            Object parameter) throws CertificateException {
    chain = engineValidate(chain, otherCerts, constraints, parameter);

    // omit EE extension check if EE cert is also trust anchor
    if (chain.length > 1) {
        // EndEntityChecker does not need to check unresolved critical
        // extensions when validating with a TYPE_PKIX Validator.
        // A TYPE_PKIX Validator will already have run checks on all
        // certs' extensions, including checks by any PKIXCertPathCheckers
        // included in the PKIXParameters, so the extra checks would be
        // redundant.
        boolean checkUnresolvedCritExts =
                (type == TYPE_PKIX) ? false : true;
        endEntityChecker.check(chain, parameter,
                               checkUnresolvedCritExts);
    }

    return chain;
}
 
Example #15
Source File: SSLAlgorithmConstraints.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private static AlgorithmConstraints getConstraints(SSLSocket socket) {
    if (socket != null) {
        // Note that the KeyManager or TrustManager implementation may be
        // not implemented in the same provider as SSLSocket/SSLEngine.
        // Please check the instance before casting to use SSLSocketImpl.
        if (socket instanceof SSLSocketImpl) {
            HandshakeContext hc =
                    ((SSLSocketImpl)socket).conContext.handshakeContext;
            if (hc != null) {
                return hc.sslConfig.algorithmConstraints;
            }
        } else {
            return socket.getSSLParameters().getAlgorithmConstraints();
        }
    }

    return null;
}
 
Example #16
Source File: SSLSocketImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
SSLSocketImpl(SSLContextImpl context, boolean serverMode,
        CipherSuiteList suites, byte clientAuth,
        boolean sessionCreation, ProtocolList protocols,
        String identificationProtocol,
        AlgorithmConstraints algorithmConstraints,
        Collection<SNIMatcher> sniMatchers,
        boolean preferLocalCipherSuites) throws IOException {

    super();
    doClientAuth = clientAuth;
    enableSessionCreation = sessionCreation;
    this.identificationProtocol = identificationProtocol;
    this.algorithmConstraints = algorithmConstraints;
    this.sniMatchers = sniMatchers;
    this.preferLocalCipherSuites = preferLocalCipherSuites;
    init(context, serverMode);

    /*
     * Override what was picked out for us.
     */
    enabledCipherSuites = suites;
    enabledProtocols = protocols;
}
 
Example #17
Source File: X509KeyManagerImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private AlgorithmConstraints getAlgorithmConstraints(SSLEngine engine) {
    if (engine != null) {
        SSLSession session = engine.getHandshakeSession();
        if (session != null) {
            if (ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) {
                String[] peerSupportedSignAlgs = null;

                if (session instanceof ExtendedSSLSession) {
                    ExtendedSSLSession extSession =
                        (ExtendedSSLSession)session;
                    peerSupportedSignAlgs =
                        extSession.getPeerSupportedSignatureAlgorithms();
                }

                return new SSLAlgorithmConstraints(
                    engine, peerSupportedSignAlgs, true);
            }
        }
    }

    return new SSLAlgorithmConstraints(engine, true);
}
 
Example #18
Source File: Validator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Validate the given certificate chain.
 *
 * @param chain the target certificate chain
 * @param otherCerts a Collection of additional X509Certificates that
 *        could be helpful for path building (or null)
 * @param responseList a List of zero or more byte arrays, each
 *        one being a DER-encoded OCSP response (per RFC 6960).  Entries
 *        in the List must match the order of the certificates in the
 *        chain parameter.  It is possible that fewer responses may be
 *        in the list than are elements in {@code chain} and a missing
 *        response for a matching element in {@code chain} can be
 *        represented with a zero-length byte array.
 * @param constraints algorithm constraints for certification path
 *        processing
 * @param parameter an additional parameter object to pass specific data.
 *        This parameter object maybe one of the two below:
 *        1) TLS_SERVER variant validators, where it must be non null and
 *        the name of the TLS key exchange algorithm being used
 *        (see JSSE X509TrustManager specification).
 *        2) {@code Timestamp} object from a signed JAR file.
 * @return a non-empty chain that was used to validate the path. The
 *        end entity cert is at index 0, the trust anchor at index n-1.
 */
public final X509Certificate[] validate(X509Certificate[] chain,
            Collection<X509Certificate> otherCerts,
            List<byte[]> responseList,
            AlgorithmConstraints constraints,
            Object parameter) throws CertificateException {
    chain = engineValidate(chain, otherCerts, responseList, constraints,
            parameter);

    // omit EE extension check if EE cert is also trust anchor
    if (chain.length > 1) {
        // EndEntityChecker does not need to check unresolved critical
        // extensions when validating with a TYPE_PKIX Validator.
        // A TYPE_PKIX Validator will already have run checks on all
        // certs' extensions, including checks by any PKIXCertPathCheckers
        // included in the PKIXParameters, so the extra checks would be
        // redundant.
        boolean checkUnresolvedCritExts =
                (type == TYPE_PKIX) ? false : true;
        endEntityChecker.check(chain[0], parameter,
                               checkUnresolvedCritExts);
    }

    return chain;
}
 
Example #19
Source File: EllipticCurvesExtension.java    From dragonwell8_jdk 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 #20
Source File: SSLSocketImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
SSLSocketImpl(SSLContextImpl context, boolean serverMode,
        CipherSuiteList suites, byte clientAuth,
        boolean sessionCreation, ProtocolList protocols,
        String identificationProtocol,
        AlgorithmConstraints algorithmConstraints,
        Collection<SNIMatcher> sniMatchers,
        boolean preferLocalCipherSuites) throws IOException {

    super();
    doClientAuth = clientAuth;
    enableSessionCreation = sessionCreation;
    this.identificationProtocol = identificationProtocol;
    this.algorithmConstraints = algorithmConstraints;
    this.sniMatchers = sniMatchers;
    this.preferLocalCipherSuites = preferLocalCipherSuites;
    init(context, serverMode);

    /*
     * Override what was picked out for us.
     */
    enabledCipherSuites = suites;
    enabledProtocols = protocols;
}
 
Example #21
Source File: X509KeyManagerImpl.java    From openjsse with GNU General Public License v2.0 6 votes vote down vote up
private AlgorithmConstraints getAlgorithmConstraints(javax.net.ssl.SSLEngine engine) {
    if (engine != null) {
        SSLSession session = engine.getHandshakeSession();
        if (session != null) {
            if (ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) {
                String[] peerSupportedSignAlgs = null;

                if (session instanceof ExtendedSSLSession) {
                    ExtendedSSLSession extSession =
                        (ExtendedSSLSession)session;
                    peerSupportedSignAlgs =
                        extSession.getPeerSupportedSignatureAlgorithms();
                }

                return new SSLAlgorithmConstraints(
                    (org.openjsse.javax.net.ssl.SSLEngine)engine, peerSupportedSignAlgs, true);
            }
        }
    }

    return new SSLAlgorithmConstraints((org.openjsse.javax.net.ssl.SSLEngine)engine, true);
}
 
Example #22
Source File: SupportedGroupsExtension.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
static NamedGroup getPreferredGroup(
        ProtocolVersion negotiatedProtocol,
        AlgorithmConstraints constraints, NamedGroupSpec[] types,
        List<NamedGroup> requestedNamedGroups) {
    for (NamedGroup namedGroup : requestedNamedGroups) {
        if ((NamedGroupSpec.arrayContains(types, namedGroup.spec)) &&
                namedGroup.isAvailable(negotiatedProtocol) &&
                isSupported(namedGroup) &&
                namedGroup.isPermitted(constraints)) {
            return namedGroup;
        }
    }

    return null;
}
 
Example #23
Source File: SupportedGroupsExtension.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
static NamedGroup getPreferredGroup(
        ProtocolVersion negotiatedProtocol,
        AlgorithmConstraints constraints, NamedGroupSpec[] types) {
    for (NamedGroup namedGroup : supportedNamedGroups) {
        if ((NamedGroupSpec.arrayContains(types, namedGroup.spec)) &&
                namedGroup.isAvailable(negotiatedProtocol) &&
                namedGroup.isPermitted(constraints)) {
            return namedGroup;
        }
    }

    return null;
}
 
Example #24
Source File: EllipticCurvesExtension.java    From TencentKona-8 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 #25
Source File: AlgorithmChecker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a new {@code AlgorithmChecker} with the
 * given {@code TrustAnchor}, {@code AlgorithmConstraints},
 * {@code Timestamp}, and {@code String} variant.
 *
 * @param anchor the trust anchor selected to validate the target
 *     certificate
 * @param constraints the algorithm constraints (or null)
 * @param pkixdate The date specified by the PKIXParameters date.  If the
 *                 PKIXParameters is null, the current date is used.  This
 *                 should be null when jar files are being checked.
 * @param jarTimestamp Timestamp passed for JAR timestamp constraint
 *                     checking. Set to null if not applicable.
 * @param variant is the Validator variants of the operation. A null value
 *                passed will set it to Validator.GENERIC.
 */
public AlgorithmChecker(TrustAnchor anchor,
        AlgorithmConstraints constraints, Date pkixdate,
        Timestamp jarTimestamp, String variant) {

    if (anchor != null) {
        if (anchor.getTrustedCert() != null) {
            this.trustedPubKey = anchor.getTrustedCert().getPublicKey();
            // Check for anchor certificate restrictions
            trustedMatch = checkFingerprint(anchor.getTrustedCert());
            if (trustedMatch && debug != null) {
                debug.println("trustedMatch = true");
            }
        } else {
            this.trustedPubKey = anchor.getCAPublicKey();
        }
    } else {
        this.trustedPubKey = null;
        if (debug != null) {
            debug.println("TrustAnchor is null, trustedMatch is false.");
        }
    }

    this.prevPubKey = this.trustedPubKey;
    this.constraints = (constraints == null ? certPathDefaultConstraints :
            constraints);
    // If we are checking jar files, set pkixdate the same as the timestamp
    // for certificate checking
    this.pkixdate = (jarTimestamp != null ? jarTimestamp.getTimestamp() :
            pkixdate);
    this.jarTimestamp = jarTimestamp;
    this.variant = (variant == null ? Validator.VAR_GENERIC : variant);
}
 
Example #26
Source File: Handshaker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the algorithm constraints. Called from the constructor or
 * SSLSocketImpl/SSLEngineImpl.setAlgorithmConstraints() (if the
 * handshake is not yet in progress).
 */
void setAlgorithmConstraints(AlgorithmConstraints algorithmConstraints) {
    activeCipherSuites = null;
    activeProtocols = null;

    this.algorithmConstraints =
        new SSLAlgorithmConstraints(algorithmConstraints);
    this.localSupportedSignAlgs = null;
}
 
Example #27
Source File: X509KeyManagerImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private AlgorithmConstraints getAlgorithmConstraints(Socket socket) {
    if (socket != null && socket.isConnected() &&
                                    socket instanceof SSLSocket) {

        SSLSocket sslSocket = (SSLSocket)socket;
        SSLSession session = sslSocket.getHandshakeSession();

        if (session != null) {
            if (ProtocolVersion.useTLS12PlusSpec(session.getProtocol())) {
                String[] peerSupportedSignAlgs = null;

                if (session instanceof ExtendedSSLSession) {
                    ExtendedSSLSession extSession =
                        (ExtendedSSLSession)session;
                    peerSupportedSignAlgs =
                        extSession.getPeerSupportedSignatureAlgorithms();
                }

                return new SSLAlgorithmConstraints(
                    sslSocket, peerSupportedSignAlgs, true);
            }
        }

        return new SSLAlgorithmConstraints(sslSocket, true);
    }

    return new SSLAlgorithmConstraints((SSLSocket)null, true);
}
 
Example #28
Source File: SupportedEllipticCurvesExtension.java    From jdk8u-jdk 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 #29
Source File: Handshaker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the algorithm constraints. Called from the constructor or
 * SSLSocketImpl/SSLEngineImpl.setAlgorithmConstraints() (if the
 * handshake is not yet in progress).
 */
void setAlgorithmConstraints(AlgorithmConstraints algorithmConstraints) {
    activeCipherSuites = null;
    activeProtocols = null;

    this.algorithmConstraints =
        new SSLAlgorithmConstraints(algorithmConstraints);
    this.localSupportedSignAlgs = null;
}
 
Example #30
Source File: SignatureAndHashAlgorithm.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static Collection<SignatureAndHashAlgorithm>
        getSupportedAlgorithms(AlgorithmConstraints constraints) {

    Collection<SignatureAndHashAlgorithm> supported = new ArrayList<>();
    for (SignatureAndHashAlgorithm sigAlg : priorityMap.values()) {
        if (sigAlg.priority <= SUPPORTED_ALG_PRIORITY_MAX_NUM &&
                constraints.permits(SIGNATURE_PRIMITIVE_SET,
                        sigAlg.algorithm, null)) {
            supported.add(sigAlg);
        }
    }

    return supported;
}