public function signRequest(RequestInterface $request, CredentialsInterface $credentials) { $ldt = gmdate(self::ISO8601_BASIC); $sdt = substr($ldt, 0, 8); $parsed = $this->parseRequest($request); $parsed['headers']['X-Amz-Date'] = [$ldt]; if ($token = $credentials->getSecurityToken()) { $parsed['headers']['X-Amz-Security-Token'] = [$token]; } $cs = $this->createScope($sdt, $this->region, $this->service); $payload = $this->getPayload($request); $context = $this->createContext($parsed, $payload); $toSign = $this->createStringToSign($ldt, $cs, $context['creq']); $signingKey = $this->getSigningKey($sdt, $this->region, $this->service, $credentials->getSecretKey()); $signature = hash_hmac('sha256', $toSign, $signingKey); $parsed['headers']['Authorization'] = ["AWS4-HMAC-SHA256 " . "Credential={$credentials->getAccessKeyId()}/{$cs}, " . "SignedHeaders={$context['headers']}, Signature={$signature}"]; return $this->buildRequest($parsed); }
protected function getPolicyAndSignature(CredentialsInterface $credentials, array $policy) { $ldt = gmdate(SignatureV4::ISO8601_BASIC); $sdt = substr($ldt, 0, 8); $policy['conditions'][] = ['X-Amz-Date' => $ldt]; $region = $this->client->getRegion(); $scope = $this->createScope($sdt, $region, 's3'); $creds = "{$credentials->getAccessKeyId()}/{$scope}"; $policy['conditions'][] = ['X-Amz-Credential' => $creds]; $policy['conditions'][] = ['X-Amz-Algorithm' => "AWS4-HMAC-SHA256"]; $jsonPolicy64 = base64_encode(json_encode($policy)); $key = $this->getSigningKey($sdt, $region, 's3', $credentials->getSecretKey()); return ['X-Amz-Credential' => $creds, 'X-Amz-Algorithm' => "AWS4-HMAC-SHA256", 'X-Amz-Date' => $ldt, 'Policy' => $jsonPolicy64, 'X-Amz-Signature' => bin2hex(hash_hmac('sha256', $jsonPolicy64, $key, true))]; }
protected function getPolicyAndSignature(CredentialsInterface $creds) { $jsonPolicy64 = base64_encode($this->jsonPolicy); return ['AWSAccessKeyId' => $creds->getAccessKeyId(), 'policy' => $jsonPolicy64, 'signature' => base64_encode(hash_hmac('sha1', $jsonPolicy64, $creds->getSecretKey(), true))]; }