diff --git a/tests/XMDS.http b/tests/XMDS.http index fd906e970d..4a6208d8cc 100644 --- a/tests/XMDS.http +++ b/tests/XMDS.http @@ -16,6 +16,16 @@ Content-Type: application/xml 400 {{macAddress}} trial + XMR_test_channel + -----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8tUH0MqtiB7Hq7a+Au0v +3MHFDnlwBmSz9S+44dGir0d119pbZQKb1D5JaGTWsBq0Ca4yAW/XtDwL5Olbue8n +y2PBygUArJulUQdCeguAKmHCcRw6rce0ZsQymUe84dclf9l7yyCbo1VTDBH651UT +a/ei6ATBPeLhh98lDKDpz/RmsXuW695thxhTRXPIILDDKYkK5yQF2DNEgVoShFjG +TRys5AL2ZUrGHrrT5dxOfbNE0sU8qvoYVQIjyUVhANzh66bu8QTbjDcRLMiKE1lJ +l5U/XOnNkKi+qNimFWRKlNS0sOvPdTJHHZZEaoFa2FXGYGL8/XAidwT6YSY702Gb +8wIDAQAB +-----END PUBLIC KEY----- diff --git a/tests/Xmr/playerSub.php b/tests/Xmr/playerSub.php new file mode 100644 index 0000000000..d29b939543 --- /dev/null +++ b/tests/Xmr/playerSub.php @@ -0,0 +1,74 @@ +. + */ + +// 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); \ No newline at end of file