mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-14 02:27:23 -07:00
v2: Updates
* Simplifies & beautifies everything * Introduces a new Class system. * Errors are defaulted to AWS's handler. * New function names & more efficient handling. * Should fix a majority of the errors. Please read the README for more!
This commit is contained in:
parent
ad0726e41e
commit
e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions
|
@ -7,7 +7,7 @@ namespace Aws\CloudFront;
|
|||
class Signer
|
||||
{
|
||||
private $keyPairId;
|
||||
private $pk;
|
||||
private $pkHandle;
|
||||
|
||||
/**
|
||||
* A signer for creating the signature values used in CloudFront signed URLs
|
||||
|
@ -15,11 +15,12 @@ class Signer
|
|||
*
|
||||
* @param $keyPairId string ID of the key pair
|
||||
* @param $privateKey string Path to the private key used for signing
|
||||
* @param $passphrase string Passphrase to private key file, if one exists
|
||||
*
|
||||
* @throws \RuntimeException if the openssl extension is missing
|
||||
* @throws \InvalidArgumentException if the private key cannot be found.
|
||||
*/
|
||||
public function __construct($keyPairId, $privateKey)
|
||||
public function __construct($keyPairId, $privateKey, $passphrase = "")
|
||||
{
|
||||
if (!extension_loaded('openssl')) {
|
||||
//@codeCoverageIgnoreStart
|
||||
|
@ -30,13 +31,22 @@ class Signer
|
|||
|
||||
$this->keyPairId = $keyPairId;
|
||||
|
||||
if (!file_exists($privateKey)) {
|
||||
throw new \InvalidArgumentException("PK file not found: $privateKey");
|
||||
if (!$this->pkHandle = openssl_pkey_get_private($privateKey, $passphrase)) {
|
||||
if (!file_exists($privateKey)) {
|
||||
throw new \InvalidArgumentException("PK file not found: $privateKey");
|
||||
} else {
|
||||
$this->pkHandle = openssl_pkey_get_private("file://$privateKey", $passphrase);
|
||||
if (!$this->pkHandle) {
|
||||
throw new \InvalidArgumentException(openssl_error_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->pk = file_get_contents($privateKey);
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->pkHandle && openssl_pkey_free($this->pkHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the values used to construct signed URLs and cookies.
|
||||
|
@ -66,6 +76,7 @@ class Signer
|
|||
$policy = preg_replace('/\s/s', '', $policy);
|
||||
$signatureHash['Policy'] = $this->encode($policy);
|
||||
} elseif ($resource && $expires) {
|
||||
$expires = (int) $expires; // Handle epoch passed as string
|
||||
$policy = $this->createCannedPolicy($resource, $expires);
|
||||
$signatureHash['Expires'] = $expires;
|
||||
} else {
|
||||
|
@ -96,7 +107,7 @@ class Signer
|
|||
private function sign($policy)
|
||||
{
|
||||
$signature = '';
|
||||
openssl_sign($policy, $signature, $this->pk);
|
||||
openssl_sign($policy, $signature, $this->pkHandle);
|
||||
|
||||
return $signature;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue