Nitrokey / libnitrokey

Communicate with Nitrokey devices in a clean and easy manner
https://nitrokey.com/
GNU Lesser General Public License v3.0
65 stars 34 forks source link

Add getters for OTP and PWS properties #198

Open robinkrahl opened 3 years ago

robinkrahl commented 3 years ago

This patch adds getters for the number of PWS, TOTP and HOTP slots on the current device and the maximum length of a PWS slot name, login and password as well as a OTP slot name and secret.

Fixes #197.

szszszsz commented 3 years ago

Hi! Please let me know once the PR is ready to go.

robinkrahl commented 3 years ago

Sure!

My current plan is to cache the firmware version for the current device. This would avoid executing GET_STATUS multiple times for example when first validating the string length and then writing to the slot. This might be problematic if the user upgrades the firmware while libnitrokey is still connected to the device, but that is a tradeoff I would be willing to make. What do you think?

szszszsz commented 3 years ago

Indeed, the firmware update is not very much frequent event, but should be taken into account anyway (e.g. for the tools that check the changed firmware version). Until now I was expecting the client applications to do the caching (see Nitrokey App and its libnitrokey wrapper), and libnitrokey to do the raw communication, to not add too much hidden logic or unexpected side-effects.

We need some cache invalidation mechanism with that, e.g. in a form of a logout function. Perhaps calling "device lock" could function as such, so there would not be a need for extending the API. Thoughts?

robinkrahl commented 3 years ago

Can’t we use NK_logout / NitrokeyManager::disconnect for that?

szszszsz commented 3 years ago

Yes, sounds like a better choice