lib/AcmeService.php
public function requestCertificate(string $csr): Promise {
        return call(function () use ($csr) {
            $begin = 'REQUEST-----';
            $end = '----END';

            $beginPos = strpos($csr, $begin) + strlen($begin);

            if ($beginPos === false) {
                throw new InvalidArgumentException("Invalid CSR, maybe not in PEM format?\n{$csr}");
            }

            $csr = substr($csr, $beginPos);

            $endPos = strpos($csr, $end);

            if ($endPos === false) {
                throw new InvalidArgumentException("Invalid CSR, maybe not in PEM format?\n{$csr}");
            }

            $csr = substr($csr, 0, $endPos);

            $enc = new Base64UrlSafeEncoder;

            /** @var Response $response */
            $response = yield $this->acmeClient->post(AcmeResource::NEW_CERTIFICATE, [
                'csr' => $enc->encode(base64_decode($csr)),
            ]);

            if ($response->getStatus() === 201) {
                if (!$response->hasHeader('location')) {
                    throw new AcmeException('Protocol Violation: No Location Header');
                }

                return $response->getHeader('location');
            }

            throw $this->generateException($response, yield $response->getBody());
        });
    }
public function requestCertificate(string $csr): Promise {
        return call(function () use ($csr) {
            $begin = 'REQUEST-----';
            $end = '----END';

            $beginPos = strpos($csr, $begin) + strlen($begin);

            if ($beginPos === false) {
                throw new InvalidArgumentException("Invalid CSR, maybe not in PEM format?\n{$csr}");
            }

            $csr = substr($csr, $beginPos);

            $endPos = strpos($csr, $end);

            if ($endPos === false) {
                throw new InvalidArgumentException("Invalid CSR, maybe not in PEM format?\n{$csr}");
            }

            $csr = substr($csr, 0, $endPos);

            $enc = new Base64UrlSafeEncoder;

            /** @var Response $response */
            $response = yield $this->acmeClient->post(AcmeResource::NEW_CERTIFICATE, [
                'csr' => $enc->encode(base64_decode($csr)),
            ]);

            if ($response->getStatus() === 201) {
                if (!$response->hasHeader('location')) {
                    throw new AcmeException('Protocol Violation: No Location Header');
                }

                return $response->getHeader('location');
            }

            throw $this->generateException($response, yield $response->getBody());
        });
    }
public function requestCertificate ( string $ csr ) : Promise { return call ( function ( ) use ( $ csr ) { $ begin = 'REQUEST-----' ; $ end = '----END' ; $ beginPos = strpos ( $ csr , $ begin ) + strlen ( $ begin ) ; if ( $ beginPos === false ) { throw new InvalidArgumentException ( "Invalid CSR, maybe not in PEM format?\n{$csr}" ) ; } $ csr = substr ( $ csr , $ beginPos ) ; $ endPos = strpos ( $ csr , $ end ) ; if ( $ endPos === false ) { throw new InvalidArgumentException ( "Invalid CSR, maybe not in PEM format?\n{$csr}" ) ; } $ csr = substr ( $ csr , 0 , $ endPos ) ; $ enc = new Base64UrlSafeEncoder ; /** @var Response $response */ $ response = yield $ this -> acmeClient -> post ( AcmeResource :: NEW_CERTIFICATE , [ 'csr' => $ enc -> encode ( base64_decode ( $ csr ) ) , ] ) ; if ( $ response -> getStatus ( ) === 201 ) { if ( ! $ response -> hasHeader ( 'location' ) ) { throw new AcmeException ( 'Protocol Violation: No Location Header' ) ; } return $ response -> getHeader ( 'location' ) ; } throw $ this -> generateException ( $ response , yield $ response -> getBody ( ) ) ; } ) ; }
Requests a new certificate.

@api

@param string $csr certificate signing request

@return Promise resolves to the URI where the certificate will be provided
@throws AcmeException If something went wrong.
Requests a new certificate .