diff --git a/src/LEAccount.php b/src/LEAccount.php index cff2d6d..027c4e0 100644 --- a/src/LEAccount.php +++ b/src/LEAccount.php @@ -96,7 +96,7 @@ private function createLEAccount($email) $sign = $this->connector->signRequestJWK(array('contact' => $contact, 'termsOfServiceAgreed' => true), $this->connector->newAccount); $post = $this->connector->post($this->connector->newAccount, $sign); - if(strpos($post['header'], "201 Created") !== false) + if($post['status'] === 201) { if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]); } @@ -113,7 +113,7 @@ private function getLEAccount() $sign = $this->connector->signRequestJWK(array('onlyReturnExisting' => true), $this->connector->newAccount); $post = $this->connector->post($this->connector->newAccount, $sign); - if(strpos($post['header'], "200 OK") !== false) + if($post['status'] === 200) { if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]); } @@ -127,7 +127,7 @@ private function getLEAccountData() { $sign = $this->connector->signRequestKid(array('' => ''), $this->connector->accountURL, $this->connector->accountURL); $post = $this->connector->post($this->connector->accountURL, $sign); - if(strpos($post['header'], "200 OK") !== false) + if($post['status'] === 200) { $this->id = isset($post['body']['id']) ? $post['body']['id'] : ''; $this->key = $post['body']['key']; @@ -156,7 +156,7 @@ public function updateAccount($email) $sign = $this->connector->signRequestKid(array('contact' => $contact), $this->connector->accountURL, $this->connector->accountURL); $post = $this->connector->post($this->connector->accountURL, $sign); - if(strpos($post['header'], "200 OK") !== false) + if($post['status'] === 200) { $this->id = $post['body']['id']; $this->key = $post['body']['key']; @@ -196,7 +196,7 @@ public function changeAccountKeys() $outerPayload = $this->connector->signRequestJWK($innerPayload, $this->connector->keyChange, $this->accountKeys['private_key'].'.new'); $sign = $this->connector->signRequestKid($outerPayload, $this->connector->accountURL, $this->connector->keyChange); $post = $this->connector->post($this->connector->keyChange, $sign); - if(strpos($post['header'], "200 OK") !== false) + if($post['status'] === 200) { unlink($this->accountKeys['private_key']); unlink($this->accountKeys['public_key']); @@ -227,7 +227,7 @@ public function deactivateAccount() { $sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $this->connector->accountURL); $post = $this->connector->post($this->connector->accountURL, $sign); - if(strpos($post['header'], "200 OK") !== false) + if($post['status'] === 200) { $this->connector->accountDeactivated = true; if($this->log instanceof \Psr\Log\LoggerInterface) diff --git a/src/LEAuthorization.php b/src/LEAuthorization.php index 8b216dd..8277e7b 100644 --- a/src/LEAuthorization.php +++ b/src/LEAuthorization.php @@ -61,7 +61,7 @@ public function __construct($connector, $log, $authorizationURL) $this->authorizationURL = $authorizationURL; $get = $this->connector->get($this->authorizationURL); - if(strpos($get['header'], "200 OK") !== false) + if($get['status'] === 200) { $this->identifier = $get['body']['identifier']; $this->status = $get['body']['status']; @@ -85,7 +85,7 @@ public function __construct($connector, $log, $authorizationURL) public function updateData() { $get = $this->connector->get($this->authorizationURL); - if(strpos($get['header'], "200 OK") !== false) + if($get['status'] === 200) { $this->identifier = $get['body']['identifier']; $this->status = $get['body']['status']; diff --git a/src/LEConnector.php b/src/LEConnector.php index 47e2dfd..019c50f 100644 --- a/src/LEConnector.php +++ b/src/LEConnector.php @@ -87,7 +87,7 @@ private function getLEDirectory() */ private function getNewNonce() { - if(strpos($this->head($this->newNonce)['header'], "200 OK") == false) throw new \RuntimeException('No new nonce.'); + if($this->head($this->newNonce)['status'] !== 200) throw new \RuntimeException('No new nonce.'); } /** @@ -97,7 +97,7 @@ private function getNewNonce() * @param string $URL The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended. * @param object $data The body to attach to a POST request. Expected as a JSON encoded string. * - * @return array Returns an array with the keys 'request', 'header' and 'body'. + * @return array Returns an array with the keys 'request', 'header', 'status' and 'body'. */ private function request($method, $URL, $data = null) { @@ -132,20 +132,26 @@ private function request($method, $URL, $data = null) throw new \RuntimeException('Curl: ' . curl_error($handle)); } - $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE); + $headerSize = curl_getinfo($handle, CURLINFO_HEADER_SIZE); + $statusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); - $header = substr($response, 0, $header_size); - $body = substr($response, $header_size); + $header = substr($response, 0, $headerSize); + $body = substr($response, $headerSize); $jsonbody = json_decode($body, true); - $jsonresponse = array('request' => $method . ' ' . $requestURL, 'header' => $header, 'body' => $jsonbody === null ? $body : $jsonbody); + $jsonresponse = array( + 'request' => $method . ' ' . $requestURL, + 'header' => $header, + 'status' => $statusCode, + 'body' => $jsonbody === null ? $body : $jsonbody, + ); if($this->log instanceof \Psr\Log\LoggerInterface) { $this->log->debug($method . ' response received', $jsonresponse); } elseif($this->log >= LEClient::LOG_DEBUG) LEFunctions::log($jsonresponse); - if( (($method == 'POST' OR $method == 'GET') AND strpos($header, "200 OK") === false AND strpos($header, "201 Created") === false) OR - ($method == 'HEAD' AND strpos($header, "200 OK") === false)) + if((($method == 'POST' OR $method == 'GET') AND $statusCode !== 200 AND $statusCode !== 201) OR + ($method == 'HEAD' AND $statusCode !== 200)) { throw new \RuntimeException('Invalid response, header: ' . $header); } @@ -167,7 +173,7 @@ private function request($method, $URL, $data = null) * * @param string $url The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended. * - * @return array Returns an array with the keys 'request', 'header' and 'body'. + * @return array Returns an array with the keys 'request', 'header', 'status' and 'body'. */ public function get($url) { @@ -180,7 +186,7 @@ public function get($url) * @param string $url The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended. * @param object $data The body to attach to a POST request. Expected as a json string. * - * @return array Returns an array with the keys 'request', 'header' and 'body'. + * @return array Returns an array with the keys 'request', 'header', 'status' and 'body'. */ public function post($url, $data = null) { @@ -192,7 +198,7 @@ public function post($url, $data = null) * * @param string $url The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended. * - * @return array Returns an array with the keys 'request', 'header' and 'body'. + * @return array Returns an array with the keys 'request', 'header', 'status' and 'body'. */ public function head($url) { diff --git a/src/LEOrder.php b/src/LEOrder.php index 3518091..d10a854 100644 --- a/src/LEOrder.php +++ b/src/LEOrder.php @@ -107,7 +107,7 @@ public function __construct($connector, $log, $certificateKeys, $basename, $doma if (filter_var($this->orderURL, FILTER_VALIDATE_URL)) { $get = $this->connector->get($this->orderURL); - if(strpos($get['header'], "200 OK") !== false && $get['body']['status'] != "invalid") + if($get['status'] === 200 && $get['body']['status'] != "invalid") { $orderdomains = array_map(function($ident) { return $ident['value']; }, $get['body']['identifiers']); $diff = array_merge(array_diff($orderdomains, $domains), array_diff($domains, $orderdomains)); @@ -198,7 +198,7 @@ private function createOrder($domains, $notBefore, $notAfter) $sign = $this->connector->signRequestKid($payload, $this->connector->accountURL, $this->connector->newOrder); $post = $this->connector->post($this->connector->newOrder, $sign); - if(strpos($post['header'], "201 Created") !== false) + if($post['status'] === 201) { if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) { @@ -253,7 +253,7 @@ private function createOrder($domains, $notBefore, $notAfter) private function updateOrderData() { $get = $this->connector->get($this->orderURL); - if(strpos($get['header'], "200 OK") !== false) + if($get['status'] === 200) { $this->status = $get['body']['status']; $this->expires = $get['body']['expires']; @@ -398,7 +398,7 @@ public function verifyPendingOrderAuthorization($identifier, $type, $localcheck { $sign = $this->connector->signRequestKid(array('keyAuthorization' => $keyAuthorization), $this->connector->accountURL, $challenge['url']); $post = $this->connector->post($challenge['url'], $sign); - if(strpos($post['header'], "200 OK") !== false) + if($post['status'] === 200) { if($localcheck) { @@ -431,7 +431,7 @@ public function verifyPendingOrderAuthorization($identifier, $type, $localcheck { $sign = $this->connector->signRequestKid(array('keyAuthorization' => $keyAuthorization), $this->connector->accountURL, $challenge['url']); $post = $this->connector->post($challenge['url'], $sign); - if(strpos($post['header'], "200 OK") !== false) + if($post['status'] === 200) { if($localcheck) { @@ -481,7 +481,7 @@ public function deactivateOrderAuthorization($identifier) { $sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $auth->authorizationURL); $post = $this->connector->post($auth->authorizationURL, $sign); - if(strpos($post['header'], "200 OK") !== false) + if($post['status'] === 200) { if($this->log instanceof \Psr\Log\LoggerInterface) { @@ -573,7 +573,7 @@ public function finalizeOrder($csr = '') $csr = trim(LEFunctions::Base64UrlSafeEncode(base64_decode($csr))); $sign = $this->connector->signRequestKid(array('csr' => $csr), $this->connector->accountURL, $this->finalizeURL); $post = $this->connector->post($this->finalizeURL, $sign); - if(strpos($post['header'], "200 OK") !== false) + if($post['status'] === 200) { $this->status = $post['body']['status']; $this->expires = $post['body']['expires']; @@ -643,7 +643,7 @@ public function getCertificate() if($this->status == 'valid' && !empty($this->certificateURL)) { $get = $this->connector->get($this->certificateURL); - if(strpos($get['header'], "200 OK") !== false) + if($get['status'] === 200) { if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $get['body'], $matches)) { @@ -718,7 +718,7 @@ public function revokeCertificate($reason = 0) $sign = $this->connector->signRequestJWK(array('certificate' => $certificate, 'reason' => $reason), $this->connector->revokeCert, $this->certificateKeys['private_key']); $post = $this->connector->post($this->connector->revokeCert, $sign); - if(strpos($post['header'], "200 OK") !== false) + if($post['status'] === 200) { if($this->log instanceof \Psr\Log\LoggerInterface) {