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 Mar 13, 2023
1 parent 4889eff commit 202795e
Show file tree
Hide file tree
Showing 2 changed files with 16 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."
}
]
10 changes: 9 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,14 @@ 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 202795e

Please sign in to comment.