File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
src/main/java/eu/webeid/security/validator/certvalidators Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 3636public 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 ();
You can’t perform that action at this time.
0 commit comments