Skip to content

Commit a4998d7

Browse files
author
Jamie C. Driver
committed
messaging: reduce the fixed output buffer in 'reject_message()'
Remove the unused 'data' parameter from the call, and reduce the cbor serialisation buffer size from 'MAX_STANDARD_OUTPUT_MSG_SIZE' to 256 bytes.
1 parent f399876 commit a4998d7

40 files changed

+212
-241
lines changed

main/process.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,12 +600,11 @@ void jade_process_reject_message_ex(const cbor_msg_t ctx, int code, const char*
600600
written > 0 ? id : "00", code, message, data, datalen, buffer, buffer_len, ctx.source);
601601
}
602602

603-
void jade_process_reject_message(jade_process_t* process, int code, const char* message, const char* data)
603+
void jade_process_reject_message(jade_process_t* process, int code, const char* message)
604604
{
605605
if (HAS_CURRENT_MESSAGE(process)) {
606-
uint8_t buf[MAX_STANDARD_OUTPUT_MSG_SIZE];
607-
jade_process_reject_message_ex(
608-
process->ctx, code, message, (const uint8_t*)data, data ? strlen(data) : 0, buf, sizeof(buf));
606+
uint8_t buf[256];
607+
jade_process_reject_message_ex(process->ctx, code, message, NULL, 0, buf, sizeof(buf));
609608
} else {
610609
JADE_LOGW("Ignoring attempt to reject 'no-message'");
611610
}

main/process.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void jade_process_reply_to_message_result(
100100
void jade_process_reply_to_message_ok(jade_process_t* process);
101101
void jade_process_reply_to_message_fail(jade_process_t* process);
102102
void jade_process_reply_to_message_ex(jade_msg_source_t source, const uint8_t* reply_payload, size_t payload_len);
103-
void jade_process_reject_message(jade_process_t* process, int code, const char* message, const char* data);
103+
void jade_process_reject_message(jade_process_t* process, int code, const char* message);
104104
void jade_process_reject_message_with_id(const char* id, int code, const char* message, const uint8_t* data,
105105
size_t datalen, uint8_t* buffer, size_t buffer_len, jade_msg_source_t source);
106106
void jade_process_reject_message_ex(cbor_msg_t ctx, int code, const char* message, const uint8_t* data, size_t datalen,

main/process/auth_user.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void check_wallet_erase_pin(jade_process_t* process, const uint8_t* pin_e
4242
keychain_persist_key_flags();
4343

4444
// Show/return 'Internal Error' message, and shut-down
45-
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "Internal Error", NULL);
45+
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "Internal Error");
4646

4747
const char* message[] = { "Internal Error!" };
4848
await_error_activity(message, 1);
@@ -92,7 +92,7 @@ static bool get_pin_get_aeskey(jade_process_t* process, const char* title, uint8
9292
#ifndef CONFIG_DEBUG_UNATTENDED_CI
9393
if (!run_pin_entry_loop(&pin_insert)) {
9494
// User abandoned entering pin
95-
jade_process_reject_message(process, CBOR_RPC_USER_CANCELLED, "User abandonded pin entry", NULL);
95+
jade_process_reject_message(process, CBOR_RPC_USER_CANCELLED, "User abandonded pin entry");
9696
SENSITIVE_POP(&pin_insert);
9797
return false;
9898
}
@@ -139,7 +139,7 @@ static bool set_pin_get_aeskey(jade_process_t* process, const char* title, uint8
139139
#ifndef CONFIG_DEBUG_UNATTENDED_CI
140140
if (!run_pin_entry_loop(&pin_insert)) {
141141
// User abandoned setting new pin
142-
jade_process_reject_message(process, CBOR_RPC_USER_CANCELLED, "User abandoned setting new PIN", NULL);
142+
jade_process_reject_message(process, CBOR_RPC_USER_CANCELLED, "User abandoned setting new PIN");
143143
SENSITIVE_POP(&pin_insert);
144144
return false;
145145
}
@@ -174,7 +174,7 @@ static bool set_pin_get_aeskey(jade_process_t* process, const char* title, uint8
174174
const char* message[] = { "Pin mismatch,", "please try again." };
175175
if (!await_continueback_activity(NULL, message, 2, true, NULL)) {
176176
// Abandon setting new pin
177-
jade_process_reject_message(process, CBOR_RPC_USER_CANCELLED, "User abandoned setting new PIN", NULL);
177+
jade_process_reject_message(process, CBOR_RPC_USER_CANCELLED, "User abandoned setting new PIN");
178178
SENSITIVE_POP(&pin_insert);
179179
return false;
180180
}
@@ -243,7 +243,7 @@ static bool get_pin_load_keys(jade_process_t* process, const bool suppress_pin_c
243243
if (!keychain_complete_derivation_with_passphrase(passphrase)) {
244244
SENSITIVE_POP(passphrase);
245245
JADE_LOGE("Failed to derive wallet");
246-
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "Failed to derive wallet", NULL);
246+
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "Failed to derive wallet");
247247

248248
const char* message[] = { "Failed to derive wallet" };
249249
await_error_activity(message, 1);
@@ -320,7 +320,7 @@ static bool set_pin_save_keys(jade_process_t* process)
320320
if (!keychain_store(aeskey, sizeof(aeskey))) {
321321
JADE_LOGE("Failed to store key data encrypted in flash memory!");
322322
jade_process_reject_message(
323-
process, CBOR_RPC_INTERNAL_ERROR, "Failed to store key data encrypted in flash memory", NULL);
323+
process, CBOR_RPC_INTERNAL_ERROR, "Failed to store key data encrypted in flash memory");
324324

325325
const char* message[] = { "Failed to persist key data" };
326326
await_error_activity(message, 1);
@@ -358,7 +358,7 @@ void auth_user_process(void* process_ptr)
358358
const char* errmsg = NULL;
359359
const int errcode = params_set_epoch_time(&params, &errmsg);
360360
if (errcode) {
361-
jade_process_reject_message(process, errcode, errmsg, NULL);
361+
jade_process_reject_message(process, errcode, errmsg);
362362
goto cleanup;
363363
}
364364
}
@@ -399,7 +399,7 @@ void auth_user_process(void* process_ptr)
399399
// Reject the message as hw locked
400400
JADE_LOGI("Trying to reuse temporary keychain with different message-source");
401401
jade_process_reject_message(process, CBOR_RPC_HW_LOCKED,
402-
"Cannot process message - temporary wallet associated with different connection", NULL);
402+
"Cannot process message - temporary wallet associated with different connection");
403403
}
404404
} else if (keychain_has_pin()) {
405405
// Jade is initialised with persisted wallet - if required use PIN to unlock

main/process/dashboard.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static void process_add_entropy_request(jade_process_t* process)
389389

390390
if (!written) {
391391
jade_process_reject_message(
392-
process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract valid entropy bytes from parameters", NULL);
392+
process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract valid entropy bytes from parameters");
393393
goto cleanup;
394394
}
395395

@@ -410,7 +410,7 @@ static void process_set_epoch_request(jade_process_t* process)
410410
const char* errmsg = NULL;
411411
const int errcode = params_set_epoch_time(&params, &errmsg);
412412
if (errcode) {
413-
jade_process_reject_message(process, errcode, errmsg, NULL);
413+
jade_process_reject_message(process, errcode, errmsg);
414414
goto cleanup;
415415
}
416416

@@ -497,8 +497,7 @@ static void dispatch_message(jade_process_t* process)
497497
task_function = ota_process;
498498
} else {
499499
// Reject the message as hw locked
500-
jade_process_reject_message(
501-
process, CBOR_RPC_HW_LOCKED, "OTA is only allowed on new or logged-in device.", NULL);
500+
jade_process_reject_message(process, CBOR_RPC_HW_LOCKED, "OTA is only allowed on new or logged-in device.");
502501
}
503502
} else if (IS_METHOD("ota_delta")) {
504503
if (ota_allowed(process->ctx.source)) {
@@ -509,7 +508,7 @@ static void dispatch_message(jade_process_t* process)
509508
} else {
510509
// Reject the message as hw locked
511510
jade_process_reject_message(
512-
process, CBOR_RPC_HW_LOCKED, "OTA delta is only allowed on new or logged-in device.", NULL);
511+
process, CBOR_RPC_HW_LOCKED, "OTA delta is only allowed on new or logged-in device.");
513512
}
514513
#ifdef CONFIG_DEBUG_MODE
515514
} else if (IS_METHOD("debug_selfcheck")) {
@@ -523,7 +522,7 @@ static void dispatch_message(jade_process_t* process)
523522
jade_process_reply_to_message_result(
524523
process->ctx, buf, sizeof(buf), &elapsed_time_ms, cbor_result_uint64_cb);
525524
} else {
526-
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "ERROR", NULL);
525+
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "ERROR");
527526
}
528527
} else if (IS_METHOD("debug_clean_reset")) {
529528
task_function = debug_clean_reset_process;
@@ -549,7 +548,7 @@ static void dispatch_message(jade_process_t* process)
549548
if (!KEYCHAIN_UNLOCKED_BY_MESSAGE_SOURCE(process)) {
550549
// Reject the message as hw locked
551550
jade_process_reject_message(
552-
process, CBOR_RPC_HW_LOCKED, "Cannot process message - hardware locked or uninitialized", NULL);
551+
process, CBOR_RPC_HW_LOCKED, "Cannot process message - hardware locked or uninitialized");
553552
} else if (IS_METHOD("register_otp")) {
554553
task_function = register_otp_process;
555554
} else if (IS_METHOD("get_otp_code")) {
@@ -601,10 +600,10 @@ static void dispatch_message(jade_process_t* process)
601600
} else if (IS_METHOD("ota_data") || IS_METHOD("ota_complete") || IS_METHOD("tx_input")
602601
|| IS_METHOD("get_extended_data") || IS_METHOD("get_signature") || IS_METHOD("pin")) {
603602
// Method we only expect as part of a multi-message protocol
604-
jade_process_reject_message(process, CBOR_RPC_PROTOCOL_ERROR, "Unexpected method", NULL);
603+
jade_process_reject_message(process, CBOR_RPC_PROTOCOL_ERROR, "Unexpected method");
605604
} else {
606605
// Reject the message as unknown, and free message
607-
jade_process_reject_message(process, CBOR_RPC_UNKNOWN_METHOD, "Unknown method", NULL);
606+
jade_process_reject_message(process, CBOR_RPC_UNKNOWN_METHOD, "Unknown method");
608607
}
609608
}
610609

main/process/debug_handshake.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void debug_handshake(void* process_ptr)
9292
if (!keychain_store(aeskey1, sizeof(aeskey1))) {
9393
JADE_LOGE("Failed to store key data encrypted in flash memory!");
9494
jade_process_reject_message(
95-
process, CBOR_RPC_INTERNAL_ERROR, "Failed to store key data encrypted in flash memory", NULL);
95+
process, CBOR_RPC_INTERNAL_ERROR, "Failed to store key data encrypted in flash memory");
9696
}
9797

9898
JADE_ASSERT(keychain_has_pin());

main/process/debug_scan_qr.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void debug_capture_image_data_process(void* process_ptr)
137137
// (We can detect as the callback frees the 'current message' on successful completion)
138138
if (HAS_CURRENT_MESSAGE(process)) {
139139
// The camera callback was not called - ie. camera screen was 'Exit'-ed.
140-
jade_process_reject_message(process, CBOR_RPC_USER_CANCELLED, "User declined to capture image", NULL);
140+
jade_process_reject_message(process, CBOR_RPC_USER_CANCELLED, "User declined to capture image");
141141
}
142142

143143
cleanup:
@@ -158,8 +158,7 @@ void debug_scan_qr_process(void* process_ptr)
158158
const uint8_t* data = NULL;
159159
rpc_get_bytes_ptr("image", &params, &data, &len);
160160
if (!data || !len) {
161-
jade_process_reject_message(
162-
process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract image data from parameters", NULL);
161+
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract image data from parameters");
163162
goto cleanup;
164163
}
165164

@@ -169,7 +168,7 @@ void debug_scan_qr_process(void* process_ptr)
169168
jade_process_free_on_exit(process, decompressed);
170169
const size_t decompressed_len = decompress_impl(data, len, decompressed, decompressed_buflen);
171170
if (!decompressed_len || decompressed_len != decompressed_buflen) {
172-
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, "Failed to decompress image data", NULL);
171+
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, "Failed to decompress image data");
173172
goto cleanup;
174173
}
175174

main/process/debug_set_mnemonic.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void debug_set_mnemonic_process(void* process_ptr)
5151
rpc_get_bytes_ptr("seed", &params, &seed, &written);
5252
if (written != 32 && written != 64) {
5353
jade_process_reject_message(
54-
process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract valid seed from parameters", NULL);
54+
process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract valid seed from parameters");
5555
goto cleanup;
5656
}
5757
keychain_derive_from_seed(seed, written, &keydata);
@@ -69,7 +69,7 @@ void debug_set_mnemonic_process(void* process_ptr)
6969
}
7070
if (qr_data.len == 0) {
7171
jade_process_reject_message(
72-
process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract mnemonic prefixes from parameters", NULL);
72+
process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract mnemonic prefixes from parameters");
7373
goto cleanup;
7474
}
7575

@@ -78,7 +78,7 @@ void debug_set_mnemonic_process(void* process_ptr)
7878
// NOTE: only the English wordlist is supported.
7979
if (!import_and_validate_mnemonic(&qr_data)) {
8080
jade_process_reject_message(
81-
process, CBOR_RPC_BAD_PARAMETERS, "Failed to expand mnemonic prefixes into full mnemonic words", NULL);
81+
process, CBOR_RPC_BAD_PARAMETERS, "Failed to expand mnemonic prefixes into full mnemonic words");
8282
goto cleanup;
8383
}
8484

@@ -88,16 +88,15 @@ void debug_set_mnemonic_process(void* process_ptr)
8888
rpc_get_string("passphrase", sizeof(passphrase), &params, passphrase, &written);
8989
if (written == 0 || written > PASSPHRASE_MAX_LEN) {
9090
jade_process_reject_message(
91-
process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract valid passphrase from parameters", NULL);
91+
process, CBOR_RPC_BAD_PARAMETERS, "Failed to extract valid passphrase from parameters");
9292
goto cleanup;
9393
}
9494
p_passphrase = passphrase;
9595
}
9696

9797
// Derive a keychain from the passed mnemonic and passphrase
9898
if (!keychain_derive_from_mnemonic((const char*)qr_data.data, p_passphrase, &keydata)) {
99-
jade_process_reject_message(
100-
process, CBOR_RPC_BAD_PARAMETERS, "Failed to derive keychain from mnemonic", NULL);
99+
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, "Failed to derive keychain from mnemonic");
101100
goto cleanup;
102101
}
103102
}

main/process/get_bip85_entropy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void get_bip85_bip39_entropy_process(void* process_ptr)
297297
bip85_data_t bip85_data = { .encrypted_len = 0 };
298298
const int errcode = get_bip85_bip39_entropy_data(&params, &bip85_data, &errmsg);
299299
if (errcode) {
300-
jade_process_reject_message(process, errcode, errmsg, NULL);
300+
jade_process_reject_message(process, errcode, errmsg);
301301
goto cleanup;
302302
}
303303

@@ -324,7 +324,7 @@ void get_bip85_rsa_entropy_process(void* process_ptr)
324324
bip85_data_t bip85_data = { .encrypted_len = 0 };
325325
const int errcode = get_bip85_rsa_entropy_data(&params, &bip85_data, &errmsg);
326326
if (errcode) {
327-
jade_process_reject_message(process, errcode, errmsg, NULL);
327+
jade_process_reject_message(process, errcode, errmsg);
328328
goto cleanup;
329329
}
330330

main/process/get_bip85_pubkey.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ void get_bip85_pubkey_process(void* process_ptr)
2323
size_t index = 0;
2424

2525
if (!params_get_bip85_rsa_key(&params, &key_bits, &index, &errmsg)) {
26-
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, errmsg, NULL);
26+
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, errmsg);
2727
goto cleanup;
2828
}
2929

3030
display_processing_message_activity();
3131

3232
char pubkey_pem[896];
3333
if (!rsa_get_bip85_pubkey_pem(key_bits, index, pubkey_pem, sizeof(pubkey_pem))) {
34-
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "Failed to generate RSA key", NULL);
34+
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "Failed to generate RSA key");
3535
goto cleanup;
3636
}
3737

main/process/get_blinding_factor.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void get_blinding_factor_process(void* process_ptr)
2323
const uint8_t* hash_prevouts = NULL;
2424
size_t output_index = 0;
2525
if (!params_hashprevouts_outputindex(&params, &hash_prevouts, &hash_prevouts_len, &output_index, &errmsg)) {
26-
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, errmsg, NULL);
26+
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, errmsg);
2727
goto cleanup;
2828
}
2929

@@ -32,7 +32,7 @@ void get_blinding_factor_process(void* process_ptr)
3232
rpc_get_string("type", sizeof(type_str), &params, type_str, &written);
3333
if (written == 0) {
3434
jade_process_reject_message(
35-
process, CBOR_RPC_BAD_PARAMETERS, "Cannot extract blinding factor type from parameters", NULL);
35+
process, CBOR_RPC_BAD_PARAMETERS, "Cannot extract blinding factor type from parameters");
3636
goto cleanup;
3737
}
3838

@@ -46,21 +46,21 @@ void get_blinding_factor_process(void* process_ptr)
4646
type = BF_VALUE;
4747
} else {
4848
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS,
49-
"Invalid blinding factor type - must be either 'ASSET', 'VALUE' or 'ASSET_AND_VALUE'", NULL);
49+
"Invalid blinding factor type - must be either 'ASSET', 'VALUE' or 'ASSET_AND_VALUE'");
5050
goto cleanup;
5151
}
5252

5353
uint8_t master_blinding_key[HMAC_SHA512_LEN];
5454
if (!params_get_master_blindingkey(&params, master_blinding_key, sizeof(master_blinding_key), &errmsg)) {
55-
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, errmsg, NULL);
55+
jade_process_reject_message(process, CBOR_RPC_BAD_PARAMETERS, errmsg);
5656
goto cleanup;
5757
}
5858

5959
uint8_t blinding_factor[WALLY_ABF_VBF_LEN]; // sufficient for both-at-once
6060
const size_t bf_len = type == BF_ASSET_VALUE ? WALLY_ABF_VBF_LEN : BLINDING_FACTOR_LEN;
6161
if (!wallet_get_blinding_factor(master_blinding_key, sizeof(master_blinding_key), hash_prevouts, hash_prevouts_len,
6262
output_index, type, blinding_factor, bf_len)) {
63-
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "Cannot get blinding factor for output", NULL);
63+
jade_process_reject_message(process, CBOR_RPC_INTERNAL_ERROR, "Cannot get blinding factor for output");
6464
goto cleanup;
6565
}
6666

0 commit comments

Comments
 (0)