Skip to content

Commit 6738f03

Browse files
committed
Allow id-card authentication when Extended Key Usage is not present in certificate
WE2-1026 Signed-off-by: Sven Mitt <[email protected]>
1 parent 935f697 commit 6738f03

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/java/eu/webeid/security/validator/certvalidators/SubjectCertificatePurposeValidator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
public final class SubjectCertificatePurposeValidator {
3737

3838
private static final Logger LOG = LoggerFactory.getLogger(SubjectCertificatePurposeValidator.class);
39+
private static final int KEY_USAGE_DIGITAL_SIGNATURE = 0;
3940
private static final String EXTENDED_KEY_USAGE_CLIENT_AUTHENTICATION = "1.3.6.1.5.5.7.3.2";
40-
4141
/**
4242
* Validates that the purpose of the user certificate from the authentication token contains client authentication.
4343
*
@@ -46,9 +46,18 @@ public final class SubjectCertificatePurposeValidator {
4646
*/
4747
public static void validateCertificatePurpose(X509Certificate subjectCertificate) throws AuthTokenException {
4848
try {
49+
final boolean[] keyUsage = subjectCertificate.getKeyUsage();
50+
if (keyUsage == null) {
51+
throw new UserCertificateMissingPurposeException();
52+
}
53+
if (!keyUsage[KEY_USAGE_DIGITAL_SIGNATURE]) {
54+
throw new UserCertificateWrongPurposeException();
55+
}
4956
final List<String> usages = subjectCertificate.getExtendedKeyUsage();
5057
if (usages == null || usages.isEmpty()) {
51-
throw new UserCertificateMissingPurposeException();
58+
// Digital Signature extension present, but Extended Key Usage extension not present,
59+
// assume it is an authentication certificate (e.g. Luxembourg eID).
60+
return;
5261
}
5362
if (!usages.contains(EXTENDED_KEY_USAGE_CLIENT_AUTHENTICATION)) {
5463
throw new UserCertificateWrongPurposeException();

0 commit comments

Comments
 (0)