-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use HttpClient to gather certificates in certmonitor too
- Loading branch information
Showing
12 changed files
with
237 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Http\Client; | ||
|
||
use MichalSpacekCz\Http\Exceptions\HttpClientTlsCertificateNotAvailableException; | ||
use MichalSpacekCz\Http\Exceptions\HttpClientTlsCertificateNotCapturedException; | ||
use OpenSSLCertificate; | ||
|
||
class HttpClientResponse | ||
{ | ||
|
||
public function __construct( | ||
private readonly HttpClientRequest $request, | ||
private readonly string $body, | ||
private readonly ?OpenSSLCertificate $tlsCertificate, | ||
) { | ||
} | ||
|
||
|
||
public function getBody(): string | ||
{ | ||
return $this->body; | ||
} | ||
|
||
|
||
/** | ||
* @throws HttpClientTlsCertificateNotAvailableException | ||
* @throws HttpClientTlsCertificateNotCapturedException | ||
*/ | ||
public function getTlsCertificate(): OpenSSLCertificate | ||
{ | ||
$scheme = parse_url($this->request->getUrl(), PHP_URL_SCHEME); | ||
if (!is_string($scheme) || strtolower($scheme) !== 'https') { | ||
throw new HttpClientTlsCertificateNotAvailableException($this->request->getUrl()); | ||
} | ||
if (!$this->request->getTlsCaptureCertificate() || !$this->tlsCertificate) { | ||
throw new HttpClientTlsCertificateNotCapturedException(); | ||
} | ||
return $this->tlsCertificate; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
site/app/Http/Exceptions/HttpClientTlsCertificateNotAvailableException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Http\Exceptions; | ||
|
||
use Exception; | ||
use Throwable; | ||
|
||
class HttpClientTlsCertificateNotAvailableException extends Exception | ||
{ | ||
|
||
public function __construct(string $url, ?Throwable $previous = null) | ||
{ | ||
parent::__construct("Can't get TLS certificate because the request is not HTTPS: {$url}", previous: $previous); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
site/app/Http/Exceptions/HttpClientTlsCertificateNotCapturedException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Http\Exceptions; | ||
|
||
use Exception; | ||
use Throwable; | ||
|
||
class HttpClientTlsCertificateNotCapturedException extends Exception | ||
{ | ||
|
||
public function __construct(?Throwable $previous = null) | ||
{ | ||
parent::__construct("TLS certificate wasn't captured, HttpClientRequest::setTlsCaptureCertificate(true) not called", previous: $previous); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.