Skip to content

Commit

Permalink
Self Signed detection
Browse files Browse the repository at this point in the history
Fix self signed detection, switch to authorityKeyIdentifier instead of compare subject and issuer
  • Loading branch information
lbuchs committed Nov 21, 2022
1 parent b57d37f commit 4780c7b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Attestation/Format/FormatBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,23 @@ protected function _createX5cChainFile() {
if (\is_array($this->_x5c_chain) && \count($this->_x5c_chain) > 0) {
foreach ($this->_x5c_chain as $x5c) {
$certInfo = \openssl_x509_parse($this->_createCertificatePem($x5c));
// check if issuer = subject (self signed)

// check if certificate is self signed
if (\is_array($certInfo) && \is_array($certInfo['issuer']) && \is_array($certInfo['subject'])) {
$selfSigned = true;
foreach ($certInfo['issuer'] as $k => $v) {
if ($certInfo['subject'][$k] !== $v) {
$selfSigned = false;
break;
}
$selfSigned = false;

$subjectKeyIdentifier = $certInfo['extensions']['subjectKeyIdentifier'] ?? null;
$authorityKeyIdentifier = $certInfo['extensions']['authorityKeyIdentifier'] ?? null;

if ($authorityKeyIdentifier && substr($authorityKeyIdentifier, 0, 6) === 'keyid:') {
$authorityKeyIdentifier = substr($authorityKeyIdentifier, 6);
}
if ($subjectKeyIdentifier && substr($subjectKeyIdentifier, 0, 6) === 'keyid:') {
$subjectKeyIdentifier = substr($subjectKeyIdentifier, 6);
}

if (($subjectKeyIdentifier && !$authorityKeyIdentifier) || ($authorityKeyIdentifier && $authorityKeyIdentifier === $subjectKeyIdentifier)) {
$selfSigned = true;
}

if (!$selfSigned) {
Expand Down

0 comments on commit 4780c7b

Please sign in to comment.