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
|
@ -81,8 +81,8 @@ void RegistDialog::ValidateInput()
|
|||
void RegistDialog::accept()
|
||||
{
|
||||
ChiakiRegistInfo info = {};
|
||||
QByteArray psn_id = psn_id_edit->text().toUtf8();
|
||||
QByteArray host = host_edit->text().toUtf8();
|
||||
QByteArray psn_id = psn_id_edit->text().trimmed().toUtf8();
|
||||
QByteArray host = host_edit->text().trimmed().toUtf8();
|
||||
info.psn_id = psn_id.data();
|
||||
info.host = host.data();
|
||||
info.pin = (uint32_t)pin_edit->text().toULong();
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "log.h"
|
||||
#include "thread.h"
|
||||
#include "stoppipe.h"
|
||||
#include "rpcrypt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -62,6 +63,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_start(ChiakiRegist *regist, ChiakiLo
|
|||
CHIAKI_EXPORT void chiaki_regist_fini(ChiakiRegist *regist);
|
||||
CHIAKI_EXPORT void chiaki_regist_stop(ChiakiRegist *regist);
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_request_payload_format(uint8_t *buf, size_t *buf_size, ChiakiRPCrypt *crypt, const char *psn_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -27,19 +27,19 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CHIAKI_KEY_BYTES 0x10
|
||||
#define CHIAKI_RPCRYPT_KEY_SIZE 0x10
|
||||
|
||||
typedef struct chiaki_rpcrypt_t
|
||||
{
|
||||
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];
|
||||
} ChiakiRPCrypt;
|
||||
|
||||
CHIAKI_EXPORT void chiaki_rpcrypt_bright_ambassador(uint8_t *bright, uint8_t *ambassador, const uint8_t *nonce, const uint8_t *morning);
|
||||
CHIAKI_EXPORT void chiaki_rpcrypt_aeropause(uint8_t *aeropause, const uint8_t *nonce);
|
||||
CHIAKI_EXPORT void chiaki_rpcrypt_aeropause(uint8_t *aeropause, const uint8_t *ambassador);
|
||||
|
||||
CHIAKI_EXPORT void chiaki_rpcrypt_init_auth(ChiakiRPCrypt *rpcrypt, const uint8_t *nonce, const uint8_t *morning);
|
||||
CHIAKI_EXPORT void chiaki_rpcrypt_init_regist(ChiakiRPCrypt *rpcrypt, const uint8_t *nonce, uint32_t pin);
|
||||
CHIAKI_EXPORT void chiaki_rpcrypt_init_regist(ChiakiRPCrypt *rpcrypt, const uint8_t *ambassador, uint32_t pin);
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_rpcrypt_generate_iv(ChiakiRPCrypt *rpcrypt, uint8_t *iv, uint64_t counter);
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_rpcrypt_encrypt(ChiakiRPCrypt *rpcrypt, uint64_t counter, uint8_t *in, uint8_t *out, size_t sz);
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_rpcrypt_decrypt(ChiakiRPCrypt *rpcrypt, uint64_t counter, uint8_t *in, uint8_t *out, size_t sz);
|
||||
|
|
|
@ -137,13 +137,13 @@ typedef struct chiaki_session_t
|
|||
char hostname[128];
|
||||
char *regist_key;
|
||||
char *ostype;
|
||||
char auth[CHIAKI_KEY_BYTES];
|
||||
uint8_t morning[CHIAKI_KEY_BYTES];
|
||||
char auth[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
uint8_t morning[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
uint8_t did[CHIAKI_RP_DID_SIZE];
|
||||
ChiakiConnectVideoProfile video_profile;
|
||||
} connect_info;
|
||||
|
||||
uint8_t nonce[CHIAKI_KEY_BYTES];
|
||||
uint8_t nonce[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
ChiakiRPCrypt rpcrypt;
|
||||
char session_id[CHIAKI_SESSION_ID_SIZE_MAX]; // zero-terminated
|
||||
uint8_t handshake_key[CHIAKI_HANDSHAKE_KEY_SIZE];
|
||||
|
|
|
@ -341,11 +341,11 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
|
|||
CHIAKI_LOGI(session->log, "Connected to %s:%d", session->connect_info.hostname, SESSION_CTRL_PORT);
|
||||
|
||||
|
||||
uint8_t auth_enc[CHIAKI_KEY_BYTES];
|
||||
ChiakiErrorCode err = chiaki_rpcrypt_encrypt(&session->rpcrypt, 0, (uint8_t *)session->connect_info.auth, auth_enc, CHIAKI_KEY_BYTES);
|
||||
uint8_t auth_enc[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
ChiakiErrorCode err = chiaki_rpcrypt_encrypt(&session->rpcrypt, 0, (uint8_t *)session->connect_info.auth, auth_enc, CHIAKI_RPCRYPT_KEY_SIZE);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
goto error;
|
||||
char auth_b64[CHIAKI_KEY_BYTES*2];
|
||||
char auth_b64[CHIAKI_RPCRYPT_KEY_SIZE*2];
|
||||
err = chiaki_base64_encode(auth_enc, sizeof(auth_enc), auth_b64, sizeof(auth_b64));
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
goto error;
|
||||
|
|
|
@ -93,14 +93,30 @@ static const char * const request_fmt =
|
|||
|
||||
static const char * const request_inner_fmt =
|
||||
"Client-Type: Windows\r\n"
|
||||
"Np-Online-Id: %s\r\n\r\n";
|
||||
"Np-Online-Id: %s\r\n";
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_regist_request_payload_format(uint8_t *buf, size_t *buf_size, ChiakiRPCrypt *crypt, const char *psn_id)
|
||||
{
|
||||
size_t buf_size_val = *buf_size;
|
||||
static const size_t inner_header_off = 0x1e0;
|
||||
if(buf_size_val < inner_header_off)
|
||||
return CHIAKI_ERR_BUF_TOO_SMALL;
|
||||
memset(buf, 'A', inner_header_off);
|
||||
chiaki_rpcrypt_aeropause(buf + 0x11c, crypt->ambassador);
|
||||
int inner_header_size = snprintf((char *)buf + inner_header_off, buf_size_val - inner_header_off, request_inner_fmt, psn_id);
|
||||
if(inner_header_size < 0 || inner_header_size >= buf_size_val - inner_header_off)
|
||||
return CHIAKI_ERR_BUF_TOO_SMALL;
|
||||
ChiakiErrorCode err = chiaki_rpcrypt_encrypt(crypt, 0, buf + inner_header_off, buf + inner_header_off, inner_header_size);
|
||||
*buf_size = inner_header_off + inner_header_size;
|
||||
return err;
|
||||
}
|
||||
|
||||
static void *regist_thread_func(void *user)
|
||||
{
|
||||
ChiakiRegist *regist = user;
|
||||
|
||||
uint8_t nonce[CHIAKI_KEY_BYTES];
|
||||
ChiakiErrorCode err = chiaki_random_bytes_crypt(nonce, sizeof(nonce));
|
||||
uint8_t ambassador[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
ChiakiErrorCode err = chiaki_random_bytes_crypt(ambassador, sizeof(ambassador));
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(regist->log, "Regist failed to generate random nonce");
|
||||
|
@ -108,20 +124,16 @@ static void *regist_thread_func(void *user)
|
|||
}
|
||||
|
||||
ChiakiRPCrypt crypt;
|
||||
chiaki_rpcrypt_init_regist(&crypt, nonce, regist->info.pin);
|
||||
chiaki_rpcrypt_init_regist(&crypt, ambassador, regist->info.pin);
|
||||
|
||||
uint8_t payload[0x400];
|
||||
static const size_t inner_header_off = 0x1e0;
|
||||
memset(payload, 'A', inner_header_off);
|
||||
chiaki_rpcrypt_aeropause(payload + 0x11c, nonce);
|
||||
int inner_header_size = snprintf((char *)payload + inner_header_off, sizeof(payload) - inner_header_off, request_inner_fmt, regist->info.psn_id);
|
||||
if(inner_header_size >= sizeof(payload) - inner_header_off)
|
||||
size_t payload_size = sizeof(payload);
|
||||
err = chiaki_regist_request_payload_format(payload, &payload_size, &crypt, regist->info.psn_id);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(regist->log, "Regist failed to format payload");
|
||||
goto fail;
|
||||
}
|
||||
chiaki_rpcrypt_encrypt(&crypt, 0, payload + inner_header_off, payload + inner_header_off, inner_header_size);
|
||||
size_t payload_size = inner_header_off + inner_header_size;
|
||||
|
||||
char request_header[0x100];
|
||||
int request_header_size = snprintf(request_header, sizeof(request_header), request_fmt, (unsigned long long)payload_size);
|
||||
|
|
|
@ -29,7 +29,7 @@ CHIAKI_EXPORT void chiaki_rpcrypt_bright_ambassador(uint8_t *bright, uint8_t *am
|
|||
{
|
||||
static const uint8_t echo_a[] = { 0x01, 0x49, 0x87, 0x9b, 0x65, 0x39, 0x8b, 0x39, 0x4b, 0x3a, 0x8d, 0x48, 0xc3, 0x0a, 0xef, 0x51 };
|
||||
|
||||
for(uint8_t i=0; i<CHIAKI_KEY_BYTES; i++)
|
||||
for(uint8_t i=0; i<CHIAKI_RPCRYPT_KEY_SIZE; i++)
|
||||
{
|
||||
uint8_t v = nonce[i];
|
||||
v -= i;
|
||||
|
@ -38,7 +38,7 @@ CHIAKI_EXPORT void chiaki_rpcrypt_bright_ambassador(uint8_t *bright, uint8_t *am
|
|||
ambassador[i] = v;
|
||||
}
|
||||
|
||||
for(uint8_t i=0; i<CHIAKI_KEY_BYTES; i++)
|
||||
for(uint8_t i=0; i<CHIAKI_RPCRYPT_KEY_SIZE; i++)
|
||||
{
|
||||
uint8_t v = morning[i];
|
||||
v -= i;
|
||||
|
@ -49,11 +49,11 @@ CHIAKI_EXPORT void chiaki_rpcrypt_bright_ambassador(uint8_t *bright, uint8_t *am
|
|||
}
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT void chiaki_rpcrypt_aeropause(uint8_t *aeropause, const uint8_t *nonce)
|
||||
CHIAKI_EXPORT void chiaki_rpcrypt_aeropause(uint8_t *aeropause, const uint8_t *ambassador)
|
||||
{
|
||||
for(size_t i=0; i<CHIAKI_KEY_BYTES; i++)
|
||||
for(size_t i=0; i<CHIAKI_RPCRYPT_KEY_SIZE; i++)
|
||||
{
|
||||
uint8_t v = nonce[i];
|
||||
uint8_t v = ambassador[i];
|
||||
v -= i;
|
||||
v -= 0x29;
|
||||
v ^= echo_b[i];
|
||||
|
@ -66,10 +66,10 @@ CHIAKI_EXPORT void chiaki_rpcrypt_init_auth(ChiakiRPCrypt *rpcrypt, const uint8_
|
|||
chiaki_rpcrypt_bright_ambassador(rpcrypt->bright, rpcrypt->ambassador, nonce, morning);
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT void chiaki_rpcrypt_init_regist(ChiakiRPCrypt *rpcrypt, const uint8_t *nonce, uint32_t pin)
|
||||
CHIAKI_EXPORT void chiaki_rpcrypt_init_regist(ChiakiRPCrypt *rpcrypt, const uint8_t *ambassador, uint32_t pin)
|
||||
{
|
||||
static const uint8_t regist_aes_key[CHIAKI_KEY_BYTES] = { 0x3f, 0x1c, 0xc4, 0xb6, 0xdc, 0xbb, 0x3e, 0xcc, 0x50, 0xba, 0xed, 0xef, 0x97, 0x34, 0xc7, 0xc9 };
|
||||
memcpy(rpcrypt->ambassador, nonce, sizeof(rpcrypt->ambassador));
|
||||
static const uint8_t regist_aes_key[CHIAKI_RPCRYPT_KEY_SIZE] = { 0x3f, 0x1c, 0xc4, 0xb6, 0xdc, 0xbb, 0x3e, 0xcc, 0x50, 0xba, 0xed, 0xef, 0x97, 0x34, 0xc7, 0xc9 };
|
||||
memcpy(rpcrypt->ambassador, ambassador, sizeof(rpcrypt->ambassador));
|
||||
memcpy(rpcrypt->bright, regist_aes_key, sizeof(rpcrypt->bright));
|
||||
rpcrypt->bright[0] ^= (uint8_t)((pin >> 0x18) & 0xff);
|
||||
rpcrypt->bright[1] ^= (uint8_t)((pin >> 0x10) & 0xff);
|
||||
|
@ -81,26 +81,26 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_rpcrypt_generate_iv(ChiakiRPCrypt *rpcrypt,
|
|||
{
|
||||
uint8_t hmac_key[] = { 0xac, 0x07, 0x88, 0x83, 0xc8, 0x3a, 0x1f, 0xe8, 0x11, 0x46, 0x3a, 0xf3, 0x9e, 0xe3, 0xe3, 0x77 };
|
||||
|
||||
uint8_t buf[CHIAKI_KEY_BYTES + 8];
|
||||
memcpy(buf, rpcrypt->ambassador, CHIAKI_KEY_BYTES);
|
||||
buf[CHIAKI_KEY_BYTES + 0] = (uint8_t)((counter >> 0x38) & 0xff);
|
||||
buf[CHIAKI_KEY_BYTES + 1] = (uint8_t)((counter >> 0x30) & 0xff);
|
||||
buf[CHIAKI_KEY_BYTES + 2] = (uint8_t)((counter >> 0x28) & 0xff);
|
||||
buf[CHIAKI_KEY_BYTES + 3] = (uint8_t)((counter >> 0x20) & 0xff);
|
||||
buf[CHIAKI_KEY_BYTES + 4] = (uint8_t)((counter >> 0x18) & 0xff);
|
||||
buf[CHIAKI_KEY_BYTES + 5] = (uint8_t)((counter >> 0x10) & 0xff);
|
||||
buf[CHIAKI_KEY_BYTES + 6] = (uint8_t)((counter >> 0x08) & 0xff);
|
||||
buf[CHIAKI_KEY_BYTES + 7] = (uint8_t)((counter >> 0x00) & 0xff);
|
||||
uint8_t buf[CHIAKI_RPCRYPT_KEY_SIZE + 8];
|
||||
memcpy(buf, rpcrypt->ambassador, CHIAKI_RPCRYPT_KEY_SIZE);
|
||||
buf[CHIAKI_RPCRYPT_KEY_SIZE + 0] = (uint8_t)((counter >> 0x38) & 0xff);
|
||||
buf[CHIAKI_RPCRYPT_KEY_SIZE + 1] = (uint8_t)((counter >> 0x30) & 0xff);
|
||||
buf[CHIAKI_RPCRYPT_KEY_SIZE + 2] = (uint8_t)((counter >> 0x28) & 0xff);
|
||||
buf[CHIAKI_RPCRYPT_KEY_SIZE + 3] = (uint8_t)((counter >> 0x20) & 0xff);
|
||||
buf[CHIAKI_RPCRYPT_KEY_SIZE + 4] = (uint8_t)((counter >> 0x18) & 0xff);
|
||||
buf[CHIAKI_RPCRYPT_KEY_SIZE + 5] = (uint8_t)((counter >> 0x10) & 0xff);
|
||||
buf[CHIAKI_RPCRYPT_KEY_SIZE + 6] = (uint8_t)((counter >> 0x08) & 0xff);
|
||||
buf[CHIAKI_RPCRYPT_KEY_SIZE + 7] = (uint8_t)((counter >> 0x00) & 0xff);
|
||||
|
||||
uint8_t hmac[32];
|
||||
unsigned int hmac_len = 0;
|
||||
if(!HMAC(EVP_sha256(), hmac_key, CHIAKI_KEY_BYTES, buf, sizeof(buf), hmac, &hmac_len))
|
||||
if(!HMAC(EVP_sha256(), hmac_key, CHIAKI_RPCRYPT_KEY_SIZE, buf, sizeof(buf), hmac, &hmac_len))
|
||||
return CHIAKI_ERR_UNKNOWN;
|
||||
|
||||
if(hmac_len < CHIAKI_KEY_BYTES)
|
||||
if(hmac_len < CHIAKI_RPCRYPT_KEY_SIZE)
|
||||
return CHIAKI_ERR_UNKNOWN;
|
||||
|
||||
memcpy(iv, hmac, CHIAKI_KEY_BYTES);
|
||||
memcpy(iv, hmac, CHIAKI_RPCRYPT_KEY_SIZE);
|
||||
return CHIAKI_ERR_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ static ChiakiErrorCode chiaki_rpcrypt_crypt(ChiakiRPCrypt *rpcrypt, uint64_t cou
|
|||
if(!ctx)
|
||||
return CHIAKI_ERR_UNKNOWN;
|
||||
|
||||
uint8_t iv[CHIAKI_KEY_BYTES];
|
||||
uint8_t iv[CHIAKI_RPCRYPT_KEY_SIZE];
|
||||
ChiakiErrorCode err = chiaki_rpcrypt_generate_iv(rpcrypt, iv, counter);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
return err;
|
||||
|
|
|
@ -584,9 +584,9 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
|
||||
if(response.success)
|
||||
{
|
||||
size_t nonce_len = CHIAKI_KEY_BYTES;
|
||||
size_t nonce_len = CHIAKI_RPCRYPT_KEY_SIZE;
|
||||
err = chiaki_base64_decode(response.nonce, strlen(response.nonce), session->nonce, &nonce_len);
|
||||
if(err != CHIAKI_ERR_SUCCESS || nonce_len != CHIAKI_KEY_BYTES)
|
||||
if(err != CHIAKI_ERR_SUCCESS || nonce_len != CHIAKI_RPCRYPT_KEY_SIZE)
|
||||
{
|
||||
CHIAKI_LOGE(session->log, "Nonce invalid");
|
||||
response.success = false;
|
||||
|
|
|
@ -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