11<?php
22
33/**
4- *
4+ *
55 *
66 * @author Vitex <vitex@hippy.cz>
77 * @copyright 2023 Vitex@hippy.cz (G)
8- *
8+ *
99 * PHP 7
1010 */
1111
@@ -25,12 +25,12 @@ class ApiClient extends \GuzzleHttp\Client
2525 protected $ xIBMClientId = null ;
2626
2727 /**
28- * the end IP address of the client application (no server) in IPv4 or IPv6
29- * format. If the bank client (your user) uses a browser by which he
30- * accesses your server app, we need to know the IP address of his browser.
31- * Always provide the closest IP address to the real end-user possible.
28+ * the end IP address of the client application (no server) in IPv4 or IPv6
29+ * format. If the bank client (your user) uses a browser by which he
30+ * accesses your server app, we need to know the IP address of his browser.
31+ * Always provide the closest IP address to the real end-user possible.
3232 * (optional)
33- *
33+ *
3434 * @var string
3535 */
3636 protected $ pSUIPAddress = null ;
@@ -43,13 +43,13 @@ class ApiClient extends \GuzzleHttp\Client
4343
4444 /**
4545 * @inheritDoc
46- *
46+ *
4747 * $config['clientid'] - obtained from Developer Portal - when you registered your app with us.
4848 * $config['cert'] = ['/path/to/cert.p12','certificat password']
4949 * $config['clientpubip'] = the closest IP address to the real end-user
5050 * $config['mocking'] = true to use /rbcz/premium/mock/* endpoints
51- *
52- * @param array $config
51+ *
52+ * @param array $config
5353 * @throws \Exception CERT_FILE is not set
5454 * @throws \Exception CERT_PASS is not set
5555 */
@@ -73,7 +73,7 @@ public function __construct(array $config = [])
7373
7474 if (array_key_exists ('debug ' , $ config ) === false ) {
7575 $ config ['debug ' ] = \Ease \Shared::cfg ('API_DEBUG ' , false );
76- }
76+ }
7777
7878 if (array_key_exists ('clientpubip ' , $ config )) {
7979 $ this ->pSUIPAddress = $ config ['clientpubip ' ];
@@ -88,7 +88,7 @@ public function __construct(array $config = [])
8888
8989 /**
9090 * ClientID obtained from Developer Portal
91- *
91+ *
9292 * @return string
9393 */
9494 public function getXIBMClientId ()
@@ -98,17 +98,17 @@ public function getXIBMClientId()
9898
9999 /**
100100 * Keep user public IP here
101- *
101+ *
102102 * @return string
103103 */
104104 public function getpSUIPAddress ()
105105 {
106106 return $ this ->pSUIPAddress ;
107- }
107+ }
108108
109109 /**
110110 * Use mocking uri for api calls ?
111- *
111+ *
112112 * @return boolean
113113 */
114114 public function getMockMode ()
@@ -118,9 +118,9 @@ public function getMockMode()
118118
119119 /**
120120 * Obtain Your current Public IP
121- *
121+ *
122122 * @deprecated since version 0.1 - Do not use in production Environment!
123- *
123+ *
124124 * @return string
125125 */
126126 public static function getPublicIP ()
@@ -136,9 +136,9 @@ public static function getPublicIP()
136136
137137 /**
138138 * Source Identifier
139- *
139+ *
140140 * @deprecated since version 0.1 - Do not use in production Environment!
141- *
141+ *
142142 * @return string
143143 */
144144 public static function sourceString ()
@@ -148,15 +148,15 @@ public static function sourceString()
148148
149149 /**
150150 * Try to check certificate readibilty
151- *
152- *
151+ *
152+ *
153153 * @param string $certFile path to certificate
154154 * @param boolean $die throw exception or return false ?
155155 * @throws Exception - Certificate file not found
156- *
156+ *
157157 * @return boolean certificate file
158158 */
159- public static function checkCertificatePresence ($ certFile , $ die = false )
159+ public static function checkCertificatePresence (string $ certFile , bool $ die = false ): bool
160160 {
161161 $ found = false ;
162162 if ((file_exists ($ certFile ) === false ) || (is_readable ($ certFile ) === false )) {
@@ -168,14 +168,30 @@ public static function checkCertificatePresence($certFile, $die = false)
168168 } else {
169169 $ found = true ;
170170 }
171- return $ found ;
171+ return $ found ;
172+ }
173+
174+ public static function checkCertificate ($ certFile , $ password ): bool
175+ {
176+ return self ::checkCertificatePresence ($ certFile ) && self ::checkCertificatePassword ($ certFile , $ password );
177+ }
178+
179+ public static function checkCertificatePassword (string $ certFile , string $ password ): bool
180+ {
181+ $ certContent = file_get_contents ($ certFile );
182+ if (openssl_pkcs12_read ($ certContent , $ certs , $ password ) === false ) {
183+ fwrite (\STDERR , 'Cannot read PKCS12 certificate file: ' .$ certFile .\PHP_EOL );
184+ exit (1 );
185+ }
186+ return true ;
172187 }
173188
189+
174190 /**
175191 * Request Identifier
176- *
192+ *
177193 * @deprecated since version 0.1 - Do not use in production Environment!
178- *
194+ *
179195 * @return string
180196 */
181197 public static function getxRequestId ()
0 commit comments