Giter VIP home page Giter VIP logo

Comments (4)

bircoph avatar bircoph commented on May 29, 2024 2

Hi! I confirm that it works fine for me with nitrocli-0.3.0.

from nitrocli.

d-e-s-o avatar d-e-s-o commented on May 29, 2024

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.

d-e-s-o avatar d-e-s-o commented on May 29, 2024

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.

d-e-s-o avatar d-e-s-o commented on May 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.