replace HMAC with bitcore\'s hmac

This commit is contained in:
Matias Alejo Garcia 2014-04-24 11:58:29 -03:00
parent 6ace16e20d
commit e56a5c3e1b
2 changed files with 6 additions and 19 deletions

View File

@ -491,7 +491,6 @@
<script src="lib/peerjs/peer.js"></script> <script src="lib/peerjs/peer.js"></script>
<script src="lib/bitcore.js"></script> <script src="lib/bitcore.js"></script>
<script src="lib/crypto-js/rollups/aes.js"></script> <script src="lib/crypto-js/rollups/aes.js"></script>
<script src="lib/crypto-js/rollups/hmac-sha256.js"></script>
<script src="lib/file-saver/FileSaver.js"></script> <script src="lib/file-saver/FileSaver.js"></script>
<script src="lib/socket.io.js"></script> <script src="lib/socket.io.js"></script>
<script src="js/copayBundle.js"></script> <script src="js/copayBundle.js"></script>

View File

@ -4,7 +4,6 @@ var EventEmitter= imports.EventEmitter || require('events').EventEmitter;
var bitcore = require('bitcore'); var bitcore = require('bitcore');
var util = bitcore.util; var util = bitcore.util;
var Key = bitcore.Key; var Key = bitcore.Key;
/* /*
* Emits * Emits
* 'networkChange' * 'networkChange'
@ -83,8 +82,6 @@ Network.prototype.connectedCopayers = function() {
}; };
Network.prototype._onClose = function(peerId) { Network.prototype._onClose = function(peerId) {
console.log('[WebRTC.js.72:_onClose:]');
delete this.connections[peerId]; delete this.connections[peerId];
this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers); this.connectedPeers = Network._arrayRemove(peerId, this.connectedPeers);
this._notifyNetworkChange(); this._notifyNetworkChange();
@ -92,11 +89,7 @@ console.log('[WebRTC.js.72:_onClose:]');
Network.prototype._connectToCopayers = function(copayerIds) { Network.prototype._connectToCopayers = function(copayerIds) {
var self = this; var self = this;
console.log('[WebRTC.js.96] _connectToCopayers', copayerIds, this.connectedCopayers() ); //TODO
var arrayDiff= Network._arrayDiff(copayerIds, this.connectedCopayers()); var arrayDiff= Network._arrayDiff(copayerIds, this.connectedCopayers());
console.log('[WebRTC.js.99:arrayDiff:]',arrayDiff); //TODO
arrayDiff.forEach(function(copayerId) { arrayDiff.forEach(function(copayerId) {
console.log('### CONNECTING TO:', copayerId); console.log('### CONNECTING TO:', copayerId);
self.connectTo(copayerId); self.connectTo(copayerId);
@ -291,7 +284,6 @@ Network.prototype.setCopayerId = function(copayerId) {
if (this.started) { if (this.started) {
throw new Error ('network already started: can not change peerId') throw new Error ('network already started: can not change peerId')
} }
console.log('[WebRTC.js.295] SETING COPAYER ID:' + copayerId); //TODO
this.copayerId = copayerId; this.copayerId = copayerId;
this.copayerIdBuf = new Buffer(copayerId,'hex'); this.copayerIdBuf = new Buffer(copayerId,'hex');
this.peerId = this.peerFromCopayer(this.copayerId); this.peerId = this.peerFromCopayer(this.copayerId);
@ -331,7 +323,6 @@ Network.prototype.start = function(opts, openCallback) {
this.connectTo(otherPeerId); this.connectTo(otherPeerId);
} }
this.started = true; this.started = true;
console.log('[WebRTC.js.237] started TRUE'); //TODO
}; };
@ -339,18 +330,15 @@ Network.prototype._sign = function(payload, copayerId) {
var ret=''; var ret='';
var str = JSON.stringify(payload); var str = JSON.stringify(payload);
if (payload.type ==='hello') { if (payload.type ==='hello') {
console.log('[WebRTC.js.331] SIGNING WITH HMAC:', copayerId); //TODO ret = (
ret = CryptoJS.enc.Base64.stringify( util.sha512hmac(
CryptoJS.HmacSHA256( new Buffer(str),
str, new Buffer(copayerId,'hex')
copayerId )).toString('hex');
));
} }
else { else {
if (!this.signingKey) if (!this.signingKey)
throw new Error ('no key to sign messages :('); throw new Error ('no key to sign messages :(');
console.log('[WebRTC.js.341] SIGNING WITH ECDSA'); //TODO
ret = bitcore.Message.sign( ret = bitcore.Message.sign(
str, str,
this.signingKey this.signingKey
@ -371,7 +359,7 @@ Network.prototype._sendToOne = function(copayerId, payload, cb) {
dataConn.send(str); dataConn.send(str);
} }
else { else {
console.log('[WebRTC.js.255] WARN: NO CONNECTION TO:', peerId); //TODO console.log('[WebRTC.js.255] WARN: NO CONNECTION TO:', peerId); //TODO
} }
} }
if (typeof cb === 'function') cb(); if (typeof cb === 'function') cb();