Skip to content

Commit

Permalink
Add exception when signature generation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
DocLM committed Jan 10, 2024
1 parent 8a2710f commit 4c4ceaf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changes/nextrelease/cloudfront-signed-urls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "enhancement",
"category": "CloudFront",
"description": "Throw exception when an empty signature for signed url is generated."
}
]
11 changes: 10 additions & 1 deletion src/CloudFront/Signer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function __destruct()
* @return array The values needed to construct a signed URL or cookie
* @throws \InvalidArgumentException when not provided either a policy or a
* resource and a expires
* @throws \RuntimeException when generated signature is empty
*
* @link http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-cookies.html
*/
Expand Down Expand Up @@ -113,7 +114,15 @@ private function createCannedPolicy($resource, $expiration)
private function sign($policy)
{
$signature = '';
openssl_sign($policy, $signature, $this->pkHandle);

if(!openssl_sign($policy, $signature, $this->pkHandle)) {
$errorMessages = [];
while(($newMessage = openssl_error_string()) !== false) {
$errorMessages[] = $newMessage;
}

throw new \RuntimeException(implode("\n",$errorMessages));
}

return $signature;
}
Expand Down

0 comments on commit 4c4ceaf

Please sign in to comment.