@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Threema GmbH |
|
4 | - * @copyright Copyright (c) 2015 Threema GmbH |
|
5 | - */ |
|
3 | + * @author Threema GmbH |
|
4 | + * @copyright Copyright (c) 2015 Threema GmbH |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | |
8 | 8 | namespace Threema\MsgApi\Tools; |
@@ -124,7 +124,7 @@ |
||
124 | 124 | * @throws Exception |
125 | 125 | */ |
126 | 126 | public function validate() { |
127 | - if(false === $this->isSupported()) { |
|
127 | + if (false === $this->isSupported()) { |
|
128 | 128 | throw new Exception('Sodium implementation not supported'); |
129 | 129 | } |
130 | 130 | return true; |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Threema GmbH |
|
4 | - * @copyright Copyright (c) 2015 Threema GmbH |
|
5 | - */ |
|
3 | + * @author Threema GmbH |
|
4 | + * @copyright Copyright (c) 2015 Threema GmbH |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | |
8 | 8 | namespace Threema\MsgApi\Tools; |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Threema GmbH |
|
4 | - * @copyright Copyright (c) 2015 Threema GmbH |
|
5 | - */ |
|
3 | + * @author Threema GmbH |
|
4 | + * @copyright Copyright (c) 2015 Threema GmbH |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | |
8 | 8 | namespace Threema\MsgApi\Tools; |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Threema GmbH |
|
4 | - * @copyright Copyright (c) 2015 Threema GmbH |
|
5 | - */ |
|
3 | + * @author Threema GmbH |
|
4 | + * @copyright Copyright (c) 2015 Threema GmbH |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | |
8 | 8 | namespace Threema\MsgApi\Tools; |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Threema GmbH |
|
4 | - * @copyright Copyright (c) 2015 Threema GmbH |
|
5 | - */ |
|
3 | + * @author Threema GmbH |
|
4 | + * @copyright Copyright (c) 2015 Threema GmbH |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | |
8 | 8 | namespace Threema\MsgApi\Tools; |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * |
33 | 33 | * @param string $keystorePath Path public key store file (PHP) |
34 | 34 | * |
35 | - * @return PhpFile public key store |
|
35 | + * @return Threema\MsgApi\PublicKeyStores\PhpFile public key store |
|
36 | 36 | */ |
37 | 37 | function CreatePublicKeyStore($keystorePath) |
38 | 38 | { |
@@ -18,7 +18,7 @@ |
||
18 | 18 | * |
19 | 19 | * @return Connection $connector |
20 | 20 | */ |
21 | -function CreateConnection($keystorePath='../../keystore.php', $useTlsOptions=true) |
|
21 | +function CreateConnection($keystorePath = '../../keystore.php', $useTlsOptions = true) |
|
22 | 22 | { |
23 | 23 | $publicKeyStore = CreatePublicKeyStore($keystorePath); |
24 | 24 | $settings = CreateConnectionSettings($publicKeyStore, $useTlsOptions); |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author rugk |
|
4 | - * @copyright Copyright (c) 2015 rugk |
|
5 | - * @license MIT |
|
6 | - */ |
|
3 | + * @author rugk |
|
4 | + * @copyright Copyright (c) 2015 rugk |
|
5 | + * @license MIT |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | use Threema\MsgApi\Connection; |
9 | 9 | use Threema\MsgApi\ConnectionSettings; |
@@ -20,11 +20,11 @@ discard block |
||
20 | 20 | */ |
21 | 21 | function CreateConnection($keystorePath='../../keystore.php', $useTlsOptions=true) |
22 | 22 | { |
23 | - $publicKeyStore = CreatePublicKeyStore($keystorePath); |
|
24 | - $settings = CreateConnectionSettings($publicKeyStore, $useTlsOptions); |
|
25 | - $connector = InitiateConnection($settings, $publicKeyStore); |
|
23 | + $publicKeyStore = CreatePublicKeyStore($keystorePath); |
|
24 | + $settings = CreateConnectionSettings($publicKeyStore, $useTlsOptions); |
|
25 | + $connector = InitiateConnection($settings, $publicKeyStore); |
|
26 | 26 | |
27 | - return $connector; |
|
27 | + return $connector; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | */ |
37 | 37 | function CreatePublicKeyStore($keystorePath) |
38 | 38 | { |
39 | - if (!file_exists($keystorePath)) { |
|
40 | - if (!touch($keystorePath)) { |
|
41 | - throw new Exception("PHP keystore could not be created."); |
|
42 | - } |
|
43 | - } |
|
44 | - return $publicKeyStore = new Threema\MsgApi\PublicKeyStores\PhpFile($keystorePath); |
|
39 | + if (!file_exists($keystorePath)) { |
|
40 | + if (!touch($keystorePath)) { |
|
41 | + throw new Exception("PHP keystore could not be created."); |
|
42 | + } |
|
43 | + } |
|
44 | + return $publicKeyStore = new Threema\MsgApi\PublicKeyStores\PhpFile($keystorePath); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -54,27 +54,27 @@ discard block |
||
54 | 54 | */ |
55 | 55 | function CreateConnectionSettings($publicKeyStore, $useTlsOptions) |
56 | 56 | { |
57 | - if ($useTlsOptions == true) { |
|
58 | - //create a connection with advanced options |
|
59 | - $settings = new ConnectionSettings( |
|
60 | - MSGAPI_GATEWAY_THREEMA_ID, |
|
61 | - MSGAPI_GATEWAY_THREEMA_ID_SECRET, |
|
62 | - null, |
|
63 | - [ |
|
64 | - 'forceHttps' => true, |
|
65 | - 'tlsVersion' => '1.2', |
|
66 | - 'tlsCipher' => 'ECDHE-RSA-AES128-GCM-SHA256' |
|
67 | - ] |
|
68 | - ); |
|
69 | - } else { |
|
70 | - //create a connection with default options |
|
71 | - $settings = new ConnectionSettings( |
|
72 | - MSGAPI_GATEWAY_THREEMA_ID, |
|
73 | - MSGAPI_GATEWAY_THREEMA_ID_SECRET |
|
74 | - ); |
|
75 | - } |
|
57 | + if ($useTlsOptions == true) { |
|
58 | + //create a connection with advanced options |
|
59 | + $settings = new ConnectionSettings( |
|
60 | + MSGAPI_GATEWAY_THREEMA_ID, |
|
61 | + MSGAPI_GATEWAY_THREEMA_ID_SECRET, |
|
62 | + null, |
|
63 | + [ |
|
64 | + 'forceHttps' => true, |
|
65 | + 'tlsVersion' => '1.2', |
|
66 | + 'tlsCipher' => 'ECDHE-RSA-AES128-GCM-SHA256' |
|
67 | + ] |
|
68 | + ); |
|
69 | + } else { |
|
70 | + //create a connection with default options |
|
71 | + $settings = new ConnectionSettings( |
|
72 | + MSGAPI_GATEWAY_THREEMA_ID, |
|
73 | + MSGAPI_GATEWAY_THREEMA_ID_SECRET |
|
74 | + ); |
|
75 | + } |
|
76 | 76 | |
77 | - return $settings; |
|
77 | + return $settings; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -87,5 +87,5 @@ discard block |
||
87 | 87 | */ |
88 | 88 | function InitiateConnection($settings, $publicKeyStore) |
89 | 89 | { |
90 | - return $connector = new Connection($settings, $publicKeyStore); |
|
90 | + return $connector = new Connection($settings, $publicKeyStore); |
|
91 | 91 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | * @param string $threemaId The id whose public key should be fetched |
35 | 35 | * @param string $message The message to send (max 3500 characters) |
36 | 36 | * |
37 | - * @return string|Exception |
|
37 | + * @return string |
|
38 | 38 | */ |
39 | 39 | function SendMessage($connector, $threemaId, $message) |
40 | 40 | { |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | //get params |
52 | 52 | if (ReturnGetPost('recieverid') && |
53 | - preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('recieverid')) |
|
53 | + preg_match('/'.REGEXP_THREEMAID_ANY.'/', ReturnGetPost('recieverid')) |
|
54 | 54 | ) { |
55 | 55 | $threemaId = htmlentities(ReturnGetPost('recieverid')); |
56 | 56 | $message = ReturnGetPost('message'); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | //Show direct output if the file is called directly |
78 | 78 | if (!$isIncluded) { |
79 | 79 | if ($errorMessage == null) { |
80 | - echo 'Message ID: ' . $messageId; |
|
80 | + echo 'Message ID: '.$messageId; |
|
81 | 81 | } else { |
82 | 82 | echo $errorMessage; |
83 | 83 | } |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author rugk |
|
4 | - * @copyright Copyright (c) 2015 rugk |
|
5 | - * @license MIT |
|
6 | - */ |
|
3 | + * @author rugk |
|
4 | + * @copyright Copyright (c) 2015 rugk |
|
5 | + * @license MIT |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | $isIncluded = count(get_included_files()) > 1; |
9 | 9 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | */ |
39 | 39 | function SendMessage($connector, $threemaId, $message) |
40 | 40 | { |
41 | - $e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper(KeyHexToBin(MSGAPI_PRIVATE_KEY), $connector); |
|
42 | - $result = $e2eHelper->sendTextMessage($threemaId, $message); |
|
41 | + $e2eHelper = new \Threema\MsgApi\Helpers\E2EHelper(KeyHexToBin(MSGAPI_PRIVATE_KEY), $connector); |
|
42 | + $result = $e2eHelper->sendTextMessage($threemaId, $message); |
|
43 | 43 | |
44 | - if (true === $result->isSuccess()) { |
|
45 | - return $result->getMessageId(); |
|
46 | - } else { |
|
47 | - throw new Exception($result->getErrorMessage()); |
|
48 | - } |
|
44 | + if (true === $result->isSuccess()) { |
|
45 | + return $result->getMessageId(); |
|
46 | + } else { |
|
47 | + throw new Exception($result->getErrorMessage()); |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | //get params |
52 | 52 | if (ReturnGetPost('recieverid') && |
53 | - preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('recieverid')) |
|
53 | + preg_match('/' . REGEXP_THREEMAID_ANY . '/', ReturnGetPost('recieverid')) |
|
54 | 54 | ) { |
55 | - $threemaId = htmlentities(ReturnGetPost('recieverid')); |
|
56 | - $message = ReturnGetPost('message'); |
|
55 | + $threemaId = htmlentities(ReturnGetPost('recieverid')); |
|
56 | + $message = ReturnGetPost('message'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | //create connection |
@@ -61,24 +61,24 @@ discard block |
||
61 | 61 | |
62 | 62 | //Send message |
63 | 63 | if ($threemaId != null && $message != null) { |
64 | - if (!$isIncluded) { |
|
65 | - header('Content-Type: text/plain'); |
|
66 | - } |
|
67 | - $actionDone = true; |
|
64 | + if (!$isIncluded) { |
|
65 | + header('Content-Type: text/plain'); |
|
66 | + } |
|
67 | + $actionDone = true; |
|
68 | 68 | |
69 | - try { |
|
70 | - $messageId = SendMessage($connector, $threemaId, $message); |
|
71 | - } catch (Exception $e) { |
|
72 | - http_response_code(500); |
|
73 | - $errorMessage = $e->getMessage(); |
|
74 | - } |
|
69 | + try { |
|
70 | + $messageId = SendMessage($connector, $threemaId, $message); |
|
71 | + } catch (Exception $e) { |
|
72 | + http_response_code(500); |
|
73 | + $errorMessage = $e->getMessage(); |
|
74 | + } |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | //Show direct output if the file is called directly |
78 | 78 | if (!$isIncluded) { |
79 | - if ($errorMessage == null) { |
|
80 | - echo 'Message ID: ' . $messageId; |
|
81 | - } else { |
|
82 | - echo $errorMessage; |
|
83 | - } |
|
79 | + if ($errorMessage == null) { |
|
80 | + echo 'Message ID: ' . $messageId; |
|
81 | + } else { |
|
82 | + echo $errorMessage; |
|
83 | + } |
|
84 | 84 | } |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author rugk |
|
4 | - * @copyright Copyright (c) 2015 rugk |
|
5 | - * @license MIT |
|
6 | - */ |
|
3 | + * @author rugk |
|
4 | + * @copyright Copyright (c) 2015 rugk |
|
5 | + * @license MIT |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Checks whether a HEX-key is valid. |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function KeyCheck($publicKey, $suffix='') |
16 | 16 | { |
17 | - // RegExp: https://regex101.com/r/sU5tC8/1 |
|
18 | - return preg_match('/^(' . $suffix . ')?[[:alnum:]]{64}$/', $publicKey); |
|
17 | + // RegExp: https://regex101.com/r/sU5tC8/1 |
|
18 | + return preg_match('/^(' . $suffix . ')?[[:alnum:]]{64}$/', $publicKey); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | */ |
33 | 33 | function KeyGetUserDisplay($publicKey) |
34 | 34 | { |
35 | - //force key to be binary |
|
36 | - if (ctype_alnum($publicKey)) { |
|
37 | - $publicKey = KeyHexToBin($publicKey); |
|
38 | - } |
|
35 | + //force key to be binary |
|
36 | + if (ctype_alnum($publicKey)) { |
|
37 | + $publicKey = KeyHexToBin($publicKey); |
|
38 | + } |
|
39 | 39 | |
40 | - //create short hash |
|
41 | - $shortHash = substr(hash('sha256', $publicKey, 0, 32)); |
|
42 | - return $shortHash; |
|
40 | + //create short hash |
|
41 | + $shortHash = substr(hash('sha256', $publicKey, 0, 32)); |
|
42 | + return $shortHash; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | */ |
52 | 52 | function KeyHexToBin($keyHex) |
53 | 53 | { |
54 | - //delete prefix |
|
55 | - $keyTypeCheck = substr($keyHex, 0, 8); |
|
56 | - if ($keyTypeCheck == 'private:' || $keyTypeCheck == 'public:') { |
|
57 | - $keyHex = substr($keyHex, 8); |
|
58 | - } |
|
54 | + //delete prefix |
|
55 | + $keyTypeCheck = substr($keyHex, 0, 8); |
|
56 | + if ($keyTypeCheck == 'private:' || $keyTypeCheck == 'public:') { |
|
57 | + $keyHex = substr($keyHex, 8); |
|
58 | + } |
|
59 | 59 | |
60 | - //convert key |
|
61 | - $keyBin = hex2bin($keyHex); |
|
62 | - return $keyBin; |
|
60 | + //convert key |
|
61 | + $keyBin = hex2bin($keyHex); |
|
62 | + return $keyBin; |
|
63 | 63 | } |
@@ -12,10 +12,10 @@ |
||
12 | 12 | * @param string optional suffix (usually 'private:' or 'public:') (default: '') |
13 | 13 | * @return bool whether the key is valid (true) or not (false) |
14 | 14 | */ |
15 | -function KeyCheck($publicKey, $suffix='') |
|
15 | +function KeyCheck($publicKey, $suffix = '') |
|
16 | 16 | { |
17 | 17 | // RegExp: https://regex101.com/r/sU5tC8/1 |
18 | - return preg_match('/^(' . $suffix . ')?[[:alnum:]]{64}$/', $publicKey); |
|
18 | + return preg_match('/^('.$suffix.')?[[:alnum:]]{64}$/', $publicKey); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author rugk |
|
4 | - * @copyright Copyright (c) 2015 rugk |
|
5 | - * @license MIT |
|
6 | - */ |
|
3 | + * @author rugk |
|
4 | + * @copyright Copyright (c) 2015 rugk |
|
5 | + * @license MIT |
|
6 | + */ |
|
7 | 7 | |
8 | 8 | /* CONSTANTS */ |
9 | 9 | const FILENAME_CONNCRED = 'ConnectionCredentials.php'; |