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

Updated client CA cert #31

Merged
merged 1 commit into from
Jun 7, 2024
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
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
"require": {
"php": "~7.4||~8.0",
"ext-curl": "*",
"guzzlehttp/guzzle": "~6.1|~7.0"
"guzzlehttp/guzzle": "~6.1|~7.0",
"composer/ca-bundle": "^1.5"
},
"require-dev": {
"phpunit/phpunit": "9.5.10",
"squizlabs/php_codesniffer": "3.6.1"
},
"suggest": {
"composer/ca-bundle": "Provides regularly updated root certificates list"
},
"autoload": {
"psr-4": {
"FioApi\\": "src/FioApi"
Expand Down
43 changes: 11 additions & 32 deletions src/FioApi/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,34 @@

namespace FioApi;

use Composer\CaBundle\CaBundle;
use FioApi\Exceptions\InternalErrorException;
use FioApi\Exceptions\TooGreedyException;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\ResponseInterface;

class Downloader
{
/** @var UrlBuilder */
protected $urlBuilder;

/** @var \GuzzleHttp\Client */
/** @var Client */
protected $client;

/** @var string */
protected $certificatePath;

public function __construct(
string $token,
\GuzzleHttp\ClientInterface $client = null
) {
public function __construct(string $token, ClientInterface $client = null)
{
$this->urlBuilder = new UrlBuilder($token);
$this->client = $client;
}

public function setCertificatePath(string $path)
{
$this->certificatePath = $path;
}

public function getCertificatePath(): string
{
if ($this->certificatePath) {
return $this->certificatePath;
}

if (class_exists('\Composer\CaBundle\CaBundle')) {
return \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath();
} elseif (class_exists('\Kdyby\CurlCaBundle\CertificateHelper')) {
return \Kdyby\CurlCaBundle\CertificateHelper::getCaInfoFile();
}

//Key downloaded from https://www.geotrust.com/resources/root-certificates/
return __DIR__ . '/keys/Geotrust_PCA_G3_Root.pem';
}

public function getClient(): ClientInterface
{
if (!$this->client) {
$this->client = new \GuzzleHttp\Client();
$this->client = new Client([
RequestOptions::VERIFY => CaBundle::getSystemCaRootBundlePath()
]);
}
return $this->client;
}
Expand Down Expand Up @@ -79,7 +58,7 @@ public function setLastId(string $id): void
$url = $this->urlBuilder->buildSetLastIdUrl($id);

try {
$client->request('get', $url, ['verify' => $this->getCertificatePath()]);
$client->request('get', $url);
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
$this->handleException($e);
}
Expand All @@ -91,7 +70,7 @@ private function downloadTransactionsList(string $url): TransactionList

try {
/** @var ResponseInterface $response */
$response = $client->request('get', $url, ['verify' => $this->getCertificatePath()]);
$response = $client->request('get', $url);
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
$this->handleException($e);
}
Expand Down
24 changes: 0 additions & 24 deletions src/FioApi/keys/Geotrust_PCA_G3_Root.pem

This file was deleted.

7 changes: 0 additions & 7 deletions tests/FioApi/DownloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,4 @@ public function testDownloaderSetsLastId()

$this->assertSame('https://fioapi.fio.cz/v1/rest/set-last-id/validToken/123456/', (string) $request->getUri());
}

public function testDownloaderSetCertificatePath()
{
$downloader = new Downloader('validToken');
$downloader->setCertificatePath('foo.pem');
$this->assertSame('foo.pem', $downloader->getCertificatePath());
}
}
Loading