Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed signature newline handling (Windows) #9

Merged
merged 1 commit into from
Aug 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/Http/Handler/RequestHandlerSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class RequestHandlerSignature extends RequestHandlerBase
const HEADER_PREFIX_START = 0;
const HEADER_SERVER_SIGNATURE = 'X-Bunq-Server-Signature';
const HEADER_CACHE_CONTROL = 'Cache-Control';
const HEADER_NEWLINE = "\n";

/**
* Signature message constants.
Expand Down Expand Up @@ -82,7 +83,7 @@ protected function determineRequestSignature(
$dataToSign =
$method . self::REQUEST_METHOD_PATH_SEPARATOR . $uri->getPath() .
$this->determineHeaderStringForSignedRequest($headers) .
PHP_EOL . PHP_EOL .
self::HEADER_NEWLINE . self::HEADER_NEWLINE .
$body;

return $this->privateKey->sign($dataToSign);
Expand All @@ -102,15 +103,15 @@ public function determineHeaderStringForSignedRequest(array $headers)
// Not all headers should be signed.
// The User-Agent and Cache-Control headers need to be signed.
if ($headerName === self::HEADER_USER_AGENT || $headerName === self::HEADER_CACHE_CONTROL) {
$signedDataHeaderString .= PHP_EOL;
$signedDataHeaderString .= self::HEADER_NEWLINE;
$signedDataHeaderString .= $this->determineHeaderStringLine($headerName, $headerValue);
}

// All headers with the prefix 'X-Bunq-' except 'Server-Signature' need to be signed.
if ($headerName === self::HEADER_SERVER_SIGNATURE) {
// Skip this header
} elseif (strpos($headerName, self::HEADER_PREFIX) === self::HEADER_PREFIX_START) {
$signedDataHeaderString .= PHP_EOL;
$signedDataHeaderString .= self::HEADER_NEWLINE;
$signedDataHeaderString .= $this->determineHeaderStringLine($headerName, $headerValue);
}
}
Expand Down
7 changes: 4 additions & 3 deletions lib/Http/Handler/ResponseHandlerSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ResponseHandlerSignature extends ResponseHandlerBase
const HEADER_PREFIX_START = 0;
const HEADER_SEPARATOR = ', ';
const FORMAT_HEADER = '%s: %s';
const HEADER_NEWLINE = "\n";

/**
* Http status constants.
Expand Down Expand Up @@ -64,9 +65,9 @@ public function execute(ResponseInterface $response)
} else {
$toVerify =
$response->getStatusCode() .
PHP_EOL .
self::HEADER_NEWLINE .
$this->determineHeaderStringForSignedResponse($response->getHeaders()) .
PHP_EOL . PHP_EOL .
self::HEADER_NEWLINE . self::HEADER_NEWLINE .
$response->getBody()->getContents();

$signature = base64_decode($response->getHeaderLine(self::HEADER_SERVER_SIGNATURE));
Expand Down Expand Up @@ -104,7 +105,7 @@ private function determineHeaderStringForSignedResponse(array $headers)
}
}

return implode(PHP_EOL, $signedDataHeaders);
return implode(self::HEADER_NEWLINE, $signedDataHeaders);
}

/**
Expand Down