@@ -89,7 +89,9 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | private function getNewNonce() |
| 91 | 91 | { |
| 92 | - if($this->head($this->newNonce)['status'] !== 200) throw LEConnectorException::NoNewNonceException(); |
|
| 92 | + if($this->head($this->newNonce)['status'] !== 200) { |
|
| 93 | + throw LEConnectorException::NoNewNonceException(); |
|
| 94 | + } |
|
| 93 | 95 | } |
| 94 | 96 | |
| 95 | 97 | /** |
@@ -103,7 +105,9 @@ discard block |
||
| 103 | 105 | */ |
| 104 | 106 | private function request($method, $URL, $data = null) |
| 105 | 107 | { |
| 106 | - if($this->accountDeactivated) throw LEConnectorException::AccountDeactivatedException(); |
|
| 108 | + if($this->accountDeactivated) { |
|
| 109 | + throw LEConnectorException::AccountDeactivatedException(); |
|
| 110 | + } |
|
| 107 | 111 | |
| 108 | 112 | $headers = array('Accept: application/json', 'Content-Type: application/jose+json'); |
| 109 | 113 | $requestURL = preg_match('~^http~', $URL) ? $URL : $this->baseURL . $URL; |
@@ -149,16 +153,19 @@ discard block |
||
| 149 | 153 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 150 | 154 | { |
| 151 | 155 | $this->log->debug($method . ' response received', $jsonresponse); |
| 156 | + } elseif($this->log >= LEClient::LOG_DEBUG) { |
|
| 157 | + LEFunctions::log($jsonresponse); |
|
| 152 | 158 | } |
| 153 | - elseif($this->log >= LEClient::LOG_DEBUG) LEFunctions::log($jsonresponse); |
|
| 154 | 159 | |
| 155 | 160 | if(preg_match('~Replay\-Nonce: (\S+)~i', $header, $matches)) |
| 156 | 161 | { |
| 157 | 162 | $this->nonce = trim($matches[1]); |
| 158 | - } |
|
| 159 | - else |
|
| 163 | + } else |
|
| 160 | 164 | { |
| 161 | - if($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests. |
|
| 165 | + if($method == 'POST') { |
|
| 166 | + $this->getNewNonce(); |
|
| 167 | + } |
|
| 168 | + // Not expecting a new nonce with GET and HEAD requests. |
|
| 162 | 169 | } |
| 163 | 170 | |
| 164 | 171 | if((($method == 'POST' OR $method == 'GET') AND $statusCode !== 200 AND $statusCode !== 201) OR |
@@ -218,7 +225,9 @@ discard block |
||
| 218 | 225 | */ |
| 219 | 226 | public function signRequestJWK($payload, $url, $privateKeyFile = '') |
| 220 | 227 | { |
| 221 | - if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key']; |
|
| 228 | + if($privateKeyFile == '') { |
|
| 229 | + $privateKeyFile = $this->accountKeys['private_key']; |
|
| 230 | + } |
|
| 222 | 231 | $privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile)); |
| 223 | 232 | $details = openssl_pkey_get_details($privateKey); |
| 224 | 233 | |
@@ -260,7 +269,9 @@ discard block |
||
| 260 | 269 | */ |
| 261 | 270 | public function signRequestKid($payload, $kid, $url, $privateKeyFile = '') |
| 262 | 271 | { |
| 263 | - if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key']; |
|
| 272 | + if($privateKeyFile == '') { |
|
| 273 | + $privateKeyFile = $this->accountKeys['private_key']; |
|
| 274 | + } |
|
| 264 | 275 | $privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile)); |
| 265 | 276 | $details = openssl_pkey_get_details($privateKey); |
| 266 | 277 | |
@@ -71,17 +71,19 @@ discard block |
||
| 71 | 71 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 72 | 72 | { |
| 73 | 73 | $this->log->info('No account found, attempting to create account.'); |
| 74 | + } else if($this->log >= LECLient::LOG_STATUS) { |
|
| 75 | + LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct'); |
|
| 74 | 76 | } |
| 75 | - else if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct'); |
|
| 76 | 77 | |
| 77 | 78 | LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'], $this->accountKeys['public_key']); |
| 78 | 79 | $this->connector->accountURL = $this->createLEAccount($email); |
| 79 | - } |
|
| 80 | - else |
|
| 80 | + } else |
|
| 81 | 81 | { |
| 82 | 82 | $this->connector->accountURL = $this->getLEAccount(); |
| 83 | 83 | } |
| 84 | - if($this->connector->accountURL == false) throw LEAccountException::AccountNotFoundException(); |
|
| 84 | + if($this->connector->accountURL == false) { |
|
| 85 | + throw LEAccountException::AccountNotFoundException(); |
|
| 86 | + } |
|
| 85 | 87 | $this->getLEAccountData(); |
| 86 | 88 | } |
| 87 | 89 | |
@@ -100,7 +102,9 @@ discard block |
||
| 100 | 102 | $post = $this->connector->post($this->connector->newAccount, $sign); |
| 101 | 103 | if($post['status'] === 201) |
| 102 | 104 | { |
| 103 | - if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]); |
|
| 105 | + if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) { |
|
| 106 | + return trim($matches[1]); |
|
| 107 | + } |
|
| 104 | 108 | } |
| 105 | 109 | return false; |
| 106 | 110 | } |
@@ -117,7 +121,9 @@ discard block |
||
| 117 | 121 | |
| 118 | 122 | if($post['status'] === 200) |
| 119 | 123 | { |
| 120 | - if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]); |
|
| 124 | + if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) { |
|
| 125 | + return trim($matches[1]); |
|
| 126 | + } |
|
| 121 | 127 | } |
| 122 | 128 | return false; |
| 123 | 129 | } |
@@ -138,8 +144,7 @@ discard block |
||
| 138 | 144 | $this->initialIp = $post['body']['initialIp']; |
| 139 | 145 | $this->createdAt = $post['body']['createdAt']; |
| 140 | 146 | $this->status = $post['body']['status']; |
| 141 | - } |
|
| 142 | - else |
|
| 147 | + } else |
|
| 143 | 148 | { |
| 144 | 149 | throw LEAccountException::AccountNotFoundException(); |
| 145 | 150 | } |
@@ -170,11 +175,11 @@ discard block |
||
| 170 | 175 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 171 | 176 | { |
| 172 | 177 | $this->log->info('Account data updated.'); |
| 178 | + } else if($this->log >= LEClient::LOG_STATUS) { |
|
| 179 | + LEFunctions::log('Account data updated.', 'function updateAccount'); |
|
| 173 | 180 | } |
| 174 | - else if($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Account data updated.', 'function updateAccount'); |
|
| 175 | 181 | return true; |
| 176 | - } |
|
| 177 | - else |
|
| 182 | + } else |
|
| 178 | 183 | { |
| 179 | 184 | return false; |
| 180 | 185 | } |
@@ -210,11 +215,11 @@ discard block |
||
| 210 | 215 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 211 | 216 | { |
| 212 | 217 | $this->log->info('Account keys changed.'); |
| 218 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 219 | + LEFunctions::log('Account keys changed.', 'function changeAccountKey'); |
|
| 213 | 220 | } |
| 214 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Account keys changed.', 'function changeAccountKey'); |
|
| 215 | 221 | return true; |
| 216 | - } |
|
| 217 | - else |
|
| 222 | + } else |
|
| 218 | 223 | { |
| 219 | 224 | return false; |
| 220 | 225 | } |
@@ -235,12 +240,12 @@ discard block |
||
| 235 | 240 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 236 | 241 | { |
| 237 | 242 | $this->log->info('Account deactivated.'); |
| 243 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 244 | + LEFunctions::log('Account deactivated.', 'function deactivateAccount'); |
|
| 238 | 245 | } |
| 239 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Account deactivated.', 'function deactivateAccount'); |
|
| 240 | 246 | |
| 241 | 247 | return true; |
| 242 | - } |
|
| 243 | - else |
|
| 248 | + } else |
|
| 244 | 249 | { |
| 245 | 250 | return false; |
| 246 | 251 | } |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | $this->status = $post['body']['status']; |
| 71 | 71 | $this->expires = $post['body']['expires']; |
| 72 | 72 | $this->challenges = $post['body']['challenges']; |
| 73 | - } |
|
| 74 | - else |
|
| 73 | + } else |
|
| 75 | 74 | { |
| 76 | 75 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 77 | 76 | { |
| 78 | 77 | $this->log->info('Cannot find authorization \'' . $authorizationURL . '\'.'); |
| 78 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 79 | + LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct'); |
|
| 79 | 80 | } |
| 80 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct'); |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | |
@@ -95,14 +95,14 @@ discard block |
||
| 95 | 95 | $this->status = $post['body']['status']; |
| 96 | 96 | $this->expires = $post['body']['expires']; |
| 97 | 97 | $this->challenges = $post['body']['challenges']; |
| 98 | - } |
|
| 99 | - else |
|
| 98 | + } else |
|
| 100 | 99 | { |
| 101 | 100 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 102 | 101 | { |
| 103 | 102 | $this->log->info('Cannot find authorization \'' . $this->authorizationURL . '\'.'); |
| 103 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 104 | + LEFunctions::log('Cannot find authorization \'' . $this->authorizationURL . '\'.', 'function updateData'); |
|
| 104 | 105 | } |
| 105 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $this->authorizationURL . '\'.', 'function updateData'); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
@@ -118,7 +118,9 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | foreach($this->challenges as $challenge) |
| 120 | 120 | { |
| 121 | - if($challenge['type'] == $type) return $challenge; |
|
| 121 | + if($challenge['type'] == $type) { |
|
| 122 | + return $challenge; |
|
| 123 | + } |
|
| 122 | 124 | } |
| 123 | 125 | throw LEAuthorizationException::NoChallengeFoundException($type, $this->identifier['value']); |
| 124 | 126 | } |
@@ -50,7 +50,9 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public static function RSAGenerateKeys($directory, $privateKeyFile = 'private.pem', $publicKeyFile = 'public.pem', $keySize = 4096) |
| 52 | 52 | { |
| 53 | - if ($keySize < 2048 || $keySize > 4096) throw LEFunctionsException::InvalidArgumentException('RSA key size must be between 2048 and 4096.'); |
|
| 53 | + if ($keySize < 2048 || $keySize > 4096) { |
|
| 54 | + throw LEFunctionsException::InvalidArgumentException('RSA key size must be between 2048 and 4096.'); |
|
| 55 | + } |
|
| 54 | 56 | |
| 55 | 57 | $res = openssl_pkey_new(array( |
| 56 | 58 | "private_key_type" => OPENSSL_KEYTYPE_RSA, |
@@ -97,7 +99,9 @@ discard block |
||
| 97 | 99 | */ |
| 98 | 100 | public static function ECGenerateKeys($directory, $privateKeyFile = 'private.pem', $publicKeyFile = 'public.pem', $keySize = 256) |
| 99 | 101 | { |
| 100 | - if (version_compare(PHP_VERSION, '7.1.0') == -1) throw LEFunctionsException::PHPVersionException(); |
|
| 102 | + if (version_compare(PHP_VERSION, '7.1.0') == -1) { |
|
| 103 | + throw LEFunctionsException::PHPVersionException(); |
|
| 104 | + } |
|
| 101 | 105 | |
| 102 | 106 | if ($keySize == 256) |
| 103 | 107 | { |
@@ -105,18 +109,20 @@ discard block |
||
| 105 | 109 | "private_key_type" => OPENSSL_KEYTYPE_EC, |
| 106 | 110 | "curve_name" => "prime256v1", |
| 107 | 111 | )); |
| 108 | - } |
|
| 109 | - elseif ($keySize == 384) |
|
| 112 | + } elseif ($keySize == 384) |
|
| 110 | 113 | { |
| 111 | 114 | $res = openssl_pkey_new(array( |
| 112 | 115 | "private_key_type" => OPENSSL_KEYTYPE_EC, |
| 113 | 116 | "curve_name" => "secp384r1", |
| 114 | 117 | )); |
| 118 | + } else { |
|
| 119 | + throw LEFunctionsException::InvalidArgumentException('EC key size must be 256 or 384.'); |
|
| 115 | 120 | } |
| 116 | - else throw LEFunctionsException::InvalidArgumentException('EC key size must be 256 or 384.'); |
|
| 117 | 121 | |
| 118 | 122 | |
| 119 | - if(!openssl_pkey_export($res, $privateKey)) throw LEFunctionsException::GenerateKeypairException('EC keypair export failed!'); |
|
| 123 | + if(!openssl_pkey_export($res, $privateKey)) { |
|
| 124 | + throw LEFunctionsException::GenerateKeypairException('EC keypair export failed!'); |
|
| 125 | + } |
|
| 120 | 126 | |
| 121 | 127 | $details = openssl_pkey_get_details($res); |
| 122 | 128 | |
@@ -181,8 +187,7 @@ discard block |
||
| 181 | 187 | echo '[' . date('d-m-Y H:i:s') . '] ' . $function . ":\n"; |
| 182 | 188 | print_r($data); |
| 183 | 189 | echo "\n\n"; |
| 184 | - } |
|
| 185 | - else |
|
| 190 | + } else |
|
| 186 | 191 | { |
| 187 | 192 | echo '<b>' . date('d-m-Y H:i:s') . ', ' . $function . ':</b><br>'; |
| 188 | 193 | print_r($data); |
@@ -235,7 +240,9 @@ discard block |
||
| 235 | 240 | { |
| 236 | 241 | if($answer->type === 16) |
| 237 | 242 | { |
| 238 | - if($answer->data === ('"' . $DNSDigest . '"')) return true; |
|
| 243 | + if($answer->data === ('"' . $DNSDigest . '"')) { |
|
| 244 | + return true; |
|
| 245 | + } |
|
| 239 | 246 | } |
| 240 | 247 | } |
| 241 | 248 | } |
@@ -83,13 +83,11 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | $this->keyType = 'rsa'; |
| 85 | 85 | $this->keySize = 4096; |
| 86 | - } |
|
| 87 | - elseif ($keyType == 'ec') |
|
| 86 | + } elseif ($keyType == 'ec') |
|
| 88 | 87 | { |
| 89 | 88 | $this->keyType = 'ec'; |
| 90 | 89 | $this->keySize = 256; |
| 91 | - } |
|
| 92 | - else |
|
| 90 | + } else |
|
| 93 | 91 | { |
| 94 | 92 | preg_match_all('/^(rsa|ec)\-([0-9]{3,4})$/', $keyType, $keyTypeParts, PREG_SET_ORDER, 0); |
| 95 | 93 | |
@@ -97,8 +95,9 @@ discard block |
||
| 97 | 95 | { |
| 98 | 96 | $this->keyType = $keyTypeParts[0][1]; |
| 99 | 97 | $this->keySize = intval($keyTypeParts[0][2]); |
| 98 | + } else { |
|
| 99 | + throw LEOrderException::InvalidKeyTypeException($keyType); |
|
| 100 | 100 | } |
| 101 | - else throw LEOrderException::InvalidKeyTypeException($keyType); |
|
| 102 | 101 | } |
| 103 | 102 | |
| 104 | 103 | if(preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) == false OR preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter) == false) |
@@ -128,63 +127,71 @@ discard block |
||
| 128 | 127 | { |
| 129 | 128 | foreach ($this->certificateKeys as $file) |
| 130 | 129 | { |
| 131 | - if (is_file($file)) rename($file, $file.'.old'); |
|
| 130 | + if (is_file($file)) { |
|
| 131 | + rename($file, $file.'.old'); |
|
| 132 | + } |
|
| 132 | 133 | } |
| 133 | 134 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 134 | 135 | { |
| 135 | 136 | $this->log->info('Domains do not match order data. Renaming current files and creating new order.'); |
| 137 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 138 | + LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct'); |
|
| 136 | 139 | } |
| 137 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct'); |
|
| 138 | 140 | $this->createOrder($domains, $notBefore, $notAfter, $keyType); |
| 139 | - } |
|
| 140 | - else |
|
| 141 | + } else |
|
| 141 | 142 | { |
| 142 | 143 | $this->status = $post['body']['status']; |
| 143 | 144 | $this->expires = $post['body']['expires']; |
| 144 | 145 | $this->identifiers = $post['body']['identifiers']; |
| 145 | 146 | $this->authorizationURLs = $post['body']['authorizations']; |
| 146 | 147 | $this->finalizeURL = $post['body']['finalize']; |
| 147 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
| 148 | + if(array_key_exists('certificate', $post['body'])) { |
|
| 149 | + $this->certificateURL = $post['body']['certificate']; |
|
| 150 | + } |
|
| 148 | 151 | $this->updateAuthorizations(); |
| 149 | 152 | } |
| 150 | - } |
|
| 151 | - catch (\Exception $e) |
|
| 153 | + } catch (\Exception $e) |
|
| 152 | 154 | { |
| 153 | 155 | foreach ($this->certificateKeys as $file) |
| 154 | 156 | { |
| 155 | - if (is_file($file)) unlink($file); |
|
| 157 | + if (is_file($file)) { |
|
| 158 | + unlink($file); |
|
| 159 | + } |
|
| 156 | 160 | } |
| 157 | 161 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 158 | 162 | { |
| 159 | 163 | $this->log->info('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.'); |
| 164 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 165 | + LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
| 160 | 166 | } |
| 161 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
| 162 | 167 | $this->createOrder($domains, $notBefore, $notAfter); |
| 163 | 168 | } |
| 164 | - } |
|
| 165 | - else |
|
| 169 | + } else |
|
| 166 | 170 | { |
| 167 | 171 | |
| 168 | 172 | foreach ($this->certificateKeys as $file) |
| 169 | 173 | { |
| 170 | - if (is_file($file)) unlink($file); |
|
| 174 | + if (is_file($file)) { |
|
| 175 | + unlink($file); |
|
| 176 | + } |
|
| 171 | 177 | } |
| 172 | 178 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 173 | 179 | { |
| 174 | 180 | $this->log->info('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.'); |
| 181 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 182 | + LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
| 175 | 183 | } |
| 176 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct'); |
|
| 177 | 184 | |
| 178 | 185 | $this->createOrder($domains, $notBefore, $notAfter); |
| 179 | 186 | } |
| 180 | - } |
|
| 181 | - else |
|
| 187 | + } else |
|
| 182 | 188 | { |
| 183 | 189 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 184 | 190 | { |
| 185 | 191 | $this->log->info('No order found for \'' . $this->basename . '\'. Creating new order.'); |
| 192 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 193 | + LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct'); |
|
| 186 | 194 | } |
| 187 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct'); |
|
| 188 | 195 | $this->createOrder($domains, $notBefore, $notAfter); |
| 189 | 196 | } |
| 190 | 197 | } |
@@ -201,7 +208,9 @@ discard block |
||
| 201 | 208 | $dns = array(); |
| 202 | 209 | foreach($domains as $domain) |
| 203 | 210 | { |
| 204 | - if(preg_match_all('~(\*\.)~', $domain) > 1) throw LEOrderException::InvalidArgumentException('Cannot create orders with multiple wildcards in one domain.'); |
|
| 211 | + if(preg_match_all('~(\*\.)~', $domain) > 1) { |
|
| 212 | + throw LEOrderException::InvalidArgumentException('Cannot create orders with multiple wildcards in one domain.'); |
|
| 213 | + } |
|
| 205 | 214 | $dns[] = array('type' => 'dns', 'value' => $domain); |
| 206 | 215 | } |
| 207 | 216 | $payload = array("identifiers" => $dns, 'notBefore' => $notBefore, 'notAfter' => $notAfter); |
@@ -217,12 +226,10 @@ discard block |
||
| 217 | 226 | if ($this->keyType == "rsa") |
| 218 | 227 | { |
| 219 | 228 | LEFunctions::RSAgenerateKeys(null, $this->certificateKeys['private_key'], $this->certificateKeys['public_key'], $this->keySize); |
| 220 | - } |
|
| 221 | - elseif ($this->keyType == "ec") |
|
| 229 | + } elseif ($this->keyType == "ec") |
|
| 222 | 230 | { |
| 223 | 231 | LEFunctions::ECgenerateKeys(null, $this->certificateKeys['private_key'], $this->certificateKeys['public_key'], $this->keySize); |
| 224 | - } |
|
| 225 | - else |
|
| 232 | + } else |
|
| 226 | 233 | { |
| 227 | 234 | throw LEOrderException::InvalidKeyTypeException($this->keyType); |
| 228 | 235 | } |
@@ -232,21 +239,22 @@ discard block |
||
| 232 | 239 | $this->identifiers = $post['body']['identifiers']; |
| 233 | 240 | $this->authorizationURLs = $post['body']['authorizations']; |
| 234 | 241 | $this->finalizeURL = $post['body']['finalize']; |
| 235 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
| 242 | + if(array_key_exists('certificate', $post['body'])) { |
|
| 243 | + $this->certificateURL = $post['body']['certificate']; |
|
| 244 | + } |
|
| 236 | 245 | $this->updateAuthorizations(); |
| 237 | 246 | |
| 238 | 247 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 239 | 248 | { |
| 240 | 249 | $this->log->info('Created order for \'' . $this->basename . '\'.'); |
| 250 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 251 | + LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)'); |
|
| 241 | 252 | } |
| 242 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)'); |
|
| 243 | - } |
|
| 244 | - else |
|
| 253 | + } else |
|
| 245 | 254 | { |
| 246 | 255 | throw LEOrderException::CreateFailedException('New-order returned invalid response.'); |
| 247 | 256 | } |
| 248 | - } |
|
| 249 | - else |
|
| 257 | + } else |
|
| 250 | 258 | { |
| 251 | 259 | throw LEOrderException::CreateFailedException('Creating new order failed.'); |
| 252 | 260 | } |
@@ -266,16 +274,18 @@ discard block |
||
| 266 | 274 | $this->identifiers = $post['body']['identifiers']; |
| 267 | 275 | $this->authorizationURLs = $post['body']['authorizations']; |
| 268 | 276 | $this->finalizeURL = $post['body']['finalize']; |
| 269 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
| 277 | + if(array_key_exists('certificate', $post['body'])) { |
|
| 278 | + $this->certificateURL = $post['body']['certificate']; |
|
| 279 | + } |
|
| 270 | 280 | $this->updateAuthorizations(); |
| 271 | - } |
|
| 272 | - else |
|
| 281 | + } else |
|
| 273 | 282 | { |
| 274 | 283 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 275 | 284 | { |
| 276 | 285 | $this->log->info('Cannot update data for order \'' . $this->basename . '\'.'); |
| 286 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 287 | + LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData'); |
|
| 277 | 288 | } |
| 278 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData'); |
|
| 279 | 289 | } |
| 280 | 290 | } |
| 281 | 291 | |
@@ -290,7 +300,9 @@ discard block |
||
| 290 | 300 | if (filter_var($authURL, FILTER_VALIDATE_URL)) |
| 291 | 301 | { |
| 292 | 302 | $auth = new LEAuthorization($this->connector, $this->log, $authURL); |
| 293 | - if($auth != false) $this->authorizations[] = $auth; |
|
| 303 | + if($auth != false) { |
|
| 304 | + $this->authorizations[] = $auth; |
|
| 305 | + } |
|
| 294 | 306 | } |
| 295 | 307 | } |
| 296 | 308 | } |
@@ -306,7 +318,9 @@ discard block |
||
| 306 | 318 | { |
| 307 | 319 | foreach($this->authorizations as $auth) |
| 308 | 320 | { |
| 309 | - if($auth->status != 'valid') return false; |
|
| 321 | + if($auth->status != 'valid') { |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 310 | 324 | } |
| 311 | 325 | return true; |
| 312 | 326 | } |
@@ -411,8 +425,9 @@ discard block |
||
| 411 | 425 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 412 | 426 | { |
| 413 | 427 | $this->log->info('HTTP challenge for \'' . $identifier . '\' valid.'); |
| 428 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 429 | + LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
| 414 | 430 | } |
| 415 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
| 416 | 431 | } |
| 417 | 432 | while($auth->status == 'pending') |
| 418 | 433 | { |
@@ -421,14 +436,14 @@ discard block |
||
| 421 | 436 | } |
| 422 | 437 | return true; |
| 423 | 438 | } |
| 424 | - } |
|
| 425 | - else |
|
| 439 | + } else |
|
| 426 | 440 | { |
| 427 | 441 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 428 | 442 | { |
| 429 | 443 | $this->log->info('HTTP challenge for \'' . $identifier . '\' tested locally, found invalid.'); |
| 444 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 445 | + LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
| 430 | 446 | } |
| 431 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
| 432 | 447 | } |
| 433 | 448 | break; |
| 434 | 449 | case LEOrder::CHALLENGE_TYPE_DNS: |
@@ -444,8 +459,9 @@ discard block |
||
| 444 | 459 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 445 | 460 | { |
| 446 | 461 | $this->log->info('DNS challenge for \'' . $identifier . '\' valid.'); |
| 462 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 463 | + LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
| 447 | 464 | } |
| 448 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization'); |
|
| 449 | 465 | } |
| 450 | 466 | while($auth->status == 'pending') |
| 451 | 467 | { |
@@ -454,14 +470,14 @@ discard block |
||
| 454 | 470 | } |
| 455 | 471 | return true; |
| 456 | 472 | } |
| 457 | - } |
|
| 458 | - else |
|
| 473 | + } else |
|
| 459 | 474 | { |
| 460 | 475 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 461 | 476 | { |
| 462 | 477 | $this->log->info('DNS challenge for \'' . $identifier . '\' tested locally, found invalid.'); |
| 478 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 479 | + LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
| 463 | 480 | } |
| 464 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested locally, found invalid.', 'function verifyPendingOrderAuthorization'); |
|
| 465 | 481 | } |
| 466 | 482 | break; |
| 467 | 483 | } |
@@ -492,8 +508,9 @@ discard block |
||
| 492 | 508 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 493 | 509 | { |
| 494 | 510 | $this->log->info('Authorization for \'' . $identifier . '\' deactivated.'); |
| 511 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 512 | + LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization'); |
|
| 495 | 513 | } |
| 496 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization'); |
|
| 497 | 514 | $this->updateAuthorizations(); |
| 498 | 515 | return true; |
| 499 | 516 | } |
@@ -502,8 +519,9 @@ discard block |
||
| 502 | 519 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 503 | 520 | { |
| 504 | 521 | $this->log->info('No authorization found for \'' . $identifier . '\', cannot deactivate.'); |
| 522 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 523 | + LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization'); |
|
| 505 | 524 | } |
| 506 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization'); |
|
| 507 | 525 | return false; |
| 508 | 526 | } |
| 509 | 527 | |
@@ -519,12 +537,10 @@ discard block |
||
| 519 | 537 | if(in_array($this->basename, $domains)) |
| 520 | 538 | { |
| 521 | 539 | $CN = $this->basename; |
| 522 | - } |
|
| 523 | - elseif(in_array('*.' . $this->basename, $domains)) |
|
| 540 | + } elseif(in_array('*.' . $this->basename, $domains)) |
|
| 524 | 541 | { |
| 525 | 542 | $CN = '*.' . $this->basename; |
| 526 | - } |
|
| 527 | - else |
|
| 543 | + } else |
|
| 528 | 544 | { |
| 529 | 545 | $CN = $domains[0]; |
| 530 | 546 | } |
@@ -575,8 +591,12 @@ discard block |
||
| 575 | 591 | { |
| 576 | 592 | if($this->allAuthorizationsValid()) |
| 577 | 593 | { |
| 578 | - if(empty($csr)) $csr = $this->generateCSR(); |
|
| 579 | - if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1]; |
|
| 594 | + if(empty($csr)) { |
|
| 595 | + $csr = $this->generateCSR(); |
|
| 596 | + } |
|
| 597 | + if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) { |
|
| 598 | + $csr = $matches[1]; |
|
| 599 | + } |
|
| 580 | 600 | $csr = trim(LEFunctions::Base64UrlSafeEncode(base64_decode($csr))); |
| 581 | 601 | $sign = $this->connector->signRequestKid(array('csr' => $csr), $this->connector->accountURL, $this->finalizeURL); |
| 582 | 602 | $post = $this->connector->post($this->finalizeURL, $sign); |
@@ -587,32 +607,35 @@ discard block |
||
| 587 | 607 | $this->identifiers = $post['body']['identifiers']; |
| 588 | 608 | $this->authorizationURLs = $post['body']['authorizations']; |
| 589 | 609 | $this->finalizeURL = $post['body']['finalize']; |
| 590 | - if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate']; |
|
| 610 | + if(array_key_exists('certificate', $post['body'])) { |
|
| 611 | + $this->certificateURL = $post['body']['certificate']; |
|
| 612 | + } |
|
| 591 | 613 | $this->updateAuthorizations(); |
| 592 | 614 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 593 | 615 | { |
| 594 | 616 | $this->log->info('Order for \'' . $this->basename . '\' finalized.'); |
| 617 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 618 | + LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder'); |
|
| 595 | 619 | } |
| 596 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder'); |
|
| 597 | 620 | return true; |
| 598 | 621 | } |
| 599 | - } |
|
| 600 | - else |
|
| 622 | + } else |
|
| 601 | 623 | { |
| 602 | 624 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 603 | 625 | { |
| 604 | 626 | $this->log->info('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.'); |
| 627 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 628 | + LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
| 605 | 629 | } |
| 606 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
| 607 | 630 | } |
| 608 | - } |
|
| 609 | - else |
|
| 631 | + } else |
|
| 610 | 632 | { |
| 611 | 633 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 612 | 634 | { |
| 613 | 635 | $this->log->info('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.'); |
| 636 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 637 | + LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
| 614 | 638 | } |
| 615 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder'); |
|
| 616 | 639 | } |
| 617 | 640 | return false; |
| 618 | 641 | } |
@@ -641,8 +664,9 @@ discard block |
||
| 641 | 664 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 642 | 665 | { |
| 643 | 666 | $this->log->info('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...'); |
| 667 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 668 | + LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate'); |
|
| 644 | 669 | } |
| 645 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate'); |
|
| 646 | 670 | sleep(5); |
| 647 | 671 | $this->updateOrderData(); |
| 648 | 672 | $polling++; |
@@ -657,7 +681,9 @@ discard block |
||
| 657 | 681 | { |
| 658 | 682 | if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $post['body'], $matches)) |
| 659 | 683 | { |
| 660 | - if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]); |
|
| 684 | + if (isset($this->certificateKeys['certificate'])) { |
|
| 685 | + file_put_contents($this->certificateKeys['certificate'], $matches[0][0]); |
|
| 686 | + } |
|
| 661 | 687 | |
| 662 | 688 | if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate'])) |
| 663 | 689 | { |
@@ -671,44 +697,45 @@ discard block |
||
| 671 | 697 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 672 | 698 | { |
| 673 | 699 | $this->log->info('Certificate for \'' . $this->basename . '\' saved'); |
| 700 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 701 | + LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate'); |
|
| 674 | 702 | } |
| 675 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate'); |
|
| 676 | 703 | return true; |
| 677 | - } |
|
| 678 | - else |
|
| 704 | + } else |
|
| 679 | 705 | { |
| 680 | 706 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 681 | 707 | { |
| 682 | 708 | $this->log->info('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.'); |
| 709 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 710 | + LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
| 683 | 711 | } |
| 684 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
| 685 | 712 | } |
| 686 | - } |
|
| 687 | - else |
|
| 713 | + } else |
|
| 688 | 714 | { |
| 689 | 715 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 690 | 716 | { |
| 691 | 717 | $this->log->info('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.'); |
| 718 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 719 | + LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
| 692 | 720 | } |
| 693 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate'); |
|
| 694 | 721 | } |
| 695 | - } |
|
| 696 | - else |
|
| 722 | + } else |
|
| 697 | 723 | { |
| 698 | 724 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 699 | 725 | { |
| 700 | 726 | $this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.'); |
| 727 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 728 | + LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.', 'function getCertificate'); |
|
| 701 | 729 | } |
| 702 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot find certificate URL.', 'function getCertificate'); |
|
| 703 | 730 | } |
| 704 | - } |
|
| 705 | - else |
|
| 731 | + } else |
|
| 706 | 732 | { |
| 707 | 733 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 708 | 734 | { |
| 709 | 735 | $this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.'); |
| 736 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 737 | + LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate'); |
|
| 710 | 738 | } |
| 711 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate'); |
|
| 712 | 739 | } |
| 713 | 740 | return false; |
| 714 | 741 | } |
@@ -725,9 +752,13 @@ discard block |
||
| 725 | 752 | { |
| 726 | 753 | if($this->status == 'valid' || $this->status == 'ready') |
| 727 | 754 | { |
| 728 | - if (isset($this->certificateKeys['certificate'])) $certFile = $this->certificateKeys['certificate']; |
|
| 729 | - elseif (isset($this->certificateKeys['fullchain_certificate'])) $certFile = $this->certificateKeys['fullchain_certificate']; |
|
| 730 | - else throw LEOrderException::InvalidConfigurationException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required'); |
|
| 755 | + if (isset($this->certificateKeys['certificate'])) { |
|
| 756 | + $certFile = $this->certificateKeys['certificate']; |
|
| 757 | + } elseif (isset($this->certificateKeys['fullchain_certificate'])) { |
|
| 758 | + $certFile = $this->certificateKeys['fullchain_certificate']; |
|
| 759 | + } else { |
|
| 760 | + throw LEOrderException::InvalidConfigurationException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required'); |
|
| 761 | + } |
|
| 731 | 762 | |
| 732 | 763 | if(file_exists($certFile) && file_exists($this->certificateKeys['private_key'])) |
| 733 | 764 | { |
@@ -742,35 +773,36 @@ discard block |
||
| 742 | 773 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 743 | 774 | { |
| 744 | 775 | $this->log->info('Certificate for order \'' . $this->basename . '\' revoked.'); |
| 776 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 777 | + LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate'); |
|
| 745 | 778 | } |
| 746 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate'); |
|
| 747 | 779 | return true; |
| 748 | - } |
|
| 749 | - else |
|
| 780 | + } else |
|
| 750 | 781 | { |
| 751 | 782 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 752 | 783 | { |
| 753 | 784 | $this->log->info('Certificate for order \'' . $this->basename . '\' cannot be revoked.'); |
| 785 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 786 | + LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate'); |
|
| 754 | 787 | } |
| 755 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate'); |
|
| 756 | 788 | } |
| 757 | - } |
|
| 758 | - else |
|
| 789 | + } else |
|
| 759 | 790 | { |
| 760 | 791 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 761 | 792 | { |
| 762 | 793 | $this->log->info('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.'); |
| 794 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 795 | + LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate'); |
|
| 763 | 796 | } |
| 764 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate'); |
|
| 765 | 797 | } |
| 766 | - } |
|
| 767 | - else |
|
| 798 | + } else |
|
| 768 | 799 | { |
| 769 | 800 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 770 | 801 | { |
| 771 | 802 | $this->log->info('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.'); |
| 803 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 804 | + LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate'); |
|
| 772 | 805 | } |
| 773 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate'); |
|
| 774 | 806 | } |
| 775 | 807 | return false; |
| 776 | 808 | } |
@@ -71,17 +71,23 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | if (is_bool($acmeURL)) |
| 73 | 73 | { |
| 74 | - if ($acmeURL === true) $this->baseURL = LEClient::LE_STAGING; |
|
| 75 | - elseif ($acmeURL === false) $this->baseURL = LEClient::LE_PRODUCTION; |
|
| 76 | - } |
|
| 77 | - elseif (is_string($acmeURL)) |
|
| 74 | + if ($acmeURL === true) { |
|
| 75 | + $this->baseURL = LEClient::LE_STAGING; |
|
| 76 | + } elseif ($acmeURL === false) { |
|
| 77 | + $this->baseURL = LEClient::LE_PRODUCTION; |
|
| 78 | + } |
|
| 79 | + } elseif (is_string($acmeURL)) |
|
| 78 | 80 | { |
| 79 | 81 | $this->baseURL = $acmeURL; |
| 82 | + } else { |
|
| 83 | + throw LEClientException::InvalidArgumentException('acmeURL must be set to string or bool (legacy).'); |
|
| 80 | 84 | } |
| 81 | - else throw LEClientException::InvalidArgumentException('acmeURL must be set to string or bool (legacy).'); |
|
| 82 | 85 | |
| 83 | - if (is_array($certificateKeys) && is_string($accountKeys)) throw LEClientException::InvalidArgumentException('When certificateKeys is array, accountKeys must be array too.'); |
|
| 84 | - elseif (is_array($accountKeys) && is_string($certificateKeys)) throw LEClientException::InvalidArgumentException('When accountKeys is array, certificateKeys must be array too.'); |
|
| 86 | + if (is_array($certificateKeys) && is_string($accountKeys)) { |
|
| 87 | + throw LEClientException::InvalidArgumentException('When certificateKeys is array, accountKeys must be array too.'); |
|
| 88 | + } elseif (is_array($accountKeys) && is_string($certificateKeys)) { |
|
| 89 | + throw LEClientException::InvalidArgumentException('When accountKeys is array, certificateKeys must be array too.'); |
|
| 90 | + } |
|
| 85 | 91 | |
| 86 | 92 | if (is_string($certificateKeys)) |
| 87 | 93 | { |
@@ -100,22 +106,30 @@ discard block |
||
| 100 | 106 | "fullchain_certificate" => $certificateKeys.'/fullchain.crt', |
| 101 | 107 | "order" => $certificateKeys.'/order' |
| 102 | 108 | ); |
| 103 | - } |
|
| 104 | - elseif (is_array($certificateKeys)) |
|
| 109 | + } elseif (is_array($certificateKeys)) |
|
| 105 | 110 | { |
| 106 | - if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) throw LEClientException::InvalidArgumentException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set.'); |
|
| 107 | - if (!isset($certificateKeys['private_key'])) throw LEClientException::InvalidArgumentException('certificateKeys[private_key] file path must be set.'); |
|
| 108 | - if (!isset($certificateKeys['order'])) $certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order'; |
|
| 109 | - if (!isset($certificateKeys['public_key'])) $certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem'; |
|
| 111 | + if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) { |
|
| 112 | + throw LEClientException::InvalidArgumentException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set.'); |
|
| 113 | + } |
|
| 114 | + if (!isset($certificateKeys['private_key'])) { |
|
| 115 | + throw LEClientException::InvalidArgumentException('certificateKeys[private_key] file path must be set.'); |
|
| 116 | + } |
|
| 117 | + if (!isset($certificateKeys['order'])) { |
|
| 118 | + $certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order'; |
|
| 119 | + } |
|
| 120 | + if (!isset($certificateKeys['public_key'])) { |
|
| 121 | + $certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem'; |
|
| 122 | + } |
|
| 110 | 123 | |
| 111 | 124 | foreach ($certificateKeys as $param => $file) { |
| 112 | 125 | $parentDir = dirname($file); |
| 113 | - if (!is_dir($parentDir)) throw LEClientException::InvalidDirectoryException($parentDir); |
|
| 126 | + if (!is_dir($parentDir)) { |
|
| 127 | + throw LEClientException::InvalidDirectoryException($parentDir); |
|
| 128 | + } |
|
| 114 | 129 | } |
| 115 | 130 | |
| 116 | 131 | $this->certificateKeys = $certificateKeys; |
| 117 | - } |
|
| 118 | - else |
|
| 132 | + } else |
|
| 119 | 133 | { |
| 120 | 134 | throw LEClientException::InvalidArgumentException('certificateKeys must be string or array.'); |
| 121 | 135 | } |
@@ -134,20 +148,24 @@ discard block |
||
| 134 | 148 | "private_key" => $accountKeys.'/private.pem', |
| 135 | 149 | "public_key" => $accountKeys.'/public.pem' |
| 136 | 150 | ); |
| 137 | - } |
|
| 138 | - elseif (is_array($accountKeys)) |
|
| 151 | + } elseif (is_array($accountKeys)) |
|
| 139 | 152 | { |
| 140 | - if (!isset($accountKeys['private_key'])) throw LEClientException::InvalidArgumentException('accountKeys[private_key] file path must be set.'); |
|
| 141 | - if (!isset($accountKeys['public_key'])) throw LEClientException::InvalidArgumentException('accountKeys[public_key] file path must be set.'); |
|
| 153 | + if (!isset($accountKeys['private_key'])) { |
|
| 154 | + throw LEClientException::InvalidArgumentException('accountKeys[private_key] file path must be set.'); |
|
| 155 | + } |
|
| 156 | + if (!isset($accountKeys['public_key'])) { |
|
| 157 | + throw LEClientException::InvalidArgumentException('accountKeys[public_key] file path must be set.'); |
|
| 158 | + } |
|
| 142 | 159 | |
| 143 | 160 | foreach ($accountKeys as $param => $file) { |
| 144 | 161 | $parentDir = dirname($file); |
| 145 | - if (!is_dir($parentDir)) throw LEClientException::InvalidDirectoryException($parentDir); |
|
| 162 | + if (!is_dir($parentDir)) { |
|
| 163 | + throw LEClientException::InvalidDirectoryException($parentDir); |
|
| 164 | + } |
|
| 146 | 165 | } |
| 147 | 166 | |
| 148 | 167 | $this->accountKeys = $accountKeys; |
| 149 | - } |
|
| 150 | - else |
|
| 168 | + } else |
|
| 151 | 169 | { |
| 152 | 170 | throw LEClientException::InvalidArgumentException('accountKeys must be string or array.'); |
| 153 | 171 | } |
@@ -158,8 +176,9 @@ discard block |
||
| 158 | 176 | if($this->log instanceof \Psr\Log\LoggerInterface) |
| 159 | 177 | { |
| 160 | 178 | $this->log->info('LEClient finished constructing'); |
| 179 | + } elseif($this->log >= LEClient::LOG_STATUS) { |
|
| 180 | + LEFunctions::log('LEClient finished constructing', 'function LEClient __construct'); |
|
| 161 | 181 | } |
| 162 | - elseif($this->log >= LEClient::LOG_STATUS) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct'); |
|
| 163 | 182 | } |
| 164 | 183 | |
| 165 | 184 | |
@@ -28,7 +28,9 @@ discard block |
||
| 28 | 28 | // Define the folder in which to store the challenge. For the purpose of this example, a fictitious path is set. |
| 29 | 29 | $folder = '/path/to/' . $challenge['identifier'] . '/.well-known/acme-challenge/'; |
| 30 | 30 | // Check if that directory yet exists. If not, create it. |
| 31 | - if(!file_exists($folder)) mkdir($folder, 0777, true); |
|
| 31 | + if(!file_exists($folder)) { |
|
| 32 | + mkdir($folder, 0777, true); |
|
| 33 | + } |
|
| 32 | 34 | // Store the challenge file for this domain. |
| 33 | 35 | file_put_contents($folder . $challenge['filename'], $challenge['content']); |
| 34 | 36 | // Let LetsEncrypt verify this challenge. |
@@ -40,8 +42,12 @@ discard block |
||
| 40 | 42 | if($order->allAuthorizationsValid()) |
| 41 | 43 | { |
| 42 | 44 | // Finalize the order first, if that is not yet done. |
| 43 | - if(!$order->isFinalized()) $order->finalizeOrder(); |
|
| 45 | + if(!$order->isFinalized()) { |
|
| 46 | + $order->finalizeOrder(); |
|
| 47 | + } |
|
| 44 | 48 | // Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate. |
| 45 | - if($order->isFinalized()) $order->getCertificate(); |
|
| 46 | -} |
|
| 49 | + if($order->isFinalized()) { |
|
| 50 | + $order->getCertificate(); |
|
| 51 | + } |
|
| 52 | + } |
|
| 47 | 53 | ?> |
| 48 | 54 | \ No newline at end of file |
@@ -34,8 +34,12 @@ |
||
| 34 | 34 | if($order->allAuthorizationsValid()) |
| 35 | 35 | { |
| 36 | 36 | // Finalize the order first, if that is not yet done. |
| 37 | - if(!$order->isFinalized()) $order->finalizeOrder(); |
|
| 37 | + if(!$order->isFinalized()) { |
|
| 38 | + $order->finalizeOrder(); |
|
| 39 | + } |
|
| 38 | 40 | // Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate. |
| 39 | - if($order->isFinalized()) $order->getCertificate(); |
|
| 40 | -} |
|
| 41 | + if($order->isFinalized()) { |
|
| 42 | + $order->getCertificate(); |
|
| 43 | + } |
|
| 44 | + } |
|
| 41 | 45 | ?> |
| 42 | 46 | \ No newline at end of file |