PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / CloudFront / CookieSigner.php

CookieSigner.php in Media Cloud Sync 1.4.1, at includes/sdk/s3/Aws/CloudFront/CookieSigner.php

58 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\CloudFront;
4
5 class CookieSigner
6 {
7 /** @var Signer */
8 private $signer;
9 private static $schemes = ['http' => \true, 'https' => \true];
10 /**
11 * @param $keyPairId string ID of the key pair
12 * @param $privateKey string Path to the private key used for signing
13 *
14 * @throws \RuntimeException if the openssl extension is missing
15 * @throws \InvalidArgumentException if the private key cannot be found.
16 */
17 public function __construct($keyPairId, $privateKey)
18 {
19 $this->signer = new Signer($keyPairId, $privateKey);
20 }
21 /**
22 * Create a signed Amazon CloudFront Cookie.
23 *
24 * @param string $url URL to sign (can include query string
25 * and wildcards). Not required
26 * when passing a custom $policy.
27 * @param string|integer|null $expires UTC Unix timestamp used when signing
28 * with a canned policy. Not required
29 * when passing a custom $policy.
30 * @param string $policy JSON policy. Use this option when
31 * creating a signed cookie for a custom
32 * policy.
33 *
34 * @return array The authenticated cookie parameters
35 * @throws \InvalidArgumentException if the URL provided is invalid
36 * @link http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-cookies.html
37 */
38 public function getSignedCookie($url = null, $expires = null, $policy = null)
39 {
40 if ($url) {
41 $this->validateUrl($url);
42 }
43 $cookieParameters = [];
44 $signature = $this->signer->getSignature($url, $expires, $policy);
45 foreach ($signature as $key => $value) {
46 $cookieParameters["CloudFront-{$key}"] = $value;
47 }
48 return $cookieParameters;
49 }
50 private function validateUrl($url)
51 {
52 $scheme = \str_replace('*', '', \explode('://', $url)[0]);
53 if (empty(self::$schemes[\strtolower($scheme)])) {
54 throw new \InvalidArgumentException('Invalid or missing URI scheme');
55 }
56 }
57 }
58