Skip to content

Commit 0ecf20f

Browse files
committed
Add support for turning off extKeyUsage check in PKCS11 modules
WE2-1041 Signed-off-by: Mart Somermaa <[email protected]>
1 parent 7991e0e commit 0ecf20f

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

src/electronic-ids/pkcs11/Pkcs11ElectronicID.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Pkcs11ElectronicID::Pkcs11ElectronicID(ElectronicID::Type type) :
180180
bool seenSigningToken = false;
181181

182182
for (const auto& token : manager->tokens()) {
183-
const auto certType = certificateType(token.cert);
183+
const auto certType = certificateType(token.cert, module.checkExtKeyUsage);
184184
if (certType.isAuthentication()) {
185185
authToken = token;
186186
seenAuthToken = true;

src/electronic-ids/pkcs11/Pkcs11ElectronicID.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct Pkcs11ElectronicIDModule
3838
const int8_t retryMax;
3939
const bool allowsUsingLettersAndSpecialCharactersInPin;
4040
const bool providesExternalPinDialog;
41+
const bool checkExtKeyUsage = true;
4142
};
4243

4344
class Pkcs11ElectronicID : public ElectronicID

src/electronic-ids/x509.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ inline bool hasClientAuthExtendedKeyUsage(EXTENDED_KEY_USAGE* usage) noexcept
3737
return false;
3838
}
3939

40-
inline CertificateType certificateType(const pcsc_cpp::byte_vector& cert)
40+
inline CertificateType certificateType(const pcsc_cpp::byte_vector& cert, bool checkExtKeyUsage)
4141
{
4242
auto x509 = make_x509(cert);
4343
auto keyUsage = extension(x509.get(), NID_key_usage, ASN1_BIT_STRING_free);
@@ -52,6 +52,9 @@ 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 (!checkExtKeyUsage) {
56+
return CertificateType::AUTHENTICATION;
57+
}
5558
if (auto extKeyUsage = extension(x509.get(), NID_ext_key_usage, EXTENDED_KEY_USAGE_free);
5659
extKeyUsage && hasClientAuthExtendedKeyUsage(extKeyUsage.get())) {
5760
return CertificateType::AUTHENTICATION;

tests/mock/test-pkcs11-token.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ TEST(electronic_id_test, pkcs11TokenHasAuthenticationCert)
8787
{
8888
PKCS11CardManager::Token token;
8989
token.cert = base64Decode(AUTH_CERT);
90-
EXPECT_TRUE(certificateType(token.cert).isAuthentication());
90+
EXPECT_TRUE(certificateType(token.cert, true).isAuthentication());
91+
EXPECT_FALSE(certificateType(token.cert, true).isSigning());
9192
}
9293

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

0 commit comments

Comments
 (0)