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

Complete certificate chain verification #137

Merged
merged 49 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
071d418
Bug fixed
Spomky Feb 3, 2020
619778e
Merge branch 'v3.1' into CompleteCertificateChainVerification
Spomky Feb 3, 2020
185c7ab
Merge branch 'v3.3' into CompleteCertificateChainVerification
Spomky Jun 20, 2020
6eb8cc0
wIP
Spomky Jun 21, 2020
da7b1e5
Merge branch 'v3.3' into CompleteCertificateChainVerification
Spomky Jul 21, 2020
1c13394
Merge branch 'v3.3' into CompleteCertificateChainVerification
Spomky Jul 21, 2020
54fca05
Bugs fixed
Spomky Jul 30, 2020
d3b7a90
Fixes #143
Spomky Aug 1, 2020
a24d2d9
Root certificates
Spomky Aug 2, 2020
20986e3
Merge branch 'v3.3' into CompleteCertificateChainVerification
Spomky Aug 2, 2020
70ea55c
Root certificates
Spomky Aug 2, 2020
262d509
Untrusted certificates
Spomky Aug 9, 2020
e310362
Untrusted certificates
Spomky Aug 9, 2020
fff563f
Cleanup
Spomky Aug 9, 2020
1d9d551
Net MDS package - WIP
Spomky Aug 9, 2020
8ce04a4
CRL fixed
Spomky Aug 9, 2020
0485008
CRL fixed
Spomky Aug 9, 2020
0e546c9
CRL fixed
Spomky Aug 9, 2020
187c9d7
CRL fixed
Spomky Aug 9, 2020
8408ddb
Deps tests
Spomky Aug 9, 2020
37e3ea7
Deps tests
Spomky Aug 9, 2020
fa880e3
WIP
Spomky Aug 31, 2020
9cbfd0a
Merge branch 'v3.3' into CompleteCertificateChainVerification
Spomky Aug 31, 2020
e5a7926
Merge branch 'v3.3' into CompleteCertificateChainVerification
Spomky Aug 31, 2020
438a6cd
file extension fixed
Spomky Sep 22, 2020
a609483
Typo
Spomky Nov 22, 2020
e919992
Merge branch 'v3.3' into CompleteCertificateChainVerification
Spomky Nov 22, 2020
8e288f2
Continue merge
Spomky Nov 22, 2020
5671c72
Change PHP version between CI jobs (#159)
szepeviktor Nov 23, 2020
68b6cfe
Update bc-break-test.yml
Spomky Nov 23, 2020
a2f486a
Update bc-break-test.yml
Spomky Nov 23, 2020
96becd6
Update .php_cs.dist
Spomky Nov 23, 2020
732f831
Merge branch 'v3.2' into v3.3
Spomky Nov 23, 2020
77e52de
Minor correction
Spomky Nov 23, 2020
bf01851
Merge branch 'v3.3' into CompleteCertificateChainVerification
Spomky Nov 23, 2020
5278309
Merge branch 'v3.2' into v3.3
Spomky Nov 29, 2020
716f75a
Correction x5c with root certificate
Spomky Nov 29, 2020
c50adee
Get rid of Prophecy to fix tests on PHP 7.2
Spomky Nov 29, 2020
b76e5f4
Allow PhpUnit 8.x to fix tests on PHP 7.2
Spomky Nov 29, 2020
cb1990f
Temporary interfaces marked as internal
Spomky Nov 29, 2020
f9178c4
Compliance fixed
Spomky Nov 29, 2020
100df08
WIP
Spomky Dec 4, 2020
c9fbed5
WIP
Spomky Dec 5, 2020
b890112
WIP
Spomky Dec 5, 2020
9a4b5ea
WIP
Spomky Dec 5, 2020
2e2679a
WIP
Spomky Dec 5, 2020
81e2a97
WIP
Spomky Dec 5, 2020
1d76855
Tests moved
Spomky Dec 6, 2020
10a2e11
Missing PHP 7.2 pipeline
Spomky Dec 6, 2020
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
Prev Previous commit
Next Next commit
CRL fixed
  • Loading branch information
Spomky committed Aug 9, 2020
commit 8ce04a4a2a4160668f9124426fd1a48f4943447f
44 changes: 28 additions & 16 deletions src/webauthn/src/CertificateChainChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ public function check(array $authenticatorCertificates, array $trustedCertificat
$processArguments[] = $caDirname;

foreach ($trustedCertificates as $certificate) {
$this->prepareCertificate($caDirname, $certificate, 'webauthn-trusted-', '.pem', $hasCrls);
$this->saveToTemporaryFile($caDirname, $certificate, 'webauthn-trusted-', '.pem');
$crl = $this->getCrls($certificate);
if ('' !== $crl) {
$hasCrls = true;
$this->saveToTemporaryFile($caDirname, $crl, 'webauthn-trusted-crl-', '.pem');
}
}

$rehashProcess = new Process(['openssl', 'rehash', $caDirname]);
Expand All @@ -81,11 +86,21 @@ public function check(array $authenticatorCertificates, array $trustedCertificat

$filenames = [];
$leafCertificate = array_shift($authenticatorCertificates);
$leafFilename = $this->prepareCertificate(sys_get_temp_dir(), $leafCertificate, 'webauthn-leaf-', '.pem', $hasCrls);
$leafFilename = $this->saveToTemporaryFile(sys_get_temp_dir(), $leafCertificate, 'webauthn-leaf-', '.pem');
$crl = $this->getCrls($leafCertificate);
if ('' !== $crl) {
$hasCrls = true;
$this->saveToTemporaryFile($caDirname, $crl, 'webauthn-leaf-crl-', '.pem');
}
$filenames[] = $leafFilename;

foreach ($authenticatorCertificates as $certificate) {
$untrustedFilename = $this->prepareCertificate(sys_get_temp_dir(), $certificate, 'webauthn-untrusted-', '.pem', $hasCrls);
$untrustedFilename = $this->saveToTemporaryFile(sys_get_temp_dir(), $certificate, 'webauthn-untrusted-', '.pem');
$crl = $this->getCrls($certificate);
if ('' !== $crl) {
$hasCrls = true;
$this->saveToTemporaryFile($caDirname, $crl, 'webauthn-untrusted-crl-', '.pem');
}
$processArguments[] = '-untrusted';
$processArguments[] = $untrustedFilename;
$filenames[] = $untrustedFilename;
Expand All @@ -94,6 +109,9 @@ public function check(array $authenticatorCertificates, array $trustedCertificat
$processArguments[] = $leafFilename;
if ($hasCrls) {
array_unshift($processArguments, '-crl_check');
array_unshift($processArguments, '-crl_check_all');
array_unshift($processArguments, '-crl_download');
array_unshift($processArguments, '-extended_crl');
}
array_unshift($processArguments, 'openssl', 'verify');

Expand All @@ -113,6 +131,7 @@ public function check(array $authenticatorCertificates, array $trustedCertificat
$this->deleteDirectory($caDirname);

if (!$process->isSuccessful()) {
dump($process->getCommandLine());
throw new InvalidArgumentException('Invalid certificate or certificate chain');
}
}
Expand Down Expand Up @@ -164,26 +183,19 @@ private function deleteDirectory(string $dirname): void
}
}

private function prepareCertificate(string $folder, string $certificate, string $prefix, string $suffix, bool &$hasCrls): string
private function saveToTemporaryFile(string $folder, string $certificate, string $prefix, string $suffix): string
{
$untrustedFilename = tempnam($folder, $prefix);
rename($untrustedFilename, $untrustedFilename.$suffix);
file_put_contents($untrustedFilename.$suffix, $certificate, FILE_APPEND);

$crl = $this->getCrls($certificate);
if ('' !== $crl) {
$hasCrls = true;
file_put_contents($untrustedFilename.$suffix, PHP_EOL, FILE_APPEND);
file_put_contents($untrustedFilename.$suffix, $crl, FILE_APPEND);
}
$filename = tempnam($folder, $prefix);
rename($filename, $filename.$suffix);
file_put_contents($filename.$suffix, $certificate, FILE_APPEND);

return $untrustedFilename.$suffix;
return $filename.$suffix;
}

private function getCrls(string $certificate): string
{
$parsed = openssl_x509_parse($certificate);
if ($parsed === false || !isset($parsed['extensions']['crlDistributionPoints'])) {
if (false === $parsed || !isset($parsed['extensions']['crlDistributionPoints'])) {
return '';
}
$endpoint = $parsed['extensions']['crlDistributionPoints'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AndroidSafetyNetAttestationStatementTest extends AbstractTestCase
public function anExpiredAndroidSafetyNetAttestationCannotBeVerified(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The certificate expired');
$this->expectExceptionMessage('Invalid certificate or certificate chain');
$publicKeyCredentialCreationOptions = PublicKeyCredentialCreationOptions
::create(
new PublicKeyCredentialRpEntity('My Application'),
Expand Down