19
19
20
20
#include "bip39.h"
21
21
#include "card_fetch_data.h"
22
+ #include "card_pair.h"
23
+ #include "core_error.h"
22
24
#include "inheritance/core.pb.h"
23
25
#include "inheritance_api.h"
24
26
#include "inheritance_priv.h"
25
27
#include "reconstruct_wallet_flow.h"
26
28
#include "status_api.h"
27
29
#include "ui_delay.h"
28
-
29
30
/*****************************************************************************
30
31
* EXTERN VARIABLES
31
32
*****************************************************************************/
@@ -60,8 +61,39 @@ static auth_wallet_config_t *auth = NULL;
60
61
static bool verify_auth_wallet_inputs ();
61
62
62
63
/**
63
- * @brief Retrieves encrypted data (entropy) from the card based on the wallet
64
- * ID.
64
+ * @brief Retrieves and stores seed-based entropy for authentication.
65
+ *
66
+ * Generates entropy from the seed based on the wallet ID and stores it in the
67
+ * auth structure.
68
+ *
69
+ * @return true if seed-based entropy is successfully generated and stored,
70
+ * false otherwise.
71
+ */
72
+ static bool auth_wallet_get_seed_entropy ();
73
+
74
+ /**
75
+ * @brief Pairs the card with the device.
76
+ *
77
+ * Initiates the card pairing process and updates the app flow status upon
78
+ * success.
79
+ *
80
+ * @return true if the card is successfully paired, false otherwise.
81
+ */
82
+ static bool auth_wallet_pair_card ();
83
+
84
+ /**
85
+ * @brief Retrieves and stores wallet-based entropy from the card.
86
+ *
87
+ * Fetches encrypted wallet ID data from the card to generate entropy.
88
+ *
89
+ * @return true if wallet-based entropy is successfully fetched and stored,
90
+ * false otherwise.
91
+ */
92
+ static bool auth_wallet_get_wallet_entropy ();
93
+
94
+ /**
95
+ * @brief Retrieves encrypted data (entropy) from the card based on the type
96
+ * requested from the host (seed based and/or wallet_id based)
65
97
*
66
98
* This function initializes a secure_data_t structure, fetches encrypted data
67
99
* from the card, and stores the result in the auth structure. It checks if the
@@ -126,19 +158,15 @@ static bool verify_auth_wallet_inputs() {
126
158
delay_scr_init (ui_text_inheritance_wallet_auth_fail , DELAY_TIME );
127
159
return false;
128
160
}
129
-
130
161
return true;
131
162
}
132
163
133
- static bool auth_wallet_get_entropy () {
164
+ static bool auth_wallet_get_seed_entropy () {
134
165
if (auth -> do_seed_based ) {
135
166
uint8_t seed [SIZE_SEED ] = {0 };
136
167
if (!reconstruct_seed_without_passphrase (
137
168
auth -> data .wallet_id , seed , inheritance_send_error )) {
138
169
memzero (seed , sizeof (seed ));
139
- inheritance_send_error (ERROR_COMMON_ERROR_CORRUPT_DATA_TAG ,
140
- ERROR_DATA_FLOW_INVALID_QUERY );
141
- delay_scr_init (ui_text_inheritance_wallet_auth_fail , DELAY_TIME );
142
170
return false;
143
171
}
144
172
memcpy ((void * )auth -> seed_based_data .entropy , seed , SIZE_SEED );
@@ -148,18 +176,30 @@ static bool auth_wallet_get_entropy() {
148
176
// seed generation complete
149
177
set_app_flow_status (INHERITANCE_AUTH_WALLET_STATUS_SEED_BASED_CARD_TAPPED );
150
178
}
179
+ return true;
180
+ }
181
+
182
+ static bool auth_wallet_pair_card () {
183
+ // Pair the card first
184
+ card_error_type_e status = single_card_pair_operation (
185
+ (char * )ui_text_tap_the_card , ui_text_place_card_below );
186
+ if (status != CARD_OPERATION_SUCCESS ) {
187
+ return false;
188
+ }
189
+ set_app_flow_status (INHERITANCE_AUTH_WALLET_STATUS_PAIRING_CARD_TAPPED );
190
+ return true;
191
+ }
192
+
193
+ static bool auth_wallet_get_wallet_entropy () {
151
194
if (auth -> do_wallet_based ) {
152
195
secure_data_t msgs [1 ] = {0 };
153
196
msgs [0 ].plain_data_size = WALLET_ID_SIZE ;
154
197
memcpy (msgs [0 ].plain_data , auth -> data .wallet_id , WALLET_ID_SIZE );
155
-
198
+ // fetch encrypted wallet_id
156
199
card_error_type_e status =
157
200
card_fetch_encrypt_data (auth -> data .wallet_id , msgs , 1 );
158
201
if (status != CARD_OPERATION_SUCCESS ||
159
202
msgs [0 ].encrypted_data_size > ENTROPY_SIZE_LIMIT ) {
160
- inheritance_send_error (ERROR_COMMON_ERROR_CORRUPT_DATA_TAG ,
161
- ERROR_DATA_FLOW_INVALID_DATA );
162
- delay_scr_init (ui_text_inheritance_wallet_auth_fail , DELAY_TIME );
163
203
return false;
164
204
}
165
205
memcpy ((void * )auth -> wallet_based_data .entropy ,
@@ -171,9 +211,18 @@ static bool auth_wallet_get_entropy() {
171
211
set_app_flow_status (
172
212
INHERITANCE_AUTH_WALLET_STATUS_WALLET_BASED_CARD_TAPPED );
173
213
}
214
+ return true;
215
+ }
174
216
217
+ static bool auth_wallet_get_entropy () {
218
+ if (!auth_wallet_get_seed_entropy () || !auth_wallet_pair_card () ||
219
+ !auth_wallet_get_wallet_entropy ()) {
220
+ inheritance_send_error (ERROR_COMMON_ERROR_CORRUPT_DATA_TAG ,
221
+ ERROR_DATA_FLOW_INVALID_DATA );
222
+ delay_scr_init (ui_text_inheritance_wallet_auth_fail , DELAY_TIME );
223
+ return false;
224
+ }
175
225
delay_scr_init (ui_text_inheritance_wallet_authenticating , DELAY_SHORT );
176
-
177
226
return true;
178
227
}
179
228
0 commit comments