-
Notifications
You must be signed in to change notification settings - Fork 7
Add resilient OCSP certificate revocation checker #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: WE2-1030-use-platform-ocsp
Are you sure you want to change the base?
Changes from all commits
9e042cd
a57ce1c
46dc128
59f8c2c
b98e45f
d299d3d
42dd199
1aafc02
1f07eb6
2c280b2
3c3e117
8400be7
f7c137d
e7e768c
3c27b2a
6d023f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025 Estonian Information System Authority | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| package eu.webeid.ocsp.exceptions; | ||
|
|
||
| public class OCSPClientException extends RuntimeException { | ||
|
|
||
| private byte[] responseBody; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fields should be final/immutable. |
||
|
|
||
| private Integer statusCode; | ||
|
|
||
| public OCSPClientException() { | ||
| } | ||
|
|
||
| public OCSPClientException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public OCSPClientException(Throwable cause) { | ||
| super(cause); | ||
| } | ||
|
|
||
| public OCSPClientException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
|
|
||
| public OCSPClientException(String message, byte[] responseBody, int statusCode) { | ||
| super(message); | ||
| this.responseBody = responseBody; | ||
| this.statusCode = statusCode; | ||
| } | ||
|
|
||
| public byte[] getResponseBody() { | ||
| return responseBody; | ||
| } | ||
|
|
||
| public Integer getStatusCode() { | ||
| return statusCode; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025 Estonian Information System Authority | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| package eu.webeid.ocsp.exceptions; | ||
|
|
||
| import eu.webeid.security.exceptions.AuthTokenException; | ||
|
|
||
| import java.net.URI; | ||
|
|
||
| import static eu.webeid.ocsp.exceptions.OcspResponderUriMessageAppender.appendResponderUri; | ||
|
|
||
| public class UserCertificateUnknownException extends AuthTokenException { | ||
|
|
||
| public UserCertificateUnknownException(String msg, URI ocspResponderUri) { | ||
| super(appendResponderUri("User certificate status is unknown: " + msg, ocspResponderUri)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright (c) 2020-2025 Estonian Information System Authority | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| package eu.webeid.ocsp.protocol; | ||
|
|
||
| import org.bouncycastle.asn1.x500.RDN; | ||
| import org.bouncycastle.asn1.x500.X500Name; | ||
| import org.bouncycastle.asn1.x500.style.BCStyle; | ||
| import org.bouncycastle.asn1.x500.style.IETFUtils; | ||
| import org.bouncycastle.cert.jcajce.JcaX509CertificateHolder; | ||
|
|
||
| import java.security.cert.CertificateEncodingException; | ||
| import java.security.cert.X509Certificate; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| public class IssuerCommonName { | ||
|
|
||
| public static Optional<String> getIssuerCommonName(X509Certificate certificate) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using only Common Name seems error-prone, using the full normalized Distinguished Name seems much safer. For example, in the following (hypothetical) case there would be CN collision, but DN would work: This applies to all locations where CN is used for lookup like OcspServiceProvider, AiaOcspService, FallbackOcspServiceConfiguration and AiaOcspServiceConfiguration. |
||
| Objects.requireNonNull(certificate, "certificate"); | ||
| try { | ||
| X500Name x500Name = new JcaX509CertificateHolder(certificate).getIssuer(); | ||
| final RDN cn = x500Name.getRDNs(BCStyle.CN)[0]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will throw |
||
| return Optional.of(IETFUtils.valueToString(cn.getFirst().getValue())); | ||
| } catch (CertificateEncodingException e) { | ||
| return Optional.empty(); | ||
| } | ||
| } | ||
|
|
||
| private IssuerCommonName() { | ||
| throw new IllegalStateException("Utility class"); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OCSPClientException looks more like a checked exception than a RuntimeException. Failures are part of the OcspClient contract and callers are supposed to handle them rather than let them escape accidentally.