Passed
Branch master (52717f)
by John
02:35
created
exampleHTTP.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -16,19 +16,19 @@  discard block
 block discarded – undo
16 16
 // Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
17 17
 $order = $client->getOrCreateOrder($basename, $domains);
18 18
 // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
19
-if(!$order->allAuthorizationsValid())
19
+if (!$order->allAuthorizationsValid())
20 20
 {
21 21
 	// Get the HTTP challenges from the pending authorizations.
22 22
 	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_HTTP);
23 23
 	// Walk the list of pending authorization HTTP challenges.
24
-	if(!empty($pending))
24
+	if (!empty($pending))
25 25
 	{
26
-		foreach($pending as $challenge)
26
+		foreach ($pending as $challenge)
27 27
 		{
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)) mkdir($folder, 0777, true);
32 32
 			// Store the challenge file for this domain.
33 33
 			file_put_contents($folder . $challenge['filename'], $challenge['content']);
34 34
 			// Let LetsEncrypt verify this challenge.
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 	}
38 38
 }
39 39
 // Check once more whether all authorizations are valid before we can finalize the order.
40
-if($order->allAuthorizationsValid())
40
+if ($order->allAuthorizationsValid())
41 41
 {
42 42
 	// Finalize the order first, if that is not yet done.
43
-	if(!$order->isFinalized()) $order->finalizeOrder();
43
+	if (!$order->isFinalized()) $order->finalizeOrder();
44 44
 	// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
45
-	if($order->isFinalized()) $order->getCertificate();
45
+	if ($order->isFinalized()) $order->getCertificate();
46 46
 }
47 47
 ?>
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,7 +28,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
LEClient/LEClient.php 3 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -60,17 +60,17 @@  discard block
 block discarded – undo
60 60
 	const LOG_STATUS = 1;	// Logs only messages and faults.
61 61
 	const LOG_DEBUG = 2;	// Logs messages, faults and raw responses from HTTP requests.
62 62
 
63
-    /**
64
-     * Initiates the LetsEncrypt main client.
65
-     *
66
-     * @param array		$email	 		The array of strings containing e-mail addresses. Only used in this function when creating a new account.
67
-     * @param boolean	$acmeURL		ACME URL, can be string or one of predefined values: LE_STAGING or LE_PRODUCTION. Defaults to LE_STAGING.
68
-     * @param int 		$log			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted. Defaults to LOG_OFF. (optional)
69
-     * @param string 	$certificateKeys 		The main directory in which all keys (and certificates), including account keys, are stored. Defaults to 'keys/'. (optional)
70
-		 * @param array 	$certificateKeys 		Optional array containing location of all certificate files. Required paths are public_key, private_key, order and certificate/fullchain_certificate (you can use both or only one of them)
71
-     * @param string 	$accountKeys The directory in which the account keys are stored. Is a subdir inside $certificateKeys. Defaults to '__account/'.(optional)
72
-		 * @param array 	$accountKeys Optional array containing location of account private and public keys. Required paths are private_key, public_key.
73
-     */
63
+	/**
64
+	 * Initiates the LetsEncrypt main client.
65
+	 *
66
+	 * @param array		$email	 		The array of strings containing e-mail addresses. Only used in this function when creating a new account.
67
+	 * @param boolean	$acmeURL		ACME URL, can be string or one of predefined values: LE_STAGING or LE_PRODUCTION. Defaults to LE_STAGING.
68
+	 * @param int 		$log			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted. Defaults to LOG_OFF. (optional)
69
+	 * @param string 	$certificateKeys 		The main directory in which all keys (and certificates), including account keys, are stored. Defaults to 'keys/'. (optional)
70
+	 * @param array 	$certificateKeys 		Optional array containing location of all certificate files. Required paths are public_key, private_key, order and certificate/fullchain_certificate (you can use both or only one of them)
71
+	 * @param string 	$accountKeys The directory in which the account keys are stored. Is a subdir inside $certificateKeys. Defaults to '__account/'.(optional)
72
+	 * @param array 	$accountKeys Optional array containing location of account private and public keys. Required paths are private_key, public_key.
73
+	 */
74 74
 	public function __construct($email, $acmeURL = LEClient::LE_STAGING, $log = LEClient::LOG_OFF, $certificateKeys = 'keys/', $accountKeys = '__account/')
75 75
 	{
76 76
 
@@ -171,27 +171,27 @@  discard block
 block discarded – undo
171 171
 	}
172 172
 
173 173
 
174
-    /**
175
-     * Returns the LetsEncrypt account used in the current client.
174
+	/**
175
+	 * Returns the LetsEncrypt account used in the current client.
176 176
 	 *
177 177
 	 * @return LEAccount	The LetsEncrypt Account instance used by the client.
178
-     */
178
+	 */
179 179
 	public function getAccount()
180 180
 	{
181 181
 		return $this->account;
182 182
 	}
183 183
 
184
-    /**
185
-     * Returns a LetsEncrypt order. If an order exists, this one is returned. If not, a new order is created and returned.
186
-     *
187
-     * @param string	$basename	The base name for the order. Preferable the top domain (example.org). Will be the directory in which the keys are stored. Used for the CommonName in the certificate as well.
188
-     * @param array 	$domains 	The array of strings containing the domain names on the certificate.
189
-     * @param string 		$keyType 	Type of the key we want to use for certificate. Can be provided in ALGO-SIZE format (ex. rsa-4096 or ec-256) or simple "rsa" and "ec" (using default sizes)
190
-     * @param string 	$notBefore	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid. Defaults to the moment the order is finalized. (optional)
191
-     * @param string 	$notAfter  	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid. Defaults to 90 days past the moment the order is finalized. (optional)
192
-     *
193
-     * @return LEOrder	The LetsEncrypt Order instance which is either retrieved or created.
194
-     */
184
+	/**
185
+	 * Returns a LetsEncrypt order. If an order exists, this one is returned. If not, a new order is created and returned.
186
+	 *
187
+	 * @param string	$basename	The base name for the order. Preferable the top domain (example.org). Will be the directory in which the keys are stored. Used for the CommonName in the certificate as well.
188
+	 * @param array 	$domains 	The array of strings containing the domain names on the certificate.
189
+	 * @param string 		$keyType 	Type of the key we want to use for certificate. Can be provided in ALGO-SIZE format (ex. rsa-4096 or ec-256) or simple "rsa" and "ec" (using default sizes)
190
+	 * @param string 	$notBefore	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid. Defaults to the moment the order is finalized. (optional)
191
+	 * @param string 	$notAfter  	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid. Defaults to 90 days past the moment the order is finalized. (optional)
192
+	 *
193
+	 * @return LEOrder	The LetsEncrypt Order instance which is either retrieved or created.
194
+	 */
195 195
 	public function getOrCreateOrder($basename, $domains, $keyType = 'rsa-4096', $notBefore = '', $notAfter = '')
196 196
 	{
197 197
 		return new LEOrder($this->connector, $this->log, $this->certificateKeys, $basename, $domains, $keyType, $notBefore, $notAfter);
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 
57 57
 	private $log;
58 58
 
59
-	const LOG_OFF = 0;		// Logs no messages or faults, except Runtime Exceptions.
60
-	const LOG_STATUS = 1;	// Logs only messages and faults.
61
-	const LOG_DEBUG = 2;	// Logs messages, faults and raw responses from HTTP requests.
59
+	const LOG_OFF = 0; // Logs no messages or faults, except Runtime Exceptions.
60
+	const LOG_STATUS = 1; // Logs only messages and faults.
61
+	const LOG_DEBUG = 2; // Logs messages, faults and raw responses from HTTP requests.
62 62
 
63 63
     /**
64 64
      * Initiates the LetsEncrypt main client.
@@ -95,18 +95,18 @@  discard block
 block discarded – undo
95 95
 
96 96
 			$certificateKeysDir = $certificateKeys;
97 97
 
98
-			if(!file_exists($certificateKeys))
98
+			if (!file_exists($certificateKeys))
99 99
 			{
100 100
 				mkdir($certificateKeys, 0777, true);
101 101
 				LEFunctions::createhtaccess($certificateKeys);
102 102
 			}
103 103
 
104 104
 			$this->certificateKeys = array(
105
-				"public_key" => $certificateKeys.'/public.pem',
106
-				"private_key" => $certificateKeys.'/private.pem',
107
-				"certificate" => $certificateKeys.'/certificate.crt',
108
-				"fullchain_certificate" => $certificateKeys.'/fullchain.crt',
109
-				"order" => $certificateKeys.'/order'
105
+				"public_key" => $certificateKeys . '/public.pem',
106
+				"private_key" => $certificateKeys . '/private.pem',
107
+				"certificate" => $certificateKeys . '/certificate.crt',
108
+				"fullchain_certificate" => $certificateKeys . '/fullchain.crt',
109
+				"order" => $certificateKeys . '/order'
110 110
 			);
111 111
 
112 112
 		}
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
 
116 116
 			if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set');
117 117
 			if (!isset($certificateKeys['private_key'])) throw new \RuntimeException('certificateKeys[private_key] file path must be set');
118
-			if (!isset($certificateKeys['order'])) $certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order';
119
-			if (!isset($certificateKeys['public_key'])) $certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem';
118
+			if (!isset($certificateKeys['order'])) $certificateKeys['order'] = dirname($certificateKeys['private_key']) . '/order';
119
+			if (!isset($certificateKeys['public_key'])) $certificateKeys['public_key'] = dirname($certificateKeys['private_key']) . '/public.pem';
120 120
 
121 121
 			foreach ($certificateKeys as $param => $file) {
122 122
 				$parentDir = dirname($file);
123
-				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir.' directory not found');
123
+				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir . ' directory not found');
124 124
 			}
125 125
 
126 126
 			$this->certificateKeys = $certificateKeys;
@@ -134,17 +134,17 @@  discard block
 block discarded – undo
134 134
 		if (is_string($accountKeys))
135 135
 		{
136 136
 
137
-			$accountKeys = $certificateKeysDir.'/'.$accountKeys;
137
+			$accountKeys = $certificateKeysDir . '/' . $accountKeys;
138 138
 
139
-			if(!file_exists($accountKeys))
139
+			if (!file_exists($accountKeys))
140 140
 			{
141 141
 				mkdir($accountKeys, 0777, true);
142 142
 				LEFunctions::createhtaccess($accountKeys);
143 143
 			}
144 144
 
145 145
 			$this->accountKeys = array(
146
-				"private_key" => $accountKeys.'/private.pem',
147
-				"public_key" => $accountKeys.'/public.pem'
146
+				"private_key" => $accountKeys . '/private.pem',
147
+				"public_key" => $accountKeys . '/public.pem'
148 148
 			);
149 149
 		}
150 150
 		elseif (is_array($accountKeys))
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
 			foreach ($accountKeys as $param => $file) {
156 156
 				$parentDir = dirname($file);
157
-				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir.' directory not found');
157
+				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir . ' directory not found');
158 158
 			}
159 159
 
160 160
 			$this->accountKeys = $accountKeys;
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 
168 168
 		$this->connector = new LEConnector($this->log, $this->baseURL, $this->accountKeys);
169 169
 		$this->account = new LEAccount($this->connector, $this->log, $email, $this->accountKeys);
170
-		if($this->log) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct');
170
+		if ($this->log) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct');
171 171
 	}
172 172
 
173 173
 
Please login to merge, or discard this patch.
Braces   +44 added lines, -24 removed lines patch added patch discarded remove patch
@@ -78,17 +78,23 @@  discard block
 block discarded – undo
78 78
 
79 79
 		if (is_bool($acmeURL))
80 80
 		{
81
-			if ($acmeURL === true) $this->baseURL = LEClient::LE_STAGING;
82
-			elseif ($acmeURL === false) $this->baseURL = LEClient::LE_PRODUCTION;
83
-		}
84
-		elseif (is_string($acmeURL))
81
+			if ($acmeURL === true) {
82
+				$this->baseURL = LEClient::LE_STAGING;
83
+			} elseif ($acmeURL === false) {
84
+				$this->baseURL = LEClient::LE_PRODUCTION;
85
+			}
86
+		} elseif (is_string($acmeURL))
85 87
 		{
86 88
 			$this->baseURL = $acmeURL;
89
+		} else {
90
+			throw new \RuntimeException('acmeURL must be set to string or bool (legacy)');
87 91
 		}
88
-		else throw new \RuntimeException('acmeURL must be set to string or bool (legacy)');
89 92
 
90
-		if (is_array($certificateKeys) && is_string($accountKeys)) throw new \RuntimeException('when certificateKeys is array, accountKeys must be array also');
91
-		elseif (is_array($accountKeys) && is_string($certificateKeys)) throw new \RuntimeException('when accountKeys is array, certificateKeys must be array also');
93
+		if (is_array($certificateKeys) && is_string($accountKeys)) {
94
+			throw new \RuntimeException('when certificateKeys is array, accountKeys must be array also');
95
+		} elseif (is_array($accountKeys) && is_string($certificateKeys)) {
96
+			throw new \RuntimeException('when accountKeys is array, certificateKeys must be array also');
97
+		}
92 98
 
93 99
 		if (is_string($certificateKeys))
94 100
 		{
@@ -109,24 +115,32 @@  discard block
 block discarded – undo
109 115
 				"order" => $certificateKeys.'/order'
110 116
 			);
111 117
 
112
-		}
113
-		elseif (is_array($certificateKeys))
118
+		} elseif (is_array($certificateKeys))
114 119
 		{
115 120
 
116
-			if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set');
117
-			if (!isset($certificateKeys['private_key'])) throw new \RuntimeException('certificateKeys[private_key] file path must be set');
118
-			if (!isset($certificateKeys['order'])) $certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order';
119
-			if (!isset($certificateKeys['public_key'])) $certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem';
121
+			if (!isset($certificateKeys['certificate']) && !isset($certificateKeys['fullchain_certificate'])) {
122
+				throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] file path must be set');
123
+			}
124
+			if (!isset($certificateKeys['private_key'])) {
125
+				throw new \RuntimeException('certificateKeys[private_key] file path must be set');
126
+			}
127
+			if (!isset($certificateKeys['order'])) {
128
+				$certificateKeys['order'] = dirname($certificateKeys['private_key']).'/order';
129
+			}
130
+			if (!isset($certificateKeys['public_key'])) {
131
+				$certificateKeys['public_key'] = dirname($certificateKeys['private_key']).'/public.pem';
132
+			}
120 133
 
121 134
 			foreach ($certificateKeys as $param => $file) {
122 135
 				$parentDir = dirname($file);
123
-				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir.' directory not found');
136
+				if (!is_dir($parentDir)) {
137
+					throw new \RuntimeException($parentDir.' directory not found');
138
+				}
124 139
 			}
125 140
 
126 141
 			$this->certificateKeys = $certificateKeys;
127 142
 
128
-		}
129
-		else
143
+		} else
130 144
 		{
131 145
 			throw new \RuntimeException('certificateKeys must be string or array');
132 146
 		}
@@ -146,20 +160,24 @@  discard block
 block discarded – undo
146 160
 				"private_key" => $accountKeys.'/private.pem',
147 161
 				"public_key" => $accountKeys.'/public.pem'
148 162
 			);
149
-		}
150
-		elseif (is_array($accountKeys))
163
+		} elseif (is_array($accountKeys))
151 164
 		{
152
-			if (!isset($accountKeys['private_key'])) throw new \RuntimeException('accountKeys[private_key] file path must be set');
153
-			if (!isset($accountKeys['public_key'])) throw new \RuntimeException('accountKeys[public_key] file path must be set');
165
+			if (!isset($accountKeys['private_key'])) {
166
+				throw new \RuntimeException('accountKeys[private_key] file path must be set');
167
+			}
168
+			if (!isset($accountKeys['public_key'])) {
169
+				throw new \RuntimeException('accountKeys[public_key] file path must be set');
170
+			}
154 171
 
155 172
 			foreach ($accountKeys as $param => $file) {
156 173
 				$parentDir = dirname($file);
157
-				if (!is_dir($parentDir)) throw new \RuntimeException($parentDir.' directory not found');
174
+				if (!is_dir($parentDir)) {
175
+					throw new \RuntimeException($parentDir.' directory not found');
176
+				}
158 177
 			}
159 178
 
160 179
 			$this->accountKeys = $accountKeys;
161
-		}
162
-		else
180
+		} else
163 181
 		{
164 182
 			throw new \RuntimeException('accountKeys must be string or array');
165 183
 		}
@@ -167,7 +185,9 @@  discard block
 block discarded – undo
167 185
 
168 186
 		$this->connector = new LEConnector($this->log, $this->baseURL, $this->accountKeys);
169 187
 		$this->account = new LEAccount($this->connector, $this->log, $email, $this->accountKeys);
170
-		if($this->log) LEFunctions::log('LEClient finished constructing', 'function LEClient __construct');
188
+		if($this->log) {
189
+			LEFunctions::log('LEClient finished constructing', 'function LEClient __construct');
190
+		}
171 191
 	}
172 192
 
173 193
 
Please login to merge, or discard this patch.
LEClient/src/LEOrder.php 3 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -58,18 +58,18 @@  discard block
 block discarded – undo
58 58
 	const CHALLENGE_TYPE_HTTP = 'http-01';
59 59
 	const CHALLENGE_TYPE_DNS = 'dns-01';
60 60
 
61
-    /**
62
-     * Initiates the LetsEncrypt Order class. If the base name is found in the $keysDir directory, the order data is requested. If no order was found locally, if the request is invalid or when there is a change in domain names, a new order is created.
63
-     *
64
-     * @param LEConnector	$connector	The LetsEncrypt Connector instance to use for HTTP requests.
65
-     * @param int 			$log 		The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
66
-     * @param array 		$certificateKeys 	Array containing location of certificate keys files.
67
-     * @param string 		$basename 	The base name for the order. Preferable the top domain (example.org). Will be the directory in which the keys are stored. Used for the CommonName in the certificate as well.
68
-     * @param array 		$domains 	The array of strings containing the domain names on the certificate.
69
-     * @param string 		$keyType 	Type of the key we want to use for certificate. Can be provided in ALGO-SIZE format (ex. rsa-4096 or ec-256) or simple "rsa" and "ec" (using default sizes)
70
-     * @param string 		$notBefore 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid.
71
-     * @param string 		$notAfter 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid.
72
-     */
61
+	/**
62
+	 * Initiates the LetsEncrypt Order class. If the base name is found in the $keysDir directory, the order data is requested. If no order was found locally, if the request is invalid or when there is a change in domain names, a new order is created.
63
+	 *
64
+	 * @param LEConnector	$connector	The LetsEncrypt Connector instance to use for HTTP requests.
65
+	 * @param int 			$log 		The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
66
+	 * @param array 		$certificateKeys 	Array containing location of certificate keys files.
67
+	 * @param string 		$basename 	The base name for the order. Preferable the top domain (example.org). Will be the directory in which the keys are stored. Used for the CommonName in the certificate as well.
68
+	 * @param array 		$domains 	The array of strings containing the domain names on the certificate.
69
+	 * @param string 		$keyType 	Type of the key we want to use for certificate. Can be provided in ALGO-SIZE format (ex. rsa-4096 or ec-256) or simple "rsa" and "ec" (using default sizes)
70
+	 * @param string 		$notBefore 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid.
71
+	 * @param string 		$notAfter 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid.
72
+	 */
73 73
 	public function __construct($connector, $log, $certificateKeys, $basename, $domains, $keyType = 'rsa-4096', $notBefore, $notAfter)
74 74
 	{
75 75
 		$this->connector = $connector;
@@ -159,13 +159,13 @@  discard block
 block discarded – undo
159 159
 		}
160 160
 	}
161 161
 
162
-    /**
163
-     * Creates a new LetsEncrypt order and fills this instance with its data. Subsequently creates a new RSA keypair for the certificate.
164
-     *
165
-     * @param array		$domains 	The array of strings containing the domain names on the certificate.
166
-     * @param string 	$notBefore 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid.
167
-     * @param string 	$notAfter 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid.
168
-     */
162
+	/**
163
+	 * Creates a new LetsEncrypt order and fills this instance with its data. Subsequently creates a new RSA keypair for the certificate.
164
+	 *
165
+	 * @param array		$domains 	The array of strings containing the domain names on the certificate.
166
+	 * @param string 	$notBefore 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) at which the certificate becomes valid.
167
+	 * @param string 	$notAfter 	A date string formatted like 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss) until which the certificate is valid.
168
+	 */
169 169
 	private function createOrder($domains, $notBefore, $notAfter)
170 170
 	{
171 171
 		if(preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) AND preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter))
@@ -226,9 +226,9 @@  discard block
 block discarded – undo
226 226
 		}
227 227
 	}
228 228
 
229
-    /**
230
-     * Fetches the latest data concerning this LetsEncrypt Order instance and fills this instance with the new data.
231
-     */
229
+	/**
230
+	 * Fetches the latest data concerning this LetsEncrypt Order instance and fills this instance with the new data.
231
+	 */
232 232
 	private function updateOrderData()
233 233
 	{
234 234
 		$get = $this->connector->get($this->orderURL);
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
 	}
250 250
 
251 251
 	/**
252
-     * Fetches the latest data concerning all authorizations connected to this LetsEncrypt Order instance and creates and stores a new LetsEncrypt Authorization instance for each one.
253
-     */
252
+	 * Fetches the latest data concerning all authorizations connected to this LetsEncrypt Order instance and creates and stores a new LetsEncrypt Authorization instance for each one.
253
+	 */
254 254
 	private function updateAuthorizations()
255 255
 	{
256 256
 		$this->authorizations = array();
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
 		}
265 265
 	}
266 266
 
267
-    /**
268
-     * Walks all LetsEncrypt Authorization instances and returns whether they are all valid (verified).
269
-     *
270
-     * @return boolean	Returns true if all authorizations are valid (verified), returns false if not.
271
-     */
267
+	/**
268
+	 * Walks all LetsEncrypt Authorization instances and returns whether they are all valid (verified).
269
+	 *
270
+	 * @return boolean	Returns true if all authorizations are valid (verified), returns false if not.
271
+	 */
272 272
 	public function allAuthorizationsValid()
273 273
 	{
274 274
 		if(count($this->authorizations) > 0)
@@ -282,16 +282,16 @@  discard block
 block discarded – undo
282 282
 		return false;
283 283
 	}
284 284
 
285
-    /**
286
-     * Get all pending LetsEncrypt Authorization instances and return the necessary data for verification. The data in the return object depends on the $type.
287
-     *
288
-     * @param int	$type	The type of verification to get. Supporting http-01 and dns-01. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS. Throws
285
+	/**
286
+	 * Get all pending LetsEncrypt Authorization instances and return the necessary data for verification. The data in the return object depends on the $type.
287
+	 *
288
+	 * @param int	$type	The type of verification to get. Supporting http-01 and dns-01. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS. Throws
289 289
 	 *						a Runtime Exception when requesting an unknown $type. Keep in mind a wildcard domain authorization only accepts LEOrder::CHALLENGE_TYPE_DNS.
290
-     *
291
-     * @return object	Returns an array with verification data if successful, false if not pending LetsEncrypt Authorization instances were found. The return array always
290
+	 *
291
+	 * @return object	Returns an array with verification data if successful, false if not pending LetsEncrypt Authorization instances were found. The return array always
292 292
 	 *					contains 'type' and 'identifier'. For LEOrder::CHALLENGE_TYPE_HTTP, the array contains 'filename' and 'content' for necessary the authorization file.
293 293
 	 *					For LEOrder::CHALLENGE_TYPE_DNS, the array contains 'DNSDigest', which is the content for the necessary DNS TXT entry.
294
-     */
294
+	 */
295 295
 
296 296
 	public function getPendingAuthorizations($type)
297 297
 	{
@@ -333,15 +333,15 @@  discard block
 block discarded – undo
333 333
 		return count($authorizations) > 0 ? $authorizations : false;
334 334
 	}
335 335
 
336
-    /**
337
-     * Sends a verification request for a given $identifier and $type. The function itself checks whether the verification is valid before making the request.
336
+	/**
337
+	 * Sends a verification request for a given $identifier and $type. The function itself checks whether the verification is valid before making the request.
338 338
 	 * Updates the LetsEncrypt Authorization instances after a successful verification.
339
-     *
340
-     * @param string	$identifier	The domain name to verify.
341
-     * @param int 		$type 		The type of verification. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS.
342
-     *
343
-     * @return boolean	Returns true when the verification request was successful, false if not.
344
-     */
339
+	 *
340
+	 * @param string	$identifier	The domain name to verify.
341
+	 * @param int 		$type 		The type of verification. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS.
342
+	 *
343
+	 * @return boolean	Returns true when the verification request was successful, false if not.
344
+	 */
345 345
 	public function verifyPendingOrderAuthorization($identifier, $type)
346 346
 	{
347 347
 		$privateKey = openssl_pkey_get_private(file_get_contents($this->connector->accountKeys['private_key']));
@@ -418,13 +418,13 @@  discard block
 block discarded – undo
418 418
 		return false;
419 419
 	}
420 420
 
421
-    /**
422
-     * Deactivate an LetsEncrypt Authorization instance.
423
-     *
424
-     * @param string	$identifier The domain name for which the verification should be deactivated.
425
-     *
426
-     * @return boolean	Returns true is the deactivation request was successful, false if not.
427
-     */
421
+	/**
422
+	 * Deactivate an LetsEncrypt Authorization instance.
423
+	 *
424
+	 * @param string	$identifier The domain name for which the verification should be deactivated.
425
+	 *
426
+	 * @return boolean	Returns true is the deactivation request was successful, false if not.
427
+	 */
428 428
 	public function deactivateOrderAuthorization($identifier)
429 429
 	{
430 430
 		foreach($this->authorizations as $auth)
@@ -445,12 +445,12 @@  discard block
 block discarded – undo
445 445
 		return false;
446 446
 	}
447 447
 
448
-    /**
449
-     * Generates a Certificate Signing Request for the identifiers in the current LetsEncrypt Order instance. If possible, the base name will be the certificate
448
+	/**
449
+	 * Generates a Certificate Signing Request for the identifiers in the current LetsEncrypt Order instance. If possible, the base name will be the certificate
450 450
 	 * common name and all domain names in this LetsEncrypt Order instance will be added to the Subject Alternative Names entry.
451
-     *
452
-     * @return string	Returns the generated CSR as string, unprepared for LetsEncrypt. Preparation for the request happens in finalizeOrder()
453
-     */
451
+	 *
452
+	 * @return string	Returns the generated CSR as string, unprepared for LetsEncrypt. Preparation for the request happens in finalizeOrder()
453
+	 */
454 454
 	public function generateCSR()
455 455
 	{
456 456
 		$domains = array_map(function ($dns) { return $dns['value']; }, $this->identifiers);
@@ -472,14 +472,14 @@  discard block
 block discarded – undo
472 472
 		);
473 473
 
474 474
 		$san = implode(",", array_map(function ($dns) {
475
-            return "DNS:" . $dns;
476
-        }, $domains));
477
-        $tmpConf = tmpfile();
478
-        $tmpConfMeta = stream_get_meta_data($tmpConf);
479
-        $tmpConfPath = $tmpConfMeta["uri"];
480
-
481
-        fwrite($tmpConf,
482
-            'HOME = .
475
+			return "DNS:" . $dns;
476
+		}, $domains));
477
+		$tmpConf = tmpfile();
478
+		$tmpConfMeta = stream_get_meta_data($tmpConf);
479
+		$tmpConfPath = $tmpConfMeta["uri"];
480
+
481
+		fwrite($tmpConf,
482
+			'HOME = .
483 483
 			RANDFILE = $ENV::HOME/.rnd
484 484
 			[ req ]
485 485
 			default_bits = 4096
@@ -499,13 +499,13 @@  discard block
 block discarded – undo
499 499
 		return $csr;
500 500
 	}
501 501
 
502
-    /**
503
-     * Checks, for redundancy, whether all authorizations are valid, and finalizes the order. Updates this LetsEncrypt Order instance with the new data.
504
-     *
505
-     * @param string	$csr	The Certificate Signing Request as a string. Can be a custom CSR. If empty, a CSR will be generated with the generateCSR() function.
506
-     *
507
-     * @return boolean	Returns true if the finalize request was successful, false if not.
508
-     */
502
+	/**
503
+	 * Checks, for redundancy, whether all authorizations are valid, and finalizes the order. Updates this LetsEncrypt Order instance with the new data.
504
+	 *
505
+	 * @param string	$csr	The Certificate Signing Request as a string. Can be a custom CSR. If empty, a CSR will be generated with the generateCSR() function.
506
+	 *
507
+	 * @return boolean	Returns true if the finalize request was successful, false if not.
508
+	 */
509 509
 	public function finalizeOrder($csr = '')
510 510
 	{
511 511
 		if($this->status == 'pending')
@@ -542,22 +542,22 @@  discard block
 block discarded – undo
542 542
 		return false;
543 543
 	}
544 544
 
545
-    /**
546
-     * Gets whether the LetsEncrypt Order is finalized by checking whether the status is processing or valid. Keep in mind, a certificate is not yet available when the status still is processing.
547
-     *
548
-     * @return boolean	Returns true if finalized, false if not.
549
-     */
545
+	/**
546
+	 * Gets whether the LetsEncrypt Order is finalized by checking whether the status is processing or valid. Keep in mind, a certificate is not yet available when the status still is processing.
547
+	 *
548
+	 * @return boolean	Returns true if finalized, false if not.
549
+	 */
550 550
 	public function isFinalized()
551 551
 	{
552 552
 		return ($this->status == 'processing' || $this->status == 'valid');
553 553
 	}
554 554
 
555
-    /**
556
-     * Requests the certificate for this LetsEncrypt Order instance, after finalization. When the order status is still 'processing', the order will be polled max
555
+	/**
556
+	 * Requests the certificate for this LetsEncrypt Order instance, after finalization. When the order status is still 'processing', the order will be polled max
557 557
 	 * four times with five seconds in between. If the status becomes 'valid' in the meantime, the certificate will be requested. Else, the function returns false.
558
-     *
559
-     * @return boolean	Returns true if the certificate is stored successfully, false if the certificate could not be retrieved or the status remained 'processing'.
560
-     */
558
+	 *
559
+	 * @return boolean	Returns true if the certificate is stored successfully, false if the certificate could not be retrieved or the status remained 'processing'.
560
+	 */
561 561
 	public function getCertificate()
562 562
 	{
563 563
 		$polling = 0;
@@ -607,14 +607,14 @@  discard block
 block discarded – undo
607 607
 		return false;
608 608
 	}
609 609
 
610
-    /**
611
-     * Revokes the certificate in the current LetsEncrypt Order instance, if existent. Unlike stated in the ACME draft, the certificate revoke request cannot be signed
610
+	/**
611
+	 * Revokes the certificate in the current LetsEncrypt Order instance, if existent. Unlike stated in the ACME draft, the certificate revoke request cannot be signed
612 612
 	 * with the account private key, and will be signed with the certificate private key.
613
-     *
614
-     * @param int	$reason   The reason to revoke the LetsEncrypt Order instance certificate. Possible reasons can be found in section 5.3.1 of RFC5280.
615
-     *
616
-     * @return boolean	Returns true if the certificate was successfully revoked, false if not.
617
-     */
613
+	 *
614
+	 * @param int	$reason   The reason to revoke the LetsEncrypt Order instance certificate. Possible reasons can be found in section 5.3.1 of RFC5280.
615
+	 *
616
+	 * @return boolean	Returns true if the certificate was successfully revoked, false if not.
617
+	 */
618 618
 	public function revokeCertificate($reason = 0)
619 619
 	{
620 620
 		if($this->status == 'valid')
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -100,23 +100,23 @@  discard block
 block discarded – undo
100 100
 
101 101
 		$this->certificateKeys = $certificateKeys;
102 102
 
103
-		if(file_exists($this->certificateKeys['private_key']) AND file_exists($this->certificateKeys['order']) AND file_exists($this->certificateKeys['public_key']))
103
+		if (file_exists($this->certificateKeys['private_key']) AND file_exists($this->certificateKeys['order']) AND file_exists($this->certificateKeys['public_key']))
104 104
 		{
105 105
 			$this->orderURL = file_get_contents($this->certificateKeys['order']);
106 106
 			if (filter_var($this->orderURL, FILTER_VALIDATE_URL))
107 107
 			{
108 108
 				$get = $this->connector->get($this->orderURL);
109
-				if(strpos($get['header'], "200 OK") !== false)
109
+				if (strpos($get['header'], "200 OK") !== false)
110 110
 				{
111 111
 					$orderdomains = array_map(function($ident) { return $ident['value']; }, $get['body']['identifiers']);
112 112
 					$diff = array_merge(array_diff($orderdomains, $domains), array_diff($domains, $orderdomains));
113
-					if(!empty($diff))
113
+					if (!empty($diff))
114 114
 					{
115 115
 						foreach ($this->certificateKeys as $file)
116 116
 						{
117
-							if (is_file($file)) rename($file, $file.'.old');
117
+							if (is_file($file)) rename($file, $file . '.old');
118 118
 						}
119
-						if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct');
119
+						if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct');
120 120
 						$this->createOrder($domains, $notBefore, $notAfter, $keyType);
121 121
 					}
122 122
 					else
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 						$this->identifiers = $get['body']['identifiers'];
127 127
 						$this->authorizationURLs = $get['body']['authorizations'];
128 128
 						$this->finalizeURL = $get['body']['finalize'];
129
-						if(array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
129
+						if (array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
130 130
 						$this->updateAuthorizations();
131 131
 					}
132 132
 				}
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 					{
137 137
 						if (is_file($file)) unlink($file);
138 138
 					}
139
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
139
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
140 140
 					$this->createOrder($domains, $notBefore, $notAfter);
141 141
 				}
142 142
 			}
@@ -147,14 +147,14 @@  discard block
 block discarded – undo
147 147
 				{
148 148
 					if (is_file($file)) unlink($file);
149 149
 				}
150
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
150
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
151 151
 
152 152
 				$this->createOrder($domains, $notBefore, $notAfter);
153 153
 			}
154 154
 		}
155 155
 		else
156 156
 		{
157
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct');
157
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct');
158 158
 			$this->createOrder($domains, $notBefore, $notAfter);
159 159
 		}
160 160
 	}
@@ -168,22 +168,22 @@  discard block
 block discarded – undo
168 168
      */
169 169
 	private function createOrder($domains, $notBefore, $notAfter)
170 170
 	{
171
-		if(preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) AND preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter))
171
+		if (preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notBefore) AND preg_match('~(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z|^$)~', $notAfter))
172 172
 		{
173 173
 
174 174
 			$dns = array();
175
-			foreach($domains as $domain)
175
+			foreach ($domains as $domain)
176 176
 			{
177
-				if(preg_match_all('~(\*\.)~', $domain) > 1) throw new \RuntimeException('Cannot create orders with multiple wildcards in one domain.');
177
+				if (preg_match_all('~(\*\.)~', $domain) > 1) throw new \RuntimeException('Cannot create orders with multiple wildcards in one domain.');
178 178
 				$dns[] = array('type' => 'dns', 'value' => $domain);
179 179
 			}
180 180
 			$payload = array("identifiers" => $dns, 'notBefore' => $notBefore, 'notAfter' => $notAfter);
181 181
 			$sign = $this->connector->signRequestKid($payload, $this->connector->accountURL, $this->connector->newOrder);
182 182
 			$post = $this->connector->post($this->connector->newOrder, $sign);
183 183
 
184
-			if(strpos($post['header'], "201 Created") !== false)
184
+			if (strpos($post['header'], "201 Created") !== false)
185 185
 			{
186
-				if(preg_match('~Location: (\S+)~i', $post['header'], $matches))
186
+				if (preg_match('~Location: (\S+)~i', $post['header'], $matches))
187 187
 				{
188 188
 					$this->orderURL = trim($matches[1]);
189 189
 					file_put_contents($this->certificateKeys['order'], $this->orderURL);
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
 					$this->identifiers = $post['body']['identifiers'];
206 206
 					$this->authorizationURLs = $post['body']['authorizations'];
207 207
 					$this->finalizeURL = $post['body']['finalize'];
208
-					if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
208
+					if (array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
209 209
 					$this->updateAuthorizations();
210 210
 
211
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)');
211
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)');
212 212
 				}
213 213
 				else
214 214
 				{
@@ -232,19 +232,19 @@  discard block
 block discarded – undo
232 232
 	private function updateOrderData()
233 233
 	{
234 234
 		$get = $this->connector->get($this->orderURL);
235
-		if(strpos($get['header'], "200 OK") !== false)
235
+		if (strpos($get['header'], "200 OK") !== false)
236 236
 		{
237 237
 			$this->status = $get['body']['status'];
238 238
 			$this->expires = $get['body']['expires'];
239 239
 			$this->identifiers = $get['body']['identifiers'];
240 240
 			$this->authorizationURLs = $get['body']['authorizations'];
241 241
 			$this->finalizeURL = $get['body']['finalize'];
242
-			if(array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
242
+			if (array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
243 243
 			$this->updateAuthorizations();
244 244
 		}
245 245
 		else
246 246
 		{
247
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData');
247
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData');
248 248
 		}
249 249
 	}
250 250
 
@@ -254,12 +254,12 @@  discard block
 block discarded – undo
254 254
 	private function updateAuthorizations()
255 255
 	{
256 256
 		$this->authorizations = array();
257
-		foreach($this->authorizationURLs as $authURL)
257
+		foreach ($this->authorizationURLs as $authURL)
258 258
 		{
259 259
 			if (filter_var($authURL, FILTER_VALIDATE_URL))
260 260
 			{
261 261
 				$auth = new LEAuthorization($this->connector, $this->log, $authURL);
262
-				if($auth != false) $this->authorizations[] = $auth;
262
+				if ($auth != false) $this->authorizations[] = $auth;
263 263
 			}
264 264
 		}
265 265
 	}
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
      */
272 272
 	public function allAuthorizationsValid()
273 273
 	{
274
-		if(count($this->authorizations) > 0)
274
+		if (count($this->authorizations) > 0)
275 275
 		{
276
-			foreach($this->authorizations as $auth)
276
+			foreach ($this->authorizations as $auth)
277 277
 			{
278
-				if($auth->status != 'valid') return false;
278
+				if ($auth->status != 'valid') return false;
279 279
 			}
280 280
 			return true;
281 281
 		}
@@ -308,15 +308,15 @@  discard block
 block discarded – undo
308 308
 		);
309 309
 		$digest = LEFunctions::Base64UrlSafeEncode(hash('sha256', json_encode($header), true));
310 310
 
311
-		foreach($this->authorizations as $auth)
311
+		foreach ($this->authorizations as $auth)
312 312
 		{
313
-			if($auth->status == 'pending')
313
+			if ($auth->status == 'pending')
314 314
 			{
315 315
 				$challenge = $auth->getChallenge($type);
316
-				if($challenge['status'] == 'pending')
316
+				if ($challenge['status'] == 'pending')
317 317
 				{
318 318
 					$keyAuthorization = $challenge['token'] . '.' . $digest;
319
-					switch(strtolower($type))
319
+					switch (strtolower($type))
320 320
 					{
321 321
 						case LEOrder::CHALLENGE_TYPE_HTTP:
322 322
 							$authorizations[] = array('type' => LEOrder::CHALLENGE_TYPE_HTTP, 'identifier' => $auth->identifier['value'], 'filename' => $challenge['token'], 'content' => $keyAuthorization);
@@ -355,27 +355,27 @@  discard block
 block discarded – undo
355 355
 		);
356 356
 		$digest = LEFunctions::Base64UrlSafeEncode(hash('sha256', json_encode($header), true));
357 357
 
358
-		foreach($this->authorizations as $auth)
358
+		foreach ($this->authorizations as $auth)
359 359
 		{
360
-			if($auth->identifier['value'] == $identifier)
360
+			if ($auth->identifier['value'] == $identifier)
361 361
 			{
362
-				if($auth->status == 'pending')
362
+				if ($auth->status == 'pending')
363 363
 				{
364 364
 					$challenge = $auth->getChallenge($type);
365
-					if($challenge['status'] == 'pending')
365
+					if ($challenge['status'] == 'pending')
366 366
 					{
367 367
 						$keyAuthorization = $challenge['token'] . '.' . $digest;
368
-						switch($type)
368
+						switch ($type)
369 369
 						{
370 370
 							case LEOrder::CHALLENGE_TYPE_HTTP:
371
-								if(LEFunctions::checkHTTPChallenge($identifier, $challenge['token'], $keyAuthorization))
371
+								if (LEFunctions::checkHTTPChallenge($identifier, $challenge['token'], $keyAuthorization))
372 372
 								{
373 373
 									$sign = $this->connector->signRequestKid(array('keyAuthorization' => $keyAuthorization), $this->connector->accountURL, $challenge['url']);
374 374
 									$post = $this->connector->post($challenge['url'], $sign);
375
-									if(strpos($post['header'], "200 OK") !== false)
375
+									if (strpos($post['header'], "200 OK") !== false)
376 376
 									{
377
-										if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
378
-										while($auth->status == 'pending')
377
+										if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
378
+										while ($auth->status == 'pending')
379 379
 										{
380 380
 											sleep(1);
381 381
 											$auth->updateData();
@@ -385,19 +385,19 @@  discard block
 block discarded – undo
385 385
 								}
386 386
 								else
387 387
 								{
388
-									if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
388
+									if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
389 389
 								}
390 390
 								break;
391 391
 							case LEOrder::CHALLENGE_TYPE_DNS:
392 392
 								$DNSDigest = LEFunctions::Base64UrlSafeEncode(hash('sha256', $keyAuthorization, true));
393
-								if(LEFunctions::checkDNSChallenge($identifier, $DNSDigest))
393
+								if (LEFunctions::checkDNSChallenge($identifier, $DNSDigest))
394 394
 								{
395 395
 									$sign = $this->connector->signRequestKid(array('keyAuthorization' => $keyAuthorization), $this->connector->accountURL, $challenge['url']);
396 396
 									$post = $this->connector->post($challenge['url'], $sign);
397
-									if(strpos($post['header'], "200 OK") !== false)
397
+									if (strpos($post['header'], "200 OK") !== false)
398 398
 									{
399
-										if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
400
-										while($auth->status == 'pending')
399
+										if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
400
+										while ($auth->status == 'pending')
401 401
 										{
402 402
 											sleep(1);
403 403
 											$auth->updateData();
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 								}
408 408
 								else
409 409
 								{
410
-									if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
410
+									if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
411 411
 								}
412 412
 								break;
413 413
 						}
@@ -427,21 +427,21 @@  discard block
 block discarded – undo
427 427
      */
428 428
 	public function deactivateOrderAuthorization($identifier)
429 429
 	{
430
-		foreach($this->authorizations as $auth)
430
+		foreach ($this->authorizations as $auth)
431 431
 		{
432
-			if($auth->identifier['value'] == $identifier)
432
+			if ($auth->identifier['value'] == $identifier)
433 433
 			{
434 434
 				$sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $auth->authorizationURL);
435 435
 				$post = $this->connector->post($auth->authorizationURL, $sign);
436
-				if(strpos($post['header'], "200 OK") !== false)
436
+				if (strpos($post['header'], "200 OK") !== false)
437 437
 				{
438
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization');
438
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization');
439 439
 					$this->updateAuthorizations();
440 440
 					return true;
441 441
 				}
442 442
 			}
443 443
 		}
444
-		if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization');
444
+		if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization');
445 445
 		return false;
446 446
 	}
447 447
 
@@ -453,12 +453,12 @@  discard block
 block discarded – undo
453 453
      */
454 454
 	public function generateCSR()
455 455
 	{
456
-		$domains = array_map(function ($dns) { return $dns['value']; }, $this->identifiers);
457
-		if(in_array($this->basename, $domains))
456
+		$domains = array_map(function($dns) { return $dns['value']; }, $this->identifiers);
457
+		if (in_array($this->basename, $domains))
458 458
 		{
459 459
 			$CN = $this->basename;
460 460
 		}
461
-		elseif(in_array('*.' . $this->basename, $domains))
461
+		elseif (in_array('*.' . $this->basename, $domains))
462 462
 		{
463 463
 			$CN = '*.' . $this->basename;
464 464
 		}
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 			"commonName" => $CN
472 472
 		);
473 473
 
474
-		$san = implode(",", array_map(function ($dns) {
474
+		$san = implode(",", array_map(function($dns) {
475 475
             return "DNS:" . $dns;
476 476
         }, $domains));
477 477
         $tmpConf = tmpfile();
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 
496 496
 		$privateKey = openssl_pkey_get_private(file_get_contents($this->certificateKeys['private_key']));
497 497
 		$csr = openssl_csr_new($dn, $privateKey, array('config' => $tmpConfPath, 'digest_alg' => 'sha256'));
498
-		openssl_csr_export ($csr, $csr);
498
+		openssl_csr_export($csr, $csr);
499 499
 		return $csr;
500 500
 	}
501 501
 
@@ -508,36 +508,36 @@  discard block
 block discarded – undo
508 508
      */
509 509
 	public function finalizeOrder($csr = '')
510 510
 	{
511
-		if($this->status == 'pending')
511
+		if ($this->status == 'pending')
512 512
 		{
513
-			if($this->allAuthorizationsValid())
513
+			if ($this->allAuthorizationsValid())
514 514
 			{
515
-				if(empty($csr)) $csr = $this->generateCSR();
516
-				if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1];
515
+				if (empty($csr)) $csr = $this->generateCSR();
516
+				if (preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1];
517 517
 				$csr = trim(LEFunctions::Base64UrlSafeEncode(base64_decode($csr)));
518 518
 				$sign = $this->connector->signRequestKid(array('csr' => $csr), $this->connector->accountURL, $this->finalizeURL);
519 519
 				$post = $this->connector->post($this->finalizeURL, $sign);
520
-				if(strpos($post['header'], "200 OK") !== false)
520
+				if (strpos($post['header'], "200 OK") !== false)
521 521
 				{
522 522
 					$this->status = $post['body']['status'];
523 523
 					$this->expires = $post['body']['expires'];
524 524
 					$this->identifiers = $post['body']['identifiers'];
525 525
 					$this->authorizationURLs = $post['body']['authorizations'];
526 526
 					$this->finalizeURL = $post['body']['finalize'];
527
-					if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
527
+					if (array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
528 528
 					$this->updateAuthorizations();
529
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder');
529
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder');
530 530
 					return true;
531 531
 				}
532 532
 			}
533 533
 			else
534 534
 			{
535
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder');
535
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder');
536 536
 			}
537 537
 		}
538 538
 		else
539 539
 		{
540
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder');
540
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder');
541 541
 		}
542 542
 		return false;
543 543
 	}
@@ -561,48 +561,48 @@  discard block
 block discarded – undo
561 561
 	public function getCertificate()
562 562
 	{
563 563
 		$polling = 0;
564
-		while($this->status == 'processing' && $polling < 4)
564
+		while ($this->status == 'processing' && $polling < 4)
565 565
 		{
566
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate');
566
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate');
567 567
 			sleep(5);
568 568
 			$this->updateOrderData();
569 569
 			$polling++;
570 570
 		}
571
-		if($this->status == 'valid' && !empty($this->certificateURL))
571
+		if ($this->status == 'valid' && !empty($this->certificateURL))
572 572
 		{
573 573
 			$get = $this->connector->get($this->certificateURL);
574
-			if(strpos($get['header'], "200 OK") !== false)
574
+			if (strpos($get['header'], "200 OK") !== false)
575 575
 			{
576
-				if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $get['body'], $matches))
576
+				if (preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $get['body'], $matches))
577 577
 				{
578
-					if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'],  $matches[0][0]);
578
+					if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'], $matches[0][0]);
579 579
 
580
-					if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
580
+					if (count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
581 581
 					{
582
-						$fullchain = $matches[0][0]."\n";
583
-						for($i=1;$i<count($matches[0]);$i++)
582
+						$fullchain = $matches[0][0] . "\n";
583
+						for ($i = 1; $i < count($matches[0]); $i++)
584 584
 						{
585
-							$fullchain .= $matches[0][$i]."\n";
585
+							$fullchain .= $matches[0][$i] . "\n";
586 586
 
587 587
 						}
588 588
 						file_put_contents(trim($this->certificateKeys['fullchain_certificate']), $fullchain);
589 589
 					}
590
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
590
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
591 591
 					return true;
592 592
 				}
593 593
 				else
594 594
 				{
595
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
595
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
596 596
 				}
597 597
 			}
598 598
 			else
599 599
 			{
600
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
600
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
601 601
 			}
602 602
 		}
603 603
 		else
604 604
 		{
605
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate');
605
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate');
606 606
 		}
607 607
 		return false;
608 608
 	}
@@ -617,13 +617,13 @@  discard block
 block discarded – undo
617 617
      */
618 618
 	public function revokeCertificate($reason = 0)
619 619
 	{
620
-		if($this->status == 'valid')
620
+		if ($this->status == 'valid')
621 621
 		{
622 622
 			if (isset($this->certificateKeys['certificate'])) $certFile = $this->certificateKeys['certificate'];
623 623
 			elseif (isset($this->certificateKeys['fullchain_certificate']))  $certFile = $this->certificateKeys['fullchain_certificate'];
624 624
 			else throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required');
625 625
 
626
-			if(file_exists($certFile) && file_exists($this->certificateKeys['private_key']))
626
+			if (file_exists($certFile) && file_exists($this->certificateKeys['private_key']))
627 627
 			{
628 628
 				$certificate = file_get_contents($this->certificateKeys['certificate']);
629 629
 				preg_match('~-----BEGIN\sCERTIFICATE-----(.*)-----END\sCERTIFICATE-----~s', $certificate, $matches);
@@ -631,24 +631,24 @@  discard block
 block discarded – undo
631 631
 
632 632
 				$sign = $this->connector->signRequestJWK(array('certificate' => $certificate, 'reason' => $reason), $this->connector->revokeCert);
633 633
 				$post = $this->connector->post($this->connector->revokeCert, $sign);
634
-				if(strpos($post['header'], "200 OK") !== false)
634
+				if (strpos($post['header'], "200 OK") !== false)
635 635
 				{
636
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate');
636
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate');
637 637
 					return true;
638 638
 				}
639 639
 				else
640 640
 				{
641
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate');
641
+					if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate');
642 642
 				}
643 643
 			}
644 644
 			else
645 645
 			{
646
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate');
646
+				if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate');
647 647
 			}
648 648
 		}
649 649
 		else
650 650
 		{
651
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate');
651
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate');
652 652
 		}
653 653
 		return false;
654 654
 	}
Please login to merge, or discard this patch.
Braces   +144 added lines, -89 removed lines patch added patch discarded remove patch
@@ -80,13 +80,11 @@  discard block
 block discarded – undo
80 80
 		{
81 81
 			$this->keyType = 'rsa';
82 82
 			$this->keySize = 4096;
83
-		}
84
-		elseif ($keyType == 'ec')
83
+		} elseif ($keyType == 'ec')
85 84
 		{
86 85
 			$this->keyType = 'ec';
87 86
 			$this->keySize = 256;
88
-		}
89
-		else
87
+		} else
90 88
 		{
91 89
 			preg_match_all('/^(rsa|ec)\-([0-9]{3,4})$/', $keyType, $keyTypeParts, PREG_SET_ORDER, 0);
92 90
 
@@ -94,8 +92,9 @@  discard block
 block discarded – undo
94 92
 			{
95 93
 				$this->keyType = $keyTypeParts[0][1];
96 94
 				$this->keySize = intval($keyTypeParts[0][2]);
95
+			} else {
96
+				throw new \RuntimeException('Key type \'' . $keyType . '\' not supported.');
97 97
 			}
98
-			else throw new \RuntimeException('Key type \'' . $keyType . '\' not supported.');
99 98
 		}
100 99
 
101 100
 		$this->certificateKeys = $certificateKeys;
@@ -114,47 +113,59 @@  discard block
 block discarded – undo
114 113
 					{
115 114
 						foreach ($this->certificateKeys as $file)
116 115
 						{
117
-							if (is_file($file)) rename($file, $file.'.old');
116
+							if (is_file($file)) {
117
+								rename($file, $file.'.old');
118
+							}
119
+						}
120
+						if($this->log >= LECLient::LOG_STATUS) {
121
+							LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct');
118 122
 						}
119
-						if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Domains do not match order data. Renaming current files and creating new order.', 'function LEOrder __construct');
120 123
 						$this->createOrder($domains, $notBefore, $notAfter, $keyType);
121
-					}
122
-					else
124
+					} else
123 125
 					{
124 126
 						$this->status = $get['body']['status'];
125 127
 						$this->expires = $get['body']['expires'];
126 128
 						$this->identifiers = $get['body']['identifiers'];
127 129
 						$this->authorizationURLs = $get['body']['authorizations'];
128 130
 						$this->finalizeURL = $get['body']['finalize'];
129
-						if(array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
131
+						if(array_key_exists('certificate', $get['body'])) {
132
+							$this->certificateURL = $get['body']['certificate'];
133
+						}
130 134
 						$this->updateAuthorizations();
131 135
 					}
132
-				}
133
-				else
136
+				} else
134 137
 				{
135 138
 					foreach ($this->certificateKeys as $file)
136 139
 					{
137
-						if (is_file($file)) unlink($file);
140
+						if (is_file($file)) {
141
+							unlink($file);
142
+						}
143
+					}
144
+					if($this->log >= LECLient::LOG_STATUS) {
145
+						LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
138 146
 					}
139
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
140 147
 					$this->createOrder($domains, $notBefore, $notAfter);
141 148
 				}
142
-			}
143
-			else
149
+			} else
144 150
 			{
145 151
 
146 152
 				foreach ($this->certificateKeys as $file)
147 153
 				{
148
-					if (is_file($file)) unlink($file);
154
+					if (is_file($file)) {
155
+						unlink($file);
156
+					}
157
+				}
158
+				if($this->log >= LECLient::LOG_STATUS) {
159
+					LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
149 160
 				}
150
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order data for \'' . $this->basename . '\' invalid. Deleting order data and creating new order.', 'function LEOrder __construct');
151 161
 
152 162
 				$this->createOrder($domains, $notBefore, $notAfter);
153 163
 			}
154
-		}
155
-		else
164
+		} else
156 165
 		{
157
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct');
166
+			if($this->log >= LECLient::LOG_STATUS) {
167
+				LEFunctions::log('No order found for \'' . $this->basename . '\'. Creating new order.', 'function LEOrder __construct');
168
+			}
158 169
 			$this->createOrder($domains, $notBefore, $notAfter);
159 170
 		}
160 171
 	}
@@ -174,7 +185,9 @@  discard block
 block discarded – undo
174 185
 			$dns = array();
175 186
 			foreach($domains as $domain)
176 187
 			{
177
-				if(preg_match_all('~(\*\.)~', $domain) > 1) throw new \RuntimeException('Cannot create orders with multiple wildcards in one domain.');
188
+				if(preg_match_all('~(\*\.)~', $domain) > 1) {
189
+					throw new \RuntimeException('Cannot create orders with multiple wildcards in one domain.');
190
+				}
178 191
 				$dns[] = array('type' => 'dns', 'value' => $domain);
179 192
 			}
180 193
 			$payload = array("identifiers" => $dns, 'notBefore' => $notBefore, 'notAfter' => $notAfter);
@@ -190,12 +203,10 @@  discard block
 block discarded – undo
190 203
 					if ($this->keyType == "rsa")
191 204
 					{
192 205
 						LEFunctions::RSAgenerateKeys(null, $this->certificateKeys['private_key'], $this->certificateKeys['public_key'], $this->keySize);
193
-					}
194
-					elseif ($this->keyType == "ec")
206
+					} elseif ($this->keyType == "ec")
195 207
 					{
196 208
 						LEFunctions::ECgenerateKeys(null, $this->certificateKeys['private_key'], $this->certificateKeys['public_key'], $this->keySize);
197
-					}
198
-					else
209
+					} else
199 210
 					{
200 211
 						throw new \RuntimeException('Key type \'' . $this->keyType . '\' not supported.');
201 212
 					}
@@ -205,22 +216,23 @@  discard block
 block discarded – undo
205 216
 					$this->identifiers = $post['body']['identifiers'];
206 217
 					$this->authorizationURLs = $post['body']['authorizations'];
207 218
 					$this->finalizeURL = $post['body']['finalize'];
208
-					if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
219
+					if(array_key_exists('certificate', $post['body'])) {
220
+						$this->certificateURL = $post['body']['certificate'];
221
+					}
209 222
 					$this->updateAuthorizations();
210 223
 
211
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)');
212
-				}
213
-				else
224
+					if($this->log >= LECLient::LOG_STATUS) {
225
+						LEFunctions::log('Created order for \'' . $this->basename . '\'.', 'function createOrder (function LEOrder __construct)');
226
+					}
227
+				} else
214 228
 				{
215 229
 					throw new \RuntimeException('New-order returned invalid response.');
216 230
 				}
217
-			}
218
-			else
231
+			} else
219 232
 			{
220 233
 				throw new \RuntimeException('Creating new order failed.');
221 234
 			}
222
-		}
223
-		else
235
+		} else
224 236
 		{
225 237
 			throw new \RuntimeException('notBefore and notAfter fields must be empty or be a string similar to 0000-00-00T00:00:00Z');
226 238
 		}
@@ -239,12 +251,15 @@  discard block
 block discarded – undo
239 251
 			$this->identifiers = $get['body']['identifiers'];
240 252
 			$this->authorizationURLs = $get['body']['authorizations'];
241 253
 			$this->finalizeURL = $get['body']['finalize'];
242
-			if(array_key_exists('certificate', $get['body'])) $this->certificateURL = $get['body']['certificate'];
254
+			if(array_key_exists('certificate', $get['body'])) {
255
+				$this->certificateURL = $get['body']['certificate'];
256
+			}
243 257
 			$this->updateAuthorizations();
244
-		}
245
-		else
258
+		} else
246 259
 		{
247
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData');
260
+			if($this->log >= LECLient::LOG_STATUS) {
261
+				LEFunctions::log('Cannot update data for order \'' . $this->basename . '\'.', 'function updateOrderData');
262
+			}
248 263
 		}
249 264
 	}
250 265
 
@@ -259,7 +274,9 @@  discard block
 block discarded – undo
259 274
 			if (filter_var($authURL, FILTER_VALIDATE_URL))
260 275
 			{
261 276
 				$auth = new LEAuthorization($this->connector, $this->log, $authURL);
262
-				if($auth != false) $this->authorizations[] = $auth;
277
+				if($auth != false) {
278
+					$this->authorizations[] = $auth;
279
+				}
263 280
 			}
264 281
 		}
265 282
 	}
@@ -275,7 +292,9 @@  discard block
 block discarded – undo
275 292
 		{
276 293
 			foreach($this->authorizations as $auth)
277 294
 			{
278
-				if($auth->status != 'valid') return false;
295
+				if($auth->status != 'valid') {
296
+					return false;
297
+				}
279 298
 			}
280 299
 			return true;
281 300
 		}
@@ -374,7 +393,9 @@  discard block
 block discarded – undo
374 393
 									$post = $this->connector->post($challenge['url'], $sign);
375 394
 									if(strpos($post['header'], "200 OK") !== false)
376 395
 									{
377
-										if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
396
+										if($this->log >= LECLient::LOG_STATUS) {
397
+											LEFunctions::log('HTTP challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
398
+										}
378 399
 										while($auth->status == 'pending')
379 400
 										{
380 401
 											sleep(1);
@@ -382,10 +403,11 @@  discard block
 block discarded – undo
382 403
 										}
383 404
 										return true;
384 405
 									}
385
-								}
386
-								else
406
+								} else
387 407
 								{
388
-									if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
408
+									if($this->log >= LECLient::LOG_STATUS) {
409
+										LEFunctions::log('HTTP challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
410
+									}
389 411
 								}
390 412
 								break;
391 413
 							case LEOrder::CHALLENGE_TYPE_DNS:
@@ -396,7 +418,9 @@  discard block
 block discarded – undo
396 418
 									$post = $this->connector->post($challenge['url'], $sign);
397 419
 									if(strpos($post['header'], "200 OK") !== false)
398 420
 									{
399
-										if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
421
+										if($this->log >= LECLient::LOG_STATUS) {
422
+											LEFunctions::log('DNS challenge for \'' . $identifier . '\' valid.', 'function verifyPendingOrderAuthorization');
423
+										}
400 424
 										while($auth->status == 'pending')
401 425
 										{
402 426
 											sleep(1);
@@ -404,10 +428,11 @@  discard block
 block discarded – undo
404 428
 										}
405 429
 										return true;
406 430
 									}
407
-								}
408
-								else
431
+								} else
409 432
 								{
410
-									if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
433
+									if($this->log >= LECLient::LOG_STATUS) {
434
+										LEFunctions::log('DNS challenge for \'' . $identifier . '\' tested, found invalid.', 'function verifyPendingOrderAuthorization');
435
+									}
411 436
 								}
412 437
 								break;
413 438
 						}
@@ -435,13 +460,17 @@  discard block
 block discarded – undo
435 460
 				$post = $this->connector->post($auth->authorizationURL, $sign);
436 461
 				if(strpos($post['header'], "200 OK") !== false)
437 462
 				{
438
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization');
463
+					if($this->log >= LECLient::LOG_STATUS) {
464
+						LEFunctions::log('Authorization for \'' . $identifier . '\' deactivated.', 'function deactivateOrderAuthorization');
465
+					}
439 466
 					$this->updateAuthorizations();
440 467
 					return true;
441 468
 				}
442 469
 			}
443 470
 		}
444
-		if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization');
471
+		if($this->log >= LECLient::LOG_STATUS) {
472
+			LEFunctions::log('No authorization found for \'' . $identifier . '\', cannot deactivate.', 'function deactivateOrderAuthorization');
473
+		}
445 474
 		return false;
446 475
 	}
447 476
 
@@ -457,12 +486,10 @@  discard block
 block discarded – undo
457 486
 		if(in_array($this->basename, $domains))
458 487
 		{
459 488
 			$CN = $this->basename;
460
-		}
461
-		elseif(in_array('*.' . $this->basename, $domains))
489
+		} elseif(in_array('*.' . $this->basename, $domains))
462 490
 		{
463 491
 			$CN = '*.' . $this->basename;
464
-		}
465
-		else
492
+		} else
466 493
 		{
467 494
 			$CN = $domains[0];
468 495
 		}
@@ -512,8 +539,12 @@  discard block
 block discarded – undo
512 539
 		{
513 540
 			if($this->allAuthorizationsValid())
514 541
 			{
515
-				if(empty($csr)) $csr = $this->generateCSR();
516
-				if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) $csr = $matches[1];
542
+				if(empty($csr)) {
543
+					$csr = $this->generateCSR();
544
+				}
545
+				if(preg_match('~-----BEGIN\sCERTIFICATE\sREQUEST-----(.*)-----END\sCERTIFICATE\sREQUEST-----~s', $csr, $matches)) {
546
+					$csr = $matches[1];
547
+				}
517 548
 				$csr = trim(LEFunctions::Base64UrlSafeEncode(base64_decode($csr)));
518 549
 				$sign = $this->connector->signRequestKid(array('csr' => $csr), $this->connector->accountURL, $this->finalizeURL);
519 550
 				$post = $this->connector->post($this->finalizeURL, $sign);
@@ -524,20 +555,26 @@  discard block
 block discarded – undo
524 555
 					$this->identifiers = $post['body']['identifiers'];
525 556
 					$this->authorizationURLs = $post['body']['authorizations'];
526 557
 					$this->finalizeURL = $post['body']['finalize'];
527
-					if(array_key_exists('certificate', $post['body'])) $this->certificateURL = $post['body']['certificate'];
558
+					if(array_key_exists('certificate', $post['body'])) {
559
+						$this->certificateURL = $post['body']['certificate'];
560
+					}
528 561
 					$this->updateAuthorizations();
529
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder');
562
+					if($this->log >= LECLient::LOG_STATUS) {
563
+						LEFunctions::log('Order for \'' . $this->basename . '\' finalized.', 'function finalizeOrder');
564
+					}
530 565
 					return true;
531 566
 				}
532
-			}
533
-			else
567
+			} else
534 568
 			{
535
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder');
569
+				if($this->log >= LECLient::LOG_STATUS) {
570
+					LEFunctions::log('Not all authorizations are valid for \'' . $this->basename . '\'. Cannot finalize order.', 'function finalizeOrder');
571
+				}
536 572
 			}
537
-		}
538
-		else
573
+		} else
539 574
 		{
540
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder');
575
+			if($this->log >= LECLient::LOG_STATUS) {
576
+				LEFunctions::log('Order status for \'' . $this->basename . '\' is \'' . $this->status . '\'. Cannot finalize order.', 'function finalizeOrder');
577
+			}
541 578
 		}
542 579
 		return false;
543 580
 	}
@@ -563,7 +600,9 @@  discard block
 block discarded – undo
563 600
 		$polling = 0;
564 601
 		while($this->status == 'processing' && $polling < 4)
565 602
 		{
566
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate');
603
+			if($this->log >= LECLient::LOG_STATUS) {
604
+				LEFunctions::log('Certificate for \'' . $this->basename . '\' being processed. Retrying in 5 seconds...', 'function getCertificate');
605
+			}
567 606
 			sleep(5);
568 607
 			$this->updateOrderData();
569 608
 			$polling++;
@@ -575,7 +614,9 @@  discard block
 block discarded – undo
575 614
 			{
576 615
 				if(preg_match_all('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i', $get['body'], $matches))
577 616
 				{
578
-					if (isset($this->certificateKeys['certificate'])) file_put_contents($this->certificateKeys['certificate'],  $matches[0][0]);
617
+					if (isset($this->certificateKeys['certificate'])) {
618
+						file_put_contents($this->certificateKeys['certificate'],  $matches[0][0]);
619
+					}
579 620
 
580 621
 					if(count($matches[0]) > 1 && isset($this->certificateKeys['fullchain_certificate']))
581 622
 					{
@@ -587,22 +628,27 @@  discard block
 block discarded – undo
587 628
 						}
588 629
 						file_put_contents(trim($this->certificateKeys['fullchain_certificate']), $fullchain);
589 630
 					}
590
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
631
+					if($this->log >= LECLient::LOG_STATUS) {
632
+						LEFunctions::log('Certificate for \'' . $this->basename . '\' saved', 'function getCertificate');
633
+					}
591 634
 					return true;
592
-				}
593
-				else
635
+				} else
594 636
 				{
595
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
637
+					if($this->log >= LECLient::LOG_STATUS) {
638
+						LEFunctions::log('Received invalid certificate for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
639
+					}
596 640
 				}
597
-			}
598
-			else
641
+			} else
599 642
 			{
600
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
643
+				if($this->log >= LECLient::LOG_STATUS) {
644
+					LEFunctions::log('Invalid response for certificate request for \'' . $this->basename . '\'. Cannot save certificate.', 'function getCertificate');
645
+				}
601 646
 			}
602
-		}
603
-		else
647
+		} else
604 648
 		{
605
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate');
649
+			if($this->log >= LECLient::LOG_STATUS) {
650
+				LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot retrieve certificate.', 'function getCertificate');
651
+			}
606 652
 		}
607 653
 		return false;
608 654
 	}
@@ -619,9 +665,13 @@  discard block
 block discarded – undo
619 665
 	{
620 666
 		if($this->status == 'valid')
621 667
 		{
622
-			if (isset($this->certificateKeys['certificate'])) $certFile = $this->certificateKeys['certificate'];
623
-			elseif (isset($this->certificateKeys['fullchain_certificate']))  $certFile = $this->certificateKeys['fullchain_certificate'];
624
-			else throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required');
668
+			if (isset($this->certificateKeys['certificate'])) {
669
+				$certFile = $this->certificateKeys['certificate'];
670
+			} elseif (isset($this->certificateKeys['fullchain_certificate'])) {
671
+				$certFile = $this->certificateKeys['fullchain_certificate'];
672
+			} else {
673
+				throw new \RuntimeException('certificateKeys[certificate] or certificateKeys[fullchain_certificate] required');
674
+			}
625 675
 
626 676
 			if(file_exists($certFile) && file_exists($this->certificateKeys['private_key']))
627 677
 			{
@@ -633,22 +683,27 @@  discard block
 block discarded – undo
633 683
 				$post = $this->connector->post($this->connector->revokeCert, $sign);
634 684
 				if(strpos($post['header'], "200 OK") !== false)
635 685
 				{
636
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate');
686
+					if($this->log >= LECLient::LOG_STATUS) {
687
+						LEFunctions::log('Certificate for order \'' . $this->basename . '\' revoked.', 'function revokeCertificate');
688
+					}
637 689
 					return true;
638
-				}
639
-				else
690
+				} else
640 691
 				{
641
-					if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate');
692
+					if($this->log >= LECLient::LOG_STATUS) {
693
+						LEFunctions::log('Certificate for order \'' . $this->basename . '\' cannot be revoked.', 'function revokeCertificate');
694
+					}
642 695
 				}
643
-			}
644
-			else
696
+			} else
645 697
 			{
646
-				if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate');
698
+				if($this->log >= LECLient::LOG_STATUS) {
699
+					LEFunctions::log('Certificate for order \'' . $this->basename . '\' not found. Cannot revoke certificate.', 'function revokeCertificate');
700
+				}
647 701
 			}
648
-		}
649
-		else
702
+		} else
650 703
 		{
651
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate');
704
+			if($this->log >= LECLient::LOG_STATUS) {
705
+				LEFunctions::log('Order for \'' . $this->basename . '\' not valid. Cannot revoke certificate.', 'function revokeCertificate');
706
+			}
652 707
 		}
653 708
 		return false;
654 709
 	}
Please login to merge, or discard this patch.
LEClient/src/LEAccount.php 3 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -49,14 +49,14 @@  discard block
 block discarded – undo
49 49
 
50 50
 	private $log;
51 51
 
52
-    /**
53
-     * Initiates the LetsEncrypt Account class.
54
-     *
55
-     * @param LEConnector	$connector 		The LetsEncrypt Connector instance to use for HTTP requests.
56
-     * @param int 			$log 			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
57
-     * @param array 		$email	 		The array of strings containing e-mail addresses. Only used when creating a new account.
58
-     * @param array 		$accountKeys Array containing location of account keys files.
59
-     */
52
+	/**
53
+	 * Initiates the LetsEncrypt Account class.
54
+	 *
55
+	 * @param LEConnector	$connector 		The LetsEncrypt Connector instance to use for HTTP requests.
56
+	 * @param int 			$log 			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
57
+	 * @param array 		$email	 		The array of strings containing e-mail addresses. Only used when creating a new account.
58
+	 * @param array 		$accountKeys Array containing location of account keys files.
59
+	 */
60 60
 	public function __construct($connector, $log, $email, $accountKeys)
61 61
 	{
62 62
 		$this->connector = $connector;
@@ -77,13 +77,13 @@  discard block
 block discarded – undo
77 77
 		$this->getLEAccountData();
78 78
 	}
79 79
 
80
-    /**
81
-     * Creates a new LetsEncrypt account.
82
-     *
83
-     * @param array 	$email 	The array of strings containing e-mail addresses.
84
-     *
85
-     * @return object	Returns the new account URL when the account was successfully created, false if not.
86
-     */
80
+	/**
81
+	 * Creates a new LetsEncrypt account.
82
+	 *
83
+	 * @param array 	$email 	The array of strings containing e-mail addresses.
84
+	 *
85
+	 * @return object	Returns the new account URL when the account was successfully created, false if not.
86
+	 */
87 87
 	private function createLEAccount($email)
88 88
 	{
89 89
 		$contact = array_map(function($addr) { return empty($addr) ? '' : (strpos($addr, 'mailto') === false ? 'mailto:' . $addr : $addr); }, $email);
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 		return false;
98 98
 	}
99 99
 
100
-    /**
101
-     * Gets the LetsEncrypt account URL associated with the stored account keys.
102
-     *
103
-     * @return object	Returns the account URL if it is found, or false when none is found.
104
-     */
100
+	/**
101
+	 * Gets the LetsEncrypt account URL associated with the stored account keys.
102
+	 *
103
+	 * @return object	Returns the account URL if it is found, or false when none is found.
104
+	 */
105 105
 	private function getLEAccount()
106 106
 	{
107 107
 		$sign = $this->connector->signRequestJWK(array('onlyReturnExisting' => true), $this->connector->newAccount);
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 		return false;
115 115
 	}
116 116
 
117
-    /**
118
-     * Gets the LetsEncrypt account data from the account URL.
119
-     */
117
+	/**
118
+	 * Gets the LetsEncrypt account data from the account URL.
119
+	 */
120 120
 	private function getLEAccountData()
121 121
 	{
122 122
 		$sign = $this->connector->signRequestKid(array('' => ''), $this->connector->accountURL, $this->connector->accountURL);
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
 		}
138 138
 	}
139 139
 
140
-    /**
141
-     * Updates account data. Now just supporting new contact information.
142
-     *
143
-     * @param array 	$email	The array of strings containing e-mail adresses.
144
-     *
145
-     * @return boolean	Returns true if the update is successful, false if not.
146
-     */
140
+	/**
141
+	 * Updates account data. Now just supporting new contact information.
142
+	 *
143
+	 * @param array 	$email	The array of strings containing e-mail adresses.
144
+	 *
145
+	 * @return boolean	Returns true if the update is successful, false if not.
146
+	 */
147 147
 	public function updateAccount($email)
148 148
 	{
149 149
 		$contact = array_map(function($addr) { return empty($addr) ? '' : (strpos($addr, 'mailto') === false ? 'mailto:' . $addr : $addr); }, $email);
@@ -168,17 +168,17 @@  discard block
 block discarded – undo
168 168
 		}
169 169
 	}
170 170
 
171
-    /**
172
-     * Creates new RSA account keys and updates the keys with LetsEncrypt.
173
-     *
174
-     * @return boolean	Returns true if the update is successful, false if not.
175
-     */
171
+	/**
172
+	 * Creates new RSA account keys and updates the keys with LetsEncrypt.
173
+	 *
174
+	 * @return boolean	Returns true if the update is successful, false if not.
175
+	 */
176 176
 	public function changeAccountKeys()
177 177
 	{
178 178
 		LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'].'.new', $this->accountKeys['public_key'].'.new');
179 179
 		$privateKey = openssl_pkey_get_private(file_get_contents($this->accountKeys['private_key'].'.new'));
180 180
 		$details = openssl_pkey_get_details($privateKey);
181
-    $innerPayload = array('account' => $this->connector->accountURL, 'newKey' => array(
181
+	$innerPayload = array('account' => $this->connector->accountURL, 'newKey' => array(
182 182
 			"kty" => "RSA",
183 183
 			"n" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["n"]),
184 184
 			"e" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["e"])
@@ -204,11 +204,11 @@  discard block
 block discarded – undo
204 204
 		}
205 205
 	}
206 206
 
207
-    /**
208
-     * Deactivates the LetsEncrypt account.
209
-     *
210
-     * @return boolean	Returns true if the deactivation is successful, false if not.
211
-     */
207
+	/**
208
+	 * Deactivates the LetsEncrypt account.
209
+	 *
210
+	 * @return boolean	Returns true if the deactivation is successful, false if not.
211
+	 */
212 212
 	public function deactivateAccount()
213 213
 	{
214 214
 		$sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $this->connector->accountURL);
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 		$this->accountKeys = $accountKeys;
64 64
 		$this->log = $log;
65 65
 
66
-		if(!file_exists($this->accountKeys['private_key']) OR !file_exists($this->accountKeys['public_key']))
66
+		if (!file_exists($this->accountKeys['private_key']) OR !file_exists($this->accountKeys['public_key']))
67 67
 		{
68
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct');
68
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct');
69 69
 			LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'], $this->accountKeys['public_key']);
70 70
 			$this->connector->accountURL = $this->createLEAccount($email);
71 71
 		}
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		{
74 74
 			$this->connector->accountURL = $this->getLEAccount();
75 75
 		}
76
-		if($this->connector->accountURL == false) throw new \RuntimeException('Account not found or deactivated.');
76
+		if ($this->connector->accountURL == false) throw new \RuntimeException('Account not found or deactivated.');
77 77
 		$this->getLEAccountData();
78 78
 	}
79 79
 
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 
91 91
 		$sign = $this->connector->signRequestJWK(array('contact' => $contact, 'termsOfServiceAgreed' => true), $this->connector->newAccount);
92 92
 		$post = $this->connector->post($this->connector->newAccount, $sign);
93
-		if(strpos($post['header'], "201 Created") !== false)
93
+		if (strpos($post['header'], "201 Created") !== false)
94 94
 		{
95
-			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
95
+			if (preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
96 96
 		}
97 97
 		return false;
98 98
 	}
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
 		$sign = $this->connector->signRequestJWK(array('onlyReturnExisting' => true), $this->connector->newAccount);
108 108
 		$post = $this->connector->post($this->connector->newAccount, $sign);
109 109
 
110
-		if(strpos($post['header'], "200 OK") !== false)
110
+		if (strpos($post['header'], "200 OK") !== false)
111 111
 		{
112
-			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
112
+			if (preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
113 113
 		}
114 114
 		return false;
115 115
 	}
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	{
122 122
 		$sign = $this->connector->signRequestKid(array('' => ''), $this->connector->accountURL, $this->connector->accountURL);
123 123
 		$post = $this->connector->post($this->connector->accountURL, $sign);
124
-		if(strpos($post['header'], "200 OK") !== false)
124
+		if (strpos($post['header'], "200 OK") !== false)
125 125
 		{
126 126
 			$this->id = $post['body']['id'];
127 127
 			$this->key = $post['body']['key'];
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 
151 151
 		$sign = $this->connector->signRequestKid(array('contact' => $contact), $this->connector->accountURL, $this->connector->accountURL);
152 152
 		$post = $this->connector->post($this->connector->accountURL, $sign);
153
-		if(strpos($post['header'], "200 OK") !== false)
153
+		if (strpos($post['header'], "200 OK") !== false)
154 154
 		{
155 155
 			$this->id = $post['body']['id'];
156 156
 			$this->key = $post['body']['key'];
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 			$this->initialIp = $post['body']['initialIp'];
160 160
 			$this->createdAt = $post['body']['createdAt'];
161 161
 			$this->status = $post['body']['status'];
162
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account data updated.', 'function updateAccount');
162
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account data updated.', 'function updateAccount');
163 163
 			return true;
164 164
 		}
165 165
 		else
@@ -175,27 +175,27 @@  discard block
 block discarded – undo
175 175
      */
176 176
 	public function changeAccountKeys()
177 177
 	{
178
-		LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'].'.new', $this->accountKeys['public_key'].'.new');
179
-		$privateKey = openssl_pkey_get_private(file_get_contents($this->accountKeys['private_key'].'.new'));
178
+		LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'] . '.new', $this->accountKeys['public_key'] . '.new');
179
+		$privateKey = openssl_pkey_get_private(file_get_contents($this->accountKeys['private_key'] . '.new'));
180 180
 		$details = openssl_pkey_get_details($privateKey);
181 181
     $innerPayload = array('account' => $this->connector->accountURL, 'newKey' => array(
182 182
 			"kty" => "RSA",
183 183
 			"n" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["n"]),
184 184
 			"e" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["e"])
185 185
 		));
186
-		$outerPayload = $this->connector->signRequestJWK($innerPayload, $this->connector->keyChange, $this->accountKeys['private_key'].'.new');
186
+		$outerPayload = $this->connector->signRequestJWK($innerPayload, $this->connector->keyChange, $this->accountKeys['private_key'] . '.new');
187 187
 		$sign = $this->connector->signRequestKid($outerPayload, $this->connector->accountURL, $this->connector->keyChange);
188 188
 		$post = $this->connector->post($this->connector->keyChange, $sign);
189
-		if(strpos($post['header'], "200 OK") !== false)
189
+		if (strpos($post['header'], "200 OK") !== false)
190 190
 		{
191 191
 			$this->getLEAccountData();
192 192
 
193 193
 			unlink($this->accountKeys['private_key']);
194 194
 			unlink($this->accountKeys['public_key']);
195
-			rename($this->accountKeys['private_key'].'.new', $this->accountKeys['private_key']);
196
-			rename($this->accountKeys['public_key'].'.new', $this->accountKeys['public_key']);
195
+			rename($this->accountKeys['private_key'] . '.new', $this->accountKeys['private_key']);
196
+			rename($this->accountKeys['public_key'] . '.new', $this->accountKeys['public_key']);
197 197
 
198
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account keys changed.', 'function changeAccountKey');
198
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account keys changed.', 'function changeAccountKey');
199 199
 			return true;
200 200
 		}
201 201
 		else
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
 	{
214 214
 		$sign = $this->connector->signRequestKid(array('status' => 'deactivated'), $this->connector->accountURL, $this->connector->accountURL);
215 215
 		$post = $this->connector->post($this->connector->accountURL, $sign);
216
-		if(strpos($post['header'], "200 OK") !== false)
216
+		if (strpos($post['header'], "200 OK") !== false)
217 217
 		{
218 218
 			$this->connector->accountDeactivated = true;
219
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account deactivated.', 'function deactivateAccount');
219
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account deactivated.', 'function deactivateAccount');
220 220
 		}
221 221
 		else
222 222
 		{
Please login to merge, or discard this patch.
Braces   +26 added lines, -17 removed lines patch added patch discarded remove patch
@@ -65,15 +65,18 @@  discard block
 block discarded – undo
65 65
 
66 66
 		if(!file_exists($this->accountKeys['private_key']) OR !file_exists($this->accountKeys['public_key']))
67 67
 		{
68
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct');
68
+			if($this->log >= LECLient::LOG_STATUS) {
69
+				LEFunctions::log('No account found, attempting to create account.', 'function LEAccount __construct');
70
+			}
69 71
 			LEFunctions::RSAgenerateKeys(null, $this->accountKeys['private_key'], $this->accountKeys['public_key']);
70 72
 			$this->connector->accountURL = $this->createLEAccount($email);
71
-		}
72
-		else
73
+		} else
73 74
 		{
74 75
 			$this->connector->accountURL = $this->getLEAccount();
75 76
 		}
76
-		if($this->connector->accountURL == false) throw new \RuntimeException('Account not found or deactivated.');
77
+		if($this->connector->accountURL == false) {
78
+			throw new \RuntimeException('Account not found or deactivated.');
79
+		}
77 80
 		$this->getLEAccountData();
78 81
 	}
79 82
 
@@ -92,7 +95,9 @@  discard block
 block discarded – undo
92 95
 		$post = $this->connector->post($this->connector->newAccount, $sign);
93 96
 		if(strpos($post['header'], "201 Created") !== false)
94 97
 		{
95
-			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
98
+			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) {
99
+				return trim($matches[1]);
100
+			}
96 101
 		}
97 102
 		return false;
98 103
 	}
@@ -109,7 +114,9 @@  discard block
 block discarded – undo
109 114
 
110 115
 		if(strpos($post['header'], "200 OK") !== false)
111 116
 		{
112
-			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) return trim($matches[1]);
117
+			if(preg_match('~Location: (\S+)~i', $post['header'], $matches)) {
118
+				return trim($matches[1]);
119
+			}
113 120
 		}
114 121
 		return false;
115 122
 	}
@@ -130,8 +137,7 @@  discard block
 block discarded – undo
130 137
 			$this->initialIp = $post['body']['initialIp'];
131 138
 			$this->createdAt = $post['body']['createdAt'];
132 139
 			$this->status = $post['body']['status'];
133
-		}
134
-		else
140
+		} else
135 141
 		{
136 142
 			throw new \RuntimeException('Account data cannot be found.');
137 143
 		}
@@ -159,10 +165,11 @@  discard block
 block discarded – undo
159 165
 			$this->initialIp = $post['body']['initialIp'];
160 166
 			$this->createdAt = $post['body']['createdAt'];
161 167
 			$this->status = $post['body']['status'];
162
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account data updated.', 'function updateAccount');
168
+			if($this->log >= LECLient::LOG_STATUS) {
169
+				LEFunctions::log('Account data updated.', 'function updateAccount');
170
+			}
163 171
 			return true;
164
-		}
165
-		else
172
+		} else
166 173
 		{
167 174
 			return false;
168 175
 		}
@@ -195,10 +202,11 @@  discard block
 block discarded – undo
195 202
 			rename($this->accountKeys['private_key'].'.new', $this->accountKeys['private_key']);
196 203
 			rename($this->accountKeys['public_key'].'.new', $this->accountKeys['public_key']);
197 204
 
198
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account keys changed.', 'function changeAccountKey');
205
+			if($this->log >= LECLient::LOG_STATUS) {
206
+				LEFunctions::log('Account keys changed.', 'function changeAccountKey');
207
+			}
199 208
 			return true;
200
-		}
201
-		else
209
+		} else
202 210
 		{
203 211
 			return false;
204 212
 		}
@@ -216,9 +224,10 @@  discard block
 block discarded – undo
216 224
 		if(strpos($post['header'], "200 OK") !== false)
217 225
 		{
218 226
 			$this->connector->accountDeactivated = true;
219
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Account deactivated.', 'function deactivateAccount');
220
-		}
221
-		else
227
+			if($this->log >= LECLient::LOG_STATUS) {
228
+				LEFunctions::log('Account deactivated.', 'function deactivateAccount');
229
+			}
230
+		} else
222 231
 		{
223 232
 			return false;
224 233
 		}
Please login to merge, or discard this patch.
LEClient/src/LEFunctions.php 3 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class LEFunctions
38 38
 {
39
-    /**
40
-     * Generates a new RSA keypair and saves both keys to a new file.
41
-     *
42
-     * @param string	$directory		The directory in which to store the new keys. If set to null or empty string - privateKeyFile and publicKeyFile will be treated as absolute paths.
43
-     * @param string	$privateKeyFile	The filename for the private key file.
44
-     * @param string	$publicKeyFile  The filename for the public key file.
45
-     * @param string	$keySize 	RSA key size, must be between 2048 and 4096 (default is 4096)
46
-     */
39
+	/**
40
+	 * Generates a new RSA keypair and saves both keys to a new file.
41
+	 *
42
+	 * @param string	$directory		The directory in which to store the new keys. If set to null or empty string - privateKeyFile and publicKeyFile will be treated as absolute paths.
43
+	 * @param string	$privateKeyFile	The filename for the private key file.
44
+	 * @param string	$publicKeyFile  The filename for the public key file.
45
+	 * @param string	$keySize 	RSA key size, must be between 2048 and 4096 (default is 4096)
46
+	 */
47 47
 	public static function RSAGenerateKeys($directory, $privateKeyFile = 'private.pem', $publicKeyFile = 'public.pem', $keySize = 4096)
48 48
 	{
49 49
 
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
 
73 73
 
74 74
 
75
-    /**
76
-     * Generates a new EC prime256v1 keypair and saves both keys to a new file.
77
-     *
78
-     * @param string	$directory		The directory in which to store the new keys. If set to null or empty string - privateKeyFile and publicKeyFile will be treated as absolute paths.
79
-     * @param string	$privateKeyFile	The filename for the private key file.
80
-     * @param string	$publicKeyFile  The filename for the public key file.
81
-     * @param string	$keysize  EC key size, possible values are 256 (prime256v1) or 384 (secp384r1), default is 256
82
-     */
75
+	/**
76
+	 * Generates a new EC prime256v1 keypair and saves both keys to a new file.
77
+	 *
78
+	 * @param string	$directory		The directory in which to store the new keys. If set to null or empty string - privateKeyFile and publicKeyFile will be treated as absolute paths.
79
+	 * @param string	$privateKeyFile	The filename for the private key file.
80
+	 * @param string	$publicKeyFile  The filename for the public key file.
81
+	 * @param string	$keysize  EC key size, possible values are 256 (prime256v1) or 384 (secp384r1), default is 256
82
+	 */
83 83
 	public static function ECGenerateKeys($directory, $privateKeyFile = 'private.pem', $publicKeyFile = 'public.pem', $keySize = 256)
84 84
 	{
85 85
 		if (version_compare(PHP_VERSION, '7.1.0') == -1) throw new \RuntimeException("PHP 7.1+ required for EC keys");
@@ -120,43 +120,43 @@  discard block
 block discarded – undo
120 120
 
121 121
 
122 122
 
123
-    /**
124
-     * Encodes a string input to a base64 encoded string which is URL safe.
125
-     *
126
-     * @param string	$input 	The input string to encode.
127
-     *
128
-     * @return string	Returns a URL safe base64 encoded string.
129
-     */
123
+	/**
124
+	 * Encodes a string input to a base64 encoded string which is URL safe.
125
+	 *
126
+	 * @param string	$input 	The input string to encode.
127
+	 *
128
+	 * @return string	Returns a URL safe base64 encoded string.
129
+	 */
130 130
 	public static function Base64UrlSafeEncode($input)
131
-    {
132
-        return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
133
-    }
134
-
135
-    /**
136
-     * Decodes a string that is URL safe base64 encoded.
137
-     *
138
-     * @param string	$input	The encoded input string to decode.
139
-     *
140
-     * @return string	Returns the decoded input string.
141
-     */
142
-    public static function Base64UrlSafeDecode($input)
143
-    {
144
-        $remainder = strlen($input) % 4;
145
-        if ($remainder) {
146
-            $padlen = 4 - $remainder;
147
-            $input .= str_repeat('=', $padlen);
148
-        }
149
-        return base64_decode(strtr($input, '-_', '+/'));
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * Outputs a log message.
156
-     *
157
-     * @param object	$data		The data to print.
158
-     * @param string	$function	The function name to print above. Defaults to the calling function's name from the stacktrace. (optional)
159
-     */
131
+	{
132
+		return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
133
+	}
134
+
135
+	/**
136
+	 * Decodes a string that is URL safe base64 encoded.
137
+	 *
138
+	 * @param string	$input	The encoded input string to decode.
139
+	 *
140
+	 * @return string	Returns the decoded input string.
141
+	 */
142
+	public static function Base64UrlSafeDecode($input)
143
+	{
144
+		$remainder = strlen($input) % 4;
145
+		if ($remainder) {
146
+			$padlen = 4 - $remainder;
147
+			$input .= str_repeat('=', $padlen);
148
+		}
149
+		return base64_decode(strtr($input, '-_', '+/'));
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * Outputs a log message.
156
+	 *
157
+	 * @param object	$data		The data to print.
158
+	 * @param string	$function	The function name to print above. Defaults to the calling function's name from the stacktrace. (optional)
159
+	 */
160 160
 	public static function log($data, $function = '')
161 161
 	{
162 162
 		$e = new Exception();
@@ -178,34 +178,34 @@  discard block
 block discarded – undo
178 178
 
179 179
 
180 180
 
181
-    /**
182
-     * Makes a request to the HTTP challenge URL and checks whether the authorization is valid for the given $domain.
183
-     *
184
-     * @param string	$domain 			The domain to check the authorization for.
185
-     * @param string 	$token 				The token (filename) to request.
186
-     * @param string 	$keyAuthorization 	the keyAuthorization (file content) to compare.
187
-     *
188
-     * @return boolean	Returns true if the challenge is valid, false if not.
189
-     */
181
+	/**
182
+	 * Makes a request to the HTTP challenge URL and checks whether the authorization is valid for the given $domain.
183
+	 *
184
+	 * @param string	$domain 			The domain to check the authorization for.
185
+	 * @param string 	$token 				The token (filename) to request.
186
+	 * @param string 	$keyAuthorization 	the keyAuthorization (file content) to compare.
187
+	 *
188
+	 * @return boolean	Returns true if the challenge is valid, false if not.
189
+	 */
190 190
 	public static function checkHTTPChallenge($domain, $token, $keyAuthorization)
191 191
 	{
192 192
 		$requestURL = $domain . '/.well-known/acme-challenge/' . $token;
193 193
 		$handle = curl_init();
194
-        curl_setopt($handle, CURLOPT_URL, $requestURL);
195
-        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
196
-        curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
197
-        $response = curl_exec($handle);
194
+		curl_setopt($handle, CURLOPT_URL, $requestURL);
195
+		curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
196
+		curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
197
+		$response = curl_exec($handle);
198 198
 		return (!empty($response) && $response == $keyAuthorization);
199 199
 	}
200 200
 
201
-    /**
202
-     * Checks whether the applicable DNS TXT record is a valid authorization for the given $domain.
203
-     *
204
-     * @param string	$domain 	The domain to check the authorization for.
205
-     * @param string	$DNSDigest	The digest to compare the DNS record to.
206
-     *
207
-     * @return boolean	Returns true if the challenge is valid, false if not.
208
-     */
201
+	/**
202
+	 * Checks whether the applicable DNS TXT record is a valid authorization for the given $domain.
203
+	 *
204
+	 * @param string	$domain 	The domain to check the authorization for.
205
+	 * @param string	$DNSDigest	The digest to compare the DNS record to.
206
+	 *
207
+	 * @return boolean	Returns true if the challenge is valid, false if not.
208
+	 */
209 209
 	public static function checkDNSChallenge($domain, $DNSDigest)
210 210
 	{
211 211
 		$DNS = '_acme-challenge.' . str_replace('*.', '', $domain);
@@ -219,11 +219,11 @@  discard block
 block discarded – undo
219 219
 
220 220
 
221 221
 
222
-    /**
223
-     * Creates a simple .htaccess file in $directory which denies from all.
224
-     *
225
-     * @param string	$directory	The directory in which to put the .htaccess file.
226
-     */
222
+	/**
223
+	 * Creates a simple .htaccess file in $directory which denies from all.
224
+	 *
225
+	 * @param string	$directory	The directory in which to put the .htaccess file.
226
+	 */
227 227
 	public static function createhtaccess($directory)
228 228
 	{
229 229
 		file_put_contents($directory . '.htaccess', "order deny,allow\ndeny from all");
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
 			"private_key_bits" => intval($keySize),
55 55
 		));
56 56
 
57
-		if(!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("RSA keypair export failed!");
57
+		if (!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("RSA keypair export failed!");
58 58
 
59 59
 		$details = openssl_pkey_get_details($res);
60 60
 
61 61
 		if ($directory !== null && $directory !== '')
62 62
 		{
63
-			$privateKeyFile = $directory.$privateKeyFile;
64
-			$publicKeyFile = $directory.$publicKeyFile;
63
+			$privateKeyFile = $directory . $privateKeyFile;
64
+			$publicKeyFile = $directory . $publicKeyFile;
65 65
 		}
66 66
 
67 67
 		file_put_contents($privateKeyFile, $privateKey);
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
 		else throw new \RuntimeException("EC key size must be 256 or 384");
103 103
 
104 104
 
105
-		if(!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("EC keypair export failed!");
105
+		if (!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("EC keypair export failed!");
106 106
 
107 107
 		$details = openssl_pkey_get_details($res);
108 108
 
109 109
 		if ($directory !== null && $directory !== '')
110 110
 		{
111
-			$privateKeyFile = $directory.$privateKeyFile;
112
-			$publicKeyFile = $directory.$publicKeyFile;
111
+			$privateKeyFile = $directory . $privateKeyFile;
112
+			$publicKeyFile = $directory . $publicKeyFile;
113 113
 		}
114 114
 
115 115
 		file_put_contents($privateKeyFile, $privateKey);
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	{
162 162
 		$e = new Exception();
163 163
 		$trace = $e->getTrace();
164
-		$function = $function == '' ? 'function ' .  $trace[3]['function'] . ' (function ' . $trace[2]['function'] . ')' : $function;
164
+		$function = $function == '' ? 'function ' . $trace[3]['function'] . ' (function ' . $trace[2]['function'] . ')' : $function;
165 165
 		if (PHP_SAPI == "cli")
166 166
 		{
167 167
 			echo '[' . date('d-m-Y H:i:s') . '] ' . $function . ":\n";
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
 	{
211 211
 		$DNS = '_acme-challenge.' . str_replace('*.', '', $domain);
212 212
 		$records = dns_get_record($DNS, DNS_TXT);
213
-		foreach($records as $record)
213
+		foreach ($records as $record)
214 214
 		{
215
-			if($record['host'] == $DNS && $record['type'] == 'TXT' && $record['txt'] == $DNSDigest) return true;
215
+			if ($record['host'] == $DNS && $record['type'] == 'TXT' && $record['txt'] == $DNSDigest) return true;
216 216
 		}
217 217
 		return false;
218 218
 	}
Please login to merge, or discard this patch.
Braces   +19 added lines, -10 removed lines patch added patch discarded remove patch
@@ -47,14 +47,18 @@  discard block
 block discarded – undo
47 47
 	public static function RSAGenerateKeys($directory, $privateKeyFile = 'private.pem', $publicKeyFile = 'public.pem', $keySize = 4096)
48 48
 	{
49 49
 
50
-		if ($keySize < 2048 || $keySize > 4096)  throw new \RuntimeException("RSA key size must be between 2048 and 4096");
50
+		if ($keySize < 2048 || $keySize > 4096) {
51
+			throw new \RuntimeException("RSA key size must be between 2048 and 4096");
52
+		}
51 53
 
52 54
 		$res = openssl_pkey_new(array(
53 55
 			"private_key_type" => OPENSSL_KEYTYPE_RSA,
54 56
 			"private_key_bits" => intval($keySize),
55 57
 		));
56 58
 
57
-		if(!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("RSA keypair export failed!");
59
+		if(!openssl_pkey_export($res, $privateKey)) {
60
+			throw new \RuntimeException("RSA keypair export failed!");
61
+		}
58 62
 
59 63
 		$details = openssl_pkey_get_details($res);
60 64
 
@@ -82,7 +86,9 @@  discard block
 block discarded – undo
82 86
      */
83 87
 	public static function ECGenerateKeys($directory, $privateKeyFile = 'private.pem', $publicKeyFile = 'public.pem', $keySize = 256)
84 88
 	{
85
-		if (version_compare(PHP_VERSION, '7.1.0') == -1) throw new \RuntimeException("PHP 7.1+ required for EC keys");
89
+		if (version_compare(PHP_VERSION, '7.1.0') == -1) {
90
+			throw new \RuntimeException("PHP 7.1+ required for EC keys");
91
+		}
86 92
 
87 93
 
88 94
 		if ($keySize == 256)
@@ -91,18 +97,20 @@  discard block
 block discarded – undo
91 97
 						"private_key_type" => OPENSSL_KEYTYPE_EC,
92 98
 						"curve_name" => "prime256v1",
93 99
 				));
94
-		}
95
-		elseif ($keySize == 384)
100
+		} elseif ($keySize == 384)
96 101
 		{
97 102
 				$res = openssl_pkey_new(array(
98 103
 						"private_key_type" => OPENSSL_KEYTYPE_EC,
99 104
 						"curve_name" => "secp384r1",
100 105
 				));
106
+		} else {
107
+			throw new \RuntimeException("EC key size must be 256 or 384");
101 108
 		}
102
-		else throw new \RuntimeException("EC key size must be 256 or 384");
103 109
 
104 110
 
105
-		if(!openssl_pkey_export($res, $privateKey)) throw new \RuntimeException("EC keypair export failed!");
111
+		if(!openssl_pkey_export($res, $privateKey)) {
112
+			throw new \RuntimeException("EC keypair export failed!");
113
+		}
106 114
 
107 115
 		$details = openssl_pkey_get_details($res);
108 116
 
@@ -167,8 +175,7 @@  discard block
 block discarded – undo
167 175
 			echo '[' . date('d-m-Y H:i:s') . '] ' . $function . ":\n";
168 176
 			print_r($data);
169 177
 			echo "\n\n";
170
-		}
171
-		else
178
+		} else
172 179
 		{
173 180
 			echo '<b>' . date('d-m-Y H:i:s') . ', ' . $function . ':</b><br>';
174 181
 			print_r($data);
@@ -212,7 +219,9 @@  discard block
 block discarded – undo
212 219
 		$records = dns_get_record($DNS, DNS_TXT);
213 220
 		foreach($records as $record)
214 221
 		{
215
-			if($record['host'] == $DNS && $record['type'] == 'TXT' && $record['txt'] == $DNSDigest) return true;
222
+			if($record['host'] == $DNS && $record['type'] == 'TXT' && $record['txt'] == $DNSDigest) {
223
+				return true;
224
+			}
216 225
 		}
217 226
 		return false;
218 227
 	}
Please login to merge, or discard this patch.
LEClient/src/LEConnector.php 3 patches
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 
44 44
 	public $keyChange;
45 45
 	public $newAccount;
46
-    public $newNonce;
46
+	public $newNonce;
47 47
 	public $newOrder;
48 48
 	public $revokeCert;
49 49
 
@@ -52,13 +52,13 @@  discard block
 block discarded – undo
52 52
 
53 53
 	private $log;
54 54
 
55
-    /**
56
-     * Initiates the LetsEncrypt Connector class.
57
-     *
58
-     * @param int 		$log			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
59
-     * @param string	$baseURL 		The LetsEncrypt server URL to make requests to.
60
-     * @param array	$accountKeys Array containing location of account keys files.
61
-     */
55
+	/**
56
+	 * Initiates the LetsEncrypt Connector class.
57
+	 *
58
+	 * @param int 		$log			The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
59
+	 * @param string	$baseURL 		The LetsEncrypt server URL to make requests to.
60
+	 * @param array	$accountKeys Array containing location of account keys files.
61
+	 */
62 62
 	public function __construct($log, $baseURL, $accountKeys)
63 63
 	{
64 64
 		$this->baseURL = $baseURL;
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 		$this->getNewNonce();
69 69
 	}
70 70
 
71
-    /**
72
-     * Requests the LetsEncrypt Directory and stores the necessary URLs in this LetsEncrypt Connector instance.
73
-     */
71
+	/**
72
+	 * Requests the LetsEncrypt Directory and stores the necessary URLs in this LetsEncrypt Connector instance.
73
+	 */
74 74
 	private function getLEDirectory()
75 75
 	{
76 76
 		$req = $this->get('/directory');
@@ -81,42 +81,42 @@  discard block
 block discarded – undo
81 81
 		$this->revokeCert = $req['body']['revokeCert'];
82 82
 	}
83 83
 
84
-    /**
85
-     * Requests a new nonce from the LetsEncrypt server and stores it in this LetsEncrypt Connector instance.
86
-     */
84
+	/**
85
+	 * Requests a new nonce from the LetsEncrypt server and stores it in this LetsEncrypt Connector instance.
86
+	 */
87 87
 	private function getNewNonce()
88 88
 	{
89 89
 		if(strpos($this->head($this->newNonce)['header'], "204 No Content") == false) throw new \RuntimeException('No new nonce.');
90 90
 	}
91 91
 
92
-    /**
93
-     * Makes a Curl request.
94
-     *
95
-     * @param string	$method	The HTTP method to use. Accepting GET, POST and HEAD requests.
96
-     * @param string 	$URL 	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
97
-     * @param object 	$data  	The body to attach to a POST request. Expected as a JSON encoded string.
98
-     *
99
-     * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
100
-     */
92
+	/**
93
+	 * Makes a Curl request.
94
+	 *
95
+	 * @param string	$method	The HTTP method to use. Accepting GET, POST and HEAD requests.
96
+	 * @param string 	$URL 	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
97
+	 * @param object 	$data  	The body to attach to a POST request. Expected as a JSON encoded string.
98
+	 *
99
+	 * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
100
+	 */
101 101
 	private function request($method, $URL, $data = null)
102 102
 	{
103 103
 		if($this->accountDeactivated) throw new \RuntimeException('The account was deactivated. No further requests can be made.');
104 104
 
105 105
 		$headers = array('Accept: application/json', 'Content-Type: application/json');
106 106
 		$requestURL = preg_match('~^http~', $URL) ? $URL : $this->baseURL . $URL;
107
-        $handle = curl_init();
108
-        curl_setopt($handle, CURLOPT_URL, $requestURL);
109
-        curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
110
-        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
111
-        curl_setopt($handle, CURLOPT_HEADER, true);
112
-
113
-        switch ($method) {
114
-            case 'GET':
115
-                break;
116
-            case 'POST':
117
-                curl_setopt($handle, CURLOPT_POST, true);
118
-                curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
119
-                break;
107
+		$handle = curl_init();
108
+		curl_setopt($handle, CURLOPT_URL, $requestURL);
109
+		curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
110
+		curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
111
+		curl_setopt($handle, CURLOPT_HEADER, true);
112
+
113
+		switch ($method) {
114
+			case 'GET':
115
+				break;
116
+			case 'POST':
117
+				curl_setopt($handle, CURLOPT_POST, true);
118
+				curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
119
+				break;
120 120
 			case 'HEAD':
121 121
 				curl_setopt($handle, CURLOPT_CUSTOMREQUEST, 'HEAD');
122 122
 				curl_setopt($handle, CURLOPT_NOBODY, true);
@@ -124,17 +124,17 @@  discard block
 block discarded – undo
124 124
 			default:
125 125
 				throw new \RuntimeException('HTTP request ' . $method . ' not supported.');
126 126
 				break;
127
-        }
128
-        $response = curl_exec($handle);
127
+		}
128
+		$response = curl_exec($handle);
129 129
 
130
-        if(curl_errno($handle)) {
131
-            throw new \RuntimeException('Curl: ' . curl_error($handle));
132
-        }
130
+		if(curl_errno($handle)) {
131
+			throw new \RuntimeException('Curl: ' . curl_error($handle));
132
+		}
133 133
 
134
-        $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
134
+		$header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
135 135
 
136
-        $header = substr($response, 0, $header_size);
137
-        $body = substr($response, $header_size);
136
+		$header = substr($response, 0, $header_size);
137
+		$body = substr($response, $header_size);
138 138
 		$jsonbody = json_decode($body, true);
139 139
 		$jsonresponse = array('request' => $method . ' ' . $requestURL, 'header' => $header, 'body' => $jsonbody === null ? $body : $jsonbody);
140 140
 		if($this->log >= LECLient::LOG_DEBUG) LEFunctions::log($jsonresponse);
@@ -154,124 +154,124 @@  discard block
 block discarded – undo
154 154
 			if($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests.
155 155
 		}
156 156
 
157
-        return $jsonresponse;
157
+		return $jsonresponse;
158 158
 	}
159 159
 
160
-    /**
161
-     * Makes a GET request.
162
-     *
163
-     * @param string	$url 	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
164
-     *
165
-     * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
166
-     */
160
+	/**
161
+	 * Makes a GET request.
162
+	 *
163
+	 * @param string	$url 	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
164
+	 *
165
+	 * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
166
+	 */
167 167
 	public function get($url)
168 168
 	{
169 169
 		return $this->request('GET', $url);
170 170
 	}
171 171
 
172 172
 	/**
173
-     * Makes a POST request.
174
-     *
175
-     * @param string 	$url	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
173
+	 * Makes a POST request.
174
+	 *
175
+	 * @param string 	$url	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
176 176
 	 * @param object 	$data	The body to attach to a POST request. Expected as a json string.
177
-     *
178
-     * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
179
-     */
177
+	 *
178
+	 * @return array 	Returns an array with the keys 'request', 'header' and 'body'.
179
+	 */
180 180
 	public function post($url, $data = null)
181 181
 	{
182 182
 		return $this->request('POST', $url, $data);
183 183
 	}
184 184
 
185 185
 	/**
186
-     * Makes a HEAD request.
187
-     *
188
-     * @param string 	$url	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
189
-     *
190
-     * @return array	Returns an array with the keys 'request', 'header' and 'body'.
191
-     */
186
+	 * Makes a HEAD request.
187
+	 *
188
+	 * @param string 	$url	The URL or partial URL to make the request to. If it is partial, the baseURL will be prepended.
189
+	 *
190
+	 * @return array	Returns an array with the keys 'request', 'header' and 'body'.
191
+	 */
192 192
 	public function head($url)
193 193
 	{
194 194
 		return $this->request('HEAD', $url);
195 195
 	}
196 196
 
197
-    /**
198
-     * Generates a JSON Web Key signature to attach to the request.
199
-     *
200
-     * @param array 	$payload		The payload to add to the signature.
201
-     * @param string	$url 			The URL to use in the signature.
202
-     * @param string 	$privateKeyFile The private key to sign the request with. Defaults to 'private.pem'. Defaults to accountKeys[private_key].
203
-     *
204
-     * @return string	Returns a JSON encoded string containing the signature.
205
-     */
197
+	/**
198
+	 * Generates a JSON Web Key signature to attach to the request.
199
+	 *
200
+	 * @param array 	$payload		The payload to add to the signature.
201
+	 * @param string	$url 			The URL to use in the signature.
202
+	 * @param string 	$privateKeyFile The private key to sign the request with. Defaults to 'private.pem'. Defaults to accountKeys[private_key].
203
+	 *
204
+	 * @return string	Returns a JSON encoded string containing the signature.
205
+	 */
206 206
 	public function signRequestJWK($payload, $url, $privateKeyFile = '')
207
-    {
207
+	{
208 208
 		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
209 209
 		$privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
210
-        $details = openssl_pkey_get_details($privateKey);
211
-
212
-        $protected = array(
213
-            "alg" => "RS256",
214
-            "jwk" => array(
215
-                "kty" => "RSA",
216
-                "n" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["n"]),
217
-                "e" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["e"]),
218
-            ),
210
+		$details = openssl_pkey_get_details($privateKey);
211
+
212
+		$protected = array(
213
+			"alg" => "RS256",
214
+			"jwk" => array(
215
+				"kty" => "RSA",
216
+				"n" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["n"]),
217
+				"e" => LEFunctions::Base64UrlSafeEncode($details["rsa"]["e"]),
218
+			),
219 219
 			"nonce" => $this->nonce,
220 220
 			"url" => $url
221
-        );
221
+		);
222 222
 
223
-        $payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
224
-        $protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
223
+		$payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
224
+		$protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
225 225
 
226
-        openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
227
-        $signed64 = LEFunctions::Base64UrlSafeEncode($signed);
226
+		openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
227
+		$signed64 = LEFunctions::Base64UrlSafeEncode($signed);
228 228
 
229
-        $data = array(
230
-            'protected' => $protected64,
231
-            'payload' => $payload64,
232
-            'signature' => $signed64
233
-        );
229
+		$data = array(
230
+			'protected' => $protected64,
231
+			'payload' => $payload64,
232
+			'signature' => $signed64
233
+		);
234 234
 
235
-        return json_encode($data);
236
-    }
235
+		return json_encode($data);
236
+	}
237 237
 
238 238
 	/**
239
-     * Generates a Key ID signature to attach to the request.
240
-     *
241
-     * @param array 	$payload		The payload to add to the signature.
239
+	 * Generates a Key ID signature to attach to the request.
240
+	 *
241
+	 * @param array 	$payload		The payload to add to the signature.
242 242
 	 * @param string	$kid			The Key ID to use in the signature.
243
-     * @param string	$url 			The URL to use in the signature.
244
-     * @param string 	$privateKeyFile The private key to sign the request with. Defaults to 'private.pem'. Defaults to accountKeys[private_key].
245
-     *
246
-     * @return string	Returns a JSON encoded string containing the signature.
247
-     */
243
+	 * @param string	$url 			The URL to use in the signature.
244
+	 * @param string 	$privateKeyFile The private key to sign the request with. Defaults to 'private.pem'. Defaults to accountKeys[private_key].
245
+	 *
246
+	 * @return string	Returns a JSON encoded string containing the signature.
247
+	 */
248 248
 	public function signRequestKid($payload, $kid, $url, $privateKeyFile = '')
249
-    {
249
+	{
250 250
 		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
251
-        $privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
252
-        $details = openssl_pkey_get_details($privateKey);
251
+		$privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
252
+		$details = openssl_pkey_get_details($privateKey);
253 253
 
254
-        $protected = array(
255
-            "alg" => "RS256",
256
-            "kid" => $kid,
254
+		$protected = array(
255
+			"alg" => "RS256",
256
+			"kid" => $kid,
257 257
 			"nonce" => $this->nonce,
258 258
 			"url" => $url
259
-        );
259
+		);
260 260
 
261
-        $payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
262
-        $protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
261
+		$payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
262
+		$protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
263 263
 
264
-        openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
265
-        $signed64 = LEFunctions::Base64UrlSafeEncode($signed);
264
+		openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
265
+		$signed64 = LEFunctions::Base64UrlSafeEncode($signed);
266 266
 
267
-        $data = array(
268
-            'protected' => $protected64,
269
-            'payload' => $payload64,
270
-            'signature' => $signed64
271
-        );
267
+		$data = array(
268
+			'protected' => $protected64,
269
+			'payload' => $payload64,
270
+			'signature' => $signed64
271
+		);
272 272
 
273
-        return json_encode($data);
274
-    }
273
+		return json_encode($data);
274
+	}
275 275
 }
276 276
 
277 277
 ?>
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      */
87 87
 	private function getNewNonce()
88 88
 	{
89
-		if(strpos($this->head($this->newNonce)['header'], "204 No Content") == false) throw new \RuntimeException('No new nonce.');
89
+		if (strpos($this->head($this->newNonce)['header'], "204 No Content") == false) throw new \RuntimeException('No new nonce.');
90 90
 	}
91 91
 
92 92
     /**
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      */
101 101
 	private function request($method, $URL, $data = null)
102 102
 	{
103
-		if($this->accountDeactivated) throw new \RuntimeException('The account was deactivated. No further requests can be made.');
103
+		if ($this->accountDeactivated) throw new \RuntimeException('The account was deactivated. No further requests can be made.');
104 104
 
105 105
 		$headers = array('Accept: application/json', 'Content-Type: application/json');
106 106
 		$requestURL = preg_match('~^http~', $URL) ? $URL : $this->baseURL . $URL;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         }
128 128
         $response = curl_exec($handle);
129 129
 
130
-        if(curl_errno($handle)) {
130
+        if (curl_errno($handle)) {
131 131
             throw new \RuntimeException('Curl: ' . curl_error($handle));
132 132
         }
133 133
 
@@ -137,21 +137,21 @@  discard block
 block discarded – undo
137 137
         $body = substr($response, $header_size);
138 138
 		$jsonbody = json_decode($body, true);
139 139
 		$jsonresponse = array('request' => $method . ' ' . $requestURL, 'header' => $header, 'body' => $jsonbody === null ? $body : $jsonbody);
140
-		if($this->log >= LECLient::LOG_DEBUG) LEFunctions::log($jsonresponse);
140
+		if ($this->log >= LECLient::LOG_DEBUG) LEFunctions::log($jsonresponse);
141 141
 
142
-		if(	(($method == 'POST' OR $method == 'GET') AND strpos($header, "200 OK") === false AND strpos($header, "201 Created") === false) OR
142
+		if ((($method == 'POST' OR $method == 'GET') AND strpos($header, "200 OK") === false AND strpos($header, "201 Created") === false) OR
143 143
 			($method == 'HEAD' AND strpos($header, "204 No Content") === false))
144 144
 		{
145 145
 			throw new \RuntimeException('Invalid response, header: ' . $header);
146 146
 		}
147 147
 
148
-		if(preg_match('~Replay\-Nonce: (\S+)~i', $header, $matches))
148
+		if (preg_match('~Replay\-Nonce: (\S+)~i', $header, $matches))
149 149
 		{
150 150
 			$this->nonce = trim($matches[1]);
151 151
 		}
152 152
 		else
153 153
 		{
154
-			if($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests.
154
+			if ($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests.
155 155
 		}
156 156
 
157 157
         return $jsonresponse;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      */
206 206
 	public function signRequestJWK($payload, $url, $privateKeyFile = '')
207 207
     {
208
-		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
208
+		if ($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
209 209
 		$privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
210 210
         $details = openssl_pkey_get_details($privateKey);
211 211
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
         $payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
224 224
         $protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
225 225
 
226
-        openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
226
+        openssl_sign($protected64 . '.' . $payload64, $signed, $privateKey, "SHA256");
227 227
         $signed64 = LEFunctions::Base64UrlSafeEncode($signed);
228 228
 
229 229
         $data = array(
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
 	public function signRequestKid($payload, $kid, $url, $privateKeyFile = '')
249 249
     {
250
-		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
250
+		if ($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
251 251
         $privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
252 252
         $details = openssl_pkey_get_details($privateKey);
253 253
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
         $payload64 = LEFunctions::Base64UrlSafeEncode(str_replace('\\/', '/', is_array($payload) ? json_encode($payload) : $payload));
262 262
         $protected64 = LEFunctions::Base64UrlSafeEncode(json_encode($protected));
263 263
 
264
-        openssl_sign($protected64.'.'.$payload64, $signed, $privateKey, "SHA256");
264
+        openssl_sign($protected64 . '.' . $payload64, $signed, $privateKey, "SHA256");
265 265
         $signed64 = LEFunctions::Base64UrlSafeEncode($signed);
266 266
 
267 267
         $data = array(
Please login to merge, or discard this patch.
Braces   +20 added lines, -8 removed lines patch added patch discarded remove patch
@@ -86,7 +86,9 @@  discard block
 block discarded – undo
86 86
      */
87 87
 	private function getNewNonce()
88 88
 	{
89
-		if(strpos($this->head($this->newNonce)['header'], "204 No Content") == false) throw new \RuntimeException('No new nonce.');
89
+		if(strpos($this->head($this->newNonce)['header'], "204 No Content") == false) {
90
+			throw new \RuntimeException('No new nonce.');
91
+		}
90 92
 	}
91 93
 
92 94
     /**
@@ -100,7 +102,9 @@  discard block
 block discarded – undo
100 102
      */
101 103
 	private function request($method, $URL, $data = null)
102 104
 	{
103
-		if($this->accountDeactivated) throw new \RuntimeException('The account was deactivated. No further requests can be made.');
105
+		if($this->accountDeactivated) {
106
+			throw new \RuntimeException('The account was deactivated. No further requests can be made.');
107
+		}
104 108
 
105 109
 		$headers = array('Accept: application/json', 'Content-Type: application/json');
106 110
 		$requestURL = preg_match('~^http~', $URL) ? $URL : $this->baseURL . $URL;
@@ -137,7 +141,9 @@  discard block
 block discarded – undo
137 141
         $body = substr($response, $header_size);
138 142
 		$jsonbody = json_decode($body, true);
139 143
 		$jsonresponse = array('request' => $method . ' ' . $requestURL, 'header' => $header, 'body' => $jsonbody === null ? $body : $jsonbody);
140
-		if($this->log >= LECLient::LOG_DEBUG) LEFunctions::log($jsonresponse);
144
+		if($this->log >= LECLient::LOG_DEBUG) {
145
+			LEFunctions::log($jsonresponse);
146
+		}
141 147
 
142 148
 		if(	(($method == 'POST' OR $method == 'GET') AND strpos($header, "200 OK") === false AND strpos($header, "201 Created") === false) OR
143 149
 			($method == 'HEAD' AND strpos($header, "204 No Content") === false))
@@ -148,10 +154,12 @@  discard block
 block discarded – undo
148 154
 		if(preg_match('~Replay\-Nonce: (\S+)~i', $header, $matches))
149 155
 		{
150 156
 			$this->nonce = trim($matches[1]);
151
-		}
152
-		else
157
+		} else
153 158
 		{
154
-			if($method == 'POST') $this->getNewNonce(); // Not expecting a new nonce with GET and HEAD requests.
159
+			if($method == 'POST') {
160
+				$this->getNewNonce();
161
+			}
162
+			// Not expecting a new nonce with GET and HEAD requests.
155 163
 		}
156 164
 
157 165
         return $jsonresponse;
@@ -205,7 +213,9 @@  discard block
 block discarded – undo
205 213
      */
206 214
 	public function signRequestJWK($payload, $url, $privateKeyFile = '')
207 215
     {
208
-		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
216
+		if($privateKeyFile == '') {
217
+			$privateKeyFile = $this->accountKeys['private_key'];
218
+		}
209 219
 		$privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
210 220
         $details = openssl_pkey_get_details($privateKey);
211 221
 
@@ -247,7 +257,9 @@  discard block
 block discarded – undo
247 257
      */
248 258
 	public function signRequestKid($payload, $kid, $url, $privateKeyFile = '')
249 259
     {
250
-		if($privateKeyFile == '') $privateKeyFile = $this->accountKeys['private_key'];
260
+		if($privateKeyFile == '') {
261
+			$privateKeyFile = $this->accountKeys['private_key'];
262
+		}
251 263
         $privateKey = openssl_pkey_get_private(file_get_contents($privateKeyFile));
252 264
         $details = openssl_pkey_get_details($privateKey);
253 265
 
Please login to merge, or discard this patch.
LEClient/src/LEAuthorization.php 3 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 	
47 47
 	private $log;
48 48
 	
49
-    /**
50
-     * Initiates the LetsEncrypt Authorization class. Child of a LetsEncrypt Order instance.
51
-     * 
52
-     * @param LEConnector	$connector			The LetsEncrypt Connector instance to use for HTTP requests.
53
-     * @param int 			$log 				The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
54
-     * @param string 		$authorizationURL 	The URL of the authorization, given by a LetsEncrypt order request.
55
-     */
49
+	/**
50
+	 * Initiates the LetsEncrypt Authorization class. Child of a LetsEncrypt Order instance.
51
+	 * 
52
+	 * @param LEConnector	$connector			The LetsEncrypt Connector instance to use for HTTP requests.
53
+	 * @param int 			$log 				The level of logging. Defaults to no logging. LOG_OFF, LOG_STATUS, LOG_DEBUG accepted.
54
+	 * @param string 		$authorizationURL 	The URL of the authorization, given by a LetsEncrypt order request.
55
+	 */
56 56
 	public function __construct($connector, $log, $authorizationURL)
57 57
 	{
58 58
 		$this->connector = $connector;
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
 		}
74 74
 	}
75 75
 	
76
-    /**
77
-     * Updates the data associated with the current LetsEncrypt Authorization instance.
78
-     */
76
+	/**
77
+	 * Updates the data associated with the current LetsEncrypt Authorization instance.
78
+	 */
79 79
 	
80 80
 	public function updateData()
81 81
 	{
@@ -93,14 +93,14 @@  discard block
 block discarded – undo
93 93
 		}
94 94
 	}
95 95
 	
96
-    /**
97
-     * Gets the challenge of the given $type for this LetsEncrypt Authorization instance. Throws a Runtime Exception if the given $type is not found in this
96
+	/**
97
+	 * Gets the challenge of the given $type for this LetsEncrypt Authorization instance. Throws a Runtime Exception if the given $type is not found in this
98 98
 	 * LetsEncrypt Authorization instance.
99
-     * 
100
-     * @param int	$type 	The type of verification. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS.
101
-     * 
102
-     * @return array	Returns an array with the challenge of the requested $type.
103
-     */
99
+	 * 
100
+	 * @param int	$type 	The type of verification. Supporting LEOrder::CHALLENGE_TYPE_HTTP and LEOrder::CHALLENGE_TYPE_DNS.
101
+	 * 
102
+	 * @return array	Returns an array with the challenge of the requested $type.
103
+	 */
104 104
 	public function getChallenge($type)
105 105
 	{
106 106
 		foreach($this->challenges as $challenge)
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 		$this->authorizationURL = $authorizationURL;
61 61
 		
62 62
 		$get = $this->connector->get($this->authorizationURL);
63
-		if(strpos($get['header'], "200 OK") !== false)
63
+		if (strpos($get['header'], "200 OK") !== false)
64 64
 		{
65 65
 			$this->identifier = $get['body']['identifier'];
66 66
 			$this->status = $get['body']['status'];
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 		}
70 70
 		else
71 71
 		{
72
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct');
72
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct');
73 73
 		}
74 74
 	}
75 75
 	
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	public function updateData()
81 81
 	{
82 82
 		$get = $this->connector->get($this->authorizationURL);
83
-		if(strpos($get['header'], "200 OK") !== false)
83
+		if (strpos($get['header'], "200 OK") !== false)
84 84
 		{
85 85
 			$this->identifier = $get['body']['identifier'];
86 86
 			$this->status = $get['body']['status'];
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		}
90 90
 		else
91 91
 		{
92
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function updateData');
92
+			if ($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function updateData');
93 93
 		}
94 94
 	}
95 95
 	
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
      */
104 104
 	public function getChallenge($type)
105 105
 	{
106
-		foreach($this->challenges as $challenge)
106
+		foreach ($this->challenges as $challenge)
107 107
 		{
108
-			if($challenge['type'] == $type) return $challenge;
108
+			if ($challenge['type'] == $type) return $challenge;
109 109
 		}
110 110
 		throw new \RuntimeException('No challenge found for type \'' . $type . '\' and identifier \'' . $this->identifier['value'] . '\'.');
111 111
 	}
Please login to merge, or discard this patch.
Braces   +11 added lines, -7 removed lines patch added patch discarded remove patch
@@ -66,10 +66,11 @@  discard block
 block discarded – undo
66 66
 			$this->status = $get['body']['status'];
67 67
 			$this->expires = $get['body']['expires'];
68 68
 			$this->challenges = $get['body']['challenges'];
69
-		}
70
-		else
69
+		} else
71 70
 		{
72
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct');
71
+			if($this->log >= LECLient::LOG_STATUS) {
72
+				LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function LEAuthorization __construct');
73
+			}
73 74
 		}
74 75
 	}
75 76
 	
@@ -86,10 +87,11 @@  discard block
 block discarded – undo
86 87
 			$this->status = $get['body']['status'];
87 88
 			$this->expires = $get['body']['expires'];
88 89
 			$this->challenges = $get['body']['challenges'];
89
-		}
90
-		else
90
+		} else
91 91
 		{
92
-			if($this->log >= LECLient::LOG_STATUS) LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function updateData');
92
+			if($this->log >= LECLient::LOG_STATUS) {
93
+				LEFunctions::log('Cannot find authorization \'' . $authorizationURL . '\'.', 'function updateData');
94
+			}
93 95
 		}
94 96
 	}
95 97
 	
@@ -105,7 +107,9 @@  discard block
 block discarded – undo
105 107
 	{
106 108
 		foreach($this->challenges as $challenge)
107 109
 		{
108
-			if($challenge['type'] == $type) return $challenge;
110
+			if($challenge['type'] == $type) {
111
+				return $challenge;
112
+			}
109 113
 		}
110 114
 		throw new \RuntimeException('No challenge found for type \'' . $type . '\' and identifier \'' . $this->identifier['value'] . '\'.');
111 115
 	}
Please login to merge, or discard this patch.
exampleDNSInit.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@
 block discarded – undo
16 16
 // Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
17 17
 $order = $client->getOrCreateOrder($basename, $domains);
18 18
 // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
19
-if(!$order->allAuthorizationsValid())
19
+if (!$order->allAuthorizationsValid())
20 20
 {
21 21
 	// Get the DNS challenges from the pending authorizations.
22 22
 	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_DNS);
23 23
 	// Walk the list of pending authorization DNS challenges.
24
-	if(!empty($pending))
24
+	if (!empty($pending))
25 25
 	{
26
-		foreach($pending as $challenge)
26
+		foreach ($pending as $challenge)
27 27
 		{
28 28
 			// For the purpose of this example, a fictitious functions creates or updates the ACME challenge DNS record for this domain. 
29 29
 			setDNSRecord($challenge['identifier'], $challenge['DNSDigest'])
Please login to merge, or discard this patch.
exampleDNSFinish.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
 // Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
17 17
 $order = $client->getOrCreateOrder($basename, $domains);
18 18
 // Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
19
-if(!$order->allAuthorizationsValid())
19
+if (!$order->allAuthorizationsValid())
20 20
 {
21 21
 	// Get the DNS challenges from the pending authorizations.
22 22
 	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_DNS);
23 23
 	// Walk the list of pending authorization DNS challenges.
24
-	if(!empty($pending))
24
+	if (!empty($pending))
25 25
 	{
26
-		foreach($pending as $challenge)
26
+		foreach ($pending as $challenge)
27 27
 		{
28 28
 			// Let LetsEncrypt verify this challenge, which should have been fulfilled in exampleDNSStart.php.
29 29
 			$order->verifyPendingOrderAuthorization($challenge['identifier'], LEOrder::CHALLENGE_TYPE_DNS);
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
 	}
32 32
 }
33 33
 // Check once more whether all authorizations are valid before we can finalize the order.
34
-if($order->allAuthorizationsValid())
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()) $order->finalizeOrder();
38 38
 	// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
39
-	if($order->isFinalized()) $order->getCertificate();
39
+	if ($order->isFinalized()) $order->getCertificate();
40 40
 }
41 41
 ?>
42 42
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -34,8 +34,12 @@
 block discarded – undo
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
Please login to merge, or discard this patch.