Spatie\Commands\ResolveCommand::getCertificateChain PHP Method

getCertificateChain() protected method

Get a string with the contents of the given certificatefile and it's entire trust chain.
protected getCertificateChain ( string $certificateFile, Symfony\Component\Console\Output\OutputInterface $output ) : string
$certificateFile string
$output Symfony\Component\Console\Output\OutputInterface
return string
    protected function getCertificateChain($certificateFile, OutputInterface $output)
    {
        $output->writeln('');
        $certificateCounter = 1;
        $certificate = new Certificate(file_get_contents($certificateFile));
        $certificateChain = $certificate->getContents();
        while ($certificate->hasParentInTrustChain()) {
            $output->writeln('<comment>Adding certificate ' . $certificateCounter . '</comment>');
            $output->writeln('<comment>downloading certificate from URL: ' . $certificate->getParentCertificateURL() . '</comment>');
            $httpResponse = $this->httpClient->get($certificate->getParentCertificateURL());
            if ($httpResponse->getStatusCode() != 200) {
                throw new Exception('could not download certifcate at ' . $certificate->getParentCertificateURL());
            }
            $certificate = new Certificate((string) $httpResponse->getBody());
            $certificateChain .= $certificate->getContents();
            $output->writeln('<comment>added downloaded certificate to trustchain, issuer DN: ' . $certificate->getIssuerDN() . '</comment>');
            $output->writeln('');
            $certificateCounter++;
        }
        return $certificateChain;
    }