mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 18:57:07 -07:00
Add Regist Tests
This commit is contained in:
parent
2a20ac4246
commit
0694af09ad
12 changed files with 187 additions and 58 deletions
|
@ -12,7 +12,8 @@ add_executable(chiaki-unit
|
|||
reorderqueue.c
|
||||
fec.c
|
||||
test_log.c
|
||||
test_log.h)
|
||||
test_log.h
|
||||
regist.c)
|
||||
|
||||
target_link_libraries(chiaki-unit chiaki-lib munit)
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ extern MunitTest tests_rpcrypt[];
|
|||
extern MunitTest tests_gkcrypt[];
|
||||
extern MunitTest tests_takion[];
|
||||
extern MunitTest tests_fec[];
|
||||
extern MunitTest tests_regist[];
|
||||
|
||||
static MunitSuite suites[] = {
|
||||
{
|
||||
|
@ -75,6 +76,13 @@ static MunitSuite suites[] = {
|
|||
1,
|
||||
MUNIT_SUITE_OPTION_NONE
|
||||
},
|
||||
{
|
||||
"/regist",
|
||||
tests_regist,
|
||||
NULL,
|
||||
1,
|
||||
MUNIT_SUITE_OPTION_NONE
|
||||
},
|
||||
{ NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE }
|
||||
};
|
||||
|
||||
|
|
105
test/regist.c
Normal file
105
test/regist.c
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <munit.h>
|
||||
|
||||
#include <chiaki/rpcrypt.h>
|
||||
#include <chiaki/regist.h>
|
||||
|
||||
static const uint8_t ambassador[CHIAKI_RPCRYPT_KEY_SIZE] = { 0x13, 0x37, 0xde, 0xad, 0xbe, 0xef, 0xc0, 0xff, 0xee, 0x42, 0x63, 0x68, 0x69, 0x61, 0x6b, 0x69 };
|
||||
static const uint32_t pin = 13374201;
|
||||
static const char * const psn_id = "ChiakiNanami1337";
|
||||
|
||||
static MunitResult test_aeropause(const MunitParameter params[], void *user)
|
||||
{
|
||||
uint8_t expected[CHIAKI_RPCRYPT_KEY_SIZE] = { 0x0b, 0xe1, 0x2f, 0xbb, 0x4c, 0x7c, 0x99, 0x4a, 0x41, 0x1e, 0x2d, 0x4c, 0xa4, 0x19, 0xf4, 0x35 };
|
||||
uint8_t aeropause[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
chiaki_rpcrypt_aeropause(aeropause, ambassador);
|
||||
munit_assert_memory_equal(sizeof(expected), aeropause, expected);
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
static MunitResult test_pin_bright(const MunitParameter params[], void *user)
|
||||
{
|
||||
uint8_t expected[CHIAKI_RPCRYPT_KEY_SIZE] = { 0x3f, 0xd0, 0xd6, 0x4f, 0xdc, 0xbb, 0x3e, 0xcc, 0x50, 0xba, 0xed, 0xef, 0x97, 0x34, 0xc7, 0xc9 };
|
||||
ChiakiRPCrypt rpcrypt;
|
||||
chiaki_rpcrypt_init_regist(&rpcrypt, ambassador, pin);
|
||||
munit_assert_memory_equal(sizeof(expected), rpcrypt.bright, expected);
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
static MunitResult test_request_payload(const MunitParameter params[], void *user)
|
||||
{
|
||||
uint8_t expected[] = {
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x0b, 0xe1, 0x2f, 0xbb,
|
||||
0x4c, 0x7c, 0x99, 0x4a, 0x41, 0x1e, 0x2d, 0x4c, 0xa4, 0x19, 0xf4, 0x35, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
|
||||
0xf2, 0xfd, 0x4d, 0xdc, 0x86, 0x21, 0xda, 0x3d, 0x9f, 0x35, 0xf3, 0xdf, 0x82, 0x58, 0x65, 0x08, 0x6f, 0xb5, 0xee, 0xd1, 0x1e, 0xdd, 0xdd, 0xaa, 0x5a, 0xce, 0x28, 0xdf, 0x2f, 0x13, 0x9c, 0x0c,
|
||||
0x66, 0x6f, 0xec, 0x1c, 0x5d, 0xd1, 0x9f, 0x08, 0x15, 0xdd, 0x5c, 0x61, 0x57, 0xe6, 0xad, 0x69, 0x60, 0x12, 0x67, 0x2d, 0x4b, 0x64,
|
||||
};
|
||||
|
||||
ChiakiRPCrypt rpcrypt;
|
||||
chiaki_rpcrypt_init_regist(&rpcrypt, ambassador, pin);
|
||||
|
||||
uint8_t payload[0x400];
|
||||
size_t payload_size = sizeof(payload);
|
||||
ChiakiErrorCode err = chiaki_regist_request_payload_format(payload, &payload_size, &rpcrypt, psn_id);
|
||||
munit_assert_int(err, ==, CHIAKI_ERR_SUCCESS);
|
||||
munit_assert_size(payload_size, ==, sizeof(expected));
|
||||
munit_assert_memory_equal(sizeof(expected), payload, expected);
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
MunitTest tests_regist[] = {
|
||||
{
|
||||
"/aeropause",
|
||||
test_aeropause,
|
||||
NULL,
|
||||
NULL,
|
||||
MUNIT_TEST_OPTION_NONE,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
"/pin_bright",
|
||||
test_pin_bright,
|
||||
NULL,
|
||||
NULL,
|
||||
MUNIT_TEST_OPTION_NONE,
|
||||
NULL
|
||||
},
|
||||
{
|
||||
"/request_payload",
|
||||
test_request_payload,
|
||||
NULL,
|
||||
NULL,
|
||||
MUNIT_TEST_OPTION_NONE,
|
||||
NULL
|
||||
},
|
||||
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
|
||||
};
|
|
@ -29,12 +29,12 @@ static MunitResult test_bright_ambassador(const MunitParameter params[], void *u
|
|||
static const uint8_t bright_expected[] = { 0xa4, 0x4e, 0x2a, 0x16, 0x5e, 0x20, 0xd3, 0xf, 0xaa, 0x11, 0x8b, 0xc7, 0x7c, 0xa7, 0xdc, 0x11 };
|
||||
static const uint8_t ambassador_expected[] = { 0x1d, 0xa8, 0xb9, 0x1f, 0x6e, 0x26, 0x64, 0x2e, 0xbc, 0x8, 0x8b, 0x0, 0x4f, 0x1, 0x5b, 0x52 };
|
||||
|
||||
uint8_t bright[CHIAKI_KEY_BYTES];
|
||||
uint8_t ambassador[CHIAKI_KEY_BYTES];
|
||||
uint8_t bright[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
uint8_t ambassador[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
chiaki_rpcrypt_bright_ambassador(bright, ambassador, nonce, morning);
|
||||
|
||||
munit_assert_memory_equal(CHIAKI_KEY_BYTES, bright, bright_expected);
|
||||
munit_assert_memory_equal(CHIAKI_KEY_BYTES, ambassador, ambassador_expected);
|
||||
munit_assert_memory_equal(CHIAKI_RPCRYPT_KEY_SIZE, bright, bright_expected);
|
||||
munit_assert_memory_equal(CHIAKI_RPCRYPT_KEY_SIZE, ambassador, ambassador_expected);
|
||||
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
@ -49,27 +49,27 @@ static MunitResult test_iv(const MunitParameter params[], void *user)
|
|||
|
||||
chiaki_rpcrypt_init_auth(&rpcrypt, nonce, morning);
|
||||
|
||||
uint8_t iv[CHIAKI_KEY_BYTES];
|
||||
uint8_t iv[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
|
||||
err = chiaki_rpcrypt_generate_iv(&rpcrypt, iv, 0);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return MUNIT_ERROR;
|
||||
munit_assert_memory_equal(CHIAKI_KEY_BYTES, iv, iv_a_expected);
|
||||
munit_assert_memory_equal(CHIAKI_RPCRYPT_KEY_SIZE, iv, iv_a_expected);
|
||||
|
||||
err = chiaki_rpcrypt_generate_iv(&rpcrypt, iv, 0);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return MUNIT_ERROR;
|
||||
munit_assert_memory_equal(CHIAKI_KEY_BYTES, iv, iv_a_expected);
|
||||
munit_assert_memory_equal(CHIAKI_RPCRYPT_KEY_SIZE, iv, iv_a_expected);
|
||||
|
||||
err = chiaki_rpcrypt_generate_iv(&rpcrypt, iv, 0x0102030405060708);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return MUNIT_ERROR;
|
||||
munit_assert_memory_equal(CHIAKI_KEY_BYTES, iv, iv_b_expected);
|
||||
munit_assert_memory_equal(CHIAKI_RPCRYPT_KEY_SIZE, iv, iv_b_expected);
|
||||
|
||||
err = chiaki_rpcrypt_generate_iv(&rpcrypt, iv, 0x0102030405060708);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return MUNIT_ERROR;
|
||||
munit_assert_memory_equal(CHIAKI_KEY_BYTES, iv, iv_b_expected);
|
||||
munit_assert_memory_equal(CHIAKI_RPCRYPT_KEY_SIZE, iv, iv_b_expected);
|
||||
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue