Conversation
ed385dd to
2c1de73
Compare
| * @throws AuthTokenException when user certificate is revoked or revocation check fails. | ||
| */ | ||
| public void validateCertificateNotRevoked(X509Certificate subjectCertificate) throws AuthTokenException { | ||
| public RevocationInfo validateCertificateNotRevoked(X509Certificate subjectCertificate, X509Certificate issuerCertificate) throws AuthTokenException { |
Check notice
Code scanning / CodeQL
Missing Override annotation
| private static class OcpClientThatThrowsException extends IOException { | ||
| } | ||
|
|
||
| public static AuthTokenValidator getAuthTokenValidatorWithOverriddenOcspClient(OcspClient ocspClient) throws CertificateException, JceException, IOException { |
Check notice
Code scanning / CodeQL
Useless parameter
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 2 months ago
The best way to fix this problem is to remove the unused parameter from the method signature and update all method calls to stop passing the unnecessary argument. This keeps the code clean and prevents confusion for future maintainers. Specifically, in src/test/java/eu/webeid/ocsp/client/OcspClientOverrideTest.java, modify the signature of getAuthTokenValidatorWithOverriddenOcspClient to remove the OcspClient ocspClient parameter, and update invocations at lines 47 and 63 to call it without arguments. No additional imports or method definitions are required; only method signatures and usages need updating.
| @@ -44,7 +44,7 @@ | ||
|
|
||
| @Test | ||
| void whenOcspClientIsOverridden_thenItIsUsed() throws JceException, CertificateException, IOException { | ||
| final AuthTokenValidator validator = getAuthTokenValidatorWithOverriddenOcspClient(new OcpClientThatThrows()); | ||
| final AuthTokenValidator validator = getAuthTokenValidatorWithOverriddenOcspClient(); | ||
| assertThatThrownBy(() -> validator.validate(validAuthToken, VALID_CHALLENGE_NONCE)) | ||
| .cause() | ||
| .isInstanceOf(OcpClientThatThrowsException.class); | ||
| @@ -60,9 +60,7 @@ | ||
| @Test | ||
| @Disabled("Demonstrates how to configure the built-in HttpClient instance for OcspClientImpl") | ||
| void whenOcspClientIsConfiguredWithCustomHttpClient_thenOcspCallSucceeds() throws JceException, CertificateException, IOException { | ||
| final AuthTokenValidator validator = getAuthTokenValidatorWithOverriddenOcspClient( | ||
| new OcspClientImpl(HttpClient.newBuilder().build(), Duration.ofSeconds(5)) | ||
| ); | ||
| final AuthTokenValidator validator = getAuthTokenValidatorWithOverriddenOcspClient(); | ||
| assertThatCode(() -> validator.validate(validAuthToken, VALID_CHALLENGE_NONCE)) | ||
| .doesNotThrowAnyException(); | ||
| } | ||
| @@ -77,7 +75,7 @@ | ||
| private static class OcpClientThatThrowsException extends IOException { | ||
| } | ||
|
|
||
| public static AuthTokenValidator getAuthTokenValidatorWithOverriddenOcspClient(OcspClient ocspClient) throws CertificateException, JceException, IOException { | ||
| public static AuthTokenValidator getAuthTokenValidatorWithOverriddenOcspClient() throws CertificateException, JceException, IOException { | ||
| // FIXME: test override | ||
| return AuthTokenValidators.getAuthTokenValidator(); | ||
| } |
9f7fb95 to
2e783f3
Compare
20426da to
7e98567
Compare
daf2a6c to
d6eebea
Compare
b7b0220 to
10e86be
Compare
…tation to eu.webeid.ocsp and make it optional WE2-1030 Signed-off-by: Mart Somermaa <mrts@users.noreply.github.com>
10e86be to
310224e
Compare
| * depending on {@code revocationMode}. | ||
| * <p> | ||
| * Trust validation is performed by building a certification path from {@code certificate} to one of the | ||
| * configured {@code trustedCACertificateAnchors} using the supplied {@code trustedCACertificateCertStore}. |
There was a problem hiding this comment.
Add that it is assumed that the trust anchor is the intermediate certificate authority that is the issuer of the subject certificate.
…mentException WE2-1030 Signed-off-by: Sven Mitt <svenzik@users.noreply.github.com>
|
| if (ocspResponderUri == null) { | ||
| return message; | ||
| } | ||
| return message + " (OCSP responder: " + ocspResponderUri + ")"; |
There was a problem hiding this comment.
This class name is OcspResponderUriMessage, but content is used like formatter.
First method argument is never null, Is this class even needed?
If it is, then
I suggest we rename the method formatResponderUri and class to OcspResponderUriMessageFormatter or similar.
I would suggest we improve API by having two methods, one for each usecase:
static String formatResponderUri(URI ocspResponderUri)
static String formatResponderUri(String message, URI ocspResponderUri)
Usage in code:
formatResponderUri(ocspResponderUri)
formatResponderUri("User certificate has been revoked", ocspResponderUri)
| final X509Certificate trustedCACert = result.getTrustAnchor().getTrustedCert(); | ||
| List<RevocationInfo> revocationInfoList = List.of(); | ||
|
|
||
| switch (revocationMode) { |
There was a problem hiding this comment.
Assigning a variable revocationInfoList and returning it later is a code smell.
This switch should be refactored into a separate method.
For example:
List<RevocationInfo> revocationInfoList = getRevocationInfos(revocationMode, certificateRevocationChecker, customPkixRevocationChecker, pkixBuilderParameters, certPathBuilder);
This allows the code flow at the end of the method to be more readable:
if (revocationMode == RevocationMode.CUSTOM_CHECKER) {
if (!certificate.getIssuerX500Principal().equals(trustedCACert.getSubjectX500Principal())) {
throw new IllegalStateException(
"Trust anchor is not the issuer of the subject certificate, check your configured certificate authorities. " +
"Subject issuer=" + certificate.getIssuerX500Principal() +
", trust anchor subject=" + trustedCACert.getSubjectX500Principal()
);
}
return certificateRevocationChecker.validateCertificateNotRevoked(certificate, trustedCACert);
} else {
return getRevocationInfos(revocationMode, certificateRevocationChecker, customPkixRevocationChecker, pkixBuilderParameters, certPathBuilder);
}
This will make code readable, the method responsiblity is now to choose between custom or default implementation and default implementation is properly isolated into method.
NB! Spring usually introduces a delegator pattern, which only purpose is to choose which implementation to use. Currently this class chooses the implementation and is the default implementation.



WE2-1030
Signed-off-by: Mart Somermaa mrts@users.noreply.github.com