Skip to content
Open
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"symfony/cache": ">=4.0"
},
"require-dev": {
"paragonie/certainty": "^2|^3",
"phpunit/phpunit": "*"
},
"autoload": {
Expand Down
5 changes: 5 additions & 0 deletions src/ActivityPhp/Server/Configuration/HttpConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class HttpConfiguration extends AbstractConfiguration
*/
protected $sleep = 5;

/**
* @var string File path for cacert.pem file for TLS validation
*/
protected string $cacertPath = '';

/**
* Dispatch configuration parameters
*
Expand Down
13 changes: 10 additions & 3 deletions src/ActivityPhp/Server/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,25 @@ class Request
* @param float|int $timeout
* @param string $agent
*/
public function __construct($timeout = 10.0, $agent = '')
public function __construct(float|int $timeout = 10.0, string $agent = '', string $cacertPath = '')
{
$headers = ['Accept' => self::HTTP_HEADER_ACCEPT];

if ($agent) {
$headers['User-Agent'] = $agent;
}

$this->client = new Client([
$clientConfig = [
'timeout' => $timeout,
'headers' => $headers
]);
];
if (!empty($cacertPath)) {
if (!is_readable($cacertPath)) {
throw new Exception('Cannot read cacert file path: ' . $cacertPath);
}
$clientConfig['verify'] = $cacertPath;
}
$this->client = new Client($clientConfig);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/ActivityPhp/Server/Http/WebFingerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public static function get(string $handle, string $scheme = 'https')
$content = Util::decodeJson(
(new Request(
self::$server->config('http.timeout'),
self::$server->config('http.agent')
self::$server->config('http.agent'),
self::$server->config('http.cacert') ?? ''
))->get($url)
);

Expand Down
18 changes: 18 additions & 0 deletions tests/ActivityPhp/Server/ServerHttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ActivityPhpTest\Server;

use ActivityPhp\Server;
use ParagonIE\Certainty\RemoteFetch;
use PHPUnit\Framework\TestCase;

class ServerHttpTest extends TestCase
Expand Down Expand Up @@ -60,4 +61,21 @@ public function testUserAgentCustomization()
"MyUserAgent"
);
}

public function testCaCert()
{
mkdir(__DIR__ . '/tmp');
$latestCaCert = (new RemoteFetch(__DIR__ . '/tmp'))
->getLatestBundle(false, false)
->getFilePath();
$server = new Server([
'http' => [
'cacert' => $latestCaCert
]
]);
$this->assertSame(
$latestCaCert,
$server->config('http.cacert')
);
}
}