Fix when importing a dkek and it fails.

Now the dkek state is returned to the previous one.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2022-12-06 20:11:26 +01:00
parent 6a57e67629
commit 691aa3308c

View File

@@ -56,9 +56,12 @@ int cmd_key_domain() {
} }
import_dkek_share(p2, apdu.data); import_dkek_share(p2, apdu.data);
if (++current_dkeks >= dkeks) { if (++current_dkeks >= dkeks) {
if (save_dkek_key(p2, NULL) != CCID_OK) if (save_dkek_key(p2, NULL) != CCID_OK) {
/* On fail, it will return to previous dkek state. */
import_dkek_share(p2, apdu.data);
return SW_FILE_NOT_FOUND(); return SW_FILE_NOT_FOUND();
} }
}
uint8_t t[MAX_KEY_DOMAINS*2]; uint8_t t[MAX_KEY_DOMAINS*2];
memcpy(t, kdata, tf_kd_size); memcpy(t, kdata, tf_kd_size);
t[2*p2+1] = current_dkeks; t[2*p2+1] = current_dkeks;