@@ -12,9 +12,9 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\Threema; |
14 | 14 | |
15 | -use chillerlan\Threema\Crypto\CryptoInterface; |
|
16 | 15 | use ReflectionClass; |
17 | 16 | use ReflectionMethod; |
17 | +use chillerlan\Threema\Crypto\CryptoInterface; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | return $this->log2cli($method->invokeArgs($this, $arguments)); |
103 | 103 | } |
104 | 104 | catch(GatewayException $gatewayException){ |
105 | - return $this->log2cli('ERROR: '.$gatewayException->getMessage()); |
|
105 | + return $this->log2cli('ERROR: ' . $gatewayException->getMessage()); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @return string |
118 | 118 | */ |
119 | 119 | protected function log2cli(string $string):string{ |
120 | - return PHP_EOL.wordwrap($string, 78, PHP_EOL).PHP_EOL; |
|
120 | + return PHP_EOL . wordwrap($string, 78, PHP_EOL) . PHP_EOL; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function help():string{ |
147 | 147 | // return info in case no command was found |
148 | - $help = 'Threema Gateway CLI tool.'.PHP_EOL; |
|
149 | - $help .= 'Crypto: '.$this->threemaGateway->cryptoVersion().PHP_EOL.PHP_EOL; |
|
148 | + $help = 'Threema Gateway CLI tool.' . PHP_EOL; |
|
149 | + $help .= 'Crypto: ' . $this->threemaGateway->cryptoVersion() . PHP_EOL . PHP_EOL; |
|
150 | 150 | |
151 | 151 | foreach(self::COMMANDS as $command => $method){ |
152 | 152 | $comment = $this->reflection->getMethod($method)->getDocComment(); |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | if(isset($p[1])){ |
165 | 165 | if($p[0] === 'param'){ |
166 | 166 | $p = (explode(' ', trim($p[1]), 3)); |
167 | - $paramNames[] = '<'.trim($p[1], ' $').'>'; |
|
168 | - $d = trim($p[1]); |
|
167 | + $paramNames[] = '<' . trim($p[1], ' $') . '>'; |
|
168 | + $d = trim($p[1]); |
|
169 | 169 | # $d .= ' ('.trim($p[0]).'): '; |
170 | - $d .= isset($p[2]) ? ': '.trim($p[2]) : ''; |
|
170 | + $d .= isset($p[2]) ? ': ' . trim($p[2]) : ''; |
|
171 | 171 | $paramDoc[] = $d; |
172 | 172 | } |
173 | 173 | else if($p[0] === 'return'){ |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - $help .= PHP_EOL.'threema.php '.$command.' '.implode(' ', $paramNames).PHP_EOL; |
|
184 | - $help .= str_repeat('-', strlen($command)+12).PHP_EOL; |
|
185 | - $help .= PHP_EOL.$comment.PHP_EOL; |
|
186 | - $help .= PHP_EOL.implode(PHP_EOL, $paramDoc).PHP_EOL; |
|
187 | - $help .= PHP_EOL.'Returns: '.$returnDoc.PHP_EOL; |
|
183 | + $help .= PHP_EOL . 'threema.php ' . $command . ' ' . implode(' ', $paramNames) . PHP_EOL; |
|
184 | + $help .= str_repeat('-', strlen($command) + 12) . PHP_EOL; |
|
185 | + $help .= PHP_EOL . $comment . PHP_EOL; |
|
186 | + $help .= PHP_EOL . implode(PHP_EOL, $paramDoc) . PHP_EOL; |
|
187 | + $help .= PHP_EOL . 'Returns: ' . $returnDoc . PHP_EOL; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | return $help; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | public function getKeypair(string $privateKeyFile = null, string $publicKeyFile = null):string{ |
198 | 198 | $keypair = $this->cryptoInterface->getKeypair(); |
199 | 199 | |
200 | - return 'private:'.$keypair->privateKey.PHP_EOL.'public:'.$keypair->publicKey; |
|
200 | + return 'private:' . $keypair->privateKey . PHP_EOL . 'public:' . $keypair->publicKey; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | public function version():string{ |
23 | 23 | /** @noinspection PhpUndefinedNamespaceInspection @noinspection PhpUndefinedFunctionInspection */ |
24 | - return 'libsodium '.\Sodium\version_string(); |
|
24 | + return 'libsodium ' . \Sodium\version_string(); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | throw new CryptoException('invalid data'); |
78 | 78 | } |
79 | 79 | |
80 | - if(!preg_match('/^[a-f\d]{128}$/i', $privateKey.$publicKey)){ |
|
80 | + if(!preg_match('/^[a-f\d]{128}$/i', $privateKey . $publicKey)){ |
|
81 | 81 | throw new CryptoException('invalid keypair'); |
82 | 82 | } |
83 | 83 |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $reflectionClass = new ReflectionClass($gatewayOptions->gatewayInterface); |
73 | 73 | |
74 | 74 | if(!$reflectionClass->implementsInterface(GatewayInterface::class)){ |
75 | - throw new GatewayException('"'.$gatewayOptions->gatewayInterface.'" does not implement GatewayInterface'); |
|
75 | + throw new GatewayException('"' . $gatewayOptions->gatewayInterface . '" does not implement GatewayInterface'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | $this->gatewayInterface = $reflectionClass->newInstanceArgs([$cryptoInterface, $gatewayOptions]); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | return $reflectionMethod->invokeArgs($this->gatewayInterface, $params); |
94 | 94 | } |
95 | 95 | |
96 | - throw new GatewayException('method "'.$method.'" does not exist'); |
|
96 | + throw new GatewayException('method "' . $method . '" does not exist'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | ####################### |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @throws \chillerlan\TinyCurl\RequestException |
66 | 66 | */ |
67 | 67 | protected function getResponse(string $endpoint, array $params = [], array $body = []):Response{ |
68 | - $endpoint = self::API_BASE.$endpoint; |
|
68 | + $endpoint = self::API_BASE . $endpoint; |
|
69 | 69 | $params = array_merge($params, [ |
70 | 70 | 'from' => getenv('THREEMA_GATEWAY_ID'), |
71 | 71 | 'secret' => getenv('THREEMA_GATEWAY_SECRET') |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | return $response; |
82 | 82 | } |
83 | 83 | elseif(array_key_exists($response->info->http_code, self::API_ERRORS)){ |
84 | - throw new GatewayException('gateway error: '.self::API_ERRORS[$response->info->http_code]); |
|
84 | + throw new GatewayException('gateway error: ' . self::API_ERRORS[$response->info->http_code]); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | throw new GatewayException('unknown error: "compiles on my machine."'); // @codeCoverageIgnore |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @inheritdoc |
99 | 99 | */ |
100 | 100 | public function checkCapabilities(string $threemaID):array{ |
101 | - $response = $this->getResponse('/capabilities/'.$this->checkThreemaID($threemaID))->body->content; |
|
101 | + $response = $this->getResponse('/capabilities/' . $this->checkThreemaID($threemaID))->body->content; |
|
102 | 102 | $response = !empty($response) ? explode(',', $response) : []; |
103 | 103 | |
104 | 104 | sort($response); |
@@ -110,35 +110,35 @@ discard block |
||
110 | 110 | * @inheritdoc |
111 | 111 | */ |
112 | 112 | public function getIdByPhone(string $phoneno):string{ |
113 | - return $this->getResponse('/lookup/phone/'.$this->checkPhoneNo($phoneno))->body->content; |
|
113 | + return $this->getResponse('/lookup/phone/' . $this->checkPhoneNo($phoneno))->body->content; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
117 | 117 | * @inheritdoc |
118 | 118 | */ |
119 | 119 | public function getIdByPhoneHash(string $phonenoHash):string{ |
120 | - return $this->getResponse('/lookup/phone_hash/'.$this->checkHash($phonenoHash))->body->content; |
|
120 | + return $this->getResponse('/lookup/phone_hash/' . $this->checkHash($phonenoHash))->body->content; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @inheritdoc |
125 | 125 | */ |
126 | 126 | public function getIdByEmail(string $email):string{ |
127 | - return $this->getResponse('/lookup/email/'.$this->checkEmail($email))->body->content; |
|
127 | + return $this->getResponse('/lookup/email/' . $this->checkEmail($email))->body->content; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @inheritdoc |
132 | 132 | */ |
133 | 133 | public function getIdByEmailHash(string $emailHash):string{ |
134 | - return $this->getResponse('/lookup/email_hash/'.$this->checkHash($emailHash))->body->content; |
|
134 | + return $this->getResponse('/lookup/email_hash/' . $this->checkHash($emailHash))->body->content; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
138 | 138 | * @inheritdoc |
139 | 139 | */ |
140 | 140 | public function getPublicKey(string $threemaID):string{ |
141 | - return $this->checkHash($this->getResponse('/pubkeys/'.$this->checkThreemaID($threemaID))->body->content); |
|
141 | + return $this->checkHash($this->getResponse('/pubkeys/' . $this->checkThreemaID($threemaID))->body->content); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @var string |
27 | 27 | */ |
28 | - public $configPath = __DIR__.'/../config'; |
|
28 | + public $configPath = __DIR__ . '/../config'; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * @var string |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @var string |
37 | 37 | */ |
38 | - public $storagePath = __DIR__.'/../storage'; |
|
38 | + public $storagePath = __DIR__ . '/../storage'; |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * full path to the CA Root Certificates for use with CURL/SSL |
@@ -43,6 +43,6 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @var string |
45 | 45 | */ |
46 | - public $cacert = __DIR__.'/../storage/cacert.pem'; |
|
46 | + public $cacert = __DIR__ . '/../storage/cacert.pem'; |
|
47 | 47 | |
48 | 48 | } |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Interface GatewayInterface |
|
4 | - * |
|
5 | - * @filesource GatewayInterface.php |
|
6 | - * @created 01.04.2016 |
|
7 | - * @package chillerlan\Threema |
|
8 | - * @author Smiley <[email protected]> |
|
9 | - * @copyright 2016 Smiley |
|
10 | - * @license MIT |
|
11 | - */ |
|
3 | + * Interface GatewayInterface |
|
4 | + * |
|
5 | + * @filesource GatewayInterface.php |
|
6 | + * @created 01.04.2016 |
|
7 | + * @package chillerlan\Threema |
|
8 | + * @author Smiley <[email protected]> |
|
9 | + * @copyright 2016 Smiley |
|
10 | + * @license MIT |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | namespace chillerlan\Threema; |
14 | 14 |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Class GatewayException |
|
4 | - * |
|
5 | - * @filesource GatewayException.php |
|
6 | - * @created 02.04.2016 |
|
7 | - * @package chillerlan\Threema |
|
8 | - * @author Smiley <[email protected]> |
|
9 | - * @copyright 2016 Smiley |
|
10 | - * @license MIT |
|
11 | - */ |
|
3 | + * Class GatewayException |
|
4 | + * |
|
5 | + * @filesource GatewayException.php |
|
6 | + * @created 02.04.2016 |
|
7 | + * @package chillerlan\Threema |
|
8 | + * @author Smiley <[email protected]> |
|
9 | + * @copyright 2016 Smiley |
|
10 | + * @license MIT |
|
11 | + */ |
|
12 | 12 | |
13 | 13 | namespace chillerlan\Threema; |
14 | 14 |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @filesource threema.php |
|
4 | - * @created 02.04.2016 |
|
5 | - * @author Smiley <[email protected]> |
|
6 | - * @copyright 2016 Smiley |
|
7 | - * @license MIT |
|
8 | - */ |
|
3 | + * @filesource threema.php |
|
4 | + * @created 02.04.2016 |
|
5 | + * @author Smiley <[email protected]> |
|
6 | + * @copyright 2016 Smiley |
|
7 | + * @license MIT |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | namespace chillerlan\ThreemaCLI; |
11 | 11 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace chillerlan\ThreemaCLI; |
11 | 11 | |
12 | -require_once __DIR__.'/../vendor/autoload.php'; |
|
12 | +require_once __DIR__ . '/../vendor/autoload.php'; |
|
13 | 13 | |
14 | 14 | use chillerlan\Threema\CLIRunner; |
15 | 15 | use chillerlan\Threema\Crypto\CryptoSodium; |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | |
22 | 22 | $gatewayOptions = new GatewayOptions; |
23 | 23 | $gatewayOptions->configFilename = '.threema'; // @todo TRAVIS REMINDER! |
24 | -$gatewayOptions->configPath = __DIR__.'/../config'; |
|
25 | -$gatewayOptions->storagePath = __DIR__.'/../storage'; |
|
26 | -$gatewayOptions->cacert = __DIR__.'/../storage/cacert.pem'; |
|
24 | +$gatewayOptions->configPath = __DIR__ . '/../config'; |
|
25 | +$gatewayOptions->storagePath = __DIR__ . '/../storage'; |
|
26 | +$gatewayOptions->cacert = __DIR__ . '/../storage/cacert.pem'; |
|
27 | 27 | |
28 | 28 | echo (new CLIRunner(new CryptoSodium, $gatewayOptions))->run($_SERVER['argv']); |
29 | 29 |
@@ -1,58 +1,58 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * |
|
4 | - * @filesource callback.php |
|
5 | - * @created 02.04.2016 |
|
6 | - * @author Smiley <[email protected]> |
|
7 | - * @copyright 2016 Smiley |
|
8 | - * @license MIT |
|
9 | - * |
|
10 | - * @todo |
|
11 | - * |
|
12 | - * Incoming messages and delivery receipts |
|
13 | - * |
|
14 | - * If your account is operating in end-to-end encrypted mode and incoming messages have been enabled on it, you can |
|
15 | - * specify an HTTPS URL callback that will be called whenever an incoming message or delivery receipt arrives for your |
|
16 | - * API identity. You can set or change the callback URL in the Threema Gateway administration panel. |
|
17 | - * |
|
18 | - * Callback parameters |
|
19 | - * |
|
20 | - * Your callback URL will be called with the following POST parameters (application/x-www-form-urlencoded): |
|
21 | - * |
|
22 | - * from sender identity (8 characters) |
|
23 | - * to your API identity (8 characters, usually starts with '*') |
|
24 | - * messageId message ID assigned by the sender (8 bytes, hex encoded) |
|
25 | - * date message date set by the sender (UNIX timestamp) |
|
26 | - * nonce nonce used for encryption (24 bytes, hex encoded) |
|
27 | - * box encrypted message data (max. 4000 bytes, hex encoded) |
|
28 | - * mac Message Authentication Code (32 bytes, hex encoded, see below) |
|
29 | - * Note that the message first needs to be decrypted before it can be determined whether it is an incoming text message |
|
30 | - * or a delivery receipt. |
|
31 | - * |
|
32 | - * MAC calculation |
|
33 | - * |
|
34 | - * For each callback, the server includes a mac parameter than can be used to verify the authenticity of the call and |
|
35 | - * the included information. This parameter is calculated as follows: |
|
36 | - * |
|
37 | - * mac = HMAC-SHA256(from || to || messageId || date || nonce || box, secret) |
|
38 | - * |
|
39 | - * || denotes concatenation. The parameters are concatenated in the same form as they were included in the POST (i.e. |
|
40 | - * including any hex encoding, but not including any URL encoding). The secret that is used for the HMAC operation is |
|
41 | - * the API authentication secret. |
|
42 | - * |
|
43 | - * It is recommended that receivers verify the mac parameter before attempting to parse the other parameters and |
|
44 | - * decrypt the message. |
|
45 | - * |
|
46 | - * Callback results and retry |
|
47 | - * |
|
48 | - * If the connection to your callback URL fails or your callback does not return an HTTP 200 status, the API will retry |
|
49 | - * 3 more times in intervals of 5 minutes. If all attempts fail, the message is discarded. |
|
50 | - * |
|
51 | - * Certificates and cipher suites |
|
52 | - * |
|
53 | - * The server that hosts the callback URL must use a valid and trusted SSL/TLS certificate (not self-signed). If in |
|
54 | - * doubt, please contact customer service and specify the issuing CA of your certificate. |
|
55 | - */ |
|
3 | + * |
|
4 | + * @filesource callback.php |
|
5 | + * @created 02.04.2016 |
|
6 | + * @author Smiley <[email protected]> |
|
7 | + * @copyright 2016 Smiley |
|
8 | + * @license MIT |
|
9 | + * |
|
10 | + * @todo |
|
11 | + * |
|
12 | + * Incoming messages and delivery receipts |
|
13 | + * |
|
14 | + * If your account is operating in end-to-end encrypted mode and incoming messages have been enabled on it, you can |
|
15 | + * specify an HTTPS URL callback that will be called whenever an incoming message or delivery receipt arrives for your |
|
16 | + * API identity. You can set or change the callback URL in the Threema Gateway administration panel. |
|
17 | + * |
|
18 | + * Callback parameters |
|
19 | + * |
|
20 | + * Your callback URL will be called with the following POST parameters (application/x-www-form-urlencoded): |
|
21 | + * |
|
22 | + * from sender identity (8 characters) |
|
23 | + * to your API identity (8 characters, usually starts with '*') |
|
24 | + * messageId message ID assigned by the sender (8 bytes, hex encoded) |
|
25 | + * date message date set by the sender (UNIX timestamp) |
|
26 | + * nonce nonce used for encryption (24 bytes, hex encoded) |
|
27 | + * box encrypted message data (max. 4000 bytes, hex encoded) |
|
28 | + * mac Message Authentication Code (32 bytes, hex encoded, see below) |
|
29 | + * Note that the message first needs to be decrypted before it can be determined whether it is an incoming text message |
|
30 | + * or a delivery receipt. |
|
31 | + * |
|
32 | + * MAC calculation |
|
33 | + * |
|
34 | + * For each callback, the server includes a mac parameter than can be used to verify the authenticity of the call and |
|
35 | + * the included information. This parameter is calculated as follows: |
|
36 | + * |
|
37 | + * mac = HMAC-SHA256(from || to || messageId || date || nonce || box, secret) |
|
38 | + * |
|
39 | + * || denotes concatenation. The parameters are concatenated in the same form as they were included in the POST (i.e. |
|
40 | + * including any hex encoding, but not including any URL encoding). The secret that is used for the HMAC operation is |
|
41 | + * the API authentication secret. |
|
42 | + * |
|
43 | + * It is recommended that receivers verify the mac parameter before attempting to parse the other parameters and |
|
44 | + * decrypt the message. |
|
45 | + * |
|
46 | + * Callback results and retry |
|
47 | + * |
|
48 | + * If the connection to your callback URL fails or your callback does not return an HTTP 200 status, the API will retry |
|
49 | + * 3 more times in intervals of 5 minutes. If all attempts fail, the message is discarded. |
|
50 | + * |
|
51 | + * Certificates and cipher suites |
|
52 | + * |
|
53 | + * The server that hosts the callback URL must use a valid and trusted SSL/TLS certificate (not self-signed). If in |
|
54 | + * doubt, please contact customer service and specify the issuing CA of your certificate. |
|
55 | + */ |
|
56 | 56 | |
57 | 57 | |
58 | 58 |