Add resilient OCSP certificate revocation checker#99
Add resilient OCSP certificate revocation checker#99madislm wants to merge 24 commits intoweb-eid:WE2-1030-use-platform-ocspfrom
Conversation
0e6161a to
e927de2
Compare
e96286a to
a324e96
Compare
10a405b to
74e7af2
Compare
9cdcc89 to
ef4ae35
Compare
74e7af2 to
f55d636
Compare
Co-authored-by: Madis Jaagup Laurson <madisjaagup.laurson@nortal.com>
…OCSP certificate revocation checker Co-authored-by: Madis Jaagup Laurson <madisjaagup.laurson@nortal.com>
…n into eu.webeid.ocsp.service
…tificateRevocationChecker
…llows old OCSP responses
|
|
||
| @Override | ||
| public Optional<FallbackOcspService> getFallbackService() { | ||
| return Optional.of(fallbackOcspService); |
There was a problem hiding this comment.
fallbackOcspService can be null, so
| return Optional.of(fallbackOcspService); | |
| return Optional.ofNullable(fallbackOcspService); |
Optional.of(null) throws NPE while Optional.ofNullable(null) returns Optional.empty().
| } | ||
| this.doesSupportNonce = doesSupportNonce; | ||
| this.nextFallbackConfiguration = nextFallbackConfiguration; | ||
| this.issuerDN = issuerDN; |
There was a problem hiding this comment.
Assert non-null check here as well, issuerDN can be misconfigured to null:
| this.issuerDN = issuerDN; | |
| this.issuerDN = Objects.requireNonNull(issuerDN, "issuerDN"); |
| this.trustedCACertificateAnchors = Objects.requireNonNull(trustedCACertificateAnchors); | ||
| this.trustedCACertificateCertStore = Objects.requireNonNull(trustedCACertificateCertStore); |
There was a problem hiding this comment.
Add parameter name to requireNonNull:
| this.trustedCACertificateAnchors = Objects.requireNonNull(trustedCACertificateAnchors); | |
| this.trustedCACertificateCertStore = Objects.requireNonNull(trustedCACertificateCertStore); | |
| this.trustedCACertificateAnchors = Objects.requireNonNull(trustedCACertificateAnchors, "trustedCACertificateAnchors"); | |
| this.trustedCACertificateCertStore = Objects.requireNonNull(trustedCACertificateCertStore, "trustedCACertificateCertStore"); |
Without it you will get a plain NPE with no message, with it a much more clear
java.lang.NullPointerException: trustedCACertificateAnchors
| package eu.webeid.ocsp; | ||
|
|
||
| import eu.webeid.ocsp.client.OcspClient; | ||
| import eu.webeid.ocsp.client.OcspClient;import eu.webeid.ocsp.exceptions.OCSPClientException; |
| @@ -26,7 +26,11 @@ | |||
|
|
|||
| public record RevocationInfo(URI ocspResponderUri, Map<String, Object> ocspResponseAttributes) { | |||
There was a problem hiding this comment.
Should we make ocspResponseAttributes immutable with Map.copyOf()?
Also List<RevocationInfo> revocationInfoList should be immutable in ValidationInfo with List.copyOf().
| public static Optional<X500Name> getIssuerDistinguishedName(X509Certificate certificate) { | ||
| Objects.requireNonNull(certificate, "certificate"); | ||
| String issuerDN = certificate.getIssuerX500Principal().getName(); | ||
| if (issuerDN.isEmpty()) { | ||
| return Optional.empty(); | ||
| } | ||
| return Optional.of(new X500Name(issuerDN)); | ||
| } |
There was a problem hiding this comment.
As far as I understand, getIssuerX500Principal() does not return null for a valid X509Certificate, so Optional is probably not justified.
A cleaner helper that does not rely on string parsing would be:
| public static Optional<X500Name> getIssuerDistinguishedName(X509Certificate certificate) { | |
| Objects.requireNonNull(certificate, "certificate"); | |
| String issuerDN = certificate.getIssuerX500Principal().getName(); | |
| if (issuerDN.isEmpty()) { | |
| return Optional.empty(); | |
| } | |
| return Optional.of(new X500Name(issuerDN)); | |
| } | |
| public static X500Name getIssuerDistinguishedName(X509Certificate certificate) { | |
| Objects.requireNonNull(certificate, "certificate"); | |
| return X500Name.getInstance(certificate.getIssuerX500Principal().getEncoded()); | |
| } |
| ResilientUserCertificateOCSPCheckFailedException exception = new ResilientUserCertificateOCSPCheckFailedException("Response status: " + ocspStatusToString(response.getStatus())); | ||
| RevocationInfo revocationInfo = new RevocationInfo(ocspService.getAccessLocation(), new HashMap<>(Map.ofEntries( | ||
| Map.entry(RevocationInfo.KEY_OCSP_ERROR, exception), | ||
| Map.entry(RevocationInfo.KEY_OCSP_REQUEST, request), | ||
| Map.entry(RevocationInfo.KEY_OCSP_RESPONSE, response), | ||
| Map.entry(RevocationInfo.KEY_REQUEST_DURATION, requestDuration), | ||
| Map.entry(RevocationInfo.KEY_OCSP_RESPONSE_TIME, responseTime) | ||
| ))); | ||
| exception.setValidationInfo(new ValidationInfo(subjectCertificate, List.of(revocationInfo))); | ||
| throw exception; |
There was a problem hiding this comment.
Here and in other error cases below, the code could be simplified and made immutable-friendlier.
AUT-2514
Signed-off-by: Madis Jaagup Laurson madisjaagup.laurson@nortal.com