From 7ffd9f3226feca6995a404ca3251ed32c6e755a6 Mon Sep 17 00:00:00 2001 From: Kevin Hellemun Date: Tue, 29 May 2018 20:30:50 +0200 Subject: [PATCH 1/2] Merge pull request #150 from bunq/move-to-new-sandbox-bunq/sdk_php#149 Move to new sandbox bunq/sdk_php#149 --- src/Context/ApiContext.php | 2 +- src/Http/ApiClient.php | 58 ++++++++++++------- .../sandbox.public.api.bunq.com.pubkey.pem | 9 --- 3 files changed, 39 insertions(+), 30 deletions(-) delete mode 100644 src/Http/Certificate/sandbox.public.api.bunq.com.pubkey.pem diff --git a/src/Context/ApiContext.php b/src/Context/ApiContext.php index 538ae8bc..b073edcc 100644 --- a/src/Context/ApiContext.php +++ b/src/Context/ApiContext.php @@ -21,7 +21,7 @@ class ApiContext * Api environment urls. */ const BASE_URL_PRODUCTION = 'https://api.bunq.com/v1/'; - const BASE_URL_SANDBOX = 'https://sandbox.public.api.bunq.com/v1/'; + const BASE_URL_SANDBOX = 'https://public-api.sandbox.bunq.com/v1/'; /** * Error constants. diff --git a/src/Http/ApiClient.php b/src/Http/ApiClient.php index c42725df..ab8a1b51 100644 --- a/src/Http/ApiClient.php +++ b/src/Http/ApiClient.php @@ -20,6 +20,16 @@ */ class ApiClient { + /** + * Error constants. + */ + const ERROR_ENVIRONMENT_TYPE_UNKNOWN = 'Unknown environmentType "%s"'; + const ERROR_MAC_OS_CURL_VERSION = 'Your PHP seems to be linked to the MacOS provided curl binary. ' . + 'This is incompatible with our SDK, please reinstall by running: "brew reinstall %s --with-homebrew-curl".%s'; + const ERROR_CURL_DOES_NOT_SUPPORT_ROOT_CERTIFICATE_PINNING = + //@codingStandardsIgnoreLine + 'Curl does not support root certificate pinning. See https://curl.haxx.se/docs/todo.html#Support_intermediate_root_pinn'; + /** * Endpoints not requiring active session for the request to succeed. */ @@ -34,17 +44,9 @@ class ApiClient const INSTALLATION_URL = 'installation'; const SESSION_SERVER_URL = 'session-server'; - /** - * Error constants. - */ - const ERROR_ENVIRONMENT_TYPE_UNKNOWN = 'Unknown environmentType "%s"'; - const ERROR_MAC_OS_CURL_VERSION = 'Your PHP seems to be linked to the MacOS provided curl binary. ' . - 'This is incompatible with our SDK, please reinstall by running: "brew reinstall %s --with-homebrew-curl".%s'; - /** * Public key locations. */ - const FILE_PUBLIC_KEY_ENVIRONMENT_SANDBOX = '/Certificate/sandbox.public.api.bunq.com.pubkey.pem'; const FILE_PUBLIC_KEY_ENVIRONMENT_PRODUCTION = '/Certificate/api.bunq.com.pubkey.pem'; /** @@ -237,18 +239,18 @@ private function initializeHttpClient() $middleware = $this->determineMiddleware(); $this->httpClient = new Client( - [ - self::OPTION_DEFAULTS => [ - self::OPTION_ALLOW_REDIRECTS => false, - self::OPTION_EXCEPTIONS => false, - ], - self::OPTION_HANDLER => $middleware, - self::OPTION_VERIFY => true, - self::OPTION_CURL => [ - CURLOPT_PINNEDPUBLICKEY => $this->determinePinnedServerPublicKey(), + array_merge( + [ + self::OPTION_DEFAULTS => [ + self::OPTION_ALLOW_REDIRECTS => false, + self::OPTION_EXCEPTIONS => false, + ], + self::OPTION_HANDLER => $middleware, + self::OPTION_VERIFY => true, + self::OPTION_PROXY => $this->apiContext->getProxy(), ], - self::OPTION_PROXY => $this->apiContext->getProxy(), - ] + $this->determinePinnedKeySetting() + ) ); } } @@ -283,6 +285,22 @@ private function determineMiddleware(): HandlerStack return $handlerStack; } + /** + * @return string[] + */ + private function determinePinnedKeySetting(): array + { + if ($this->apiContext->getEnvironmentType()->equals(BunqEnumApiEnvironmentType::SANDBOX())) { + return []; + } else { + return [ + self::OPTION_CURL => [ + CURLOPT_PINNEDPUBLICKEY => $this->determinePinnedServerPublicKey(), + ], + ]; + } + } + /** * @return string * @throws BunqException when the environment type is unknown. @@ -292,7 +310,7 @@ private function determinePinnedServerPublicKey(): string $environmentType = $this->apiContext->getEnvironmentType(); if ($environmentType->equals(BunqEnumApiEnvironmentType::SANDBOX())) { - return __DIR__ . self::FILE_PUBLIC_KEY_ENVIRONMENT_SANDBOX; + throw new BunqException(self::ERROR_CURL_DOES_NOT_SUPPORT_ROOT_CERTIFICATE_PINNING); } elseif ($environmentType->equals(BunqEnumApiEnvironmentType::PRODUCTION())) { return __DIR__ . self::FILE_PUBLIC_KEY_ENVIRONMENT_PRODUCTION; } else { diff --git a/src/Http/Certificate/sandbox.public.api.bunq.com.pubkey.pem b/src/Http/Certificate/sandbox.public.api.bunq.com.pubkey.pem deleted file mode 100644 index fa26328d..00000000 --- a/src/Http/Certificate/sandbox.public.api.bunq.com.pubkey.pem +++ /dev/null @@ -1,9 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0vsFAdvOK0v4NOLNCyYi -iw06obUmRkTI9VfbDtuIjNLFFHQo5V1K8KztFQjzysgBpqKr9WCWS/Cknsjk95zw -E0HsWbR7daoNwNcAyiqvC+4WKaxEXgpz9UPWCYfcJqUnmwhZBgrZPz9MXHOgtU7l -mk5TJEy2/bhTuMmW0NfjBVl2bVSgPh8U0v5uYA69ypVPXDzFuGs3eyrgUroQOuja -TiCVbWIyvQpyn5McBUO3uF14RAVOIYFqFOHQkxcgFMeFylsKE7hBHpdpKvRmB1LS -2KsHB4oQ0XayLg4yV0KAyNvdt/XHrOvA2JFg5H7hDZbhsxWVQniF8CbEakgOiose -iwIDAQAB ------END PUBLIC KEY----- From 6baf36218458f986dba48e8c4de89fcddf1e405d Mon Sep 17 00:00:00 2001 From: Kevin Hellemun Date: Wed, 30 May 2018 11:01:36 +0200 Subject: [PATCH 2/2] Version bump to 0.13.2 --- CHANGELOG.md | 12 ++++++++++++ src/Http/ApiClient.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92f06023..5ba5eb6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Change Log +## [0.13.2](https://github.com/bunq/sdk_php/tree/0.13.2) + +[Full Changelog](https://github.com/bunq/sdk_php/compare/0.13.1...0.13.2) + +**Closed issues:** + +- Move to new sandbox . [\#149](https://github.com/bunq/sdk_php/issues/149) + +**Merged pull requests:** + +- Move to new sandbox bunq/sdk_php#149. [\#115](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) [Full Changelog](https://github.com/bunq/sdk_php/compare/0.13.0...0.13.1) diff --git a/src/Http/ApiClient.php b/src/Http/ApiClient.php index ab8a1b51..45d1ed64 100644 --- a/src/Http/ApiClient.php +++ b/src/Http/ApiClient.php @@ -77,7 +77,7 @@ class ApiClient /** * User agent constants. */ - const HEADER_USER_AGENT_BUNQ_SDK_DEFAULT = 'bunq-sdk-php/0.13.1'; + const HEADER_USER_AGENT_BUNQ_SDK_DEFAULT = 'bunq-sdk-php/0.13.2'; /** * Binary request constants.