Repository navigation
Conversation
madislm
force-pushed
the
AUT-2981
branch
4 times, most recently
from
October 5, 2026 12:17
5a45d6d to
56d68ae
Compare
Signed-off-by: Madis Jaagup Laurson <[email protected]>
mrts
requested changes
Oct 8, 2026
madislm
force-pushed
the
AUT-2981
branch
4 times, most recently
from
October 12, 2026 11:10
b313adf to
1a97a19
Compare
mrts
requested changes
Oct 12, 2026
mrts
requested changes
Oct 13, 2026
|
|
||
| import eu.webeid.security.exceptions.AuthTokenException; | ||
|
|
||
| public class UserCertificateOCSPException extends AuthTokenException { |
Member
There was a problem hiding this comment.
Should this extend CertificateRevocationCheckFailedException? UserCertificateOCSPException errors prevent determining revocation status and should be caught through that common type.
|
|
||
| These checks are implemented by [OcspResponseValidator](protocol/OcspResponseValidator.java). | ||
|
|
||
| By default, OCSP responder certificates must have the Key Usage extension with Digital Signature. To accept responder certificates that lack the Key Usage extension or do not assert Digital Signature in it, pass `false` as the last `isKeyUsageRequired` argument of the `AiaOcspServiceConfiguration`, `DesignatedOcspServiceConfiguration` or `FallbackOcspServiceConfiguration` constructor. If the Key Usage extension is present, it must still not contain Certificate Signing, the Extended Key Usage extension must still contain OCSP Signing, and the certificate must still not be a CA certificate. For AIA services, the setting applies only to delegated responder certificates, not to the issuer CA signing its own responses. The setting of a fallback configuration does not propagate to its `nextFallbackConfiguration`. |
Member
There was a problem hiding this comment.
How about this:
Suggested change
| By default, OCSP responder certificates must have the Key Usage extension with Digital Signature. To accept responder certificates that lack the Key Usage extension or do not assert Digital Signature in it, pass `false` as the last `isKeyUsageRequired` argument of the `AiaOcspServiceConfiguration`, `DesignatedOcspServiceConfiguration` or `FallbackOcspServiceConfiguration` constructor. If the Key Usage extension is present, it must still not contain Certificate Signing, the Extended Key Usage extension must still contain OCSP Signing, and the certificate must still not be a CA certificate. For AIA services, the setting applies only to delegated responder certificates, not to the issuer CA signing its own responses. The setting of a fallback configuration does not propagate to its `nextFallbackConfiguration`. | |
| The examples require OCSP responder certificates to have the Key Usage extension. To accept responder certificates that lack the Key Usage extension, pass `false` as the last `isKeyUsageRequired` argument of the `AiaOcspServiceConfiguration`, `DesignatedOcspServiceConfiguration` or `FallbackOcspServiceConfiguration` constructor. If the Key Usage extension is present, it must contain Digital Signature or Non Repudiation and must not contain Certificate Signing. The Extended Key Usage extension must still contain OCSP Signing, and the certificate must still not be a CA certificate. For AIA services, the setting applies only to delegated responder certificates, not to the issuer CA signing its own responses. The setting of a fallback configuration does not propagate to its `nextFallbackConfiguration`. |
| CertificateValidator.buildCertStoreFromCertificates(trustedCAs), | ||
| OcspCertificateRevocationChecker.DEFAULT_THIS_UPDATE_AGE, | ||
| OcspCertificateRevocationChecker.DEFAULT_NEXT_UPDATE_AGE, | ||
| true // Require the Key Usage extension with Digital Signature in responder certificates. |
Member
There was a problem hiding this comment.
Suggested change
| true // Require the Key Usage extension with Digital Signature in responder certificates. | |
| true // Require the Key Usage extension in responder certificates. |
| true, // This service supports nonces. | ||
| OcspCertificateRevocationChecker.DEFAULT_THIS_UPDATE_AGE, | ||
| OcspCertificateRevocationChecker.DEFAULT_NEXT_UPDATE_AGE, | ||
| true // Require the Key Usage extension with Digital Signature in responder certificates. |
Member
There was a problem hiding this comment.
Suggested change
| true // Require the Key Usage extension with Digital Signature in responder certificates. | |
| true // Require the Key Usage extension in responder certificates. |
Comment on lines
+55
to
+90
| /** | ||
| * The flag controls whether Key Usage must be present. If present, Key Usage must include | ||
| * Digital Signature or Non Repudiation. | ||
| */ | ||
| public static void validateKeyUsageDigitalSignature(X509Certificate certificate, boolean isKeyUsageRequired) throws OCSPCertificateException { | ||
| Objects.requireNonNull(certificate, "certificate"); | ||
| final boolean[] keyUsage = certificate.getKeyUsage(); | ||
| if (keyUsage == null) { | ||
| if (!isKeyUsageRequired) { | ||
| return; | ||
| } | ||
| throw new OCSPCertificateException("Certificate " + certificate.getSubjectX500Principal() + | ||
| " does not contain the Key Usage extension required for OCSP response signing"); | ||
| } | ||
| final boolean hasDigitalSignature = keyUsage.length > KEY_USAGE_DIGITAL_SIGNATURE_BIT_INDEX | ||
| && keyUsage[KEY_USAGE_DIGITAL_SIGNATURE_BIT_INDEX]; | ||
| // RFC 5280 section 4.2.1.12 also permits Non Repudiation for OCSP signing. | ||
| final boolean hasNonRepudiation = keyUsage.length > KEY_USAGE_NON_REPUDIATION_BIT_INDEX | ||
| && keyUsage[KEY_USAGE_NON_REPUDIATION_BIT_INDEX]; | ||
| if (!hasDigitalSignature && !hasNonRepudiation) { | ||
| throw new OCSPCertificateException("Certificate " + certificate.getSubjectX500Principal() + | ||
| " Key Usage extension does not contain Digital Signature or Non Repudiation, which is required for OCSP response signing"); | ||
| } | ||
| } | ||
|
|
||
| public static void validateKeyUsageNotCertificateSigning(X509Certificate certificate) throws OCSPCertificateException { | ||
| Objects.requireNonNull(certificate, "certificate"); | ||
| final boolean[] keyUsage = certificate.getKeyUsage(); | ||
| if (keyUsage == null) { | ||
| return; | ||
| } | ||
| if (keyUsage.length > KEY_USAGE_KEY_CERT_SIGN_BIT_INDEX && keyUsage[KEY_USAGE_KEY_CERT_SIGN_BIT_INDEX]) { | ||
| throw new OCSPCertificateException("Certificate " + certificate.getSubjectX500Principal() + | ||
| " Key Usage extension contains Certificate Signing, which is not allowed for OCSP responder"); | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
I think validateKeyUsageDigitalSignature() and validateKeyUsageNotCertificateSigning() can be merged into one validateKeyUsageOcspSigning() for consistency:
/**
* The flag controls whether Key Usage must be present. If present, Key Usage must include
* Digital Signature or Non Repudiation and must not include Certificate Signing.
*/
public static void validateKeyUsageOcspSigning(X509Certificate certificate, boolean isKeyUsageRequired) throws OCSPCertificateException {
Objects.requireNonNull(certificate, "certificate");
final boolean[] keyUsage = certificate.getKeyUsage();
if (keyUsage == null) {
if (!isKeyUsageRequired) {
return;
}
throw new OCSPCertificateException("Certificate " + certificate.getSubjectX500Principal() +
" does not contain the Key Usage extension required for OCSP response signing");
}
final boolean hasDigitalSignature = keyUsage.length > KEY_USAGE_DIGITAL_SIGNATURE_BIT_INDEX
&& keyUsage[KEY_USAGE_DIGITAL_SIGNATURE_BIT_INDEX];
// RFC 5280 section 4.2.1.12 also permits Non Repudiation for OCSP signing.
final boolean hasNonRepudiation = keyUsage.length > KEY_USAGE_NON_REPUDIATION_BIT_INDEX
&& keyUsage[KEY_USAGE_NON_REPUDIATION_BIT_INDEX];
if (!hasDigitalSignature && !hasNonRepudiation) {
throw new OCSPCertificateException("Certificate " + certificate.getSubjectX500Principal() +
" Key Usage extension does not contain Digital Signature or Non Repudiation, which is required for OCSP response signing");
}
if (keyUsage.length > KEY_USAGE_KEY_CERT_SIGN_BIT_INDEX && keyUsage[KEY_USAGE_KEY_CERT_SIGN_BIT_INDEX]) {
throw new OCSPCertificateException("Certificate " + certificate.getSubjectX500Principal() +
" Key Usage extension contains Certificate Signing, which is not allowed for OCSP responder");
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AUT-2981
Signed-off-by: Madis Jaagup Laurson <[email protected]>