diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f38912 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +vendor +composer.lock diff --git a/README.md b/README.md new file mode 100644 index 0000000..52cc6dd --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Omnipay: ČSOB + +**ČSOB driver for the Omnipay PHP payment processing library** + +[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment +processing library for PHP 5.3+. This package implements PayPal support for Omnipay. + +ČSOB Online Payment Gateway [documentation](https://github.com/csob/paymentgateway/wiki) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..bca3c00 --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "bileto/omnipay-csob", + "type": "library", + "description": "ČSOB gateway for Omnipay payment processing library", + "keywords": [ + "gateway", + "merchant", + "omnipay", + "pay", + "payment", + "csob", + "purchase" + ], + "homepage": "https://github.com/bileto/omnipay-csob", + "license": "MIT", + "authors": [ + { + "name": "Michal Sänger", + "email": "michal.sanger@bileto.cz" + } + ], + "autoload": { + "psr-4": { "Omnipay\\Csob\\" : "src/" } + }, + "require": { + "omnipay/common": "^2.3" + }, + "require-dev": { + "omnipay/tests": "^2.0", + "symfony/var-dumper": "^2.7" + } +} diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..fc6bb9d --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,23 @@ + + + + + ./tests/ + + + + + + + + + diff --git a/src/Gateway.php b/src/Gateway.php new file mode 100644 index 0000000..2eacfe3 --- /dev/null +++ b/src/Gateway.php @@ -0,0 +1,118 @@ +signator = $signator; + } + + /** + * @param DataVerifier $verifier + */ + public function setVerifier(DataVerifier $verifier) + { + $this->verifier = $verifier; + } + + /** + * @param array $parameters + * @return InitPaymentRequest + * @throws \Exception + */ + public function initPayment(array $parameters = array()) + { + return $this->createRequest(InitPaymentRequest::class, $parameters); + } + + /** + * @param array $parameters + * @return ProcessPaymentRequest + * @throws \Exception + */ + public function processPayment(array $parameters = array()) + { + return $this->createRequest(ProcessPaymentRequest::class, $parameters); + } + + /** + * @param array $parameters + * @return InitPaymentRequest + * @throws \Exception + */ + public function purchase(array $parameters = array()) + { + $initRequest = $this->initPayment($parameters); + /** @var PaymentResponse $initResponse */ + $initResponse = $initRequest->send(); + if (!$initResponse->isSuccessful()) { + throw new InvalidResponseException($initResponse->getMessage(), $initResponse->getCode()); + } + $processRequest = $this->processPayment([ + 'merchantId' => $initRequest->getMerchantId(), + 'payId' => $initResponse->getTransactionReference(), + 'dttm' => $initResponse->getDttm(), + ]); + return $processRequest; + } + + /** + * @param array $parameters + * @return CompletePurchaseRequest + * @throws \Exception + */ + public function completePurchase(array $parameters = array()) + { + return $this->createRequest(CompletePurchaseRequest::class, $parameters); + } + + protected function createRequest($class, array $parameters) + { + if (!($this->signator instanceof DataSignator)) { + throw new \Exception('Cannot create request, Signator is not set'); + } + if (!($this->verifier instanceof DataVerifier)) { + throw new \Exception('Cannot create request, Verifier is not set'); + } + + /** @var \Omnipay\Csob\Message\AbstractRequest $request */ + $request = parent::createRequest($class, $parameters); + + $request->setSignator($this->signator); + $request->setVerifier($this->verifier); + + return $request; + } + + +} \ No newline at end of file diff --git a/src/GatewayFactory.php b/src/GatewayFactory.php new file mode 100644 index 0000000..a0a9323 --- /dev/null +++ b/src/GatewayFactory.php @@ -0,0 +1,34 @@ +setSignator($dataSignator); + $gateway->setVerifier($dataVerifier); + return $gateway; + } +} \ No newline at end of file diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php new file mode 100644 index 0000000..eb7adac --- /dev/null +++ b/src/Message/AbstractRequest.php @@ -0,0 +1,47 @@ +signator = $signator; + } + + /** + * @return DataSignator + */ + public function getSignator() + { + return $this->signator; + } + + /** + * @return DataVerifier + */ + public function getVerifier() + { + return $this->verifier; + } + + /** + * @param DataVerifier $verifier + */ + public function setVerifier(DataVerifier $verifier) + { + $this->verifier = $verifier; + } +} \ No newline at end of file diff --git a/src/Message/AbstractResponse.php b/src/Message/AbstractResponse.php new file mode 100644 index 0000000..0859561 --- /dev/null +++ b/src/Message/AbstractResponse.php @@ -0,0 +1,77 @@ +verifier = $verifier; + } + + public function isVerified() + { + if ($this->isVerified === null) { + $data = $this->getData(); + $arrayKeys = ['payId', 'dttm', 'resultCode', 'resultMessage', 'paymentStatus', 'authCode', 'merchantData']; + $signature = $this->getSignature(); + $this->isVerified = $this->verifier->verify($data, $arrayKeys, $signature); + } + return $this->isVerified; + } + + /** + * Is the response successful? + * + * @return boolean + */ + public function isSuccessful() + { + if (!$this->isVerified()) { + return false; + } + return $this->getCode() === 0 || $this->getCode() === "0"; + } + + public function getSignature() + { + if (isset($this->data['signature'])) { + return $this->data['signature']; + } + } + + public function getDttm() + { + if (isset($this->data['dttm'])) { + return $this->data['dttm']; + } + } + + public function getCode() + { + if (isset($this->data['resultCode'])) { + return $this->data['resultCode']; + } + } + + public function getMessage() + { + if (!$this->isVerified()) { + return 'Verification error, the signature cannot be verified with given public key.'; + } + if (isset($this->data['resultMessage'])) { + return $this->data['resultMessage']; + } + } +} \ No newline at end of file diff --git a/src/Message/CompletePurchaseRequest.php b/src/Message/CompletePurchaseRequest.php new file mode 100644 index 0000000..3fecc35 --- /dev/null +++ b/src/Message/CompletePurchaseRequest.php @@ -0,0 +1,70 @@ +setParameter('authCode', $value); + } + + public function setSignature($value) + { + $this->setParameter('signature', $value); + } + + public function setDttm($value) + { + $this->setParameter('dttm', $value); + } + + public function setResultCode($value) + { + $this->setParameter('resultCode', $value); + } + + public function setPayId($value) + { + $this->setParameter('payId', $value); + } + + public function setResultMessage($value) + { + $this->setParameter('resultMessage', $value); + } + + public function setPaymentStatus($value) + { + $this->setParameter('paymentStatus', $value); + } + + public function setMerchantData($value) + { + $this->setParameter('merchantData', $value); + } + + /** + * Get the raw data array for this message. The format of this varies from gateway to + * gateway, but will usually be either an associative array, or a SimpleXMLElement. + * + * @return mixed + */ + public function getData() + { + return $this->getParameters(); + } + + /** + * Send the request with specified data + * + * @param mixed $data The data to send + * @return PaymentResponse + */ + public function sendData($data) + { + $response = new PaymentResponse($this, $data); + $response->setVerifier($this->getVerifier()); + return $this->response = $response; + } +} \ No newline at end of file diff --git a/src/Message/InitPaymentRequest.php b/src/Message/InitPaymentRequest.php new file mode 100644 index 0000000..6638abc --- /dev/null +++ b/src/Message/InitPaymentRequest.php @@ -0,0 +1,152 @@ +setParameter('merchantId', $value); + } + + public function getMerchantId() + { + return $this->getParameter('merchantId'); + } + + public function setOrderNo($value) + { + $this->setParameter('orderNo', $value); + } + + public function setDttm($value) + { + $this->setParameter('dttm', $value); + } + + public function setPayOperation($value) + { + $this->setParameter('payOperation', $value); + } + + public function setPayMethod($value) + { + $this->setParameter('payMethod', $value); + } + + public function setTotalAmount($value) + { + $this->setParameter('totalAmount', $value); + } + + public function setCurrency($value) + { + $this->setParameter('currency', $value); + } + + public function setClosePayment($value) + { + $this->setParameter('closePayment', $value); + } + + public function setReturnUrl($value) + { + $this->setParameter('returnUrl', $value); + } + + public function setReturnMethod($value) + { + $this->setParameter('returnMethod', $value); + } + + public function setCart(array $value) + { + $this->setParameter('cart', $value); + } + + public function setDescription($value) + { + $this->setParameter('description', $value); + } + + public function setMerchantData($value) + { + $this->setParameter('merchantData', $value); + } + + public function setCustomerId($value) + { + $this->setParameter('customerId', $value); + } + + public function setLanguage($value) + { + $this->setParameter('language', $value); + } + + /** + * Get the raw data array for this message. The format of this varies from gateway to + * gateway, but will usually be either an associative array, or a SimpleXMLElement. + * + * @return mixed + */ + public function getData() + { + $data = [ + "merchantId" => $this->getParameter('merchantId'), + "orderNo" => $this->getParameter('orderNo'), + "dttm" => $this->getParameter('dttm'), + "payOperation" => $this->getParameter('payOperation'), + "payMethod" => $this->getParameter('payMethod'), + "totalAmount" => $this->getParameter('totalAmount'), + "currency" => $this->getParameter('currency'), + "closePayment" => $this->getParameter('closePayment'), + "returnUrl" => $this->getParameter('returnUrl'), + "returnMethod" => $this->getParameter('returnMethod'), + "cart" => $this->getParameter('cart'), + "description" => $this->getParameter('description'), + "merchantData" => $this->getParameter('merchantData'), + "customerId" => $this->getParameter('customerId'), + "language" => $this->getParameter('language'), + ]; + $data['signature'] = $this->signData($data); + return $data; + } + + private function signData($data) + { + $arrayKeys = [ + 'merchantId', 'orderNo', 'dttm', 'payOperation', 'payMethod', 'totalAmount', 'currency', 'closePayment', 'returnUrl', + 'returnMethod', 'cart', 'description', 'merchantData', 'customerId', 'language' + ]; + return $this->getSignator()->sign($data, $arrayKeys); + } + + /** + * Send the request with specified data + * + * @param mixed $data The data to send + * @return ResponseInterface + */ + public function sendData($data) + { + $httpRequest = $this->httpClient->createRequest( + RequestInterface::POST, + 'https://iapi.iplatebnibrana.csob.cz/api/v1/payment/init', + ['Content-Type' => 'application/json'], + json_encode($data) + ); + + $httpResponse = $httpRequest->send(); + $data = $httpResponse->json(); + $response = new PaymentResponse($this, $data); + $response->setVerifier($this->getVerifier()); + + return $this->response = $response; + } + +} \ No newline at end of file diff --git a/src/Message/PaymentResponse.php b/src/Message/PaymentResponse.php new file mode 100644 index 0000000..2fbaa0d --- /dev/null +++ b/src/Message/PaymentResponse.php @@ -0,0 +1,35 @@ +data['authCode'])) { + return $this->data['authCode']; + } + } + + public function getTransactionReference() + { + if (isset($this->data['payId'])) { + return $this->data['payId']; + } + } + + + public function getPaymentStatus() + { + if (isset($this->data['paymentStatus'])) { + return $this->data['paymentStatus']; + } + } + + public function getMerchantData() + { + if (isset($this->data['merchantData'])) { + return $this->data['merchantData']; + } + } +} \ No newline at end of file diff --git a/src/Message/ProcessPaymentRequest.php b/src/Message/ProcessPaymentRequest.php new file mode 100644 index 0000000..ac4acbc --- /dev/null +++ b/src/Message/ProcessPaymentRequest.php @@ -0,0 +1,72 @@ +setParameter('dttm', $value); + } + + public function setPayId($value) + { + return $this->setParameter('payId', $value); + } + + public function setMerchantId($value) + { + return $this->setParameter('merchantId', $value); + } + + /** + * Get the raw data array for this message. The format of this varies from gateway to + * gateway, but will usually be either an associative array, or a SimpleXMLElement. + * + * @return mixed + */ + public function getData() + { + return $this->getParameters(); + $data = [ + "merchantId" => $this->getParameter('merchantId'), + "payId" => $this->getParameter('payId'), + "dttm" => $this->getParameter('dttm'), + ]; + return $data; + } + + /** + * Send the request with specified data + * + * @param mixed $data The data to send + * @return ProcessPaymentResponse + */ + public function sendData($data) + { + $httpRequest = $this->httpClient->createRequest( + RequestInterface::GET, + $this->createUri() + ); + + $httpResponse = $httpRequest->send(); + return $this->response = new ProcessPaymentResponse($this, $httpResponse->getEffectiveUrl()); + } + + private function createUri() + { + $uri = 'https://iapi.iplatebnibrana.csob.cz/api/v1/payment/process'; + + $signator = $this->getSignator(); + $signature = $signator->sign($this->getParameters(), ['merchantId', 'payId', 'dttm']); + + return $uri . '/' . + urlencode($this->getParameter('merchantId')) . '/' . + urlencode($this->getParameter('payId')) . '/' . + urlencode($this->getParameter('dttm')) . '/' . + urlencode($signature); + } + +} \ No newline at end of file diff --git a/src/Message/ProcessPaymentResponse.php b/src/Message/ProcessPaymentResponse.php new file mode 100644 index 0000000..4884cc2 --- /dev/null +++ b/src/Message/ProcessPaymentResponse.php @@ -0,0 +1,61 @@ +redirectUrl = $redirectUrl; + parent::__construct($request, null); + } + + /** + * Is the response successful? + * + * @return boolean + */ + public function isSuccessful() + { + return false; + } + + /** + * Gets the redirect target url. + */ + public function getRedirectUrl() + { + return $this->redirectUrl; + } + + /** + * Get the required redirect method (either GET or POST). + */ + public function getRedirectMethod() + { + return GuzzleRequestInterface::GET; + } + + /** + * Gets the redirect form data array, if the redirect method is POST. + */ + public function getRedirectData() + { + return; + } + + public function isRedirect() + { + return true; + } + + +} \ No newline at end of file diff --git a/src/Sign/DataSignator.php b/src/Sign/DataSignator.php new file mode 100644 index 0000000..f743776 --- /dev/null +++ b/src/Sign/DataSignator.php @@ -0,0 +1,29 @@ +preparer = $preparer; + $this->signator = $signator; + } + + /** + * @param array $data + * @param array $arrayKeys + * @return string Base64 encoded + */ + public function sign(array $data, array $arrayKeys) + { + $strToSign = $this->preparer->getStringToSign($data, $arrayKeys); + return $this->signator->sign($strToSign); + } +} \ No newline at end of file diff --git a/src/Sign/DataVerifier.php b/src/Sign/DataVerifier.php new file mode 100644 index 0000000..36fcd03 --- /dev/null +++ b/src/Sign/DataVerifier.php @@ -0,0 +1,30 @@ +preparer = $preparer; + $this->verifier = $verifier; + } + + /** + * @param array $data + * @param array $arrayKeys + * @param string $signatureBase64 + * @return bool + */ + public function verify(array $data, array $arrayKeys, $signatureBase64) + { + $strToSign = $this->preparer->getStringToSign($data, $arrayKeys); + return $this->verifier->verify($strToSign, $signatureBase64); + } +} \ No newline at end of file diff --git a/src/Sign/Preparer.php b/src/Sign/Preparer.php new file mode 100644 index 0000000..1f1e07f --- /dev/null +++ b/src/Sign/Preparer.php @@ -0,0 +1,33 @@ +getStringToSign($value, array_keys($value)); + } else { + $str .= (string)$data[$key]; + } + $str .= '|'; + } + return rtrim($str, '|'); + } +} \ No newline at end of file diff --git a/src/Sign/Signator.php b/src/Sign/Signator.php new file mode 100644 index 0000000..f407731 --- /dev/null +++ b/src/Sign/Signator.php @@ -0,0 +1,33 @@ +privateKeyFilename = $privateKeyFilename; + $this->privateKeyPassword = $privateKeyPassword; + } + + /** + * @param string $text + * @return string Base64 encoded + */ + public function sign($text) { + $private = file_get_contents($this->privateKeyFilename); + $privateKeyId = openssl_get_privatekey($private, $this->privateKeyPassword); + + openssl_sign($text, $signature, $privateKeyId); + $signature = base64_encode($signature); + openssl_free_key($privateKeyId); + + return $signature; + } +} \ No newline at end of file diff --git a/src/Sign/Verifier.php b/src/Sign/Verifier.php new file mode 100644 index 0000000..2dce790 --- /dev/null +++ b/src/Sign/Verifier.php @@ -0,0 +1,30 @@ +publicKeyFilename = $publicKeyFilename; + } + + /** + * @param string $text + * @param string $signatureBase64 + * @return bool + */ + function verify($text, $signatureBase64) { + $public = file_get_contents($this->publicKeyFilename); + $publicKeyId = openssl_get_publickey($public); + + $signature = base64_decode($signatureBase64); + $res = openssl_verify($text, $signature, $publicKeyId); + openssl_free_key($publicKeyId); + + return $res === 1; + } +} \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..d21c14d --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,3 @@ + "A1029DTmM7", + "orderNo" => "1234560", + "dttm" => "20150624090323", + "payOperation" => "payment", + "payMethod" => "card", + "totalAmount" => 100, + "currency" => "CZK", + "closePayment" => "false", + "returnUrl" => "https://vasobchod.cz/gateway-return", + "returnMethod" => "POST", + "cart" => [ + [ + "name" => "Shopping at ...", + "quantity" => 1, + "amount" => 100, + "description" => "Lenovo ThinkPad Edge E540..." + ], + [ + "name" => "Shipping", + "quantity" => 1, + "amount" => 0, + "description" => "PPL" + ] + ], + "description" => "Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)", + "merchantData" => null, + "customerId" => "1234", + "language" => "CZ", + ]; + $arrayKeys = [ + 'merchantId', 'orderNo', 'dttm', 'payOperation', 'payMethod', 'totalAmount', 'currency', 'closePayment', 'returnUrl', + 'returnMethod', 'cart', 'description', 'merchantData', 'customerId', 'language' + ]; + $expectedSignature = "WaCyOg/6UikvZ3ut+B/6D7NaV1Vacj1eBzYEH19EC3Jwfe7fH2GyKliTK4dWZvTXNmnoAErRaR6+QSRmaQr12c2shyXG3XatfdYPRAjrneNnb3wgDwG/CgFAPc3xkw+9V2hVYiAP8QJtqX3dptvMWp+SjouGwP4jCUZQM9zebOkNdmsLn5QP8dj7qJ9n++AU0TG/WdImU0+RLMH4XRSp5xaebOVlzeLWXZKwPZB4EpVVlC/DEgF19t9dKMIKd+16Q9LVuRMPEvP/6zrx1EYbuGpV4Qbwdb5gSCyC3DkjB9gCRG0ZX8WftHsvVNbsFx9i4ujcg7SFK85KAsQuWTUXEw=="; + $stringToSign = $preparer->getStringToSign($data, $arrayKeys); + + $signature = $signator->sign($data, $arrayKeys); + + $this->assertSame($expectedSignature, $signature); + $this->assertTrue($verifier->verify($stringToSign, $signature), 'Verification failed'); + } +} diff --git a/tests/unit/Sign/DataVerifierTest.php b/tests/unit/Sign/DataVerifierTest.php new file mode 100644 index 0000000..fe8a77e --- /dev/null +++ b/tests/unit/Sign/DataVerifierTest.php @@ -0,0 +1,27 @@ + "518778", + "dttm" => "20150624173114", + "resultCode" => "0", + "payId" => "18b7c0eced91417", + "resultMessage" => "OK", + "paymentStatus" => "7" + ]; + $arrayKeys =['payId', 'dttm', 'resultCode', 'resultMessage', 'paymentStatus', 'authCode']; + $signature = 'rnIFXMnHB3HW0xPgfhiScWZ6OMyp9iiaPzPf83aJ0MD5Fywf\/XPB6lVhOfqUfCC4qoD9YYZrWKPGyYAf7Fk6EK2qUewRdPSGLNcyX7xD5hWD65SJArXYhGwg9k3kkoxbMkAk\/tluTK6Hw2K65Xi2to1cIe\/lctXV2D92kisux6JKO9Ksw\/6eFOF3xFCWjIgxxy8\/oHQDo6EksNKef2SUH7fXPaG+A0SjuGeNs6kD3A8w2a40EZYZYcY00Ny9Xg2kV4uxRNHDFSph7LFkAo6G9p3j913\/A69ngX60hr13or+14cVgN2Lixk7RqjpdFHZ5bQjpShtTAT03WR+B2Z7pcg=='; + + $isVerified = $dataVerifier->verify($data, $arrayKeys, $signature); + + $this->assertTrue($isVerified, 'Verification failed'); + } +} diff --git a/tests/unit/Sign/PreparerTest.php b/tests/unit/Sign/PreparerTest.php new file mode 100644 index 0000000..b58b96b --- /dev/null +++ b/tests/unit/Sign/PreparerTest.php @@ -0,0 +1,98 @@ + "A1029DTmM7", + "orderNo" => "1234560", + "dttm" => "20150624090323", + "payOperation" => "payment", + "payMethod" => "card", + "totalAmount" => 100, + "currency" => "CZK", + "closePayment" => "false", + "returnUrl" => "https://vasobchod.cz/gateway-return", + "returnMethod" => "POST", + "cart" => [ + [ + "name" => "Shopping at ...", + "quantity" => 1, + "amount" => 100, + "description" => "Lenovo ThinkPad Edge E540..." + ], + [ + "name" => "Shipping", + "quantity" => 1, + "amount" => 0, + "description" => "PPL" + ] + ], + "description" => "Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)", + "merchantData" => null, + "customerId" => "1234", + "language" => "CZ", + ]; + $keys = [ + 'merchantId', 'orderNo', 'dttm', 'payOperation', 'payMethod', 'totalAmount', 'currency', 'closePayment', 'returnUrl', + 'returnMethod', 'cart', 'description', 'merchantData', 'customerId', 'language' + ]; + $expectedStrToSign = "A1029DTmM7|1234560|20150624090323|payment|card|100|CZK|false|https://vasobchod.cz/gateway-return|POST|Shopping at ...|1|100|Lenovo ThinkPad Edge E540...|Shipping|1|0|PPL|Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)|1234|CZ"; + + $strToSign = $preparer->getStringToSign($data, $keys); + + $this->assertSame($expectedStrToSign, $strToSign); + } + + public function testGetDataToSignIgnoresNotRequestedKeys() + { + $preparer = new Preparer(); + $data = [ + "merchantId" => "A1029DTmM7", + "orderNo" => "1234567", + "totalAmount" => 100, + "currency" => "CZK", + "closePayment" => false, + ]; + $keys = [ + "merchantId", + "closePayment", + ]; + $expectedStrToSign = "A1029DTmM7|false"; + + $strToSign = $preparer->getStringToSign($data, $keys); + + $this->assertSame($expectedStrToSign, $strToSign); + } + + public function testGetDataToSignIgnores() + { + $preparer = new Preparer(); + $data = [ + "merchantId" => "A1029DTmM7", + "cart" => [ + [ + "name" => "Shopping at Foo", + "quantity" => 1, + "amount" => 100, + "description" => "Lenovo ThinkPad Edge E540" + ], + ], + "currency" => "CZK", + ]; + $keys = [ + "merchantId", + "cart", + "currency", + ]; + $expectedStrToSign = "A1029DTmM7|Shopping at Foo|1|100|Lenovo ThinkPad Edge E540|CZK"; + + $strToSign = $preparer->getStringToSign($data, $keys); + + $this->assertSame($expectedStrToSign, $strToSign); + } +} diff --git a/tests/unit/Sign/SignatorTest.php b/tests/unit/Sign/SignatorTest.php new file mode 100644 index 0000000..f60456d --- /dev/null +++ b/tests/unit/Sign/SignatorTest.php @@ -0,0 +1,18 @@ +sign($text); + + $this->assertNotSame($text, $signed); + $this->assertTrue($verifier->verify($text, $signed)); + } +} diff --git a/tests/unit/Sign/VerifierTest.php b/tests/unit/Sign/VerifierTest.php new file mode 100644 index 0000000..b43708c --- /dev/null +++ b/tests/unit/Sign/VerifierTest.php @@ -0,0 +1,18 @@ +sign($text); + + $this->assertTrue($verifier->verify($text, $signed)); + $this->assertFalse($verifier->verify('Other text', $signed)); + $this->assertFalse($verifier->verify($text, 'Other signed text')); + } +} diff --git a/tests/unit/Sign/assets/mips_iplatebnibrana.csob.cz.pub b/tests/unit/Sign/assets/mips_iplatebnibrana.csob.cz.pub new file mode 100644 index 0000000..56f14a8 --- /dev/null +++ b/tests/unit/Sign/assets/mips_iplatebnibrana.csob.cz.pub @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuo0GzBCQMl1wDJJrJHTQ +ykGlh2Kon7QfQjKVTPv7fPIVE8PhHeJueWBfydqTQKVeIVMB9VAUYlaPjwFhAuJ6 +zqoaCG9m+q81L7CehsQThntxacOPwRd4SSyS5o+kPzTIFji0Z3c8s6pYJJoF+YfE +atCWRW2frgrgbHbl+84AOvItt7NReYz1z4P7J+Uv4UbifFHVP7oIEh+5CJSj6puv +jHh1QHrzE+dTaoKDhtOfSkTTelHqod/hUt4QIcHai6I8X/R5nEv3y40MWoi1FxbQ +6IgtVMloneN0XaHR5U88eMeKJJyqR859I4xfun6Z6RyfyaIl5Ph3f2daeMeENPUR +BQIDAQAB +-----END PUBLIC KEY----- diff --git a/tests/unit/Sign/assets/rsa_A1029DTmM7.key b/tests/unit/Sign/assets/rsa_A1029DTmM7.key new file mode 100644 index 0000000..f6d9cd0 --- /dev/null +++ b/tests/unit/Sign/assets/rsa_A1029DTmM7.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAnDl8QHxz98t94XOIL6djAPg58KX/+Bv4YzzusyJhnj3Hfnh+ +0YPPtDRQDaLaSVBpLl1W/LkoFSWwJvc2Wg7yR9fKQB3DV3C5fVVFbfpYaO6gJWCB +ESU0IoAcnlnFS5UBfsTrD8c1F7Ic7MYyhcZefekS9htbDh5HrQxcEEpxkPRhKhgI +EbbkabXWbTED5ZTznSgHLEogzZwhDhSCF1sQ6rrc65hBsR7WkCPmjVzFeBjRF0o+ +SQo0eql3CINsIZ2zLGhHHisVLAdWLrdoRkVeC6dSQDlF10B8tbSMEd+G3XGmsvzq +Y9jdAiLFT3bERVzuD+x3J/jI1//vrxykiwS8DQIDAQABAoIBAG/2fwdUamSIMaJ3 +g33rr/fM7vF6dvXhTeYJkGVP2bhoPGZ2gyUzG5Ph/hGXymvKtmclPCeJp6FoTlPO +zuRCW/+DNw82hX5Qao/ZohXM2rnxc1L2U+nuyOuE933BhrXBh73L8U9wjKt72mET +NrhLUANbHFzHhD2dE++AsSZ3w+aHLsl12biRWhKA5xDNeWYwIXGVx1DhgBeB/wuZ +oKNOw2H96gpDK4COdmXGekbch82EcHNaJYxI5tT0ZIHmcQFSiUJJFqtp5kYhd+n9 +2M7h82i6beXTbJWE7dug5GQMqSXUue7rGNc4BFOGzVXxCV3SKdp+Xdkrwb4kuo9u +j2rXdb0CgYEA2WAEZCvNzYabv20sc8ri//Sf6NN36Y5Goc+19iLwYLIabM0bA/of +dY5aGlp8x10i4voN+E7n88eyw86UYztlWp+uRMvvVFi6IVGO3Gu+qelKoH55lIEJ +kRT98KFBFRQMhPuKnWMbUjbnNoPbkW7tbs8qchSg5kVZL7LrDAzpQl8CgYEAt/vY +qRF4QGzo+SDFlRfecghuK3I1y3n9oMmhAI46+5A+607jPb/ASQpO1LBIy3chkPUA +tNjKjhtC6Rt+Vlhp/CkwfuHLP2ktnZ+kF3j+FnNKYg9EpGXX7yayTR+WZgs5x82f +v2C9N7XdyjCVdox8rYzxQxZapLd+V56zylADkRMCgYEAn/DbKk1kv03E+WO96nEk +90mqA2jdeTbbV6H6c+GfVraVZOrBbvqx/RBB0dQ0rYgk7Dcq4kJEvwV3zkUIv77r +Q3PsiOg476ndQji9UgfhISnrZA3LLW6IeHymoFA2D+lRkON4SXermaGWHHGGtAqX +nwnFZG0zOltaVRNjiNlTJCcCgYEAhZNOaOkrEjNALeeSK73JnabrPZXM4q7t6jeZ +McsRnaTLWZHLwAAgfacDNr3KDBaxAwot+h7PaL74JD/2yH+maxIIiIYsRxx4ptDJ +lNUePHR1053cKzNZw+KnXwEI84tA5wQt8AcvOWxL20jMquYyetoyK4/mPWKPUtQB +GmhfPosCgYB65eJtPl7ZWo/GkPnkIreGcZc1SyuppW60hEtOCDEdkgMEZz5U/YeF +/DJd4bSwBKebHB2rFxA65vKP0gVj7A75vJxJeL1JZ57kMSMX7XF3YyS4EmeqxFGo +bAjeKFnfK4LJ7OwduH8ZZkd4kLDHKUBWkyZWmrm9v0xoHf/9CUdA8A== +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/tests/unit/Sign/assets/rsa_A1029DTmM7.pub b/tests/unit/Sign/assets/rsa_A1029DTmM7.pub new file mode 100644 index 0000000..983778a --- /dev/null +++ b/tests/unit/Sign/assets/rsa_A1029DTmM7.pub @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnDl8QHxz98t94XOIL6dj +APg58KX/+Bv4YzzusyJhnj3Hfnh+0YPPtDRQDaLaSVBpLl1W/LkoFSWwJvc2Wg7y +R9fKQB3DV3C5fVVFbfpYaO6gJWCBESU0IoAcnlnFS5UBfsTrD8c1F7Ic7MYyhcZe +fekS9htbDh5HrQxcEEpxkPRhKhgIEbbkabXWbTED5ZTznSgHLEogzZwhDhSCF1sQ +6rrc65hBsR7WkCPmjVzFeBjRF0o+SQo0eql3CINsIZ2zLGhHHisVLAdWLrdoRkVe +C6dSQDlF10B8tbSMEd+G3XGmsvzqY9jdAiLFT3bERVzuD+x3J/jI1//vrxykiwS8 +DQIDAQAB +-----END PUBLIC KEY----- \ No newline at end of file