Comments (4)
Hi! I confirm that it works fine for me with nitrocli-0.3.0.
from nitrocli.
Interesting. From a preliminary investigation it appears that we may be missing some padding bytes in the decoded string we ultimately produce. With the following patch your example input works:
--- nitrocli/src/commands.rs
+++ nitrocli/src/commands.rs
@@ -666,7 +666,7 @@ pub fn otp_set(
with_device(ctx, |ctx, device| {
let secret = match secret_format {
args::OtpSecretFormat::Ascii => prepare_ascii_secret(&data.secret)?,
- args::OtpSecretFormat::Base32 => prepare_base32_secret(&data.secret)?,
+ args::OtpSecretFormat::Base32 => "0".to_string() + &prepare_base32_secret(&data.secret)?,
args::OtpSecretFormat::Hex => data.secret,
};
let data = nitrokey::OtpSlotData { secret, ..data };
Theoretically it should be as simple as prepending a '0' when the decoded secret has an uneven number of characters. Will dig some more tomorrow or when I have time.
from nitrocli.
Okay, I traced that down more. The error is ultimately emitted by libnitrokey
. The call stack should look like this:
Admin::write_totp_slot
nitrokey_sys::NK_write_totp_slot
NitrokeyManager::write_TOTP_slot
NitrokeyManager::write_OTP_slot_no_authorize
misc::hex_string_to_byte
This hex_string_to_byte
function looks as follows:
::std::vector<uint8_t> hex_string_to_byte(const char* hexString){
const size_t big_string_size = 257; //arbitrary 'big' number
const size_t s_size = strnlen(hexString, big_string_size);
const size_t d_size = s_size/2;
if (s_size%2!=0 || s_size>=big_string_size){
throw InvalidHexString(0); // <------ what I suspect we hit
}
...
So, any uneven number of characters is treated as "not a hexadecimal string".
In my opinion this is a deficiency in the implementation here. Why impose this unnecessary restriction to all clients when it is very well defined what, say, 0xa
is equal to 0x0a
? And of course, it's not documented anywhere.
from nitrocli.
So the issue should be resolved in devel
now. Can you please try it out?
It seems unlikely that I'll cut another release for this fix right now, though. I am still waiting for the nitrokey
crate to be released as 0.4
as the plan was to get that out soon. However, the maintainer has gone dormant.
If you need that urgently and can't consume devel
we can probably find a solution, though.
from nitrocli.
Related Issues (20)
- Compare strings instead of byte slices in tests HOT 2
- Access PWS slots by name HOT 8
- Improve otp subcommand HOT 1
- Validate PWS and OTP string length HOT 5
- Document scdaemon reset workaround in readme
- Publishing nitrocli-ext HOT 5
- Publishing the core extensions HOT 10
- Improve installation instructions HOT 6
- Split up commands module HOT 1
- Show retry count (< 3) in pinentry HOT 1
- "Wrong password, please reenter" after device reconnection HOT 22
- "Unexpected response: OK" if empty password is entred via pinentry HOT 1
- Add log messages to nitrocli HOT 12
- Add option to otp-cache to create custom aliases HOT 4
- pinentry-tty does not work HOT 13
- Change tests to not create python scripts during builds HOT 2
- Migrate to clap 3.0.0 HOT 2
- Move CI checks to Makefile HOT 4
- nitrocli (for NK2 Pro) not responsive while NK3 plugged in HOT 4
- Document extensions in readme HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nitrocli.