Skip to content

Commit

Permalink
Receipt verification fix: if no receiptCreationDate found in the rece…
Browse files Browse the repository at this point in the history
…ipt, requestDate will be used instead
  • Loading branch information
pkotets committed Aug 23, 2023
1 parent 1718623 commit 60cdd38
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"php"
],
"homepage": "https://github.com/readdle/app-store-receipt-verification",
"version": "1.0.0",
"version": "1.1.0",
"autoload": {
"psr-4": {
"Readdle\\AppStoreReceiptVerification\\": "src/"
Expand Down
26 changes: 21 additions & 5 deletions src/ReceiptContainerVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,26 @@ public function verify(string $trustedAppleRootCertificate): bool

private function verifyCertificatesChain(): bool
{
$signedAt = $this->receiptContainer
->getReceipt()
->getFieldByType(AppReceiptField::TYPE__RECEIPT_CREATION_DATE)
->getValue()
;

if (empty($signedAt)) {
$signedAt = $this->receiptContainer
->getReceipt()
->getFieldByType(AppReceiptField::TYPE__REQUEST_DATE)
->getValue()
;
}

if (empty($signedAt)) {
return false;
}

try {
$receiptCreationDateTime = new DateTimeImmutable($this->receiptContainer->getReceipt()->getFieldByType(
AppReceiptField::TYPE__RECEIPT_CREATION_DATE
)->getValue());
$signDateTime = new DateTimeImmutable($signedAt);
} catch (Exception $e) {
return false;
}
Expand All @@ -52,8 +68,8 @@ private function verifyCertificatesChain(): bool
$validity = $signedCertificate->getCertificate()->getValidity();

if (
$receiptCreationDateTime < $validity->getNotBefore()
|| $receiptCreationDateTime > $validity->getNotAfter()
$signDateTime < $validity->getNotBefore()
|| $signDateTime > $validity->getNotAfter()
) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/AppStoreReceiptVerificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function test(): void
);
} catch (Exception $e) {
ob_end_clean();
continue;
$this->fail("[$filename]: {$e->getMessage()}");
}

file_put_contents($pathToSamples . DIRECTORY_SEPARATOR . "receipt{$m[1]}.json", ob_get_clean());
Expand Down

0 comments on commit 60cdd38

Please sign in to comment.