Skip to content

Commit

Permalink
Env: PHP8 - add XMR sub test (for E2E XMR testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
dasgarner committed Apr 11, 2023
1 parent a4216d1 commit 4234aa8
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/XMDS.http
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ Content-Type: application/xml
<clientCode xsi:type="xsd:int">400</clientCode>
<macAddress xsi:type="xsd:string">{{macAddress}}</macAddress>
<licenceResult xsi:type="xsd:string">trial</licenceResult>
<xmrChannel xsi:type="xsd:string">XMR_test_channel</xmrChannel>
<xmrPubKey xsi:type="xsd:string">-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8tUH0MqtiB7Hq7a+Au0v
3MHFDnlwBmSz9S+44dGir0d119pbZQKb1D5JaGTWsBq0Ca4yAW/XtDwL5Olbue8n
y2PBygUArJulUQdCeguAKmHCcRw6rce0ZsQymUe84dclf9l7yyCbo1VTDBH651UT
a/ei6ATBPeLhh98lDKDpz/RmsXuW695thxhTRXPIILDDKYkK5yQF2DNEgVoShFjG
TRys5AL2ZUrGHrrT5dxOfbNE0sU8qvoYVQIjyUVhANzh66bu8QTbjDcRLMiKE1lJ
l5U/XOnNkKi+qNimFWRKlNS0sOvPdTJHHZZEaoFa2FXGYGL8/XAidwT6YSY702Gb
8wIDAQAB
-----END PUBLIC KEY-----</xmrPubKey>
</tns:RegisterDisplay>
</soap:Body>
</soap:Envelope>
Expand Down
74 changes: 74 additions & 0 deletions tests/Xmr/playerSub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/

// This is a simple XMR client which connects to the display added in XMDS.http
// performing actions in the CMS which affect the display should be logged here.

define('PROJECT_ROOT', realpath(__DIR__ . '/../..'));

require PROJECT_ROOT . '/vendor/autoload.php';

// RSA key
$fp = fopen(PROJECT_ROOT . '/library/certs/private.key', 'r');
$privateKey = openssl_get_privatekey(fread($fp, 8192));
fclose($fp);

// Sub
$loop = React\EventLoop\Factory::create();

$context = new React\ZMQ\Context($loop);

$sub = $context->getSocket(ZMQ::SOCKET_SUB);
$sub->connect('tcp://xmr:9505');
$sub->subscribe('H');
$sub->subscribe('XMR_test_channel');

$sub->on('messages', function ($msg) use ($privateKey) {
try {
if ($msg[0] == 'H') {
echo '[' . date('Y-m-d H:i:s') . '] Heartbeat...' . PHP_EOL;
return;
}

// Expect messages to have a length of 3
if (count($msg) != 3) {
throw new InvalidArgumentException('Incorrect Message Length');
}

// Message will be: channel, key, message
if ($msg[0] != 'XMR_test_channel') {
throw new InvalidArgumentException('Channel does not match');
}

// Decrypt
$output = null;
openssl_open(base64_decode($msg[2]), $output, base64_decode($msg[1]), $privateKey, 'RC4');

echo '[' . date('Y-m-d H:i:s') . '] Received: ' . $output . PHP_EOL;
} catch (InvalidArgumentException $e) {
echo '[' . date('Y-m-d H:i:s') . '] E: ' . $e->getMessage() . PHP_EOL;
}
});

$loop->run();

openssl_free_key($privateKey);

0 comments on commit 4234aa8

Please sign in to comment.