Skip to content

Commit

Permalink
Strict equality, less information for invalid signature
Browse files Browse the repository at this point in the history
  • Loading branch information
boogie committed Jun 19, 2015
1 parent 3c36a5c commit aadc7a0
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/Escher.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function getSignature($secretKey, DateTime $date, $method, $url, $request
private function parseUrl($url)
{
$urlParts = parse_url($url);
$defaultPort = $urlParts['scheme'] == 'http' ? 80 : 443;
$defaultPort = $urlParts['scheme'] === 'http' ? 80 : 443;
$host = $urlParts['host'] . (isset($urlParts['port']) && $urlParts['port'] != $defaultPort ? ':' . $urlParts['port'] : '');
$path = $urlParts['path'];
$query = isset($urlParts['query']) ? $urlParts['query'] : '';
Expand Down Expand Up @@ -347,7 +347,7 @@ public function getAuthElements($vendorKey, $algoPrefix)
$queryParams = $this->getQueryParams();
if (isset($headerList[strtolower($this->authHeaderKey)])) {
return EscherAuthElements::parseFromHeaders($headerList, $this->authHeaderKey, $this->dateHeaderKey, $algoPrefix);
} else if($this->getRequestMethod() == 'GET' && isset($queryParams[$this->paramKey($vendorKey, 'Signature')])) {
} else if($this->getRequestMethod() === 'GET' && isset($queryParams[$this->paramKey($vendorKey, 'Signature')])) {
return EscherAuthElements::parseFromQuery($headerList, $queryParams, $vendorKey, $algoPrefix);
}
throw new EscherException('Request has not been signed.');
Expand Down Expand Up @@ -379,7 +379,7 @@ public function getHeaderList()

public function getCurrentUrl()
{
$scheme = $this->serverVars["HTTPS"] == "on" ? 'https' : 'http';
$scheme = $this->serverVars["HTTPS"] === "on" ? 'https' : 'http';
$host = $this->getServerHost();
$res = "$scheme://$host" . $this->serverVars["REQUEST_URI"];
return $res;
Expand All @@ -389,7 +389,7 @@ private function process(array $serverVars)
{
$headerList = array();
foreach ($serverVars as $key => $value) {
if (substr($key, 0, 5) == 'HTTP_') {
if (substr($key, 0, 5) === 'HTTP_') {
$headerList[strtolower(str_replace('_', '-', substr($key, 5)))] = $value;
}
}
Expand Down Expand Up @@ -434,7 +434,7 @@ private function normalizeHost($host, $port)

private function isDefaultPort($port)
{
$defaultPort = $this->serverVars["HTTPS"] == "on" ? '443' : '80';
$defaultPort = $this->serverVars["HTTPS"] === "on" ? '443' : '80';
return $port == $defaultPort;
}
}
Expand Down Expand Up @@ -510,7 +510,7 @@ public static function parseFromHeaders(array $headerList, $authHeaderKey, $date
public static function parseAuthHeader($headerContent, $algoPrefix)
{
$parts = explode(' ', $headerContent);
if (count($parts) != 4) {
if (count($parts) !== 4) {
throw new EscherException('Could not parse authorization header: ' . $headerContent);
}
return array(
Expand Down Expand Up @@ -593,7 +593,7 @@ private static function checkHost($headerList)
public function validateDates(EscherRequestHelper $helper, $clockSkew)
{
$shortDate = $this->dateTime->format('Ymd');
if ($shortDate != $this->getShortDate()) {
if ($shortDate !== $this->getShortDate()) {
throw new EscherException('The request date and credential date do not match.');
}

Expand All @@ -618,7 +618,7 @@ public function validateCredentials($credentialScope)

private function checkCredentials($credentialScope)
{
return $this->credentialScope == $credentialScope;
return $this->credentialScope === $credentialScope;
}

public function validateSignature(EscherRequestHelper $helper, Escher $escher, $keyDB, $vendorKey)
Expand All @@ -637,8 +637,8 @@ public function validateSignature(EscherRequestHelper $helper, Escher $escher, $
);

$provided = $this->getSignature();
if ($calculated != $provided) {
throw new EscherException("The signatures do not match (provided: $provided, calculated: $calculated)");
if ($calculated !== $provided) {
throw new EscherException("The signatures do not match (provided: $provided)");
}
}

Expand Down Expand Up @@ -715,7 +715,7 @@ private function stripAuthParams(EscherRequestHelper $helper, $vendorKey)

$query = array();
foreach ($params as $key => $value) {
if ($key != 'X-' . $vendorKey . '-Signature') {
if ($key !== 'X-' . $vendorKey . '-Signature') {
$query[$key] = $value;
}
}
Expand Down Expand Up @@ -843,7 +843,7 @@ private static function canonicalizeHeaders($rawHeaders, array $headersToSign)
private static function rawUrlEncode($urlComponent)
{
$result = rawurlencode($urlComponent);
if (version_compare(PHP_VERSION, '5.3.4') == -1) {
if (version_compare(PHP_VERSION, '5.3.4') === -1) {
$result = str_replace('%7E', '~', $result);
}
return $result;
Expand All @@ -857,7 +857,7 @@ private static function nomalizeHeaderValue($value)
{
$result = array();
foreach (explode('"', trim($value)) as $index => $piece) {
$result[] = $index % 2 == 1 ? $piece : preg_replace('/\s+/', ' ', $piece);
$result[] = $index % 2 === 1 ? $piece : preg_replace('/\s+/', ' ', $piece);
}
return implode('"', $result);
}
Expand Down Expand Up @@ -922,7 +922,7 @@ public static function parseLongDate($dateString)

public static function keysToLower($array)
{
if (count($array) == 0)
if (count($array) === 0)
{
return array();
}
Expand All @@ -947,4 +947,4 @@ protected static function advancedDateTimeFunctionsAvailable()
{
return version_compare(PHP_VERSION, '5.3.0') !== -1;
}
}
}

0 comments on commit aadc7a0

Please sign in to comment.