question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error using base32 encoding (browser support)

See original GitHub issue

Hi everybody,

I am using speakeasy in an Ember application with ember-browserify addon: https://www.npmjs.com/package/ember-browserify

Just encountered that the base32 encoding seems to not work at all. Considering the following code:

var secret = speakeasy.generateSecret(); // default length is 32
var secretKey = secret.base32;
var token = speakeasy.totp({
  secret: secretKey,
  encoding: 'base32'
});

So, just a secret generation and subsequent using it to create a new token leads to the following error:

“list” argument must be an Array of Buffers

The same issue with the speakeasy.totp.verify() method.

I’ve found the reason in the following code from index.js (lines 39-42):

// convert secret to buffer
if (!Buffer.isBuffer(secret)) {
  secret = encoding === 'base32' ? base32.decode(secret)
    : new Buffer(secret, encoding);
}

The base32.decode(secret) returns an array and not a Buffer. I’ve changed the code and got it working:

// convert secret to buffer
if (!Buffer.isBuffer(secret)) {
  secret = encoding === 'base32' ? new Buffer(base32.decode(secret)) : new Buffer(secret, encoding);
}

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
Siyfioncommented, Mar 2, 2017

@mikepb & @markbao No problem, thanks for the update anyway, sometimes it’s nice just to know that the project/issue hasn’t been forgotten about and there are people “on-it”. 👍

1reaction
mikepbcommented, Mar 2, 2017

Just thought of a more permanent fix. Instead of detecting whether the base32 returns a buffer, always import the client version and have speakeasy initialize a buffer with byte array.

On Mar 2, 2017, at 1:55 AM, Simon Mansfield notifications@github.com wrote:

@mikepb & @markbao No problem, thanks for the update anyway, sometimes it’s nice just to know that the project/issue hasn’t been forgotten about and there are people “on-it”. 👍

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

base32-browser - npm
Start using base32-browser in your project by running `npm i ... Base 32 is between hexadecimal notation and Base 64 encoding.
Read more >
1250113 – coreutils doesn't include a base32 binary
Description of problem: coreutils includes a base64 encoder, but no base32 (or base16). The base32 encoding is very useful for converting OTP ...
Read more >
base32 image for img tag - Stack Overflow
If you mean the browser isn't displaying the image, all it means is that the browser doesn't support base32. I have the same...
Read more >
Generating Base32 string examples - Yubico Support
MacOS and Ubuntu. Run the following command in a terminal to generate a 64 character Base32 random string: $ LC_ALL=C tr -dc 'A-Z2 ......
Read more >
Base32 Encode - Code Beautify
Online Base32 Encode tool is to encode base32 your String using Base32 Encoder. Convert String, File and load URL.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found