mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #196 from matiu/feature/encryption
Feature/encryption
This commit is contained in:
commit
380014a280
10
index.html
10
index.html
|
@ -217,14 +217,10 @@
|
|||
</script>
|
||||
|
||||
<script type="text/ng-template" id="peer.html">
|
||||
<div class="row">
|
||||
<div class="row" ng-if="$root.wallet.requiredCopayers > $root.wallet.network.connectedCopayers().length">
|
||||
<div class="large-12 columns p70l">
|
||||
<p class="text-info" ng-show="$root.wallet.publicKeyRing.requiredCopayers >$root.wallet.network.connectedCopayers()"> <i class="fi-alert size-28"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="large-12 columns p70l">
|
||||
{{$root.wallet.publicKeyRing.requiredCopayers}} copayers needed for signing transactions
|
||||
<p class="text-info"> <i class="fi-alert size-28"></i>
|
||||
{{$root.wallet.requiredCopayers}} copayers needed for signing transactions
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
|
|
@ -6,6 +6,9 @@ angular.module('copay.transactions').controller('TransactionsController',
|
|||
|
||||
$scope.title = 'Transactions';
|
||||
$scope.loading = false;
|
||||
|
||||
|
||||
|
||||
var _updateTxs = function() {
|
||||
var w =$rootScope.wallet;
|
||||
if (!w) return;
|
||||
|
@ -99,4 +102,13 @@ angular.module('copay.transactions').controller('TransactionsController',
|
|||
};
|
||||
|
||||
_updateTxs();
|
||||
|
||||
var w = $rootScope.wallet;
|
||||
if (w) {
|
||||
w.on('txProposalsUpdated', function() {
|
||||
console.log('[transactions.js.108: txProposalsUpdated:]'); //TODO
|
||||
_updateTxs();
|
||||
$rootScope.$digest();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -60,6 +60,7 @@ Wallet.prototype._handlePublicKeyRing = function(senderId, data, isInbound) {
|
|||
this._lockIncomming();
|
||||
}
|
||||
}
|
||||
this.emit('publicKeyRingUpdated', this.publicKeyRing);
|
||||
this.store();
|
||||
};
|
||||
|
||||
|
@ -76,6 +77,7 @@ Wallet.prototype._handleTxProposals = function(senderId, data, isInbound) {
|
|||
recipients = null;
|
||||
this.sendTxProposals(recipients);
|
||||
}
|
||||
this.emit('txProposalsUpdated', this.txProposals);
|
||||
this.store();
|
||||
};
|
||||
|
||||
|
@ -107,7 +109,7 @@ Wallet.prototype._handleData = function(senderId, data, isInbound) {
|
|||
|
||||
Wallet.prototype._handleNetworkChange = function(newCopayerId) {
|
||||
if (newCopayerId) {
|
||||
this.log('#### Setting new PEER:', newCopayerId);
|
||||
this.log('#### Setting new COPAYER:', newCopayerId);
|
||||
this.sendWalletId(newCopayerId);
|
||||
this.emit('peer', this.network.peerFromCopayer(newCopayerId));
|
||||
}
|
||||
|
@ -242,7 +244,6 @@ Wallet.prototype.sendTxProposals = function(recipients) {
|
|||
txProposals: this.txProposals.toObj(),
|
||||
walletId: this.id,
|
||||
});
|
||||
this.emit('txProposalsUpdated', this.txProposals);
|
||||
};
|
||||
|
||||
Wallet.prototype.sendWalletReady = function(recipients) {
|
||||
|
@ -256,7 +257,7 @@ Wallet.prototype.sendWalletReady = function(recipients) {
|
|||
};
|
||||
|
||||
Wallet.prototype.sendWalletId = function(recipients) {
|
||||
this.log('### SENDING walletId TO:', recipients || 'All', this.walletId);
|
||||
this.log('### SENDING walletId TO:', recipients || 'All', this.id);
|
||||
|
||||
this.network.send(recipients, {
|
||||
type: 'walletId',
|
||||
|
@ -274,7 +275,6 @@ Wallet.prototype.sendPublicKeyRing = function(recipients) {
|
|||
publicKeyRing: this.publicKeyRing.toObj(),
|
||||
walletId: this.id,
|
||||
});
|
||||
this.emit('publicKeyRingUpdated', this.publicKeyRing);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -154,23 +154,25 @@ Network.prototype._addCopayer = function(copayerId, isInbound) {
|
|||
|
||||
Network.prototype._onData = function(data, isInbound, peerId) {
|
||||
var sig, payload;
|
||||
|
||||
try {
|
||||
var dataObj = JSON.parse(data);
|
||||
sig = dataObj.sig;
|
||||
payload= dataObj.payload;
|
||||
payload= JSON.parse(this._decPayload(dataObj.encPayloadStr));
|
||||
console.log('[WebRTC.js.161:payload:]',payload); //TODO
|
||||
|
||||
} catch (e) {
|
||||
console.log('### ERROR IN DATA: "%s" ', data, isInbound, e);
|
||||
this._deletePeer(peerId);
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
console.log('### RECEIVED INBOUND?:%s TYPE: %s FROM %s',
|
||||
isInbound, payload.type, peerId, payload);
|
||||
|
||||
// TODO _func
|
||||
if(payload.type === 'hello') {
|
||||
var thisSig = this._signHMAC(payload, this.copayerId);
|
||||
if(payload.type === 'hello' && !this.authenticatedPeers[peerId]) {
|
||||
var payloadStr = JSON.stringify(payload);
|
||||
var thisSig = this._signHMAC(payloadStr, this.copayerId);
|
||||
if (thisSig !== sig) {
|
||||
console.log('#### Peer sent WRONG hello signature. Closing connection.');
|
||||
this._deletePeer(peerId);
|
||||
|
@ -199,6 +201,8 @@ Network.prototype._onData = function(data, isInbound, peerId) {
|
|||
}
|
||||
|
||||
var copayerIdBuf = new Buffer(this.copayerForPeer[peerId],'hex');
|
||||
|
||||
console.log('[WebRTC.js.204] sig:', sig); //TODO
|
||||
if (!bitcore.Message.verifyWithPubKey( copayerIdBuf, JSON.stringify(payload),
|
||||
new Buffer(sig,'hex'))) {
|
||||
console.log('[WebRTC.js.152] SIGNATURE VERIFICATION FAILED!!'); //TODO
|
||||
|
@ -375,24 +379,22 @@ Network.prototype.start = function(opts, openCallback) {
|
|||
};
|
||||
|
||||
|
||||
Network.prototype._signHMAC = function(payload, copayerId) {
|
||||
var str = JSON.stringify(payload);
|
||||
if (payload.type !=='hello')
|
||||
throw new Error ('HMAC only for hello messages')
|
||||
Network.prototype._signHMAC = function(payloadStr, copayerId) {
|
||||
|
||||
console.log('[WebRTC.js.382] SIG HMAC', payloadStr, copayerId); //TODO
|
||||
return util.sha512hmac(
|
||||
new Buffer(str),
|
||||
new Buffer(payloadStr),
|
||||
new Buffer(copayerId,'hex')
|
||||
).toString('hex');
|
||||
};
|
||||
|
||||
Network.prototype._signECDSA = function(payload) {
|
||||
Network.prototype._signECDSA = function(payloadStr) {
|
||||
var ret='';
|
||||
var str = JSON.stringify(payload);
|
||||
if (!this.signingKey)
|
||||
throw new Error ('no key to sign messages :(');
|
||||
|
||||
return bitcore.Message.sign(
|
||||
str,
|
||||
payloadStr,
|
||||
this.signingKey
|
||||
).toString('hex');
|
||||
};
|
||||
|
@ -405,14 +407,31 @@ Network.prototype.getPeer = function() {
|
|||
return this.peer;
|
||||
};
|
||||
|
||||
Network.prototype._sendToOne = function(copayerId, payload, sig, cb) {
|
||||
|
||||
Network.prototype._encPayload = function(payloadStr, copayerId) {
|
||||
if (!copayerId || !payloadStr)
|
||||
throw new Error('incomplete parameters to _encPayload'+':'+ payloadStr +':'+copayerId);
|
||||
|
||||
//console.log('[WebRTC.js.413] ENC:',payloadStr, copayerId); //TODO
|
||||
// TODO replace with asymmetric encryption (copayerId is the pub key)
|
||||
return CryptoJS.AES.encrypt(payloadStr, copayerId).toString();
|
||||
};
|
||||
|
||||
Network.prototype._decPayload = function(payloadStr) {
|
||||
// TODO replace with asymmetric encryption (decrypt using this.signingKey);
|
||||
//console.log('[WebRTC.js.413] DEC:',payloadStr, this.copayerId); //TODO
|
||||
return CryptoJS.AES.decrypt(payloadStr, this.copayerId).toString(CryptoJS.enc.Utf8);
|
||||
};
|
||||
|
||||
Network.prototype._sendToOne = function(copayerId, payloadStr, sig, cb) {
|
||||
var peerId = this.peerFromCopayer(copayerId);
|
||||
if (peerId !== this.peerId) {
|
||||
var dataConn = this.connections[peerId];
|
||||
var encPayloadStr = this._encPayload(payloadStr, copayerId);
|
||||
if (dataConn) {
|
||||
var str = JSON.stringify({
|
||||
sig: sig,
|
||||
payload: payload
|
||||
encPayloadStr: encPayloadStr,
|
||||
});
|
||||
dataConn.send(str);
|
||||
}
|
||||
|
@ -431,25 +450,26 @@ Network.prototype.send = function(copayerIds, payload, cb) {
|
|||
}
|
||||
|
||||
var sig;
|
||||
var payloadStr = JSON.stringify(payload);
|
||||
if (payload.type === 'hello') {
|
||||
var hisId = copayerIds;
|
||||
sig=this._signHMAC(payload,hisId);
|
||||
sig=this._signHMAC(payloadStr ,hisId);
|
||||
}
|
||||
else {
|
||||
sig=this._signECDSA(payload);
|
||||
sig=this._signECDSA(payloadStr);
|
||||
}
|
||||
|
||||
if (Array.isArray(copayerIds)) {
|
||||
var l = copayerIds.length;
|
||||
var i = 0;
|
||||
copayerIds.forEach(function(copayerId) {
|
||||
self._sendToOne(copayerId, payload, sig, function () {
|
||||
self._sendToOne(copayerId, payloadStr, sig, function () {
|
||||
if (++i === l && typeof cb === 'function') cb();
|
||||
});
|
||||
});
|
||||
}
|
||||
else if (typeof copayerIds === 'string')
|
||||
self._sendToOne(copayerIds, payload, sig, cb);
|
||||
self._sendToOne(copayerIds, payloadStr, sig, cb);
|
||||
};
|
||||
|
||||
Network.prototype.connectTo = function(copayerId) {
|
||||
|
|
|
@ -91,7 +91,6 @@ angular.module('copay.controllerUtils')
|
|||
console.log('### SUBSCRIBE TO', addrs[i]);
|
||||
Socket.emit('subscribe', addrs[i]);
|
||||
}
|
||||
console.log('[controllerUtils.js.64]'); //TODO
|
||||
addrs.forEach(function(addr) {
|
||||
Socket.on(addr, function(txid) {
|
||||
console.log('Received!', txid);
|
||||
|
|
Loading…
Reference in New Issue