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
183 changes: 170 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions example/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@

ini_set('display_errors', '0');

session_name('__Host-PHPSESSID');

session_set_cookie_params([
'lifetime' => 0,
'path' => '/',
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);

session_start();

// Uncomment following line to define the custom log location (by default the server log is used)
Expand Down
4 changes: 4 additions & 0 deletions src/certificate/CertificateValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public static function validateIsValidAndSignedByTrustedCA(
$now = DefaultClock::getInstance()->now();
self::certificateIsValidOnDate($certificate, $now, "User");

// Prevent SSRF via CA Issuers URI from user-provided certificate AIA.
// All trusted/intermediate CA certificates must be provided by configuration.
X509::disableURLFetch();

foreach ($trustedCertificates->getCertificates() as $trustedCertificate) {
$certificate->loadCA(
$trustedCertificate->saveX509($trustedCertificate->getCurrentCert(), X509::FORMAT_PEM)
Expand Down
4 changes: 3 additions & 1 deletion src/validator/ocsp/OcspClientImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public function request(Uri $uri, string $encodedOcspRequest): OcspResponse

$info = curl_getinfo($curl);
if ($info["http_code"] !== 200) {
throw new UserCertificateOCSPCheckFailedException("OCSP request was not successful, response: " + $result);
throw new UserCertificateOCSPCheckFailedException(
"OCSP request was not successful, response: " . (is_string($result) ? $result : '')
);
}

$response = new OcspResponse($result);
Expand Down
19 changes: 17 additions & 2 deletions src/validator/versionvalidators/AuthTokenVersion11Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class AuthTokenVersion11Validator extends AuthTokenVersion1Validator

public function supports(?string $format): bool
{
return $format !== null &&
str_starts_with($format, self::V11_SUPPORTED_TOKEN_FORMAT_PREFIX);
return $format === self::V11_SUPPORTED_TOKEN_FORMAT_PREFIX;
}

/**
Expand All @@ -84,6 +83,7 @@ public function validate(
$this->validateSameIssuer($subjectCertificate, $signingCertificate);
$this->validateSigningCertificateValidity($signingCertificate);
$this->validateKeyUsage($signingCertificate);
$this->validateSigningCertificateChain($signingCertificate);
}

return $subjectCertificate;
Expand Down Expand Up @@ -239,6 +239,21 @@ private function validateKeyUsage(X509 $signingCertificate): void
}
}

/**
* @throws AuthTokenParseException
*/
private function validateSigningCertificateChain(X509 $signingCertificate): void
{
try {
$this->buildTrustValidatorBatch()->executeFor($signingCertificate);
} catch (AuthTokenException $e) {
throw new AuthTokenParseException(
"Signing certificate chain validation failed",
$e,
);
}
}

/**
* @throws AuthTokenException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function __construct(

public function supports(?string $format): bool
{
return $format !== null &&
str_starts_with($format, self::V1_SUPPORTED_TOKEN_FORMAT_PREFIX);
return $format === self::V1_SUPPORTED_TOKEN_FORMAT_PREFIX ||
$format === "web-eid:1.0";
}

public function validate(
Expand Down Expand Up @@ -135,7 +135,7 @@ public function validate(
return $subjectCertificate;
}

private function buildTrustValidatorBatch(): SubjectCertificateValidatorBatch
protected function buildTrustValidatorBatch(): SubjectCertificateValidatorBatch
{
$trustedValidator = new SubjectCertificateTrustedValidator(
$this->trustedCACertificates,
Expand Down
Loading