PluginProbe ʕ •ᴥ•ʔ
10Web Booster – Website speed optimization, Cache & Page Speed optimizer / trunk
10Web Booster – Website speed optimization, Cache & Page Speed optimizer vtrunk
2.33.0 2.30.5 2.30.7 2.30.9 2.31.10 2.31.8 2.32.11 2.32.21 2.32.3 2.32.4 2.32.7 2.6.31 2.6.40 2.6.42 2.6.7 2.7.37 2.7.44 2.7.47 2.8.18 2.8.19 2.8.32 2.8.34 2.8.35 2.9.23 2.9.24 2.9.25 2.9.27 v2.27.4 trunk 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.17 2.0.18 2.0.21 2.0.22 2.0.25 2.0.26 2.0.27 2.0.3 2.0.7 2.0.9 2.10.46 2.10.65 2.10.66 2.10.68 2.11.41 2.11.42 2.11.43 2.12.15 2.12.21 2.12.22 2.12.23 2.12.26 2.13.37 2.13.40 2.13.41 2.13.42 2.13.44 2.13.45 2.13.47 2.14.49 2.14.50 2.15.18 2.17.21 2.17.23 2.18.17 2.19.44 2.19.45 2.19.46 2.19.49 2.2.12 2.2.15 2.2.16 2.2.18 2.2.8 2.20.31 2.20.32 2.20.33 2.21.11 2.21.12 2.21.16 2.21.25 2.22.32 2.23.13 2.23.15 2.23.16 2.23.18 2.24.12 2.24.14 2.24.18 2.25.14 2.26.6 2.28.10 2.28.13 2.28.14 2.28.7 2.29.1 2.29.2 2.29.3 2.3.0 2.3.1 2.3.2 2.3.3 2.30.18
tenweb-speed-optimizer / vendor / 10web / authorization / src / Amazon.php
tenweb-speed-optimizer / vendor / 10web / authorization / src Last commit date
config 1 month ago Amazon.php 4 years ago Helper.php 1 month ago InstalledPlugin.php 3 years ago InstalledTheme.php 4 years ago Login.php 1 month ago Product.php 4 years ago ProductActions.php 4 years ago ProductState.php 1 year ago WpAjaxUpgraderSkin.php 4 years ago
Amazon.php
180 lines
1 <?php
2 namespace Tenweb_Authorization {
3
4 class Amazon
5 {
6
7 private $key;
8 private $secret;
9 private $token;
10 private $file;
11
12 private $service = 's3';
13 private $region = 'us-west-2';
14 private $bucket = TENWEB_S3_BUCKET;
15 private $payload = "";//UNSIGNED-PAYLOAD
16
17 private $signedHeaders = "";
18 private $canonicalHeaders = "";
19
20 private $authHeader = "";
21 private $headers = array();
22
23 private $scope;
24 private $longDate;
25 private $shortDate;
26 private $host;
27 private $method = 'GET';
28 private $queryString = '';
29 private $canonicalQueryString = '';
30
31 private $signature = "";
32
33 public function __construct($key, $secret, $token, $file, $bucket = TENWEB_S3_BUCKET, $region = 'us-west-2')
34 {
35 $this->key = $key;
36 $this->secret = $secret;
37 $this->token = $token;
38 $this->file = ltrim($file, '/');
39 $this->bucket = $bucket;
40 $this->region = $region;
41
42 $this->host = $this->bucket . '.' . $this->service . '.' . $this->region . '.amazonaws.com';
43
44 }
45
46 public function setMethod($method)
47 {
48 $this->method = $method;
49 }
50
51 public function setPayload($payload)
52 {
53 $this->payload = $payload;
54 }
55
56 public function setExtraHeaders($headers)
57 {
58 $this->headers = $headers;
59 }
60
61 public function setQueryString($query_string_array)
62 {
63 $this->queryString = '';
64 $this->canonicalQueryString = '';
65 ksort($query_string_array);
66 foreach ($query_string_array as $key => $value) {
67 $this->canonicalQueryString .= rawurlencode($key) . '=' . rawurlencode($value) . '&';
68 $this->queryString .= trim($key) . '=' . trim($value) . '&';
69 }
70 $this->queryString = rtrim($this->queryString, '&');
71 $this->canonicalQueryString = rtrim($this->canonicalQueryString, '&');
72 }
73
74 public function getRequestData()
75 {
76 $this->longDate = gmdate('Ymd\THis\Z');
77 $this->shortDate = substr($this->longDate, 0, 8);
78
79 $this->createScope();
80 $this->setHeaders();
81
82 $this->calculateSignature();
83
84 $this->setAuthorizationHeader();
85
86 $headers = $this->headers;
87 $headers['Authorization'] = $this->authHeader;
88
89 $url = 'https://' . $this->host . '/' . $this->file;
90 if ($this->queryString) {
91 $url .= '?' . $this->queryString;
92 }
93 $result = array(
94 'headers' => $headers,
95 'url' => $url
96 );
97
98 return $result;
99 }
100
101
102 private function setAuthorizationHeader()
103 {
104 $credentials = $this->key . '/' . $this->scope;
105 $this->authHeader = "AWS4-HMAC-SHA256 "
106 . "Credential=" . $credentials . ", "
107 . "SignedHeaders=" . $this->signedHeaders . ", "
108 . "Signature=" . $this->signature;
109 }
110
111 private function calculateSignature()
112 {
113 $toSign = $this->getStringToSign();
114
115 $dateKey = hash_hmac('sha256', $this->shortDate, "AWS4" . $this->secret, true);
116 $regionKey = hash_hmac('sha256', $this->region, $dateKey, true);
117 $serviceKey = hash_hmac('sha256', $this->service, $regionKey, true);
118 $signingKey = hash_hmac('sha256', 'aws4_request', $serviceKey, true);
119
120 $signature = hash_hmac('sha256', $toSign, $signingKey);
121 $this->signature = $signature;
122 }
123
124 private function getStringToSign()
125 {
126 $canonical = $this->getCanonicalRequest();
127
128 $strToSign = "AWS4-HMAC-SHA256" . "\n"
129 . $this->longDate . "\n"
130 . $this->scope . "\n"
131 . hash('sha256', $canonical);
132
133 return $strToSign;
134 }
135
136 private function getCanonicalRequest()
137 {
138 $canonicalURI = '/' . $this->file;
139 $canonicalQueryString = $this->canonicalQueryString;
140 $canonicalHeaders = $this->canonicalHeaders;
141 $signedHeaders = $this->signedHeaders;
142 $payload = hash('sha256', $this->payload);
143
144 $canonical = $this->method . "\n" . $canonicalURI . "\n" . $canonicalQueryString . "\n" . $canonicalHeaders . "\n" . $signedHeaders . "\n" . $payload;
145
146 return $canonical;
147 }
148
149 private function setHeaders()
150 {
151 $this->headers += array(
152 'host' => $this->host,
153 'x-amz-content-sha256' => hash('sha256', $this->payload),
154 'x-amz-date' => $this->longDate,
155 'x-amz-security-token' => $this->token,
156 //'x-amz-server-side-encryption' => 'AES256'
157 );
158
159 ksort($this->headers);
160
161 $this->canonicalHeaders = "";
162 $this->signedHeaders = "";
163
164 foreach ($this->headers as $header => $value) {
165 $this->canonicalHeaders .= strtolower($header) . ":" . trim($value) . "\n";
166 $this->signedHeaders .= strtolower($header) . ';';
167 }
168
169 $this->signedHeaders = rtrim($this->signedHeaders, ';');
170 }
171
172
173 private function createScope()
174 {
175 $this->scope = $this->shortDate . "/" . $this->region . "/" . $this->service . "/aws4_request";
176 }
177
178 }
179 }
180