1414use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel \Claims \TypeClaimValue ;
1515use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel \Claims \VcAtContextClaimValue ;
1616use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel \Claims \VcCredentialSchemaClaimBag ;
17- use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel \Claims \VcCredentialStatusClaimValue ;
17+ use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel \Claims \VcCredentialStatusClaimBag ;
1818use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel \Claims \VcCredentialSubjectClaimBag ;
1919use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel \Claims \VcEvidenceClaimBag ;
2020use SimpleSAML \OpenID \VerifiableCredentials \VcDataModel \Claims \VcIssuerClaimValue ;
@@ -41,7 +41,7 @@ class VcSdJwt extends SdJwt implements VerifiableCredentialInterface
4141
4242 protected null |false |VcProofClaimValue $ vcProofClaimValue = null ;
4343
44- protected null |false |VcCredentialStatusClaimValue $ vcCredentialStatusClaimValue = null ;
44+ protected null |false |VcCredentialStatusClaimBag $ vcCredentialStatusClaimBag = null ;
4545
4646 protected null |false |VcCredentialSchemaClaimBag $ vcCredentialSchemaClaimBag = null ;
4747
@@ -74,6 +74,10 @@ protected function validate(): void
7474 if (array_key_exists ('vp ' , $ payload )) {
7575 throw new VcDataModelException ('SD-JWT VC MUST NOT contain a "vp" claim. ' );
7676 }
77+
78+ // Validate validFrom and validUntil claims
79+ $ this ->getValidFrom ();
80+ $ this ->getValidUntil ();
7781 }
7882
7983
@@ -244,15 +248,23 @@ public function getValidFrom(): DateTimeImmutable
244248
245249 try {
246250 $ validFromStr = $ this ->helpers ->type ()->ensureNonEmptyString ($ validFrom , ClaimsEnum::ValidFrom->value );
247- return $ this -> validFrom = $ this ->helpers ->dateTime ()->fromXsDateTime ($ validFromStr );
251+ $ validFrom = $ this ->helpers ->dateTime ()->fromXsDateTime ($ validFromStr );
248252 } catch (Exception $ exception ) {
249253 throw new VcDataModelException ('Invalid Valid From claim. ' , (int ) $ exception ->getCode (), $ exception );
250254 }
255+
256+ if ($ validFrom ->getTimestamp () - $ this ->timestampValidationLeeway ->getInSeconds () > time ()) {
257+ throw new VcDataModelException ('Credential is not valid yet. ' );
258+ }
259+
260+ return $ this ->validFrom = $ validFrom ;
251261 }
252262
253263
254264 /**
255- * Alias for getValidFrom to remain fully backwards compatible with consumers expecting getVcIssuanceDate
265+ * Alias for getValidFrom to remain fully backwards compatible with
266+ * consumers expecting `getVcIssuanceDate`.
267+ *
256268 * @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
257269 * @throws \SimpleSAML\OpenID\Exceptions\JwsException
258270 * @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
@@ -300,10 +312,16 @@ public function getValidUntil(): ?DateTimeImmutable
300312
301313 try {
302314 $ validUntilStr = $ this ->helpers ->type ()->ensureNonEmptyString ($ validUntil , ClaimsEnum::ValidUntil->value );
303- return $ this -> validUntil = $ this ->helpers ->dateTime ()->fromXsDateTime ($ validUntilStr );
315+ $ validUntil = $ this ->helpers ->dateTime ()->fromXsDateTime ($ validUntilStr );
304316 } catch (Exception $ exception ) {
305317 throw new VcDataModelException ('Invalid Valid Until claim. ' , (int ) $ exception ->getCode (), $ exception );
306318 }
319+
320+ if ($ validUntil ->getTimestamp () + $ this ->timestampValidationLeeway ->getInSeconds () < time ()) {
321+ throw new VcDataModelException ('Credential is expired. ' );
322+ }
323+
324+ return $ this ->validUntil = $ validUntil ;
307325 }
308326
309327
@@ -349,30 +367,32 @@ public function getVcProof(): ?VcProofClaimValue
349367
350368 /**
351369 * @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
370+ * @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
371+ * @throws \SimpleSAML\OpenID\Exceptions\JwsException
352372 */
353- public function getVcCredentialStatus (): ?VcCredentialStatusClaimValue
373+ public function getVcCredentialStatus (): ?VcCredentialStatusClaimBag
354374 {
355- if ($ this ->vcCredentialStatusClaimValue === false ) {
375+ if ($ this ->vcCredentialStatusClaimBag === false ) {
356376 return null ;
357377 }
358378
359- if ($ this ->vcCredentialStatusClaimValue instanceof VcCredentialStatusClaimValue ) {
360- return $ this ->vcCredentialStatusClaimValue ;
379+ if ($ this ->vcCredentialStatusClaimBag instanceof VcCredentialStatusClaimBag ) {
380+ return $ this ->vcCredentialStatusClaimBag ;
361381 }
362382
363383 $ vcCredentialStatus = $ this ->getPayloadClaim (ClaimsEnum::Credential_Status->value );
364384
365385 if (is_null ($ vcCredentialStatus )) {
366- $ this ->vcCredentialStatusClaimValue = false ;
386+ $ this ->vcCredentialStatusClaimBag = false ;
367387 return null ;
368388 }
369389
370390 if (!is_array ($ vcCredentialStatus )) {
371391 throw new VcDataModelException ('Invalid Credential Status claim. ' );
372392 }
373393
374- return $ this ->vcCredentialStatusClaimValue = $ this ->claimFactory ->forVcDataModel2 ()
375- ->buildVcCredentialStatusClaimValue ($ vcCredentialStatus );
394+ return $ this ->vcCredentialStatusClaimBag = $ this ->claimFactory ->forVcDataModel2 ()
395+ ->buildVcCredentialStatusClaimBag ($ vcCredentialStatus );
376396 }
377397
378398
0 commit comments