Skip to content

Commit

Permalink
Skipping unwanted extensions (#26)
Browse files Browse the repository at this point in the history
* Skipping unwanted extensions

* phpstan fix
  • Loading branch information
jaytaph authored Feb 23, 2023
1 parent 26596d4 commit 7ccaca7
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions src/UziReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getDataFromRequest(Request $request): ?UziUser

$uziInfo = new UziUser();

// Check if the certificate is a UZI certificate
// Check if the certificate is an UZI certificate
foreach ($cert['tbsCertificate']['subject']['rdnSequence'] as $sequence) {
$data = reset($sequence);
if ($data['type'] === 'id-at-surname') {
Expand All @@ -47,49 +47,51 @@ public function getDataFromRequest(Request $request): ?UziUser
}

foreach ($cert['tbsCertificate']['extensions'] ?? [] as $extension) {
if ($extension['extnId'] !== "id-ce-subjectAltName") {
continue;
if ($extension['extnId'] === "id-ce-subjectAltName") {
$this->parseSubjectAltName($extension, $uziInfo);
}
}

foreach ($extension['extnValue'] as $value) {
if (!isset($value['otherName']) || $value['otherName']['type-id'] !== UziConstants::OID_IA5STRING) {
return null;
}
// Only return the uzi info when we have a filled in uzi number
return $uziInfo->getUziNumber() ? $uziInfo : null;
}

if (!isset($value['otherName']['value']['ia5String'])) {
return null;
}
protected function parseSubjectAltName(array $extension, UziUser $uziInfo): void
{
foreach ($extension['extnValue'] as $value) {
if (!isset($value['otherName']) || $value['otherName']['type-id'] !== UziConstants::OID_IA5STRING) {
continue;
}

/**
* @var array $data
* Reference page 60
*
* [0] OID CA
* [1] UZI Version
* [2] UZI number
* [3] Card type
* [4] Subscriber number
* [5] Role (reference page 89)
* [6] AGB code
*/
$subjectAltName = $value['otherName']['value']['ia5String'];
/** @var string[]|false $data */
$data = explode('-', $subjectAltName);
if (!is_array($data) || count($data) < 6) {
return null;
}
$uziInfo->setOidCa($data[0]);
$uziInfo->setUziVersion($data[1]);
$uziInfo->setUziNumber($data[2]);
$uziInfo->setCardType($data[3]);
$uziInfo->setSubscriberNumber($data[4]);
$uziInfo->setRole($data[5]);
$uziInfo->setAgbCode($data[6]);
if (!isset($value['otherName']['value']['ia5String'])) {
continue;
}

return $uziInfo;
/**
* @var array $data
* Reference page 60
*
* [0] OID CA
* [1] UZI Version
* [2] UZI number
* [3] Card type
* [4] Subscriber number
* [5] Role (reference page 89)
* [6] AGB code
*/
$subjectAltName = $value['otherName']['value']['ia5String'];
/** @var string[]|false $data */
$data = explode('-', $subjectAltName);
if (!is_array($data) || count($data) < 6) {
continue;
}
$uziInfo->setOidCa($data[0]);
$uziInfo->setUziVersion($data[1]);
$uziInfo->setUziNumber($data[2]);
$uziInfo->setCardType($data[3]);
$uziInfo->setSubscriberNumber($data[4]);
$uziInfo->setRole($data[5]);
$uziInfo->setAgbCode($data[6]);
}

return null;
}
}

0 comments on commit 7ccaca7

Please sign in to comment.