1 | <?php |
||||||
2 | |||||||
3 | namespace Pronamic\WordPress\Pay\Gateways\IDealAdvancedV3; |
||||||
4 | |||||||
5 | use Pronamic\WordPress\Pay\Gateways\IDeal\AbstractIntegration; |
||||||
6 | |||||||
7 | /** |
||||||
8 | * Title: iDEAL Advanced v3 integration |
||||||
9 | * Description: |
||||||
10 | * Copyright: 2005-2019 Pronamic |
||||||
11 | * Company: Pronamic |
||||||
12 | * |
||||||
13 | * @author Remco Tolsma |
||||||
14 | * @version 2.0.0 |
||||||
15 | * @since 2.0.0 |
||||||
16 | */ |
||||||
17 | class Integration extends AbstractIntegration { |
||||||
18 | /** |
||||||
19 | * Settings constructor. |
||||||
20 | */ |
||||||
21 | public function __construct( $args = array() ) { |
||||||
22 | $args = wp_parse_args( |
||||||
23 | $args, |
||||||
24 | array( |
||||||
25 | 'id' => 'ideal-advanced-v3', |
||||||
26 | 'name' => 'iDEAL Advanced v3', |
||||||
27 | 'url' => __( 'https://www.ideal.nl/en/', 'pronamic_ideal' ), |
||||||
28 | 'product_url' => __( 'https://www.ideal.nl/en/', 'pronamic_ideal' ), |
||||||
29 | 'dashboard_url' => null, |
||||||
30 | 'provider' => null, |
||||||
31 | 'aquirer_url' => null, |
||||||
32 | 'aquirer_test_url' => null, |
||||||
33 | ) |
||||||
34 | ); |
||||||
35 | |||||||
36 | $this->id = $args['id']; |
||||||
37 | $this->name = $args['name']; |
||||||
38 | $this->url = $args['url']; |
||||||
39 | $this->product_url = $args['product_url']; |
||||||
40 | $this->dashboard_url = $args['dashboard_url']; |
||||||
41 | $this->provider = $args['provider']; |
||||||
42 | |||||||
43 | $this->aquirer_url = $args['aquirer_url']; |
||||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||||
44 | $this->aquirer_test_url = $args['aquirer_test_url']; |
||||||
0 ignored issues
–
show
|
|||||||
45 | |||||||
46 | // Supported features. |
||||||
47 | $this->supports = array( |
||||||
0 ignored issues
–
show
|
|||||||
48 | 'payment_status_request', |
||||||
49 | ); |
||||||
50 | |||||||
51 | // Actions. |
||||||
52 | add_action( 'current_screen', array( $this, 'maybe_download_private_certificate' ) ); |
||||||
53 | add_action( 'current_screen', array( $this, 'maybe_download_private_key' ) ); |
||||||
54 | } |
||||||
55 | |||||||
56 | public function get_settings_fields() { |
||||||
57 | $fields = parent::get_settings_fields(); |
||||||
0 ignored issues
–
show
The method
get_settings_fields() does not exist on Pronamic\WordPress\Pay\G...eal\AbstractIntegration . Did you maybe mean get_settings() ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
58 | |||||||
59 | /* |
||||||
60 | * Private Key and Certificate |
||||||
61 | */ |
||||||
62 | |||||||
63 | // Private key and certificate information. |
||||||
64 | $fields[] = array( |
||||||
65 | 'section' => 'general', |
||||||
66 | 'title' => __( 'Private key and certificate', 'pronamic_ideal' ), |
||||||
67 | 'type' => 'description', |
||||||
68 | 'callback' => array( $this, 'field_security' ), |
||||||
69 | ); |
||||||
70 | |||||||
71 | // Organization. |
||||||
72 | $fields[] = array( |
||||||
73 | 'section' => 'general', |
||||||
74 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
75 | 'group' => 'pk-cert', |
||||||
76 | 'meta_key' => '_pronamic_gateway_organization', |
||||||
77 | 'title' => __( 'Organization', 'pronamic_ideal' ), |
||||||
78 | 'type' => 'text', |
||||||
79 | 'tooltip' => __( 'Organization name, e.g. Pronamic', 'pronamic_ideal' ), |
||||||
80 | ); |
||||||
81 | |||||||
82 | // Organization Unit. |
||||||
83 | $fields[] = array( |
||||||
84 | 'section' => 'general', |
||||||
85 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
86 | 'group' => 'pk-cert', |
||||||
87 | 'meta_key' => '_pronamic_gateway_organization_unit', |
||||||
88 | 'title' => __( 'Organization Unit', 'pronamic_ideal' ), |
||||||
89 | 'type' => 'text', |
||||||
90 | 'tooltip' => __( 'Organization unit, e.g. Administration', 'pronamic_ideal' ), |
||||||
91 | ); |
||||||
92 | |||||||
93 | // Locality. |
||||||
94 | $fields[] = array( |
||||||
95 | 'section' => 'general', |
||||||
96 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
97 | 'group' => 'pk-cert', |
||||||
98 | 'meta_key' => '_pronamic_gateway_locality', |
||||||
99 | 'title' => __( 'City', 'pronamic_ideal' ), |
||||||
100 | 'type' => 'text', |
||||||
101 | 'tooltip' => __( 'City, e.g. Amsterdam', 'pronamic_ideal' ), |
||||||
102 | ); |
||||||
103 | |||||||
104 | // State or Province. |
||||||
105 | $fields[] = array( |
||||||
106 | 'section' => 'general', |
||||||
107 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
108 | 'group' => 'pk-cert', |
||||||
109 | 'meta_key' => '_pronamic_gateway_state_or_province', |
||||||
110 | 'title' => __( 'State / province', 'pronamic_ideal' ), |
||||||
111 | 'type' => 'text', |
||||||
112 | 'tooltip' => __( 'State or province, e.g. Friesland', 'pronamic_ideal' ), |
||||||
113 | ); |
||||||
114 | |||||||
115 | // Country. |
||||||
116 | $locale = explode( '_', get_locale() ); |
||||||
117 | |||||||
118 | $locale = array_pop( $locale ); |
||||||
119 | |||||||
120 | $fields[] = array( |
||||||
121 | 'section' => 'general', |
||||||
122 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
123 | 'group' => 'pk-cert', |
||||||
124 | 'meta_key' => '_pronamic_gateway_country', |
||||||
125 | 'title' => __( 'Country', 'pronamic_ideal' ), |
||||||
126 | 'type' => 'text', |
||||||
127 | 'tooltip' => sprintf( |
||||||
128 | '%s %s (ISO-3166-1 alpha-2)', |
||||||
129 | __( '2 letter country code, e.g.', 'pronamic_ideal' ), |
||||||
130 | strtoupper( $locale ) |
||||||
131 | ), |
||||||
132 | 'size' => 2, |
||||||
133 | 'description' => sprintf( |
||||||
134 | '%s %s', |
||||||
135 | __( '2 letter country code, e.g.', 'pronamic_ideal' ), |
||||||
136 | strtoupper( $locale ) |
||||||
137 | ), |
||||||
138 | ); |
||||||
139 | |||||||
140 | // Email Address. |
||||||
141 | $fields[] = array( |
||||||
142 | 'section' => 'general', |
||||||
143 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
144 | 'group' => 'pk-cert', |
||||||
145 | 'meta_key' => '_pronamic_gateway_email', |
||||||
146 | 'title' => __( 'E-mail address', 'pronamic_ideal' ), |
||||||
147 | 'tooltip' => sprintf( |
||||||
148 | /* translators: %s: admin email */ |
||||||
149 | __( 'E-mail address, e.g. %s', 'pronamic_ideal' ), |
||||||
150 | get_option( 'admin_email' ) |
||||||
0 ignored issues
–
show
It seems like
get_option('admin_email') can also be of type false ; however, parameter $args of sprintf() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
151 | ), |
||||||
152 | 'type' => 'text', |
||||||
153 | ); |
||||||
154 | |||||||
155 | // Number Days Valid. |
||||||
156 | $fields[] = array( |
||||||
157 | 'section' => 'general', |
||||||
158 | 'filter' => FILTER_SANITIZE_NUMBER_INT, |
||||||
159 | 'group' => 'pk-cert', |
||||||
160 | 'meta_key' => '_pronamic_gateway_number_days_valid', |
||||||
161 | 'title' => __( 'Number Days Valid', 'pronamic_ideal' ), |
||||||
162 | 'type' => 'text', |
||||||
163 | 'default' => 1825, |
||||||
164 | 'tooltip' => __( 'Number of days the generated certificate will be valid for, e.g. 1825 days for the maximum duration of 5 years.', 'pronamic_ideal' ), |
||||||
165 | ); |
||||||
166 | |||||||
167 | // Private Key Password. |
||||||
168 | $fields[] = array( |
||||||
169 | 'section' => 'general', |
||||||
170 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
171 | 'group' => 'pk-cert', |
||||||
172 | 'meta_key' => '_pronamic_gateway_ideal_private_key_password', |
||||||
173 | 'title' => __( 'Private Key Password', 'pronamic_ideal' ), |
||||||
174 | 'type' => 'text', |
||||||
175 | 'classes' => array( 'regular-text', 'code' ), |
||||||
176 | 'default' => wp_generate_password(), |
||||||
177 | 'tooltip' => __( 'A random password which will be used for the generation of the private key and certificate.', 'pronamic_ideal' ), |
||||||
178 | ); |
||||||
179 | |||||||
180 | // Private Key. |
||||||
181 | $fields[] = array( |
||||||
182 | 'section' => 'general', |
||||||
183 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
184 | 'group' => 'pk-cert', |
||||||
185 | 'meta_key' => '_pronamic_gateway_ideal_private_key', |
||||||
186 | 'title' => __( 'Private Key', 'pronamic_ideal' ), |
||||||
187 | 'type' => 'textarea', |
||||||
188 | 'callback' => array( $this, 'field_private_key' ), |
||||||
189 | 'classes' => array( 'code' ), |
||||||
190 | 'tooltip' => __( 'The private key is used for secure communication with the payment provider. If left empty, the private key will be generated using the given private key password.', 'pronamic_ideal' ), |
||||||
191 | ); |
||||||
192 | |||||||
193 | // Private Certificate. |
||||||
194 | $fields[] = array( |
||||||
195 | 'section' => 'general', |
||||||
196 | 'filter' => FILTER_SANITIZE_STRING, |
||||||
197 | 'group' => 'pk-cert', |
||||||
198 | 'meta_key' => '_pronamic_gateway_ideal_private_certificate', |
||||||
199 | 'title' => __( 'Private Certificate', 'pronamic_ideal' ), |
||||||
200 | 'type' => 'textarea', |
||||||
201 | 'callback' => array( $this, 'field_private_certificate' ), |
||||||
202 | 'classes' => array( 'code' ), |
||||||
203 | 'tooltip' => __( 'The certificate is used for secure communication with the payment provider. If left empty, the certificate will be generated using the private key and given organization details.', 'pronamic_ideal' ), |
||||||
204 | ); |
||||||
205 | |||||||
206 | // Return. |
||||||
207 | return $fields; |
||||||
208 | } |
||||||
209 | |||||||
210 | /** |
||||||
211 | * Field security |
||||||
212 | * |
||||||
213 | * @param array $field Field. |
||||||
214 | */ |
||||||
215 | public function field_security( $field ) { |
||||||
216 | $certificate = get_post_meta( get_the_ID(), '_pronamic_gateway_ideal_private_certificate', true ); |
||||||
0 ignored issues
–
show
It seems like
get_the_ID() can also be of type false ; however, parameter $post_id of get_post_meta() does only seem to accept integer , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
217 | |||||||
218 | ?> |
||||||
219 | <p> |
||||||
220 | <?php if ( empty( $certificate ) ) : ?> |
||||||
221 | |||||||
222 | <span |
||||||
223 | class="dashicons dashicons-no"></span> <?php esc_html_e( 'The private key and certificate have not yet been configured.', 'pronamic_ideal' ); ?> |
||||||
224 | <br/> |
||||||
225 | |||||||
226 | <br/> |
||||||
227 | |||||||
228 | <?php esc_html_e( 'A private key and certificate are required for communication with the payment provider. Enter the organization details from the iDEAL account below to generate these required files.', 'pronamic_ideal' ); ?> |
||||||
229 | |||||||
230 | <?php else : ?> |
||||||
231 | |||||||
232 | <span |
||||||
233 | class="dashicons dashicons-yes"></span> <?php esc_html_e( 'A private key and certificate have been configured. The certificate must be uploaded to the payment provider dashboard to complete configuration.', 'pronamic_ideal' ); ?> |
||||||
234 | <br/> |
||||||
235 | |||||||
236 | <br/> |
||||||
237 | |||||||
238 | <?php |
||||||
239 | |||||||
240 | submit_button( |
||||||
241 | __( 'Download certificate', 'pronamic_ideal' ), |
||||||
242 | 'secondary', |
||||||
243 | 'download_private_certificate', |
||||||
244 | false |
||||||
245 | ); |
||||||
246 | |||||||
247 | ?> |
||||||
248 | |||||||
249 | <a class="pronamic-pay-btn-link" href="#" id="pk-cert-fields-toggle"><?php esc_html_e( 'Show details…', 'pronamic_ideal' ); ?></a> |
||||||
250 | |||||||
251 | <?php endif; ?> |
||||||
252 | </p> |
||||||
253 | <?php |
||||||
254 | } |
||||||
255 | |||||||
256 | /** |
||||||
257 | * Field private key. |
||||||
258 | * |
||||||
259 | * @param array $field Field. |
||||||
260 | */ |
||||||
261 | public function field_private_key( $field ) { |
||||||
262 | $private_key = get_post_meta( get_the_ID(), '_pronamic_gateway_ideal_private_key', true ); |
||||||
0 ignored issues
–
show
It seems like
get_the_ID() can also be of type false ; however, parameter $post_id of get_post_meta() does only seem to accept integer , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
263 | $private_key_password = get_post_meta( get_the_ID(), '_pronamic_gateway_ideal_private_key_password', true ); |
||||||
264 | $number_days_valid = get_post_meta( get_the_ID(), '_pronamic_gateway_number_days_valid', true ); |
||||||
265 | |||||||
266 | $filename = __( 'ideal.key', 'pronamic_ideal' ); |
||||||
267 | |||||||
268 | if ( ! empty( $private_key_password ) && ! empty( $number_days_valid ) ) { |
||||||
269 | $command = sprintf( |
||||||
270 | 'openssl genrsa -aes128 -out %s -passout pass:%s 2048', |
||||||
271 | escapeshellarg( $filename ), |
||||||
272 | escapeshellarg( $private_key_password ) |
||||||
273 | ); |
||||||
274 | |||||||
275 | ?> |
||||||
276 | |||||||
277 | <p><?php esc_html_e( 'OpenSSL command', 'pronamic_ideal' ); ?></p> |
||||||
278 | <input id="pronamic_ideal_openssl_command_key" name="pronamic_ideal_openssl_command_key" value="<?php echo esc_attr( $command ); ?>" type="text" class="large-text code" readonly="readonly"/> |
||||||
279 | |||||||
280 | <?php |
||||||
281 | } else { |
||||||
282 | printf( |
||||||
283 | '<p class="pronamic-pay-description description">%s</p>', |
||||||
284 | esc_html__( 'Leave empty and save the configuration to generate the private key or view the OpenSSL command.', 'pronamic_ideal' ) |
||||||
285 | ); |
||||||
286 | } |
||||||
287 | |||||||
288 | ?> |
||||||
289 | <p> |
||||||
290 | <?php |
||||||
291 | |||||||
292 | if ( ! empty( $private_key ) ) { |
||||||
293 | submit_button( |
||||||
294 | __( 'Download', 'pronamic_ideal' ), |
||||||
295 | 'secondary', |
||||||
296 | 'download_private_key', |
||||||
297 | false |
||||||
298 | ); |
||||||
299 | |||||||
300 | echo ' '; |
||||||
301 | } |
||||||
302 | |||||||
303 | printf( |
||||||
304 | '<label class="pronamic-pay-form-control-file-button button">%s <input type="file" name="%s" /></label>', |
||||||
305 | esc_html__( 'Upload', 'pronamic_ideal' ), |
||||||
306 | '_pronamic_gateway_ideal_private_key_file' |
||||||
307 | ); |
||||||
308 | |||||||
309 | ?> |
||||||
310 | </p> |
||||||
311 | <?php |
||||||
312 | } |
||||||
313 | |||||||
314 | /** |
||||||
315 | * Field private certificate. |
||||||
316 | * |
||||||
317 | * @param array $field Field. |
||||||
318 | */ |
||||||
319 | public function field_private_certificate( $field ) { |
||||||
320 | $certificate = get_post_meta( get_the_ID(), '_pronamic_gateway_ideal_private_certificate', true ); |
||||||
0 ignored issues
–
show
It seems like
get_the_ID() can also be of type false ; however, parameter $post_id of get_post_meta() does only seem to accept integer , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
321 | |||||||
322 | $private_key_password = get_post_meta( get_the_ID(), '_pronamic_gateway_ideal_private_key_password', true ); |
||||||
323 | $number_days_valid = get_post_meta( get_the_ID(), '_pronamic_gateway_number_days_valid', true ); |
||||||
324 | |||||||
325 | $filename_key = __( 'ideal.key', 'pronamic_ideal' ); |
||||||
326 | $filename_cer = __( 'ideal.cer', 'pronamic_ideal' ); |
||||||
327 | |||||||
328 | // @link http://www.openssl.org/docs/apps/req.html |
||||||
329 | $subj_args = array( |
||||||
330 | 'C' => get_post_meta( get_the_ID(), '_pronamic_gateway_country', true ), |
||||||
331 | 'ST' => get_post_meta( get_the_ID(), '_pronamic_gateway_state_or_province', true ), |
||||||
332 | 'L' => get_post_meta( get_the_ID(), '_pronamic_gateway_locality', true ), |
||||||
333 | 'O' => get_post_meta( get_the_ID(), '_pronamic_gateway_organization', true ), |
||||||
334 | 'OU' => get_post_meta( get_the_ID(), '_pronamic_gateway_organization_unit', true ), |
||||||
335 | 'CN' => get_post_meta( get_the_ID(), '_pronamic_gateway_organization', true ), |
||||||
336 | 'emailAddress' => get_post_meta( get_the_ID(), '_pronamic_gateway_email', true ), |
||||||
337 | ); |
||||||
338 | |||||||
339 | $subj_args = array_filter( $subj_args ); |
||||||
340 | |||||||
341 | $subj = ''; |
||||||
342 | foreach ( $subj_args as $type => $value ) { |
||||||
343 | $subj .= '/' . $type . '=' . addslashes( $value ); |
||||||
344 | } |
||||||
345 | |||||||
346 | if ( ! empty( $subj ) ) { |
||||||
347 | $command = trim( |
||||||
348 | sprintf( |
||||||
349 | 'openssl req -x509 -sha256 -new -key %s -passin pass:%s -days %s -out %s %s', |
||||||
350 | escapeshellarg( $filename_key ), |
||||||
351 | escapeshellarg( $private_key_password ), |
||||||
0 ignored issues
–
show
It seems like
$private_key_password can also be of type false ; however, parameter $arg of escapeshellarg() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
352 | escapeshellarg( $number_days_valid ), |
||||||
353 | escapeshellarg( $filename_cer ), |
||||||
354 | empty( $subj ) ? '' : sprintf( '-subj %s', escapeshellarg( $subj ) ) |
||||||
355 | ) |
||||||
356 | ); |
||||||
357 | |||||||
358 | ?> |
||||||
359 | |||||||
360 | <p><?php esc_html_e( 'OpenSSL command', 'pronamic_ideal' ); ?></p> |
||||||
361 | <input id="pronamic_ideal_openssl_command_certificate" name="pronamic_ideal_openssl_command_certificate" value="<?php echo esc_attr( $command ); ?>" type="text" class="large-text code" readonly="readonly"/> |
||||||
362 | |||||||
363 | <?php |
||||||
364 | } else { |
||||||
365 | printf( |
||||||
366 | '<p class="pronamic-pay-description description">%s</p>', |
||||||
367 | esc_html__( 'Leave empty and save the configuration to generate the certificate or view the OpenSSL command.', 'pronamic_ideal' ) |
||||||
368 | ); |
||||||
369 | } |
||||||
370 | |||||||
371 | if ( ! empty( $certificate ) ) { |
||||||
372 | $fingerprint = Security::get_sha_fingerprint( $certificate ); |
||||||
373 | $fingerprint = str_split( $fingerprint, 2 ); |
||||||
374 | $fingerprint = implode( ':', $fingerprint ); |
||||||
375 | |||||||
376 | echo '<dl>'; |
||||||
377 | |||||||
378 | echo '<dt>', esc_html__( 'SHA Fingerprint', 'pronamic_ideal' ), '</dt>'; |
||||||
379 | echo '<dd>', esc_html( $fingerprint ), '</dd>'; |
||||||
380 | |||||||
381 | $info = openssl_x509_parse( $certificate ); |
||||||
382 | |||||||
383 | if ( $info ) { |
||||||
0 ignored issues
–
show
The expression
$info of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||||||
384 | $date_format = __( 'M j, Y @ G:i', 'pronamic_ideal' ); |
||||||
385 | |||||||
386 | if ( isset( $info['validFrom_time_t'] ) ) { |
||||||
387 | echo '<dt>', esc_html__( 'Valid From', 'pronamic_ideal' ), '</dt>'; |
||||||
388 | echo '<dd>', esc_html( date_i18n( $date_format, $info['validFrom_time_t'] ) ), '</dd>'; |
||||||
389 | } |
||||||
390 | |||||||
391 | if ( isset( $info['validTo_time_t'] ) ) { |
||||||
392 | echo '<dt>', esc_html__( 'Valid To', 'pronamic_ideal' ), '</dt>'; |
||||||
393 | echo '<dd>', esc_html( date_i18n( $date_format, $info['validTo_time_t'] ) ), '</dd>'; |
||||||
394 | } |
||||||
395 | } |
||||||
396 | |||||||
397 | echo '</dl>'; |
||||||
398 | } |
||||||
399 | |||||||
400 | ?> |
||||||
401 | <p> |
||||||
402 | <?php |
||||||
403 | |||||||
404 | if ( ! empty( $certificate ) ) { |
||||||
405 | submit_button( |
||||||
406 | __( 'Download', 'pronamic_ideal' ), |
||||||
407 | 'secondary', |
||||||
408 | 'download_private_certificate', |
||||||
409 | false |
||||||
410 | ); |
||||||
411 | |||||||
412 | echo ' '; |
||||||
413 | } |
||||||
414 | |||||||
415 | printf( |
||||||
416 | '<label class="pronamic-pay-form-control-file-button button">%s <input type="file" name="%s" /></label>', |
||||||
417 | esc_html__( 'Upload', 'pronamic_ideal' ), |
||||||
418 | '_pronamic_gateway_ideal_private_certificate_file' |
||||||
419 | ); |
||||||
420 | |||||||
421 | ?> |
||||||
422 | </p> |
||||||
423 | <?php |
||||||
424 | } |
||||||
425 | |||||||
426 | /** |
||||||
427 | * Download private certificate |
||||||
428 | */ |
||||||
429 | public function maybe_download_private_certificate() { |
||||||
430 | if ( filter_has_var( INPUT_POST, 'download_private_certificate' ) ) { |
||||||
431 | $post_id = filter_input( INPUT_POST, 'post_ID', FILTER_SANITIZE_STRING ); |
||||||
432 | |||||||
433 | $filename = sprintf( 'ideal-private-certificate-%s.cer', $post_id ); |
||||||
434 | |||||||
435 | header( 'Content-Description: File Transfer' ); |
||||||
436 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
||||||
437 | header( 'Content-Type: application/x-x509-ca-cert; charset=' . get_option( 'blog_charset' ), true ); |
||||||
0 ignored issues
–
show
Are you sure
get_option('blog_charset') of type false|mixed can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
438 | |||||||
439 | echo get_post_meta( $post_id, '_pronamic_gateway_ideal_private_certificate', true ); // xss ok. |
||||||
0 ignored issues
–
show
Are you sure
get_post_meta($post_id, ...ate_certificate', true) of type false|mixed|string can be used in echo ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
440 | |||||||
441 | exit; |
||||||
442 | } |
||||||
443 | } |
||||||
444 | |||||||
445 | /** |
||||||
446 | * Download private key |
||||||
447 | */ |
||||||
448 | public function maybe_download_private_key() { |
||||||
449 | if ( filter_has_var( INPUT_POST, 'download_private_key' ) ) { |
||||||
450 | $post_id = filter_input( INPUT_POST, 'post_ID', FILTER_SANITIZE_STRING ); |
||||||
451 | |||||||
452 | $filename = sprintf( 'ideal-private-key-%s.key', $post_id ); |
||||||
453 | |||||||
454 | header( 'Content-Description: File Transfer' ); |
||||||
455 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
||||||
456 | header( 'Content-Type: application/pgp-keys; charset=' . get_option( 'blog_charset' ), true ); |
||||||
0 ignored issues
–
show
Are you sure
get_option('blog_charset') of type false|mixed can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
457 | |||||||
458 | echo get_post_meta( $post_id, '_pronamic_gateway_ideal_private_key', true ); // xss ok. |
||||||
0 ignored issues
–
show
Are you sure
get_post_meta($post_id, ...eal_private_key', true) of type false|mixed|string can be used in echo ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
459 | |||||||
460 | exit; |
||||||
461 | } |
||||||
462 | } |
||||||
463 | |||||||
464 | /** |
||||||
465 | * Save post. |
||||||
466 | * |
||||||
467 | * @param int $post_id Post ID. |
||||||
468 | */ |
||||||
469 | public function save_post( $post_id ) { |
||||||
470 | // Files. |
||||||
471 | $files = array( |
||||||
472 | '_pronamic_gateway_ideal_private_key_file' => '_pronamic_gateway_ideal_private_key', |
||||||
473 | '_pronamic_gateway_ideal_private_certificate_file' => '_pronamic_gateway_ideal_private_certificate', |
||||||
474 | ); |
||||||
475 | |||||||
476 | foreach ( $files as $name => $meta_key ) { |
||||||
477 | if ( isset( $_FILES[ $name ] ) && UPLOAD_ERR_OK === $_FILES[ $name ]['error'] ) { // WPCS: input var okay. |
||||||
478 | $value = file_get_contents( $_FILES[ $name ]['tmp_name'] ); // WPCS: input var okay. // WPCS: sanitization ok. |
||||||
479 | |||||||
480 | update_post_meta( $post_id, $meta_key, $value ); |
||||||
481 | } |
||||||
482 | } |
||||||
483 | |||||||
484 | // Generate private key and certificate. |
||||||
485 | $private_key = get_post_meta( $post_id, '_pronamic_gateway_ideal_private_key', true ); |
||||||
486 | $private_key_password = get_post_meta( $post_id, '_pronamic_gateway_ideal_private_key_password', true ); |
||||||
487 | |||||||
488 | if ( empty( $private_key_password ) ) { |
||||||
489 | // Without private key password we can't create private key and certifiate. |
||||||
490 | return; |
||||||
491 | } |
||||||
492 | |||||||
493 | if ( ! in_array( 'aes-128-cbc', openssl_get_cipher_methods(), true ) ) { |
||||||
494 | // Without AES-128-CBC ciphter method we can't create private key and certificate. |
||||||
495 | return; |
||||||
496 | } |
||||||
497 | |||||||
498 | // Private key. |
||||||
499 | $pkey = openssl_pkey_get_private( $private_key, $private_key_password ); |
||||||
500 | |||||||
501 | if ( false === $pkey ) { |
||||||
502 | // If we can't open the private key we will create a new private key and certificate. |
||||||
503 | if ( defined( 'OPENSSL_CIPHER_AES_128_CBC' ) ) { |
||||||
504 | $cipher = OPENSSL_CIPHER_AES_128_CBC; |
||||||
505 | } elseif ( defined( 'OPENSSL_CIPHER_3DES' ) ) { |
||||||
506 | // @link https://www.pronamic.nl/wp-content/uploads/2011/12/iDEAL_Advanced_PHP_EN_V2.2.pdf |
||||||
507 | $cipher = OPENSSL_CIPHER_3DES; |
||||||
508 | } else { |
||||||
509 | // Unable to create private key without cipher. |
||||||
510 | return; |
||||||
511 | } |
||||||
512 | |||||||
513 | $args = array( |
||||||
514 | 'digest_alg' => 'SHA256', |
||||||
515 | 'private_key_bits' => 2048, |
||||||
516 | 'private_key_type' => OPENSSL_KEYTYPE_RSA, |
||||||
517 | 'encrypt_key' => true, |
||||||
518 | 'encrypt_key_cipher' => $cipher, |
||||||
519 | 'subjectKeyIdentifier' => 'hash', |
||||||
520 | 'authorityKeyIdentifier' => 'keyid:always,issuer:always', |
||||||
521 | 'basicConstraints' => 'CA:true', |
||||||
522 | ); |
||||||
523 | |||||||
524 | $pkey = openssl_pkey_new( $args ); |
||||||
525 | |||||||
526 | if ( false === $pkey ) { |
||||||
527 | return; |
||||||
528 | } |
||||||
529 | |||||||
530 | // Export key. |
||||||
531 | $result = openssl_pkey_export( $pkey, $private_key, $private_key_password, $args ); |
||||||
0 ignored issues
–
show
It seems like
$private_key can also be of type false ; however, parameter $out of openssl_pkey_export() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
532 | |||||||
533 | if ( false === $result ) { |
||||||
534 | return; |
||||||
535 | } |
||||||
536 | |||||||
537 | update_post_meta( $post_id, '_pronamic_gateway_ideal_private_key', $private_key ); |
||||||
538 | |||||||
539 | // Delete private certificate since this is no longer valid. |
||||||
540 | delete_post_meta( $post_id, '_pronamic_gateway_ideal_private_certificate' ); |
||||||
541 | } |
||||||
542 | |||||||
543 | // Certificate. |
||||||
544 | $private_certificate = get_post_meta( $post_id, '_pronamic_gateway_ideal_private_certificate', true ); |
||||||
545 | $number_days_valid = get_post_meta( $post_id, '_pronamic_gateway_number_days_valid', true ); |
||||||
546 | |||||||
547 | if ( empty( $private_certificate ) ) { |
||||||
548 | $required_keys = array( |
||||||
549 | 'countryName', |
||||||
550 | 'stateOrProvinceName', |
||||||
551 | 'localityName', |
||||||
552 | 'organizationName', |
||||||
553 | 'commonName', |
||||||
554 | 'emailAddress', |
||||||
555 | ); |
||||||
556 | |||||||
557 | $distinguished_name = array( |
||||||
558 | 'countryName' => get_post_meta( $post_id, '_pronamic_gateway_country', true ), |
||||||
559 | 'stateOrProvinceName' => get_post_meta( $post_id, '_pronamic_gateway_state_or_province', true ), |
||||||
560 | 'localityName' => get_post_meta( $post_id, '_pronamic_gateway_locality', true ), |
||||||
561 | 'organizationName' => get_post_meta( $post_id, '_pronamic_gateway_organization', true ), |
||||||
562 | 'organizationalUnitName' => get_post_meta( $post_id, '_pronamic_gateway_organization_unit', true ), |
||||||
563 | 'commonName' => get_post_meta( $post_id, '_pronamic_gateway_organization', true ), |
||||||
564 | 'emailAddress' => get_post_meta( $post_id, '_pronamic_gateway_email', true ), |
||||||
565 | ); |
||||||
566 | |||||||
567 | $distinguished_name = array_filter( $distinguished_name ); |
||||||
568 | |||||||
569 | /* |
||||||
570 | * Create certificate only if distinguished name contains all required elements |
||||||
571 | * |
||||||
572 | * @link http://stackoverflow.com/questions/13169588/how-to-check-if-multiple-array-keys-exists |
||||||
573 | */ |
||||||
574 | if ( count( array_intersect_key( array_flip( $required_keys ), $distinguished_name ) ) === count( $required_keys ) ) { |
||||||
575 | $csr = openssl_csr_new( $distinguished_name, $pkey ); |
||||||
576 | |||||||
577 | $cert = openssl_csr_sign( $csr, null, $pkey, $number_days_valid, $args, time() ); |
||||||
0 ignored issues
–
show
It seems like
$number_days_valid can also be of type false and string ; however, parameter $days of openssl_csr_sign() does only seem to accept integer , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
578 | |||||||
579 | openssl_x509_export( $cert, $certificate ); |
||||||
580 | |||||||
581 | update_post_meta( $post_id, '_pronamic_gateway_ideal_private_certificate', $certificate ); |
||||||
582 | } |
||||||
583 | } |
||||||
584 | } |
||||||
585 | |||||||
586 | public function get_config( $post_id ) { |
||||||
587 | $mode = get_post_meta( $post_id, '_pronamic_gateway_mode', true ); |
||||||
588 | |||||||
589 | $config = new Config(); |
||||||
590 | |||||||
591 | $config->payment_server_url = $this->aquirer_url; |
||||||
592 | |||||||
593 | if ( 'test' === $mode && null !== $this->aquirer_test_url ) { |
||||||
594 | $config->payment_server_url = $this->aquirer_test_url; |
||||||
595 | } |
||||||
596 | |||||||
597 | $config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_ideal_merchant_id', true ); |
||||||
598 | $config->sub_id = get_post_meta( $post_id, '_pronamic_gateway_ideal_sub_id', true ); |
||||||
599 | $config->purchase_id = get_post_meta( $post_id, '_pronamic_gateway_ideal_purchase_id', true ); |
||||||
0 ignored issues
–
show
|
|||||||
600 | |||||||
601 | $config->private_key = get_post_meta( $post_id, '_pronamic_gateway_ideal_private_key', true ); |
||||||
602 | $config->private_key_password = get_post_meta( $post_id, '_pronamic_gateway_ideal_private_key_password', true ); |
||||||
603 | $config->private_certificate = get_post_meta( $post_id, '_pronamic_gateway_ideal_private_certificate', true ); |
||||||
604 | |||||||
605 | return $config; |
||||||
606 | } |
||||||
607 | |||||||
608 | /** |
||||||
609 | * Get gateway. |
||||||
610 | * |
||||||
611 | * @param int $post_id Post ID. |
||||||
612 | * @return Gateway |
||||||
613 | */ |
||||||
614 | public function get_gateway( $post_id ) { |
||||||
615 | return new Gateway( $this->get_config( $post_id ) ); |
||||||
616 | } |
||||||
617 | } |
||||||
618 |