Skip to content

Improve resilient OCSP certificate revocation checker - #140

Open
madislm wants to merge 2 commits into
web-eid:v4from
madislm:AUT-2981
Open

madislm wants to merge 2 commits into
web-eid:v4from
madislm:AUT-2981

Conversation

@madislm

@madislm madislm commented Oct 2, 2026

Copy link
Copy Markdown

AUT-2981

Signed-off-by: Madis Jaagup Laurson <[email protected]>

@madislm madislm changed the title Improve resilient OCSP certificate revocation checker- #138 Improve resilient OCSP certificate revocation checker Oct 5, 2026
@madislm
madislm force-pushed the AUT-2981 branch 4 times, most recently from 5a45d6d to 56d68ae Compare October 5, 2026 12:17
Comment thread src/main/java/eu/webeid/ocsp/protocol/OcspResponseValidator.java
@madislm
madislm force-pushed the AUT-2981 branch 4 times, most recently from b313adf to 1a97a19 Compare October 12, 2026 11:10
Comment thread src/main/java/eu/webeid/ocsp/protocol/OcspResponseValidator.java Outdated

import eu.webeid.security.exceptions.AuthTokenException;

public class UserCertificateOCSPException extends AuthTokenException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants