UNPKG

she_decrypt

Version:

Pure JavaScript implementation for deciphering SHE arguments (M1, M2, etc)

495 lines (469 loc) 20.7 kB
#!/usr/bin/env node /**@FileInfo * * error.test.ts * * Tests for the she_decrypt script. This file contains the error tests for * testing the she_decrypt command behaviour. */ ((root) => { "use strict"; const FS = require('fs'); const SHE = require('../SHE_decrypt.js'); /** * TSDECErr001: * Error test for invalid M4 SHE message deciphered with default key * * $ ./bin/she_decrypt --cid --fid --channel --msg 0000000000000000000000000000001114c192927bf31676d3d63a2575b5f84e8a8be9da158e3711b4e602ba068af1fe4ae3eff29ec6c613cb03c4fd42680750 --m4 00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c666 */ test('TSDECErr001: Error test for invalid M4 deciphering SHE message) with CID/FID (long)', () => { const {spawnSync} = require('node:child_process'); const subproc = spawnSync( "node", [ "./bin/she_decrypt", "--cid", "--fid", "--channel", "--msg", "0000000000000000000000000000001114c192927bf31676d3d63a2575b5f84e8a8be9da158e3711b4e602ba068af1fe4ae3eff29ec6c613cb03c4fd42680750", "--m4", "00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c666" ], { stdio: [ 'ignore', 'pipe', 'pipe' ] } ); expect(subproc.status).toBe(0x01); expect(subproc.stdout.toString()).toBe("CID = 33554462 (0x200001e)\n"+ "FID = 0\n"+ "Kmaster: c85c499d7ed56116302371372834c3ae\n"+ "M4: \x1b[1;31mInvalid\x1b[m (00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665)\n"); expect(subproc.stderr.toString()).toBe(""); } ); /** * TSDECErr002: * Error test for invalid M4 SHE message deciphered with default key * * $ ./bin/she_decrypt -cfCm 0000000000000000000000000000001114c192927bf31676d3d63a2575b5f84e8a8be9da158e3711b4e602ba068af1fe4ae3eff29ec6c613cb03c4fd42680750 -4 00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c666 */ test('TSDECErr001: Error test for invalid M4 deciphering SHE message) with CID/FID (long)', () => { const {spawnSync} = require('node:child_process'); const subproc = spawnSync( "node", [ "./bin/she_decrypt", "-cfCm", "0000000000000000000000000000001114c192927bf31676d3d63a2575b5f84e8a8be9da158e3711b4e602ba068af1fe4ae3eff29ec6c613cb03c4fd42680750", "-4", "00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c666" ], { stdio: [ 'ignore', 'pipe', 'pipe' ] } ); expect(subproc.status).toBe(0x01); expect(subproc.stdout.toString()).toBe("CID = 33554462 (0x200001e)\n"+ "FID = 0\n"+ "Kmaster: c85c499d7ed56116302371372834c3ae\n"+ "M4: \x1b[1;31mInvalid\x1b[m (00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665)\n"); expect(subproc.stderr.toString()).toBe(""); } ); /** * TSDECErr003: * Error test for invalid M5 SHE message deciphered with default key * * $ ./bin/she_decrypt --cid --fid --channel --msg 0000000000000000000000000000001114c192927bf31676d3d63a2575b5f84e8a8be9da158e3711b4e602ba068af1fe4ae3eff29ec6c613cb03c4fd42680750 --m5 970c6d07e6ac7408bd0ffcaf71d6ffb2 */ test('TSDECErr001: Error test for invalid M4 deciphering SHE message) with CID/FID (long)', () => { const {spawnSync} = require('node:child_process'); const subproc = spawnSync( "node", [ "./bin/she_decrypt", "--cid", "--fid", "--channel", "--msg", "0000000000000000000000000000001114c192927bf31676d3d63a2575b5f84e8a8be9da158e3711b4e602ba068af1fe4ae3eff29ec6c613cb03c4fd42680750", "--m5", "970c6d07e6ac7408bd0ffcaf71d6ffb2" ], { stdio: [ 'ignore', 'pipe', 'pipe' ] } ); expect(subproc.status).toBe(0x01); expect(subproc.stdout.toString()).toBe("CID = 33554462 (0x200001e)\n"+ "FID = 0\n"+ "Kmaster: c85c499d7ed56116302371372834c3ae\n"+ "M5: \x1b[1;31mInvalid\x1b[m (970c6d07e6ac7408bd0ffcaf71d6ffb1)\n"); expect(subproc.stderr.toString()).toBe(""); } ); /** * TSDECErr004: * Error test for invalid M5 SHE message deciphered with default key * * $ ./bin/she_decrypt -cfCm 0000000000000000000000000000001114c192927bf31676d3d63a2575b5f84e8a8be9da158e3711b4e602ba068af1fe4ae3eff29ec6c613cb03c4fd42680750 -5 970c6d07e6ac7408bd0ffcaf71d6ffb2 */ test('TSDECErr004: Error test for invalid M5 deciphering SHE message) with CID/FID (long)', () => { const {spawnSync} = require('node:child_process'); const subproc = spawnSync( "node", [ "./bin/she_decrypt", "-cfCm", "0000000000000000000000000000001114c192927bf31676d3d63a2575b5f84e8a8be9da158e3711b4e602ba068af1fe4ae3eff29ec6c613cb03c4fd42680750", "-5", "970c6d07e6ac7408bd0ffcaf71d6ffb2" ], { stdio: [ 'ignore', 'pipe', 'pipe' ] } ); expect(subproc.status).toBe(0x01); expect(subproc.stdout.toString()).toBe("CID = 33554462 (0x200001e)\n"+ "FID = 0\n"+ "Kmaster: c85c499d7ed56116302371372834c3ae\n"+ "M5: \x1b[1;31mInvalid\x1b[m (970c6d07e6ac7408bd0ffcaf71d6ffb1)\n"); expect(subproc.stderr.toString()).toBe(""); } ); /** * TSDECErr005: * Error test for invalid M4/M5 SHE messages from msg2.txt deciphered with default key * * $ ./bin/she_decrypt --cid --fid --channel --msd-file tests/msg2.txt --m4 00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665 --m4 00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9 --m5 970c6d07e6ac7408bd0ffcaf71d6ffb1 --m5 45d3d4b4f8338051137d57af68d9d8f8 */ test('TSDECErr005: Error test for invalid M4/M5 deciphering SHE messages from msg2.txt) with CID/FID/Channel (long)', () => { const {spawnSync} = require('node:child_process'); const subproc = spawnSync( "node", [ "./bin/she_decrypt", "--cid", "--fid", "--channel", "--msg-file", "tests/msg2.txt", "--m4", "00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c666", "--m4", "00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9", "--m5", "970c6d07e6ac7408bd0ffcaf71d6ffb1", "--m5", "45d3d4b4f8338051137d57af68d9d8f8", ], { stdio: [ 'ignore', 'pipe', 'pipe' ] } ); expect(subproc.status).toBe(0x01); expect(subproc.stdout.toString()).toBe("CID = 33554462 (0x200001e)\n"+ "FID = 0\n"+ "Kmaster: c85c499d7ed56116302371372834c3ae\n"+ "M4: \x1b[1;31mInvalid\x1b[m (00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665)\n"+ "M5: \x1b[1;32mValid\x1b[m (970c6d07e6ac7408bd0ffcaf71d6ffb1)\n"+ "CID = 33554464 (0x2000020)\n"+ "FID = 2\n"+ "Channel = 1\n"+ "Kmac: 99900b0679387f91ea4db0119e07979a\n"+ "M4: \x1b[1;32mValid\x1b[m (00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9)\n"+ "M5: \x1b[1;32mValid\x1b[m (45d3d4b4f8338051137d57af68d9d8f8)\n"); expect(subproc.stderr.toString()).toBe(""); } ); /** * TSDECErr006: * Error test for invalid M4/M5 SHE messages from msg2.txt deciphered with default key * * $ ./bin/she_decrypt --cid --fid --channel --msd-file tests/msg2.txt --m4 00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665 --m4 00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9 --m5 970c6d07e6ac7408bd0ffcaf71d6ffb1 --m5 45d3d4b4f8338051137d57af68d9d8f8 */ test('TSDECErr006: Error test for invalid M4/M5 deciphering SHE messages from msg2.txt) with CID/FID/Channel (long)', () => { const {spawnSync} = require('node:child_process'); const subproc = spawnSync( "node", [ "./bin/she_decrypt", "--cid", "--fid", "--channel", "--msg-file", "tests/msg2.txt", "--m4", "00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665", "--m4", "00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616ba", "--m5", "970c6d07e6ac7408bd0ffcaf71d6ffb1", "--m5", "45d3d4b4f8338051137d57af68d9d8f8", ], { stdio: [ 'ignore', 'pipe', 'pipe' ] } ); expect(subproc.status).toBe(0x01); expect(subproc.stdout.toString()).toBe("CID = 33554462 (0x200001e)\n"+ "FID = 0\n"+ "Kmaster: c85c499d7ed56116302371372834c3ae\n"+ "M4: \x1b[1;32mValid\x1b[m (00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665)\n"+ "M5: \x1b[1;32mValid\x1b[m (970c6d07e6ac7408bd0ffcaf71d6ffb1)\n"+ "CID = 33554464 (0x2000020)\n"+ "FID = 2\n"+ "Channel = 1\n"+ "Kmac: 99900b0679387f91ea4db0119e07979a\n"+ "M4: \x1b[1;31mInvalid\x1b[m (00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9)\n"+ "M5: \x1b[1;32mValid\x1b[m (45d3d4b4f8338051137d57af68d9d8f8)\n"); expect(subproc.stderr.toString()).toBe(""); } ); /** * TSDECErr007: * Error test for invalid M4/M5 SHE messages from msg2.txt deciphered with default key * * $ ./bin/she_decrypt --cid --fid --channel --msd-file tests/msg2.txt --m4 00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665 --m4 00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9 --m5 970c6d07e6ac7408bd0ffcaf71d6ffb1 --m5 45d3d4b4f8338051137d57af68d9d8f8 */ test('TSDECErr007: Error test for invalid M4/M5 deciphering SHE messages from msg2.txt) with CID/FID/Channel (long)', () => { const {spawnSync} = require('node:child_process'); const subproc = spawnSync( "node", [ "./bin/she_decrypt", "--cid", "--fid", "--channel", "--msg-file", "tests/msg2.txt", "--m4", "00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665", "--m4", "00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9", "--m5", "970c6d07e6ac7408bd0ffcaf71d6ffb2", "--m5", "45d3d4b4f8338051137d57af68d9d8f8", ], { stdio: [ 'ignore', 'pipe', 'pipe' ] } ); expect(subproc.status).toBe(0x01); expect(subproc.stdout.toString()).toBe("CID = 33554462 (0x200001e)\n"+ "FID = 0\n"+ "Kmaster: c85c499d7ed56116302371372834c3ae\n"+ "M4: \x1b[1;32mValid\x1b[m (00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665)\n"+ "M5: \x1b[1;31mInvalid\x1b[m (970c6d07e6ac7408bd0ffcaf71d6ffb1)\n"+ "CID = 33554464 (0x2000020)\n"+ "FID = 2\n"+ "Channel = 1\n"+ "Kmac: 99900b0679387f91ea4db0119e07979a\n"+ "M4: \x1b[1;32mValid\x1b[m (00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9)\n"+ "M5: \x1b[1;32mValid\x1b[m (45d3d4b4f8338051137d57af68d9d8f8)\n"); expect(subproc.stderr.toString()).toBe(""); } ); /** * TSDECErr008: * Error test for invalid M4/M5 SHE messages from msg2.txt deciphered with default key * * $ ./bin/she_decrypt --cid --fid --channel --msd-file tests/msg2.txt --m4 00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665 --m4 00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9 --m5 970c6d07e6ac7408bd0ffcaf71d6ffb1 --m5 45d3d4b4f8338051137d57af68d9d8f8 */ test('TSDECErr008: Error test for invalid M4/M5 deciphering SHE messages from msg2.txt) with CID/FID/Channel (long)', () => { const {spawnSync} = require('node:child_process'); const subproc = spawnSync( "node", [ "./bin/she_decrypt", "--cid", "--fid", "--channel", "--msg-file", "tests/msg2.txt", "--m4", "00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665", "--m4", "00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9", "--m5", "970c6d07e6ac7408bd0ffcaf71d6ffb1", "--m5", "45d3d4b4f8338051137d57af68d9d8f9", ], { stdio: [ 'ignore', 'pipe', 'pipe' ] } ); expect(subproc.status).toBe(0x01); expect(subproc.stdout.toString()).toBe("CID = 33554462 (0x200001e)\n"+ "FID = 0\n"+ "Kmaster: c85c499d7ed56116302371372834c3ae\n"+ "M4: \x1b[1;32mValid\x1b[m (00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665)\n"+ "M5: \x1b[1;32mValid\x1b[m (970c6d07e6ac7408bd0ffcaf71d6ffb1)\n"+ "CID = 33554464 (0x2000020)\n"+ "FID = 2\n"+ "Channel = 1\n"+ "Kmac: 99900b0679387f91ea4db0119e07979a\n"+ "M4: \x1b[1;32mValid\x1b[m (00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9)\n"+ "M5: \x1b[1;31mInvalid\x1b[m (45d3d4b4f8338051137d57af68d9d8f8)\n"); expect(subproc.stderr.toString()).toBe(""); } ); /** * TSDECErr009: * Error test for invalid M4/M5 SHE messages from msg2.txt deciphered with default key * * $ ./bin/she_decrypt --cid --fid --channel --msd-file tests/msg2.txt --m4 00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665 --m4 00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9 --m5 970c6d07e6ac7408bd0ffcaf71d6ffb1 --m5 45d3d4b4f8338051137d57af68d9d8f8 */ test('TSDECErr009: Error test for invalid M4/M5 deciphering SHE messages from msg2.txt) with CID/FID/Channel (long)', () => { const {spawnSync} = require('node:child_process'); const subproc = spawnSync( "node", [ "./bin/she_decrypt", "--cid", "--fid", "--channel", "--msg-file", "tests/msg2.txt", "--m4", "00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665", "--m4", "00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616ba", "--m5", "970c6d07e6ac7408bd0ffcaf71d6ffb2", "--m5", "45d3d4b4f8338051137d57af68d9d8f8", ], { stdio: [ 'ignore', 'pipe', 'pipe' ] } ); expect(subproc.status).toBe(0x01); expect(subproc.stdout.toString()).toBe("CID = 33554462 (0x200001e)\n"+ "FID = 0\n"+ "Kmaster: c85c499d7ed56116302371372834c3ae\n"+ "M4: \x1b[1;32mValid\x1b[m (00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665)\n"+ "M5: \x1b[1;31mInvalid\x1b[m (970c6d07e6ac7408bd0ffcaf71d6ffb1)\n"+ "CID = 33554464 (0x2000020)\n"+ "FID = 2\n"+ "Channel = 1\n"+ "Kmac: 99900b0679387f91ea4db0119e07979a\n"+ "M4: \x1b[1;31mInvalid\x1b[m (00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9)\n"+ "M5: \x1b[1;32mValid\x1b[m (45d3d4b4f8338051137d57af68d9d8f8)\n"); expect(subproc.stderr.toString()).toBe(""); } ); /** * TSDECErr010: * Error test for invalid M4/M5 SHE messages from msg2.txt deciphered with default key * * $ ./bin/she_decrypt --cid --fid --channel --msd-file tests/msg2.txt --m4 00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665 --m4 00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9 --m5 970c6d07e6ac7408bd0ffcaf71d6ffb1 --m5 45d3d4b4f8338051137d57af68d9d8f8 */ test('TSDECErr010: Error test for invalid M4/M5 deciphering SHE messages from msg2.txt) with CID/FID/Channel (long)', () => { const {spawnSync} = require('node:child_process'); const subproc = spawnSync( "node", [ "./bin/she_decrypt", "--cid", "--fid", "--channel", "--msg-file", "tests/msg2.txt", "--m4", "00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c664", "--m4", "00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9", "--m5", "970c6d07e6ac7408bd0ffcaf71d6ffb1", "--m5", "45d3d4b4f8338051137d57af68d9d8f9", ], { stdio: [ 'ignore', 'pipe', 'pipe' ] } ); expect(subproc.status).toBe(0x01); expect(subproc.stdout.toString()).toBe("CID = 33554462 (0x200001e)\n"+ "FID = 0\n"+ "Kmaster: c85c499d7ed56116302371372834c3ae\n"+ "M4: \x1b[1;31mInvalid\x1b[m (00000000000000000000000000000011ef6e5504e37f5b686959e17b0563c665)\n"+ "M5: \x1b[1;32mValid\x1b[m (970c6d07e6ac7408bd0ffcaf71d6ffb1)\n"+ "CID = 33554464 (0x2000020)\n"+ "FID = 2\n"+ "Channel = 1\n"+ "Kmac: 99900b0679387f91ea4db0119e07979a\n"+ "M4: \x1b[1;32mValid\x1b[m (00000000000000000000000000000041a54c939fa273c1f8b452585ec7f616b9)\n"+ "M5: \x1b[1;31mInvalid\x1b[m (45d3d4b4f8338051137d57af68d9d8f8)\n"); expect(subproc.stderr.toString()).toBe(""); } ); })(this); /* * vim: et:ts=4:sw=4:sts=4 * -*- mode: JavaScript; coding: utf-8-unix; tab-width: 4 -*- */