|
@@ -36,18 +36,21 @@ class Secret extends Component
|
|
|
$this->_clientSignature = $clientSignature;
|
|
|
|
|
|
$cone = $this->findOne($client_id);
|
|
|
- if (!$cone)
|
|
|
- static::throwError("client id avail.");
|
|
|
+ if (!$cone){
|
|
|
+ static::throwError("client id avail.");
|
|
|
+ }
|
|
|
|
|
|
$sKey = isset($cone->client_key) ? $cone->client_key : '';
|
|
|
|
|
|
$headers = Yii::$app->request->getHeaders();
|
|
|
- if (!$headers)
|
|
|
- static::throwError("headers format avail.");
|
|
|
+ if (!$headers){
|
|
|
+ static::throwError("headers format avail.");
|
|
|
+ }
|
|
|
|
|
|
$strVerb = strtoupper($headers->get('verb'));
|
|
|
- if (!$strVerb || !in_array(($strVerb), ['POST', 'GET']))
|
|
|
- static::throwError("headers verb avail.");
|
|
|
+ if (!$strVerb || !in_array(($strVerb), ['POST', 'GET'])){
|
|
|
+ static::throwError("headers verb avail.");
|
|
|
+ }
|
|
|
|
|
|
$strMd5 = $headers->get('content-md5');
|
|
|
if (!$this->checkContentMd5($strVerb, $strMd5, Yii::$app->request->getBodyParams())){
|
|
@@ -66,20 +69,22 @@ class Secret extends Component
|
|
|
}
|
|
|
|
|
|
$strSM = $headers->get('signature-method');
|
|
|
- if (strtoupper($strSM) != strtoupper($this->_signatureMethod))
|
|
|
- static::throwError("headers signature method avail.");
|
|
|
+ if (strtoupper($strSM) != strtoupper($this->_signatureMethod)){
|
|
|
+ static::throwError("headers signature method avail.");
|
|
|
+ }
|
|
|
|
|
|
$strSV = $headers->get('signature-version');
|
|
|
- if ($strSV !== $this->_signatureVersion)
|
|
|
- static::throwError("headers signature version avail.");
|
|
|
+ if ($strSV !== $this->_signatureVersion){
|
|
|
+ static::throwError("headers signature version avail.");
|
|
|
+ }
|
|
|
|
|
|
$str = "{$strVerb}\n\n{$strMd5}\n{$strContentType}\n{$strDate}\n{$strSM}\n{$strSV}\n\n{$sKey}\n";
|
|
|
$base_sha1 = base64_encode(hash_hmac("sha1", $str, $sKey . '&', true));
|
|
|
|
|
|
$this->_serverSignature = md5($base_sha1);
|
|
|
- if ($this->_serverSignature != '' && $this->_serverSignature !== $this->_clientSignature)
|
|
|
+ if ($this->_serverSignature != '' && $this->_serverSignature !== $this->_clientSignature){
|
|
|
// static::throwError("Signature verification failed.");
|
|
|
-
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|