private function doRequestCertificate($csr)
{
if (!is_string($csr)) {
throw new \InvalidArgumentException(sprintf("\$csr must be of type bool, %s given", gettype($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");
}
(yield new CoroutineResult(current($response->getHeader("location"))));
return;
}
throw $this->generateException($response);
}