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

Modifying private keys results in many other valid keys #383

Open
Jolly-Pirate opened this issue May 20, 2018 · 1 comment
Open

Modifying private keys results in many other valid keys #383

Jolly-Pirate opened this issue May 20, 2018 · 1 comment

Comments

@Jolly-Pirate
Copy link

Jolly-Pirate commented May 20, 2018

Changing one of the last 4 characters in a private key may result in a validation by the wifIsValid() function. This happens in steem-js but not in steem-python (can't import an invalid key with steempy addkey).

Tested with different accounts. Some keys are showing this behavior, while others aren't.

The modified keys are also able to broadcast transactions.

Using the latest steem-js v0.7.1

Here's a snippet to verify the combinations for a given key pair.

String.prototype.replaceAt = function (index, replacement) {
  return this.substr(0, index) + replacement + this.substr(index + replacement.length);
};

// account and password example that illustrate the problem
var account = "testuser123"; // edit this
var password = "P5JvGvqo8NWhnaEhqHNsd69g7TbiFy1WcZQ5HNq8qxvaVU1bXzmX"; // edit this

var steem = require('steem');
var base58chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
var keys = steem.auth.getPrivateKeys(account, password, ['owner', 'active', 'posting', 'memo']);

//console.log(keys);

testKeys(keys.owner, keys.ownerPubkey, "owner");
testKeys(keys.active, keys.activePubkey, "active");
testKeys(keys.posting, keys.postingPubkey, "posting");
testKeys(keys.memo, keys.memoPubkey, "memo");

function testKeys(privatekey, publickey, keytype) {
  var validcount = 0;
  for (var testpos = 0; testpos <= privatekey.length; testpos++) {
    for (var i = 0; i < base58chars.length; i++) {
      var newchar = base58chars.slice(i, i + 1);
      var modifiedprivatekey = privatekey.replaceAt(testpos - 1, newchar);
      try {
        if (steem.auth.wifIsValid(modifiedprivatekey, publickey)) {
          if (privatekey !== modifiedprivatekey) {
            var slice1 = privatekey.slice(0, testpos - 1);
            var slice2 = privatekey.slice(testpos - 1, privatekey.length - 1);
            console.log(slice1 + "\x1b[36m" + newchar + "\x1b[0m" + slice2, "VALID");
            validcount++;
          }
        }
      } catch (e) {
        //console.log(e);
        //console.log(modifiedwif, newchar, "INVALID");
      }
    }
  }
  console.log("\x1b[32m" + privatekey, "ORIGINAL", keytype, "\x1b[0m");
  console.log("Found", validcount, "valid variations on the original", keytype, "key", "\r\n");
  validcount = 0;
}
@Jolly-Pirate Jolly-Pirate changed the title wifIsValid() is validating variations on the same private key Variations on the same private key are valid May 20, 2018
@Jolly-Pirate Jolly-Pirate changed the title Variations on the same private key are valid Modifying private keys results in many other valid keys May 21, 2018
@cryptohazard
Copy link

I did know someone find this bug :-(.
Anyway I investigated it and here is the explanation: https://steemit.com/utopian-io/@cryptohazard/steem-bug-private-key-format-wif-errors-in-steem-js-library

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

No branches or pull requests

2 participants