Skip to content

Commit 6b9be5d

Browse files
committed
Add support for turning off extKeyUsage check in PKCS11 modules
WE2-1041 Signed-off-by: Mart Somermaa <mrts@users.noreply.github.com>
1 parent 7991e0e commit 6b9be5d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/electronic-ids/x509.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ inline CertificateType certificateType(const pcsc_cpp::byte_vector& cert)
5252

5353
static const int KEY_USAGE_DIGITAL_SIGNATURE = 0;
5454
if (ASN1_BIT_STRING_get_bit(keyUsage.get(), KEY_USAGE_DIGITAL_SIGNATURE)) {
55-
if (auto extKeyUsage = extension(x509.get(), NID_ext_key_usage, EXTENDED_KEY_USAGE_free);
56-
extKeyUsage && hasClientAuthExtendedKeyUsage(extKeyUsage.get())) {
57-
return CertificateType::AUTHENTICATION;
55+
if (auto extKeyUsage = extension(x509.get(), NID_ext_key_usage, EXTENDED_KEY_USAGE_free)) {
56+
return hasClientAuthExtendedKeyUsage(extKeyUsage.get())
57+
? CertificateType::AUTHENTICATION
58+
: CertificateType::NONE;
5859
}
60+
// Digital Signature extension present, but Extended Key Usage extension not present,
61+
// assume it is an authentication certificate.
62+
return CertificateType::AUTHENTICATION;
5963
}
6064

6165
return CertificateType::NONE;

tests/mock/test-pkcs11-token.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@ TEST(electronic_id_test, pkcs11TokenHasAuthenticationCert)
8888
PKCS11CardManager::Token token;
8989
token.cert = base64Decode(AUTH_CERT);
9090
EXPECT_TRUE(certificateType(token.cert).isAuthentication());
91+
EXPECT_FALSE(certificateType(token.cert).isSigning());
9192
}
9293

9394
TEST(electronic_id_test, pkcs11TokenHasSigningCert)
9495
{
9596
PKCS11CardManager::Token token;
9697
token.cert = base64Decode(SIGNING_CERT);
9798
EXPECT_FALSE(certificateType(token.cert).isAuthentication());
99+
EXPECT_TRUE(certificateType(token.cert).isSigning());
98100
}

0 commit comments

Comments
 (0)