-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement factory reset #71
Conversation
After performing the factory reset, we also build the AES key so that the device is fully usable. Due to timing issue, we have to add a delay between the factory reset and building the AES key.
Thanks for implementing this feature, Robin. I seem to have some problems with this change. I always get asked to repeat my admin password. What seems to be happening is that |
Interestingly enough that seems to be a problem that I only hit on the Pro stick. And even the test seems to catch that. |
Two last (?) comments: I can't really reproduce the issue when removing the sleep and the Also, what I originally had envisioned was for us to check whether the AES keys need to be built before every command that requires them, and doing so if they have not been built yet. That may "solve" the issue. It would make things a bit more complex in that we now would need to maintain a list of those commands and add logic to check whether the keys have been built, but it would have the advantage that it would work if a user resets the device using |
Fuck it :D I also noticed that this problem seems to exist in the
Line 305 maps to: assert_eq!(Ok(()), device.build_aes_key(ADMIN_PASSWORD)); |
I was thinking about that too, but: The AES key status is currently only reported in the Storage status. So for the Pro, there is no way to find out whether the AES key exists (AFAIK).
I only tested this on the Storage as I didn’t want to reset my production stick. Just to have a minimal example reproducing the problem, could you please try to run this code with, let’s say, 2, 3 and 10 seconds? |
Oh. That's bad then :-|
I figured. The example fails with 2, 3, and 10s.
|
Thanks for checking that. Should we remove the AES stuff before this is fixed upstream, or should we postpone the |
Well, I could not let my hands off of this problem. I got things working with: --- nitrocli/src/commands.rs
+++ nitrocli/src/commands.rs
@@ -308,6 +308,7 @@ pub fn reset(ctx: &mut args::ExecCtx<'_>) -> Result<()> {
// Workaround for a timing issue between factory_reset and build_aes_key, see
// https://github.com/Nitrokey/nitrokey-storage-firmware/issues/80
thread::sleep(time::Duration::from_secs(3));
+ let _ = device.build_aes_key(NITROKEY_DEFAULT_ADMIN_PIN);
device.build_aes_key(NITROKEY_DEFAULT_ADMIN_PIN)
})
} (I had the test run >10 iterations without failure) Not sure what is happening. It's more than a stale command exit code being stashed somewhere: I tried just inquiring the serial number and that did not resolve the problem. |
Actually, it may be exactly that. Inquiring the serial number is probably just no "real" command (I traced it to some --- nitrocli/src/commands.rs
+++ nitrocli/src/commands.rs
@@ -308,6 +308,7 @@ pub fn reset(ctx: &mut args::ExecCtx<'_>) -> Result<()> {
// Workaround for a timing issue between factory_reset and build_aes_key, see
// https://github.com/Nitrokey/nitrokey-storage-firmware/issues/80
thread::sleep(time::Duration::from_secs(3));
+ let _ = device.get_user_retry_count();
device.build_aes_key(NITROKEY_DEFAULT_ADMIN_PIN)
})
} Ugh. One hack follows the next. |
Actually, it may be exactly that. Inquiring the serial number is
probably just no "real" command (I traced it to some `hidapi` call but
no further).
NK_device_serial_number is a “real” command. It runs GET_STATUS on the
Pro and GET_DEVICE_STATUS on the Storage. My guess is that we need a
command that touches the smart card.
|
Ah, that would make sense too. What do we do here? Go with such a hack? I probably should report that in the issue you filed. Do you have a better suggestion than |
I’d rather not ship a workaround until we know what actually causes the problem and whether this fix works on all devices. – I think |
I've created Nitrokey/nitrokey-storage-firmware#84. |
My vote is for getting this change in, in part because you mentioned that it is blocking the addition of tests for #77.
All that without proper comments other than those explaining the obvious. I am obviously not familiar with the code base so all this could be a problem of my understanding, but none of that builds any confidence in a context where code should be to the point and hopefully reviewed/audited. I did not want to look at that because I knew what would await me, but I wanted to see if the problem is something "obvious". Since the Nitrokey team hasn't commented on the issue it does not seem to be treated with priority. Let me know if you object or think I am overreacting :D or I shall merge that by tomorrow (after rebasing and everything). |
Well, now you know the reason why I started looking into embedded Rust. ;) It’s also the reason why I wanted to know the error cause – it sounds logical that a smart card command is the solution, but honestly, it could be everything. But I don’t have a testing Pro at hand, so if you are confident that the workaround is indeed working, I’m fine with merging it into devel. |
Thanks for your quick response, Robin. I've merged the request with minor adjustments. |
No description provided.