当前位置: 首页>>代码示例>>Java>>正文


Java CertPathValidatorException.getReason方法代码示例

本文整理汇总了Java中java.security.cert.CertPathValidatorException.getReason方法的典型用法代码示例。如果您正苦于以下问题:Java CertPathValidatorException.getReason方法的具体用法?Java CertPathValidatorException.getReason怎么用?Java CertPathValidatorException.getReason使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.cert.CertPathValidatorException的用法示例。


在下文中一共展示了CertPathValidatorException.getReason方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCertificateAlert

import java.security.cert.CertPathValidatorException; //导入方法依赖的package包/类
/**
 * When a failure happens during certificate checking from an
 * {@link X509TrustManager}, determine what TLS alert description to use.
 *
 * @param cexc The exception thrown by the {@link X509TrustManager}
 *
 * @return A byte value corresponding to a TLS alert description number.
 */
private byte getCertificateAlert(CertificateException cexc) {
    // The specific reason for the failure will determine how to
    // set the alert description value
    byte alertDesc = Alerts.alert_certificate_unknown;

    Throwable baseCause = cexc.getCause();
    if (baseCause instanceof CertPathValidatorException) {
        CertPathValidatorException cpve =
                (CertPathValidatorException)baseCause;
        Reason reason = cpve.getReason();
        if (reason == BasicReason.REVOKED) {
            alertDesc = staplingActive ?
                    Alerts.alert_bad_certificate_status_response :
                    Alerts.alert_certificate_revoked;
        } else if (reason == BasicReason.UNDETERMINED_REVOCATION_STATUS) {
            alertDesc = staplingActive ?
                    Alerts.alert_bad_certificate_status_response :
                    Alerts.alert_certificate_unknown;
        }
    }

    return alertDesc;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:ClientHandshaker.java

示例2: checkClientValidationFailure

import java.security.cert.CertPathValidatorException; //导入方法依赖的package包/类
/**
 * Checks a validation failure to see if it failed for the reason we think
 * it should.  This comes in as an SSLException of some sort, but it
 * encapsulates a ValidatorException which in turn encapsulates the
 * CertPathValidatorException we are interested in.
 *
 * @param e the exception thrown at the top level
 * @param reason the underlying CertPathValidatorException BasicReason
 * we are expecting it to have.
 *
 * @return true if the reason matches up, false otherwise.
 */
static boolean checkClientValidationFailure(Exception e,
        BasicReason reason) {
    boolean result = false;

    if (e instanceof SSLException) {
        Throwable valExc = e.getCause();
        if (valExc instanceof sun.security.validator.ValidatorException) {
            Throwable cause = valExc.getCause();
            if (cause instanceof CertPathValidatorException) {
                CertPathValidatorException cpve =
                        (CertPathValidatorException)cause;
                if (cpve.getReason() == reason) {
                    result = true;
                }
            }
        }
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:HttpsUrlConnClient.java

示例3: checkClientValidationFailure

import java.security.cert.CertPathValidatorException; //导入方法依赖的package包/类
/**
 * Checks a validation failure to see if it failed for the reason we think
 * it should.  This comes in as an SSLException of some sort, but it
 * encapsulates a ValidatorException which in turn encapsulates the
 * CertPathValidatorException we are interested in.
 *
 * @param e the exception thrown at the top level
 * @param reason the underlying CertPathValidatorException BasicReason
 * we are expecting it to have.
 *
 * @return true if the reason matches up, false otherwise.
 */
static boolean checkClientValidationFailure(Exception e,
        CertPathValidatorException.BasicReason reason) {
    boolean result = false;

    if (e instanceof SSLException) {
        Throwable sslhe = e.getCause();
        if (sslhe instanceof SSLHandshakeException) {
            Throwable valExc = sslhe.getCause();
            if (valExc instanceof sun.security.validator.ValidatorException) {
                Throwable cause = valExc.getCause();
                if (cause instanceof CertPathValidatorException) {
                    CertPathValidatorException cpve =
                            (CertPathValidatorException)cause;
                    if (cpve.getReason() == reason) {
                        result = true;
                    }
                }
            }
        }
    }
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:SSLEngineWithStapling.java

示例4: toInvalidCertificates

import java.security.cert.CertPathValidatorException; //导入方法依赖的package包/类
private Function<Map<CertificateDetails, CertificateValidity>, InvalidCertificateDto> toInvalidCertificates() {
    return input -> {
        CertificateDetails certificateDetail = getOnlyElement(input.keySet());
        CertificateValidity certificateValidity = getOnlyElement(input.values());

        CertPathValidatorException certPathValidatorException = certificateValidity.getException().get();
        return new InvalidCertificateDto(
                certificateDetail.getIssuerId(),
                certPathValidatorException.getReason(),
                certificateDetail.getKeyUse(),
                certificateDetail.getFederationEntityType(),
                certPathValidatorException.getMessage());
    };
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:15,代码来源:CertificateValidityChecker.java

示例5: getsInvalidCertificates

import java.security.cert.CertPathValidatorException; //导入方法依赖的package包/类
@Test
public void getsInvalidCertificates() throws Exception {
    String description = "Certificate invalid";
    CertPathValidatorException certPathValidatorException = new CertPathValidatorException(description);

    when(trustStoreForCertProvider.getTrustStoreFor(certificateDetails.getFederationEntityType())).thenReturn(trustStore);
    when(certificateChainValidator.validate(certificateDetails.getX509(), trustStore)).thenReturn(CertificateValidity.invalid(certPathValidatorException));

    ImmutableList<InvalidCertificateDto> invalidCertificates = certificateValidityChecker.getInvalidCertificates(ImmutableList.of(certificateDetails));

    InvalidCertificateDto expected = new InvalidCertificateDto(certificateDetails.getIssuerId(), certPathValidatorException.getReason(), CertificateType.SIGNING, certificateDetails.getFederationEntityType(), description);

    assertThat(invalidCertificates).usingFieldByFieldElementComparator().containsOnly(expected);
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:15,代码来源:CertificateValidityCheckerTest.java

示例6: main

import java.security.cert.CertPathValidatorException; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
    if (args.length != 1) {
        throw new Exception("Incorrect number of arguments");
    }
    Test test = tests[Integer.parseInt(args[0])];
    Security.setProperty("jdk.tls.disabledAlgorithms", test.tlsDisAlgs);
    Security.setProperty("jdk.certpath.disabledAlgorithms",
                         test.certPathDisAlgs);

    if (debug) {
        System.setProperty("javax.net.debug", "all");
    }

    /*
     * Start the tests.
     */
    try {
        new PKIXExtendedTM();
        if (test.fail) {
            throw new Exception("Expected MD5 certificate to be blocked");
        }
    } catch (Exception e) {
        if (test.fail) {
            // find expected cause
            boolean correctReason = false;
            Throwable cause = e.getCause();
            while (cause != null) {
                if (cause instanceof CertPathValidatorException) {
                    CertPathValidatorException cpve =
                        (CertPathValidatorException)cause;
                    if (cpve.getReason() == CertPathValidatorException.BasicReason.ALGORITHM_CONSTRAINED) {
                        correctReason = true;
                        break;
                    }
                }
                cause = cause.getCause();
            }
            if (!correctReason) {
                throw new Exception("Unexpected exception", e);
            }
        } else {
            throw e;
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:46,代码来源:PKIXExtendedTM.java


注:本文中的java.security.cert.CertPathValidatorException.getReason方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。