Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #9 Add parent to CA to for chain storage + make final (sstok)
This PR was merged into the 1.0-dev branch. Discussion ---------- | Q | A | ------------- | --- | Bug fix? | no | New feature? |yes | BC breaks? | yes | Deprecations? | no | Fixed tickets | | License | MIT Make CAResolverImp and CA model final, this shouldn't be extended but a custom implementation should be used instead. Storing the CA directly isn't possible, and so it should be transformed to an application level entity instead. Something like this. ```php use Doctrine\Persistence\ObjectManager; use App\TLS\CA; use Rollerworks\Component\X509Validator\CA as CAInfo; use Rollerworks\Component\X509Validator\CAResolverImpl; use Rollerworks\Component\X509Validator\X509DataExtractor; /** * @Final */ class CAResolver { private X509DataExtractor $extractor; private CAResolverImpl $caResolver; /** * @param ObjectManager<CA> $objectManager */ public function __construct(private ObjectManager $objectManager) { $this->extractor = new X509DataExtractor(); $this->caResolver = new CAResolverImpl(); } /** * @param array<string, string> $caList */ public function resolve(string $certificate, array $caList): ?CA { $ca = $this->caResolver->resolve($certificate, $caList); if ($ca === null) { return null; } return $this->objectManager->find(CA::class, CA::getHash($ca->contents)) ?? $this->resolveCA($ca); } private function resolveCA(?CAInfo $ca): CA { /** @var array<int, string> $tree */ $tree = []; while ($ca !== null) { $tree[] = $ca->contents; $ca = $ca->parent; } $parent = null; foreach (array_reverse($tree) as $contents) { $caEntity = $this->objectManager->find(CA::class, CA::getHash($contents)); if ($caEntity === null) { $x509Info = $this->extractor->extractRawData($contents, '', true); $caEntity = new CA($contents, $x509Info->allFields, $parent); $this->objectManager->persist($caEntity); } $parent = $caEntity; } return $caEntity; } } ``` Commits ------- 662dc7c Add parent to CA to for chain storage + make final
- Loading branch information