changes encryption of pkr to airgapped
This commit is contained in:
parent
879a352b3e
commit
9a70047852
|
@ -113,7 +113,7 @@ API.prototype._tryToCompleteFromServer = function(data, cb) {
|
|||
|
||||
API.prototype._tryToComplete = function(opts, data, cb) {
|
||||
if (opts.pkr) {
|
||||
var pkr = _decryptMessage(opts.pkr, data.sharedEncryptingKey);
|
||||
var pkr = _decryptMessage(opts.pkr,WalletUtils.privateKeyToAESKey(data.roPrivKey));
|
||||
|
||||
if (!pkr)
|
||||
return cb('Could not complete wallet');
|
||||
|
@ -219,7 +219,7 @@ API.prototype._initData = function(network, walletPrivKey, m, n) {
|
|||
var xPubKey = (new Bitcore.HDPublicKey(xPrivKey)).toString();
|
||||
var roPrivKey = xPrivKey.derive('m/1/0').privateKey;
|
||||
var rwPrivKey = xPrivKey.derive('m/1/1').privateKey;
|
||||
var sharedEncryptingKey = Bitcore.crypto.Hash.sha256(walletPrivKey.toBuffer()).slice(0, 16).toString('base64');
|
||||
var sharedEncryptingKey = WalletUtils.privateKeyToAESKey(walletPrivKey);
|
||||
var copayerId = WalletUtils.xPubToCopayerId(xPubKey);
|
||||
|
||||
var data = {
|
||||
|
@ -650,9 +650,8 @@ API.prototype.getEncryptedPublicKeyRing = function(cb) {
|
|||
|
||||
this._loadAndCheck({}, function(err, data) {
|
||||
if (err) return cb(err);
|
||||
|
||||
var pkr = JSON.stringify(data.publicKeyRing);
|
||||
return cb(null, _encryptMessage(pkr, data.sharedEncryptingKey));
|
||||
return cb(null, _encryptMessage(pkr, WalletUtils.privateKeyToAESKey(data.roPrivKey)));
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -138,4 +138,9 @@ WalletUtils.decryptMessage = function(cyphertextJson, encryptingKey) {
|
|||
return sjcl.decrypt(key, cyphertextJson);
|
||||
};
|
||||
|
||||
WalletUtils.privateKeyToAESKey = function(privKey) {
|
||||
var pk = Bitcore.PrivateKey.fromString(privKey);
|
||||
return Bitcore.crypto.Hash.sha256(pk.toBuffer()).slice(0, 16).toString('base64');
|
||||
};
|
||||
|
||||
module.exports = WalletUtils;
|
||||
|
|
|
@ -519,22 +519,35 @@ describe('client API ', function() {
|
|||
};
|
||||
clients[1].sendTxProposal(opts, function(err, x) {
|
||||
should.not.exist(err);
|
||||
clients[1].getTxProposals({
|
||||
getRawTxps: true
|
||||
}, function(err, txs, rawTxps) {
|
||||
should.not.exist(err);
|
||||
|
||||
clients[1].getEncryptedPublicKeyRing(function(err, pkr) {
|
||||
// Create the proxy, ro, connected, device (2)
|
||||
clients[0].export({
|
||||
access: 'readonly'
|
||||
}, function(err, str) {
|
||||
should.not.exist(err);
|
||||
clients[2].import(str, function(err, wallet) {
|
||||
should.not.exist(err);
|
||||
|
||||
// Will trigger _tryToComplete and use pkr
|
||||
// then, needs pkr to verify the txps
|
||||
clients[0].parseTxProposals({
|
||||
txps: rawTxps,
|
||||
pkr: pkr,
|
||||
}, function(err, txs2) {
|
||||
clients[2].getTxProposals({
|
||||
getRawTxps: true
|
||||
}, function(err, txs, rawTxps) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
|
||||
clients[2].getEncryptedPublicKeyRing(function(err, pkr) {
|
||||
should.not.exist(err);
|
||||
|
||||
// Back to the air gapped
|
||||
//
|
||||
// Will trigger _tryToComplete and use pkr
|
||||
// then, needs pkr to verify the txps
|
||||
clients[0].parseTxProposals({
|
||||
txps: rawTxps,
|
||||
pkr: pkr,
|
||||
}, function(err, txs2) {
|
||||
should.not.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue