public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
PHP
49%
JavaScript
35%
HTML
9%
CSS
4%
Shell
2%
Python
1%
Lua
0%
Perl
0%
Ruby
0%
SCSS
0%
Create file
Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git
Trace
data/web/inc/lib/WebAuthn/Attestation/Format/AndroidKey.php
Trace helps you understand code history line by line. See who changed each line, when it changed, and which commit introduced it.
Author
Date
Commit
Line
Code
1
<?php
3
namespace lbuchs\WebAuthn\Attestation\Format;
4
use lbuchs\WebAuthn\Attestation\AuthenticatorData;
5
use lbuchs\WebAuthn\WebAuthnException;
6
use lbuchs\WebAuthn\Binary\ByteBuffer;
8
class AndroidKey extends FormatBase {
9
private $_alg;
10
private $_signature;
11
private $_x5c;
13
public function __construct($AttestionObject, AuthenticatorData $authenticatorData) {
14
parent::__construct($AttestionObject, $authenticatorData);
16
// check u2f data
17
$attStmt = $this->_attestationObject['attStmt'];
19
if (!\array_key_exists('alg', $attStmt) || $this->_getCoseAlgorithm($attStmt['alg']) === null) {
20
throw new WebAuthnException('unsupported alg: ' . $attStmt['alg'], WebAuthnException::INVALID_DATA);
21
}
23
if (!\array_key_exists('sig', $attStmt) || !\is_object($attStmt['sig']) || !($attStmt['sig'] instanceof ByteBuffer)) {
24
throw new WebAuthnException('no signature found', WebAuthnException::INVALID_DATA);
25
}
27
if (!\array_key_exists('x5c', $attStmt) || !\is_array($attStmt['x5c']) || \count($attStmt['x5c']) < 1) {
28
throw new WebAuthnException('invalid x5c certificate', WebAuthnException::INVALID_DATA);
29
}
31
if (!\is_object($attStmt['x5c'][0]) || !($attStmt['x5c'][0] instanceof ByteBuffer)) {
32
throw new WebAuthnException('invalid x5c certificate', WebAuthnException::INVALID_DATA);
33
}
35
$this->_alg = $attStmt['alg'];
36
$this->_signature = $attStmt['sig']->getBinaryString();
37
$this->_x5c = $attStmt['x5c'][0]->getBinaryString();
39
if (count($attStmt['x5c']) > 1) {
40
for ($i=1; $i<count($attStmt['x5c']); $i++) {
41
$this->_x5c_chain[] = $attStmt['x5c'][$i]->getBinaryString();
42
}
43
unset ($i);
44
}
45
}
48
/*
49
* returns the key certificate in PEM format
50
* @return string
51
*/
52
public function getCertificatePem() {
53
return $this->_createCertificatePem($this->_x5c);
54
}
56
/**
57
* @param string $clientDataHash
58
*/
59
public function validateAttestation($clientDataHash) {
60
$publicKey = \openssl_pkey_get_public($this->getCertificatePem());
62
if ($publicKey === false) {
63
throw new WebAuthnException('invalid public key: ' . \openssl_error_string(), WebAuthnException::INVALID_PUBLIC_KEY);
64
}
66
// Verify that sig is a valid signature over the concatenation of authenticatorData and clientDataHash
67
// using the attestation public key in attestnCert with the algorithm specified in alg.
68
$dataToVerify = $this->_authenticatorData->getBinary();
69
$dataToVerify .= $clientDataHash;
71
$coseAlgorithm = $this->_getCoseAlgorithm($this->_alg);
73
// check certificate
74
return \openssl_verify($dataToVerify, $this->_signature, $publicKey, $coseAlgorithm->openssl) === 1;
75
}
77
/**
78
* validates the certificate against root certificates
79
* @param array $rootCas
80
* @return boolean
81
* @throws WebAuthnException
82
*/
83
public function validateRootCertificate($rootCas) {
84
$chainC = $this->_createX5cChainFile();
85
if ($chainC) {
86
$rootCas[] = $chainC;
87
}
89
$v = \openssl_x509_checkpurpose($this->getCertificatePem(), -1, $rootCas);
90
if ($v === -1) {
91
throw new WebAuthnException('error on validating root certificate: ' . \openssl_error_string(), WebAuthnException::CERTIFICATE_NOT_TRUSTED);
92
}
93
return $v;
94
}
95
}