4444use web_eid \web_eid_authtoken_validation_php \validator \ocsp \OcspClientImpl ;
4545use web_eid \web_eid_authtoken_validation_php \validator \ocsp \OcspServiceProvider ;
4646use web_eid \web_eid_authtoken_validation_php \validator \ocsp \service \AiaOcspServiceConfiguration ;
47+ use web_eid \web_eid_authtoken_validation_php \util \TrustedCertificates ;
4748
4849final class AuthTokenValidatorImpl implements AuthTokenValidator
4950{
@@ -54,11 +55,15 @@ final class AuthTokenValidatorImpl implements AuthTokenValidator
5455 private AuthTokenValidationConfiguration $ configuration ;
5556 private SubjectCertificateValidatorBatch $ simpleSubjectCertificateValidators ;
5657 private AuthTokenSignatureValidator $ authTokenSignatureValidator ;
58+ private TrustedCertificates $ trustedCACertificates ;
5759 private Log $ logger ;
5860
5961 private OcspClient $ ocspClient ;
6062 private OcspServiceProvider $ ocspServiceProvider ;
6163
64+ /**
65+ * @copyright 2022 Petr Muzikant [email protected] 66+ */
6267 public function __construct (AuthTokenValidationConfiguration $ configuration )
6368 {
6469 $ this ->logger = Log::getLogger (self ::class);
@@ -67,9 +72,10 @@ public function __construct(AuthTokenValidationConfiguration $configuration)
6772 $ this ->configuration = clone $ configuration ;
6873
6974 // Create and cache trusted CA certificate JCA objects for SubjectCertificateTrustedValidator and AiaOcspService.
70- $ this ->trustedCertificates = CertificateValidator::buildTrustFromCertificates ($ configuration ->getTrustedCACertificates ());
75+ $ this ->trustedCACertificates = CertificateValidator::buildTrustFromCertificates ($ configuration ->getTrustedCACertificates ());
76+
7177 $ this ->simpleSubjectCertificateValidators = new SubjectCertificateValidatorBatch (
72- new SubjectCertificateExpiryValidator ($ this ->trustedCertificates ),
78+ new SubjectCertificateExpiryValidator ($ this ->trustedCACertificates ),
7379 new SubjectCertificatePurposeValidator (),
7480 new SubjectCertificatePolicyValidator ($ configuration ->getDisallowedSubjectCertificatePolicies ())
7581 );
@@ -80,7 +86,7 @@ public function __construct(AuthTokenValidationConfiguration $configuration)
8086 $ configuration ->getDesignatedOcspServiceConfiguration (),
8187 new AiaOcspServiceConfiguration (
8288 $ configuration ->getNonceDisabledOcspUrls (),
83- $ this ->trustedCertificates
89+ $ this ->trustedCACertificates
8490 )
8591 );
8692 }
@@ -91,10 +97,10 @@ public function __construct(AuthTokenValidationConfiguration $configuration)
9197 private function validateTokenLength (string $ authToken ): void
9298 {
9399 if (is_null ($ authToken ) || strlen ($ authToken ) < self ::TOKEN_MIN_LENGTH ) {
94- throw new AuthTokenParseException (' Auth token is null or too short ' );
100+ throw new AuthTokenParseException (" Auth token is null or too short " );
95101 }
96102 if (strlen ($ authToken ) > self ::TOKEN_MAX_LENGTH ) {
97- throw new AuthTokenParseException (' Auth token is too long ' );
103+ throw new AuthTokenParseException (" Auth token is too long " );
98104 }
99105 }
100106
@@ -136,16 +142,16 @@ public function validate(WebEidAuthToken $authToken, string $currentChallengeNon
136142 }
137143 }
138144
139- private function validateToken (WebEidAuthToken $ authToken , string $ currentChallengeNonce ): X509
145+ private function validateToken (WebEidAuthToken $ token , string $ currentChallengeNonce ): X509
140146 {
141- if (is_null ($ authToken ->getFormat ()) || substr ($ authToken ->getFormat (), 0 , strlen (self ::CURRENT_TOKEN_FORMAT_VERSION )) != self ::CURRENT_TOKEN_FORMAT_VERSION ) {
147+ if (is_null ($ token ->getFormat ()) || substr ($ token ->getFormat (), 0 , strlen (self ::CURRENT_TOKEN_FORMAT_VERSION )) != self ::CURRENT_TOKEN_FORMAT_VERSION ) {
142148 throw new AuthTokenParseException ("Only token format version ' " . self ::CURRENT_TOKEN_FORMAT_VERSION . "' is currently supported " );
143149 }
144- if (is_null ($ authToken ->getUnverifiedCertificate ()) || empty ($ authToken ->getUnverifiedCertificate ())) {
150+ if (is_null ($ token ->getUnverifiedCertificate ()) || empty ($ token ->getUnverifiedCertificate ())) {
145151 throw new AuthTokenParseException ("'unverifiedCertificate' field is missing, null or empty " );
146152 }
147153 $ subjectCertificate = new X509 ();
148- if (!$ subjectCertificate ->loadX509 ($ authToken ->getUnverifiedCertificate ())) {
154+ if (!$ subjectCertificate ->loadX509 ($ token ->getUnverifiedCertificate ())) {
149155 throw new CertificateDecodingException ("'unverifiedCertificate' decode failed " );
150156 }
151157
@@ -156,8 +162,8 @@ private function validateToken(WebEidAuthToken $authToken, string $currentChalle
156162 // have been implicitly and correctly verified without the need to implement any additional checks.
157163
158164 $ this ->authTokenSignatureValidator ->validate (
159- $ authToken ->getAlgorithm (),
160- $ authToken ->getSignature (),
165+ $ token ->getAlgorithm (),
166+ $ token ->getSignature (),
161167 $ subjectCertificate ->getPublicKey (),
162168 $ currentChallengeNonce
163169 );
@@ -168,7 +174,7 @@ private function validateToken(WebEidAuthToken $authToken, string $currentChalle
168174 private function getCertTrustValidators (): SubjectCertificateValidatorBatch
169175 {
170176
171- $ certTrustedValidator = new SubjectCertificateTrustedValidator ($ this ->trustedCertificates );
177+ $ certTrustedValidator = new SubjectCertificateTrustedValidator ($ this ->trustedCACertificates );
172178
173179 $ validatorBatch = new SubjectCertificateValidatorBatch (
174180 $ certTrustedValidator
0 commit comments