-
Notifications
You must be signed in to change notification settings - Fork 11
Allow id-card authentication when Extended Key Usage is not present in certificate #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
svenzik
wants to merge
5
commits into
web-eid:main
Choose a base branch
from
svenzik:WE2-1028
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
39e5cef
Allow id-card authentication when Extended Key Usage is not present i…
svenzik 6fe12fb
Test should fail because key usage is missing
svenzik 5be662c
Fix documentation and formatting
svenzik c9ddc19
Add tests for certificates from Belgian and Finnish ID-cards
svenzik 99f3361
Force PSS padding to be sent to openssl_verify when algorithm is PSXXX
svenzik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,9 @@ | |
final class SubjectCertificatePurposeValidator implements SubjectCertificateValidator | ||
{ | ||
|
||
private const KEY_USAGE = 'id-ce-keyUsage'; | ||
private const KEY_USAGE_DIGITAL_SIGNATURE = 0; | ||
private const EXTENDED_KEY_USAGE = 'id-ce-extKeyUsage'; | ||
// oid 1.3.6.1.5.5.7.3.2 | ||
private const EXTENDED_KEY_USAGE_CLIENT_AUTHENTICATION = "id-kp-clientAuth"; | ||
private $logger; | ||
|
@@ -44,22 +47,33 @@ public function __construct(LoggerInterface $logger = null) | |
/** | ||
* Validates that the purpose of the user certificate from the authentication token contains client authentication. | ||
* | ||
* @copyright 2022 Petr Muzikant [email protected] | ||
* | ||
* @param subjectCertificate user certificate to be validated | ||
* @param X509 $subjectCertificate user certificate to be validated | ||
* @throws UserCertificateMissingPurposeException | ||
* @throws UserCertificateWrongPurposeException | ||
* @copyright 2022 Petr Muzikant [email protected] | ||
* | ||
*/ | ||
public function validate(X509 $subjectCertificate): void | ||
{ | ||
$usages = $subjectCertificate->getExtension('id-ce-extKeyUsage'); | ||
if (!$usages || empty($usages)) { | ||
$keyUsage = $subjectCertificate->getExtension(self::KEY_USAGE); | ||
if (!$keyUsage || empty($keyUsage)) { | ||
throw new UserCertificateMissingPurposeException(); | ||
} | ||
if (!$keyUsage[self::KEY_USAGE_DIGITAL_SIGNATURE]) { | ||
throw new UserCertificateWrongPurposeException(); | ||
} | ||
$usages = $subjectCertificate->getExtension(self::EXTENDED_KEY_USAGE); | ||
if (!$usages || empty($usages)) { | ||
// Digital Signature extension present, but Extended Key Usage extension not present, | ||
// assume it is an authentication certificate (e.g. Luxembourg eID). | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 76 has a debug log message, it is needed here as well before return for consistency. |
||
} | ||
// Extended usages must contain TLS Web Client Authentication | ||
if (!in_array(self::EXTENDED_KEY_USAGE_CLIENT_AUTHENTICATION, $usages)) { | ||
throw new UserCertificateWrongPurposeException(); | ||
} | ||
|
||
$this->logger?->debug("User certificate can be used for client authentication."); | ||
} | ||
|
||
} |
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDKTCCAq+gAwIBAgIIcND8I1qptLUwCgYIKo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AIwYJJN | ||
7bLWw8BVi/lkxRjKL/+zAJP6djGywXI1pVh4HKb0D+tipq5StO+QnM8cnPmg | ||
-----END CERTIFICATE----- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
tests/validator/AuthTokenCertificateBelgianIdCardTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) 2022-2025 Estonian Information System Authority | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
|
||
namespace web_eid\web_eid_authtoken_validation_php\validator; | ||
|
||
use DateTime; | ||
use UnexpectedValueException; | ||
use web_eid\web_eid_authtoken_validation_php\exceptions\AuthTokenParseException; | ||
use web_eid\web_eid_authtoken_validation_php\exceptions\CertificateDecodingException; | ||
use web_eid\web_eid_authtoken_validation_php\exceptions\CertificateExpiredException; | ||
use web_eid\web_eid_authtoken_validation_php\exceptions\CertificateNotTrustedException; | ||
use web_eid\web_eid_authtoken_validation_php\exceptions\CertificateNotYetValidException; | ||
use web_eid\web_eid_authtoken_validation_php\exceptions\UserCertificateDisallowedPolicyException; | ||
use web_eid\web_eid_authtoken_validation_php\exceptions\UserCertificateMissingPurposeException; | ||
use web_eid\web_eid_authtoken_validation_php\exceptions\UserCertificateOCSPCheckFailedException; | ||
use web_eid\web_eid_authtoken_validation_php\exceptions\UserCertificateWrongPurposeException; | ||
use web_eid\web_eid_authtoken_validation_php\testutil\AbstractTestWithValidator; | ||
use web_eid\web_eid_authtoken_validation_php\testutil\AuthTokenValidators; | ||
use web_eid\web_eid_authtoken_validation_php\testutil\Dates; | ||
|
||
class AuthTokenCertificateBelgianIdCardTest extends AbstractTestWithValidator | ||
{ | ||
|
||
private const BELGIAN_TEST_ID_CARD_AUTH_TOKEN_ECC = | ||
'{' . | ||
' "action": "web-eid:authenticate-success",' . | ||
' "algorithm": "ES384",' . | ||
' "appVersion": "https://web-eid.eu/web-eid-app/releases/2.7.0+965",' . | ||
' "format": "web-eid:1.0",' . | ||
' "signature": "VWCxJ+NrWpNsLJwLbJ1IXuJkkrRsxhfZ1uVmaoY3gBMPrvULaLAp+A1VYGJ2QWobL9FvhMyEQpVlO99ytovux3pX75gHkf3Z0sBjtNqr/QS0ac+qI2hEccFnU0H7deO7",' . | ||
' "unverifiedCertificate": "MIIDQDCCAsegAwIBAgIQEAAAAAAA8evx/gAAAAGKYTAKBggqhkjOPQQDAzAuMQswCQYDVQQGEwJCRTEfMB0GA1UEAwwWZUlEIFRFU1QgRUMgQ2l0aXplbiBDQTAeFw0yMDEwMjIyMjAwMDBaFw0zMDEwMjIyMjAwMDBaMHYxCzAJBgNVBAYTAkJFMScwJQYDVQQDDB5Ob3JhIFNwZWNpbWVuIChBdXRoZW50aWNhdGlvbikxETAPBgNVBAQMCFNwZWNpbWVuMRUwEwYDVQQqDAxOb3JhIEFuZ8OobGUxFDASBgNVBAUTCzAxMDUwMzk5ODY0MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEPybypdwlvczyuKQtJ87s/RmB+hRFaP4BdtR/Sc8jfQTmKUYVn0KDYZPBllh928yMPxU7F+Za3FtFrAPCnDH75IquYsn0oc5olVO7Uas5gn61Y2EA5askyCljNVLA0Gquo4IBYDCCAVwwHwYDVR0jBBgwFoAU3bN/45oZjlnJEVYCLfX6nW/ehEswDgYDVR0PAQH/BAQDAgeAMEkGA1UdIARCMEAwPgYHYDgMAQECAjAzMDEGCCsGAQUFBwIBFiVodHRwOi8vZWlkZGV2Y2FyZHMuemV0ZXNjYXJkcy5iZS9jZXJ0MBMGA1UdJQQMMAoGCCsGAQUFBwMCMEUGA1UdHwQ+MDwwOqA4oDaGNGh0dHA6Ly9laWRkZXZjYXJkcy56ZXRlc2NhcmRzLmJlL2NybC9jaXRpemVuY2FFQy5jcmwwgYEGCCsGAQUFBwEBBHUwczA+BggrBgEFBQcwAoYyaHR0cDovL2VpZGRldmNhcmRzLnpldGVzY2FyZHMuYmUvY2VydC9yb290Y2FFQy5jcnQwMQYIKwYBBQUHMAGGJWh0dHA6Ly9laWRkZXZjYXJkcy56ZXRlc2NhcmRzLmJlOjg4ODgwCgYIKoZIzj0EAwMDZwAwZAIwE7uLOjrhXbid+tRKe/5wgE/R3rFVsE6HkpHJg+9+mqlBToLrLWvckmiPRmUot85BAjBNyxy48pVF+azJEnt0Z/hipToVhgJLlMkPFwZiL2+4B3w2WtNeSphEl3gjClos+Wg="' . | ||
'}'; | ||
|
||
private const BELGIAN_TEST_ID_CARD_AUTH_TOKEN_RSA = | ||
'{' . | ||
' "action": "web-eid:authenticate-success",' . | ||
' "algorithm": "RS256",' . | ||
' "appVersion": "https://web-eid.eu/web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PQYPQ7elNFXzFCRnmgJfxt4aKSkGZ2sQFWrKeIRxzVizLFDnfW8TSV5S4tuwYSMwIDAQABo4IBYDCCAVwwHwYDVR0jBBgwFoAU3bN/45oZjlnJEVYCLfX6nW/ehEswDgYDVR0PAQH/BAQDAgeAMEkGA1UdIARCMEAwPgYHYDgMAQECAjAzMDEGCCsGAQUFBwIBFiVodHRwOi8vZWlkZGV2Y2FyZHMuemV0ZXNjYXJkcy5iZS9jZXJ0MBMGA1UdJQQMMAoGCCsGAQUFBwMCMEUGA1UdHwQ+MDwwOqA4oDaGNGh0dHA6Ly9laWRkZXZjYXJkcy56ZXRlc2NhcmRzLmJlL2NybC9jaXRpemVuY2FFQy5jcmwwgYEGCCsGAQUFBwEBBHUwczA+BggrBgEFBQcwAoYyaHR0cDovL2VpZGRldmNhcmRzLnpldGVzY2FyZHMuYmUvY2VydC9yb290Y2FFQy5jcnQwMQYIKwYBBQUHMAGGJWh0dHA6Ly9laWRkZXZjYXJkcy56ZXRlc2NhcmRzLmJlOjg4ODgwCgYIKoZIzj0EAwMDaAAwZQIwL3Mp3pSlxfjUQ6zlsAwLHBbs1//7vPiqx//IcyUZYuVXZ00KG8MelmaMNbmzDVxaAjEAnqHxkwV5sSDwQCUbb6Tofaypm+DO6C2LriHS5r+s84x2Eq+s+lAJ1L4WkcgsKxns"' . | ||
'}'; | ||
|
||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
// Ensure that the certificates do not expire. | ||
$this->mockDate("2024-12-24"); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
Dates::resetMockedCertificateValidatorDate(); | ||
} | ||
|
||
public function testWhenIdCardWithECCSignatureCertificateIsValidatedThenValidationSucceeds(): void | ||
{ | ||
$this->expectNotToPerformAssertions(); | ||
$validator = AuthTokenValidators::getAuthTokenValidatorForBelgianIdCard(); | ||
$token = $validator->parse(self::BELGIAN_TEST_ID_CARD_AUTH_TOKEN_ECC); | ||
|
||
$validator->validate($token, 'iMeEwP2cgUINY2XoO/lqEpOUn7z/ysHRqGXkGKC4VXE='); | ||
} | ||
|
||
public function testWhenIdCardWithRSASignatureCertificateIsValidatedThenValidationSucceeds(): void | ||
{ | ||
$this->expectNotToPerformAssertions(); | ||
$validator = AuthTokenValidators::getAuthTokenValidatorForBelgianIdCard(); | ||
$token = $validator->parse(self::BELGIAN_TEST_ID_CARD_AUTH_TOKEN_RSA); | ||
|
||
$validator->validate($token, 'YPVgYc7Qds0qmK/RilPLffnsIg7IIovM4BAWqGZWwiY='); | ||
} | ||
|
||
private function mockDate(string $date) | ||
{ | ||
Dates::setMockedCertificateValidatorDate(new DateTime($date)); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think exception message is needed here as the context is different than elsewhere.