Java SSL Certificate Revocation Checking

前端 未结 4 1412
旧巷少年郎
旧巷少年郎 2020-12-15 12:53

I\'m currently writing a network TCP server using SSL. In production, we\'ll finally require clients to authenticate with a certificate.

In order to revoke certifica

4条回答
  •  清酒与你
    2020-12-15 13:41

    Notice that disabling revocation checking is a bad security practice. You can do it, but make sure you know the risk!

    The currently accepted answer by @DoNuT works by setting PKIXRevocationChecker.Option.SOFT_FAIL, which causes the validator not to throw an exception even if revocation checking fails. The following answer disables revocation checking altogether, thus it is faster in case you don't want validation at all. This is because performing revocation checks needs contacting CRL distribution points or OCSP servers, and if you don't want that, you need not pay the price.

    You can simply use setRevocationEnabled(false) on an object of type PKIXBuilderParameters.

    // Initialize "anchors" to trusted certificates
    // Initialize "selector" to the certificate you want to validate
    PKIXBuilderParameters pbParams = new PKIXBuilderParameters(anchors, selector);
    
    pbParams.setRevocationEnabled(false); // disable revocation check
    
    CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX");
    CertPathBuilderResult cpbResult = cpb.build(pbParams);
    
    CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
    CertPathValidatorResult result = cpv.validate(cpbResult.getCertPath(), pbParams);
    
    System.out.println(result);
    

提交回复
热议问题