Skip to content

Commit

Permalink
Merge pull request #589 from Cypherock/fix/inheritance/session-refact…
Browse files Browse the repository at this point in the history
…or-fix

chore: Version bump (v0.6.1281)
  • Loading branch information
vrockz747 authored Nov 12, 2024
2 parents 4963d57 + 66f711c commit 649e7af
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 55 deletions.
1 change: 1 addition & 0 deletions common/core/core_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ static bool session_create_device_payload(uint8_t *payload) {
offset += POSTFIX1_SIZE;
// append posfix2
memcpy(payload + offset, signed_data.postfix2, POSTFIX2_SIZE);
return true;
}

static void initiate_request(void) {
Expand Down
97 changes: 43 additions & 54 deletions tests/unit_tests_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,25 @@
******************************************************************************
*/

#include "base58.h"
#include "bip32.h"
#include "bip39.h"
#include "curves.h"
#include "nist256p1.h"
#include "sec_flash_priv.h"
#include <stdint.h>

#include "flash_struct.h"
#include "flash_struct_priv.h"
#include "utils.h"
#include "wallet.h"
#define _DEFAULT_SOURCE /* needed for usleep() */
#include <stdlib.h>
#include <unistd.h>
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" \
issue*/
#include "application_startup.h"
#include "unity_fixture.h"

#if USE_SIMULATOR == 1
#ifdef _WIN32
#define main SDL_main
#endif
#include "sim_usb.h"
extern lv_indev_t *indev_keypad;

/*On OSX SDL needs different handling*/
#if defined(__APPLE__) && defined(TARGET_OS_MAC)
#if __APPLE__ && TARGET_OS_MAC
Expand All @@ -94,7 +91,6 @@ void RunAllTests(void) {
RUN_TEST_GROUP(ui_events_test);
RUN_TEST_GROUP(usb_evt_api_test);
RUN_TEST_GROUP(nfc_events_test);
RUN_TEST_GROUP(core_session_test);
#ifdef NFC_EVENT_CARD_DETECT_MANUAL_TEST
RUN_TEST_GROUP(nfc_events_manual_test);
#endif
Expand All @@ -118,60 +114,56 @@ void RunAllTests(void) {
RUN_TEST_GROUP(inheritance_encryption_tests);
RUN_TEST_GROUP(inheritance_decryption_tests);
}

/**
* @brief The entry point to the unit test framework
* This entry point is a parallel entry point to the int main(void) of the
* actual firmware.
*/

#if USE_SIMULATOR == 1
void create_flash_keys() {
const uint32_t version = 0x0488b21e;
const char *curve = NIST256P1_NAME;
const char *mnemonic = "embody pepper stumble";
printf("%s\n\n", mnemonic);

uint8_t seed[64];
mnemonic_to_seed(mnemonic, "", seed, NULL);
printf("\n");

HDNode m;
hdnode_from_seed(seed, 64, curve, &m);
hdnode_fill_public_key(&m);
void fill_flash_wallets() {
// get_flash_ram_instance();
is_flash_ram_instance_loaded = true;
uint8_t wallet_id[WALLET_ID_SIZE] = {0};
char *wallet_name[] = {"DEV001", "DEV002"};
int wallet_index = 0;
//"DEV001" - without pin, and passphrase
hex_string_to_byte_array(
"cf19475f04c3b78f7d03f76f624e1ae426e6cd17ae1585e65c85a064312b2bff",
64,
wallet_id);
memcpy(flash_ram_instance.wallets[wallet_index].wallet_id,
wallet_id,
WALLET_ID_SIZE);
memcpy(flash_ram_instance.wallets[wallet_index].wallet_name,
wallet_name[wallet_index],
strlen(wallet_name[wallet_index]));
flash_ram_instance.wallets[wallet_index].is_wallet_locked = 0;
flash_ram_instance.wallets[wallet_index].state = VALID_WALLET;
flash_ram_instance.wallets[wallet_index].cards_states = 15;

const uint32_t h = 0x80000000;
// m/1000'/0'/2'/0
uint32_t path[] = {1000 | h, 0 | h, 2 | h, 0}; // path to generate nodes

const size_t path_size = sizeof(path) / 4;
HDNode nodes[path_size];
HDNode last = m;
for (size_t i = 0; i < path_size; i++) {
nodes[i] = last;
hdnode_private_ckd(&nodes[i], path[i]);
hdnode_fill_public_key(&nodes[i]);
last = nodes[i];
}
uint8_t card_root_xpub[FS_KEYSTORE_XPUB_LEN] = {0};
char xpub[XPUB_SIZE];
hdnode_serialize_public(&last,
hdnode_fingerprint(&nodes[path_size - 2]),
version,
xpub,
XPUB_SIZE);
base58_decode_check(
xpub, nist256p1_info.hasher_base58, card_root_xpub, XPUB_SIZE);
get_flash_perm_instance();
memcpy(flash_perm_instance.permKeyData.ext_keys.card_root_xpub,
card_root_xpub,
FS_KEYSTORE_XPUB_LEN);
// "DEV002" - has pin
wallet_index += 1;
hex_string_to_byte_array(
"cf19475f04c3b78f7d03f76f624e1ae426e6cd17ae1585e65c85a064312b2b88",
64,
wallet_id);
memcpy(flash_ram_instance.wallets[wallet_index].wallet_id,
wallet_id,
WALLET_ID_SIZE);
memcpy(flash_ram_instance.wallets[wallet_index].wallet_name,
wallet_name[wallet_index],
strlen(wallet_name[wallet_index]));
flash_ram_instance.wallets[wallet_index].is_wallet_locked = 0;
flash_ram_instance.wallets[wallet_index].state = VALID_WALLET;
flash_ram_instance.wallets[wallet_index].cards_states = 15;
WALLET_SET_PIN(flash_ram_instance.wallets[wallet_index].wallet_info);
}
#endif

int main(void) {
#if USE_SIMULATOR == 1
create_flash_keys();
fill_flash_wallets();
#endif
application_init();
#ifdef DEV_BUILD
Expand All @@ -181,7 +173,6 @@ int main(void) {
RunAllTests();
UnityEnd();
}

#if USE_SIMULATOR == 0
/**
* @brief This function is executed in case of error occurrence.
Expand All @@ -195,7 +186,6 @@ void Error_Handler(void) {
}
/* USER CODE END Error_Handler_Debug */
}

/**
* @brief Function to transmit data in real-time over SWV channel
* @param file unused
Expand All @@ -213,5 +203,4 @@ int _write(int file, char *ptr, int len) {
return len;
#endif
}

#endif /* USE_SIMULATOR == 0 */
#endif /* USE_SIMULATOR == 0 */
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
firmware version=000:006:005:000
firmware version=000:006:005:001
hardware version=000:001:000:000
magic number=45227A01

0 comments on commit 649e7af

Please sign in to comment.