Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/crypto/OCSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <openssl/pem.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <openssl/x509v3.h>

using namespace digidoc;
using namespace std;
Expand Down Expand Up @@ -203,6 +204,10 @@ void OCSP::verifyResponse(const X509Cert &cert) const
}
}
auto store = X509CertStore::createStore(X509CertStore::OCSP, tm);
// OCSP_NOCHECKS skips ocsp_check_issuer() which requires the responder to be directly
// delegated by the cert's issuing CA. SK PKI uses a cross-CA OCSP responder issued by
// the root CA rather than the intermediate CA, so this check would always fail.
// We compensate by verifying the responder cert has id-kp-OCSPSigning EKU below.
if(OCSP_basic_verify(basic.get(), stack.get(), store.get(), OCSP_NOCHECKS | OCSP_PARTIAL_CHAIN) != 1)
{
unsigned long err = ERR_get_error();
Expand All @@ -217,7 +222,7 @@ void OCSP::verifyResponse(const X509Cert &cert) const
throw OpenSSLException(EXCEPTION_PARAMS("Failed to verify OCSP response."), err);
}

// Find issuer before OCSP validation to activate region TSL
// Find issuer before status validation
X509Cert issuer = X509CertStore::instance()->findIssuer(cert, X509CertStore::CA);
if(!issuer)
{
Expand All @@ -226,6 +231,19 @@ void OCSP::verifyResponse(const X509Cert &cert) const
throw e;
}

// Explicitly check the OCSP responder has id-kp-OCSPSigning EKU (normally done by
// ocsp_check_issuer which we skipped above).
if(X509Cert responder = responderCert(); responder)
{
bool hasOCSPSign = issuer == responder;
auto eku = make_unique_cast<EXTENDED_KEY_USAGE_free>(
X509_get_ext_d2i(responder.handle(), NID_ext_key_usage, nullptr, nullptr));
for(int i = 0; eku && i < sk_ASN1_OBJECT_num(eku.get()); i++)
hasOCSPSign |= OBJ_obj2nid(sk_ASN1_OBJECT_value(eku.get(), i)) == NID_OCSP_sign;
if(!hasOCSPSign)
THROW("OCSP responder certificate does not have id-kp-OCSPSigning EKU");
}

int status = V_OCSP_CERTSTATUS_UNKNOWN;
for(int i = 0, count = OCSP_resp_count(basic.get()); i < count; ++i)
{
Expand Down
Loading