Skip to content

Commit 4780c7b

Browse files
committed
Self Signed detection
Fix self signed detection, switch to authorityKeyIdentifier instead of compare subject and issuer
1 parent b57d37f commit 4780c7b

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

src/Attestation/Format/FormatBase.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,23 @@ protected function _createX5cChainFile() {
9696
if (\is_array($this->_x5c_chain) && \count($this->_x5c_chain) > 0) {
9797
foreach ($this->_x5c_chain as $x5c) {
9898
$certInfo = \openssl_x509_parse($this->_createCertificatePem($x5c));
99-
// check if issuer = subject (self signed)
99+
100+
// check if certificate is self signed
100101
if (\is_array($certInfo) && \is_array($certInfo['issuer']) && \is_array($certInfo['subject'])) {
101-
$selfSigned = true;
102-
foreach ($certInfo['issuer'] as $k => $v) {
103-
if ($certInfo['subject'][$k] !== $v) {
104-
$selfSigned = false;
105-
break;
106-
}
102+
$selfSigned = false;
103+
104+
$subjectKeyIdentifier = $certInfo['extensions']['subjectKeyIdentifier'] ?? null;
105+
$authorityKeyIdentifier = $certInfo['extensions']['authorityKeyIdentifier'] ?? null;
106+
107+
if ($authorityKeyIdentifier && substr($authorityKeyIdentifier, 0, 6) === 'keyid:') {
108+
$authorityKeyIdentifier = substr($authorityKeyIdentifier, 6);
109+
}
110+
if ($subjectKeyIdentifier && substr($subjectKeyIdentifier, 0, 6) === 'keyid:') {
111+
$subjectKeyIdentifier = substr($subjectKeyIdentifier, 6);
112+
}
113+
114+
if (($subjectKeyIdentifier && !$authorityKeyIdentifier) || ($authorityKeyIdentifier && $authorityKeyIdentifier === $subjectKeyIdentifier)) {
115+
$selfSigned = true;
107116
}
108117

109118
if (!$selfSigned) {

0 commit comments

Comments
 (0)