Skip to content
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

Proposing to have flush() method #89

Open
chiro-hiro opened this issue Apr 27, 2019 · 7 comments
Open

Proposing to have flush() method #89

chiro-hiro opened this issue Apr 27, 2019 · 7 comments

Comments

@chiro-hiro
Copy link

_privKey and _pubKey are always accessible that's make me uncomfortable. I'm propose to have this one.

Wallet.prototype.flush = function () {
  assert(Buffer.isBuffer(this._privKey), 'Private key should be an instance of Buffer')
  this._privKey.fill(0x00);
  assert(Buffer.isBuffer(this._pubKey), 'Public key should be an instance of Buffer')
  this._pubKey.fill(0x00);
}
@holgerd77
Copy link
Member

I think this might be a valuable addition to the API, yes.

@axic
Copy link
Member

axic commented Apr 30, 2019

I'm not fully sure what problem this is solving, since the key is not cleared from memory.

@holgerd77
Copy link
Member

@axic Is it really so easy to read things from memory with JavaScript?

@axic
Copy link
Member

axic commented Apr 30, 2019

I am just confused what benefit this gives. If a user of this library can call .flush() cannot they just invalidate references to the wallet?

@holgerd77
Copy link
Member

Hmm, that's the same with all libraries, theoretically you can use/access all (most) parts of the code but are encouraged to engage with the methods which are part of the public API, otherwise it's monkey-patching. 🐵 😄

@chiro-hiro
Copy link
Author

chiro-hiro commented May 27, 2019

I'm not fully sure what problem this is solving, since the key is not cleared from memory.

I've tried to do some experiments and observe result. We can't remove the value from the memory easily
even using delete but we can overwrite it.

image

const readline = require('readline');
let mem = Buffer.from('112233445566778899aabbccddeeff', 'hex');

readline.emitKeypressEvents(process.stdin);

process.stdin.on('keypress', (str, key) => {

  if (str === '\u0003' || (key.name === 'c' && key.ctrl)) {
    process.exit();
  }

  let fillValue = ((Math.random() * 0xff) | 0) >>> 0;
  console.log('Fill buffer with:', fillValue.toString(16));
  mem.fill(fillValue)

});

@alcuadrado
Copy link
Member

IMO having such a method would give a false sense of security to the users of this library. It's not easy to be sure that every copy of the key was erased, especially when the private key is used by external libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants