Skip to content

Commit

Permalink
Merge branch 'release/1.13.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvandegroes committed Feb 19, 2020
2 parents 9f4ce9a + 109a9e5 commit 7771fd0
Show file tree
Hide file tree
Showing 438 changed files with 6,250 additions and 6,587 deletions.
9 changes: 4 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Change Log

## [Unreleased](https://github.com/bunq/sdk_php/tree/HEAD)

[Full Changelog](https://github.com/bunq/sdk_php/compare/1.12.0...HEAD)
## [1.12.1](https://github.com/bunq/sdk_php/tree/1.12.1) (2019-09-16)
[Full Changelog](https://github.com/bunq/sdk_php/compare/1.12.0...1.12.1)

**Closed issues:**

Expand Down Expand Up @@ -156,7 +155,6 @@
**Merged pull requests:**

- Removed userContext.php \(bunq/sdk\_php\#114\) [\#116](https://github.com/bunq/sdk_php/pull/116) ([OGKevin](https://github.com/OGKevin))
- Add response id to request error. \(bunq/sdk\_php\#88\) [\#93](https://github.com/bunq/sdk_php/pull/93) ([OGKevin](https://github.com/OGKevin))
- Move to new sandbox bunq/sdk\_php\#149 [\#150](https://github.com/bunq/sdk_php/pull/150) ([OGKevin](https://github.com/OGKevin))

## [0.13.1](https://github.com/bunq/sdk_php/tree/0.13.1) (2018-03-21)
Expand Down Expand Up @@ -203,6 +201,7 @@
- Throw exception when private key generation fails. \(bunq/sdk\_php\#102\) [\#105](https://github.com/bunq/sdk_php/pull/105) ([OGKevin](https://github.com/OGKevin))
- Added missing field id for TokenQrRequestIdeal. \(bunq/sdk\_php\#97\) [\#100](https://github.com/bunq/sdk_php/pull/100) ([OGKevin](https://github.com/OGKevin))
- Regenerated code to add missing id field. \(bunq/sdk\_php\#81\) [\#95](https://github.com/bunq/sdk_php/pull/95) ([OGKevin](https://github.com/OGKevin))
- Add response id to request error. \(bunq/sdk\_php\#88\) [\#93](https://github.com/bunq/sdk_php/pull/93) ([OGKevin](https://github.com/OGKevin))
- Configure Zappr [\#92](https://github.com/bunq/sdk_php/pull/92) ([OGKevin](https://github.com/OGKevin))
- Add more info to templates. \(bunq/sdk\_php\#89\) [\#90](https://github.com/bunq/sdk_php/pull/90) ([OGKevin](https://github.com/OGKevin))
- Bunq update 7 [\#113](https://github.com/bunq/sdk_php/pull/113) ([OGKevin](https://github.com/OGKevin))
Expand Down Expand Up @@ -323,7 +322,6 @@
- \#33 bunq response [\#34](https://github.com/bunq/sdk_php/pull/34) ([dnl-blkv](https://github.com/dnl-blkv))
- \#5 Allow setting a proxy [\#27](https://github.com/bunq/sdk_php/pull/27) ([qurben](https://github.com/qurben))
- Introduction of Grumphp [\#24](https://github.com/bunq/sdk_php/pull/24) ([cafferata](https://github.com/cafferata))
- Restructure project [\#12](https://github.com/bunq/sdk_php/pull/12) ([LauLaman](https://github.com/LauLaman))

**Fixed bugs:**

Expand All @@ -342,6 +340,7 @@
- Changes the composer PHP requirement [\#19](https://github.com/bunq/sdk_php/pull/19) ([cafferata](https://github.com/cafferata))
- Removed the default PHPStorm constructor header\(s\) [\#18](https://github.com/bunq/sdk_php/pull/18) ([cafferata](https://github.com/cafferata))
- Add readme for tests. [\#16](https://github.com/bunq/sdk_php/pull/16) ([OGKevin](https://github.com/OGKevin))
- Restructure project [\#12](https://github.com/bunq/sdk_php/pull/12) ([LauLaman](https://github.com/LauLaman))
- Add PHP-CS and PHPStan dependencies and scripts to execute [\#3](https://github.com/bunq/sdk_php/pull/3) ([holtkamp](https://github.com/holtkamp))
- Add first series of unit-tests [\#1](https://github.com/bunq/sdk_php/pull/1) ([OGKevin](https://github.com/OGKevin))

Expand Down
20 changes: 1 addition & 19 deletions src/Http/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use bunq\Exception\BunqException;
use bunq\Http\Handler\HandlerUtil;
use bunq\Http\Handler\RequestHandlerAuthentication;
use bunq\Http\Handler\RequestHandlerEncryption;
use bunq\Http\Handler\RequestHandlerSignature;
use bunq\Http\Handler\ResponseHandlerError;
use bunq\Http\Handler\ResponseHandlerSignature;
Expand Down Expand Up @@ -87,7 +86,7 @@ class ApiClient
/**
* User agent constants.
*/
const HEADER_USER_AGENT_BUNQ_SDK_DEFAULT = 'bunq-sdk-php/1.12.1';
const HEADER_USER_AGENT_BUNQ_SDK_DEFAULT = 'bunq-sdk-php/1.13.0';

/**
* Binary request constants.
Expand Down Expand Up @@ -168,11 +167,6 @@ class ApiClient
*/
protected $isBinary;

/**
* @var bool
*/
protected $isEncrypted;

/**
* @param ApiContext $apiContext
*/
Expand All @@ -188,13 +182,6 @@ public function enableBinary()
$this->isBinary = true;
}

/**
*/
public function enableEncryption()
{
$this->isEncrypted = true;
}

/**
* @param string $uri
* @param string[] $params
Expand Down Expand Up @@ -308,11 +295,6 @@ private function determineMiddleware(): HandlerStack
$sessionToken = $this->apiContext->getSessionToken();
$handlerStack->push(HandlerUtil::applyRequestHandler(new RequestHandlerAuthentication($sessionToken)));

if ($this->isEncrypted) {
$publicKey = $this->apiContext->getInstallationContext()->getPublicKeyServer();
$handlerStack->push(HandlerUtil::applyRequestHandler(new RequestHandlerEncryption($publicKey)));
}

$privateKey = $this->apiContext->getInstallationContext()->getKeyPairClient()->getPrivateKey();
$handlerStack->push(HandlerUtil::applyRequestHandler(new RequestHandlerSignature($privateKey)));

Expand Down
93 changes: 0 additions & 93 deletions src/Http/Handler/RequestHandlerEncryption.php

This file was deleted.

100 changes: 3 additions & 97 deletions src/Http/Handler/RequestHandlerSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use bunq\Security\PrivateKey;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;

/**
*/
Expand All @@ -18,24 +17,6 @@ class RequestHandlerSignature extends RequestHandlerBase
* Header constants.
*/
const HEADER_CLIENT_SIGNATURE = 'X-Bunq-Client-Signature';
const HEADER_PREFIX = 'X-Bunq-';
const HEADER_PREFIX_START = 0;
const HEADER_SERVER_SIGNATURE = 'X-Bunq-Server-Signature';
const HEADER_CACHE_CONTROL = 'Cache-Control';

/**
* Signature message constants.
*/
const FORMAT_HEADER = '%s: %s';
const HEADER_SEPARATOR = ', ';
const HEADER_USER_AGENT = 'User-Agent';
const REQUEST_METHOD_PATH_SEPARATOR = ' ';
const SIGNED_DATA_EMPTY_STRING = '';

/**
* Delimiter between path and parameters.
*/
const DELIMITER_URL_QUERY = '?';

/**
* @var PrivateKey
Expand All @@ -60,94 +41,19 @@ public function execute(RequestInterface $request): RequestInterface
if ($request->getUri()->getPath() === self::ENDPOINT_INSTALLATION) {
return $request;
} else {
$signature = $this->determineRequestSignature(
$request->getUri(),
$request->getMethod(),
$request->getBody()->getContents(),
$request->getHeaders()
);
$signature = $this->generateRequestSignature($request->getBody()->getContents());

return $request->withHeader(self::HEADER_CLIENT_SIGNATURE, $signature);
}
}

/**
* @param UriInterface $uri
* @param string $method
* @param string $body
* @param string[] $headers
*
* @return string
*/
protected function determineRequestSignature(
UriInterface $uri,
string $method,
string $body,
array $headers
): string {
$dataToSign =
$method . self::REQUEST_METHOD_PATH_SEPARATOR . $this->getPathWithQuery($uri) .
$this->determineHeaderStringForSignedRequest($headers) .
self::NEWLINE . self::NEWLINE .
$body;

return $this->privateKey->sign($dataToSign);
}

/**
* @param UriInterface $uri
*
* @return string
*/
private function getPathWithQuery(UriInterface $uri): string
{
$uriString = $uri->getPath();

if (!empty($uri->getQuery())) {
$uriString .= self::DELIMITER_URL_QUERY . $uri->getQuery();
}

return $uriString;
}

/**
* @param string[][] $headers
*
* @return string
*/
public function determineHeaderStringForSignedRequest(array $headers): string
{
$signedDataHeaderString = self::SIGNED_DATA_EMPTY_STRING;
ksort($headers);

foreach ($headers as $headerName => $headerValue) {
// 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 .= self::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 .= self::NEWLINE;
$signedDataHeaderString .= $this->determineHeaderStringLine($headerName, $headerValue);
}
}

return $signedDataHeaderString;
}

/**
* @param string $headerName
* @param string[] $headerValue
*
* @return string
*/
private function determineHeaderStringLine(string $headerName, array $headerValue): string
protected function generateRequestSignature(string $body): string
{
return vsprintf(self::FORMAT_HEADER, [$headerName, implode(self::HEADER_SEPARATOR, $headerValue)]);
return $this->privateKey->sign($body);
}
}
Loading

0 comments on commit 7771fd0

Please sign in to comment.