Author: Titouan Galopin (galopintitouan@gmail.com)
Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function handle($config, CertificateResponse $response)
 {
     $domain = $response->getCertificateRequest()->getDistinguishedName()->getCommonName();
     $privateKey = $response->getCertificateRequest()->getKeyPair()->getPrivateKey();
     $certificate = $response->getCertificate();
     $this->repository->save('nginxproxy/' . $domain . '.key', $this->serializer->serialize($privateKey, PemEncoder::FORMAT));
     // Simple certificate
     $certPem = $this->serializer->serialize($certificate, PemEncoder::FORMAT);
     // Issuer chain
     $issuerChain = [];
     $issuerCertificate = $certificate->getIssuerCertificate();
     while (null !== $issuerCertificate) {
         $issuerChain[] = $this->serializer->serialize($issuerCertificate, PemEncoder::FORMAT);
         $issuerCertificate = $issuerCertificate->getIssuerCertificate();
     }
     $chainPem = implode("\n", $issuerChain);
     // Full chain
     $fullChainPem = $certPem . $chainPem;
     $this->repository->save('nginxproxy/' . $domain . '.crt', $fullChainPem);
 }
Ejemplo n.º 2
0
 /**
  * Retrieve the stored distinguishedName or create a new one if needed.
  *
  * @param string $domain
  * @param array  $alternativeNames
  *
  * @return DistinguishedName
  */
 private function getOrCreateDistinguishedName($domain, array $alternativeNames)
 {
     if ($this->repository->hasDomainDistinguishedName($domain)) {
         $original = $this->repository->loadDomainDistinguishedName($domain);
         $distinguishedName = new DistinguishedName($domain, $this->input->getOption('country') ?: $original->getCountryName(), $this->input->getOption('province') ?: $original->getStateOrProvinceName(), $this->input->getOption('locality') ?: $original->getLocalityName(), $this->input->getOption('organization') ?: $original->getOrganizationName(), $this->input->getOption('unit') ?: $original->getOrganizationalUnitName(), $this->input->getOption('email') ?: $original->getEmailAddress(), $alternativeNames);
     } else {
         // Ask DistinguishedName
         $distinguishedName = new DistinguishedName($domain, $this->input->getOption('country'), $this->input->getOption('province'), $this->input->getOption('locality'), $this->input->getOption('organization'), $this->input->getOption('unit'), $this->input->getOption('email'), $alternativeNames);
         /** @var DistinguishedNameHelper $helper */
         $helper = $this->getHelper('distinguished_name');
         if (!$helper->isReadyForRequest($distinguishedName)) {
             $asked = true;
             $this->output->writeln("\n\nSome informations about you or your company are required for the certificate:\n");
             $distinguishedName = $helper->ask($this->getHelper('question'), $this->input, $this->output, $distinguishedName);
         }
     }
     $this->repository->storeDomainDistinguishedName($domain, $distinguishedName);
     return $distinguishedName;
 }