Skip to content

Commit

Permalink
removed logging
Browse files Browse the repository at this point in the history
  • Loading branch information
elsehow committed Dec 18, 2016
1 parent ca683d1 commit 79f7037
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 46 deletions.
1 change: 1 addition & 0 deletions build/protobufs_concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Internal.protoText = function() {
module.exports = function protobuf() {
'use strict';
var dcodeIO = require('../build/dcodeIO.js');
// var protobufjs = require('protobufjs')

function loadProtoBufs(filename) {
return dcodeIO.loadProto(Internal.protoText['protos/' + filename]).build('textsecure');
Expand Down
44 changes: 25 additions & 19 deletions build/test_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34429,6 +34429,7 @@ Internal.protoText = function() {
module.exports = function protobuf() {
'use strict';
var dcodeIO = require('../build/dcodeIO.js');
// var protobufjs = require('protobufjs')

function loadProtoBufs(filename) {
return dcodeIO.loadProto(Internal.protoText['protos/' + filename]).build('textsecure');
Expand Down Expand Up @@ -59599,7 +59600,7 @@ module.exports={
"spec": ">=6.0.0 <7.0.0",
"type": "range"
},
"/home/ffff/Projects/signal-protocol/node_modules/browserify-sign"
"/Users/ffff/Projects/the-signal-protocol/node_modules/browserify-sign"
]
],
"_from": "elliptic@>=6.0.0 <7.0.0",
Expand Down Expand Up @@ -59634,7 +59635,7 @@ module.exports={
"_shasum": "e4c81e0829cf0a65ab70e998b8232723b5c1bc48",
"_shrinkwrap": null,
"_spec": "elliptic@^6.0.0",
"_where": "/home/ffff/Projects/signal-protocol/node_modules/browserify-sign",
"_where": "/Users/ffff/Projects/the-signal-protocol/node_modules/browserify-sign",
"author": {
"name": "Fedor Indutny",
"email": "fedor@indutny.com"
Expand Down Expand Up @@ -67859,7 +67860,7 @@ SessionBuilder.prototype = {
}.bind(this)).then(function() {
session = record.getSessionByBaseKey(message.baseKey);
if (session) {
console.log("Duplicate PreKeyMessage for session");
// console.log("Duplicate PreKeyMessage for session");
return;
}

Expand All @@ -67880,7 +67881,7 @@ SessionBuilder.prototype = {
record.archiveCurrentState();
}
if (message.preKeyId && !preKeyPair) {
console.log('Invalid prekey id', message.preKeyId);
// console.log('Invalid prekey id', message.preKeyId);
}
return this.initSession(false, preKeyPair, signedPreKeyPair,
message.identityKey.toArrayBuffer(),
Expand Down Expand Up @@ -68224,7 +68225,7 @@ SessionCipher.prototype = {
return Promise.reject(new Error("No session found to decrypt message from " + this.remoteAddress.toString()));
}
if (session.indexInfo.closed != -1) {
console.log('decrypting message for closed session');
// console.log('decrypting message for closed session');
}

return this.maybeStepRatchet(session, remoteEphemeralKey, message.previousCounter).then(function() {
Expand Down Expand Up @@ -68263,7 +68264,7 @@ SessionCipher.prototype = {
},
fillMessageKeys: function(chain, counter) {
if (Object.keys(chain.messageKeys).length >= 1000) {
console.log("Too many message keys for chain");
// console.log("Too many message keys for chain");
return Promise.resolve(); // Stalker, much?
}

Expand Down Expand Up @@ -68293,7 +68294,7 @@ SessionCipher.prototype = {
return Promise.resolve();
}

console.log('New remote ephemeral key');
// console.log('New remote ephemeral key');
var ratchet = session.currentRatchet;

return Promise.resolve().then(function() {
Expand Down Expand Up @@ -68521,7 +68522,7 @@ var SessionRecord = function() {
getSessionByBaseKey: function(baseKey) {
var session = this._sessions[util.toString(baseKey)];
if (session && session.indexInfo.baseKeyType === BaseKeyType.OURS) {
console.log("Tried to lookup a session using our basekey");
// console.log("Tried to lookup a session using our basekey");
return undefined;
}
return session;
Expand Down Expand Up @@ -68637,7 +68638,7 @@ var SessionRecord = function() {
if (session.indexInfo.closed > -1) {
return;
}
console.log('closing session', session.indexInfo.baseKey);
// console.log('closing session', session.indexInfo.baseKey);

// After this has run, we can still receive messages on ratchet chains which
// were already open (unless we know we dont need them),
Expand Down Expand Up @@ -68669,7 +68670,7 @@ var SessionRecord = function() {
index = i;
}
}
console.log("Deleting chain closed at", oldest.added);
// console.log("Deleting chain closed at", oldest.added);
delete session[util.toString(oldest.ephemeralKey)];
session.oldRatchetList.splice(index, 1);
}
Expand All @@ -68687,7 +68688,7 @@ var SessionRecord = function() {
oldestSession = session;
}
}
console.log("Deleting session closed at", oldestSession.indexInfo.closed);
// console.log("Deleting session closed at", oldestSession.indexInfo.closed);
delete sessions[util.toString(oldestBaseKey)];
}
},
Expand Down Expand Up @@ -68771,8 +68772,14 @@ myCrypto.crypto = {
return array.buffer;
},
encrypt: function(key, data, iv) {
return crypto.subtle.importKey('raw', key, {name: 'AES-CBC'}, false, ['encrypt']).then(function(key) {
return crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array(iv)}, key, data);
return crypto.subtle.importKey('raw', key, {
name: 'AES-CBC'
}, false, ['encrypt'])
.then(function(key) {
return crypto.subtle.encrypt({
name: 'AES-CBC',
iv: new Uint8Array(iv)
}, key, data);
});
},
decrypt: function(key, data, iv) {
Expand Down Expand Up @@ -68852,8 +68859,8 @@ myCrypto.verifyMAC = function(data, key, mac, length) {
result = result | (a[i] ^ b[i]);
}
if (result !== 0) {
console.log('Our MAC ', dcodeIO.ByteBuffer.wrap(calculated_mac).toHex());
console.log('Their MAC', dcodeIO.ByteBuffer.wrap(mac).toHex());
// console.log('Our MAC ', dcodeIO.ByteBuffer.wrap(calculated_mac).toHex());
// console.log('Their MAC', dcodeIO.ByteBuffer.wrap(mac).toHex());
throw new Error("Bad MAC");
}
});
Expand Down Expand Up @@ -69515,15 +69522,14 @@ describe('Integration test', function() {

it('can encrypt + decrypt a long message', function (done) {
bobAliceSessionCiphers()
.then(function ([ aliceSessionCipher, bobSessionCipher ]) {
// var plaintext = "Hello world";
.then(function (ciphers) {
var aliceSessionCipher = ciphers[0]
var bobSessionCipher = ciphers[1]
var plaintext = require('./long-plaintext.json').plaintext;
var b = new Buffer(plaintext, 'utf-8');
aliceSessionCipher.encrypt(b)
.then(c => bobSessionCipher.decryptPreKeyWhisperMessage(c.body, 'binary'))
.then(decodedPlaintext => {
console.log('expected', b, 'length', b.length)
console.log('decoded', new Buffer(decodedPlaintext))
assert.equal(plaintext,new Buffer(decodedPlaintext));
done();
}).catch(function (err) {
Expand Down
37 changes: 22 additions & 15 deletions dist/libsignal.js
Original file line number Diff line number Diff line change
Expand Up @@ -34429,6 +34429,7 @@ Internal.protoText = function() {
module.exports = function protobuf() {
'use strict';
var dcodeIO = require('../build/dcodeIO.js');
// var protobufjs = require('protobufjs')

function loadProtoBufs(filename) {
return dcodeIO.loadProto(Internal.protoText['protos/' + filename]).build('textsecure');
Expand Down Expand Up @@ -53593,7 +53594,7 @@ module.exports={
"spec": ">=6.0.0 <7.0.0",
"type": "range"
},
"/home/ffff/Projects/signal-protocol/node_modules/browserify-sign"
"/Users/ffff/Projects/the-signal-protocol/node_modules/browserify-sign"
]
],
"_from": "elliptic@>=6.0.0 <7.0.0",
Expand Down Expand Up @@ -53628,7 +53629,7 @@ module.exports={
"_shasum": "e4c81e0829cf0a65ab70e998b8232723b5c1bc48",
"_shrinkwrap": null,
"_spec": "elliptic@^6.0.0",
"_where": "/home/ffff/Projects/signal-protocol/node_modules/browserify-sign",
"_where": "/Users/ffff/Projects/the-signal-protocol/node_modules/browserify-sign",
"author": {
"name": "Fedor Indutny",
"email": "fedor@indutny.com"
Expand Down Expand Up @@ -61632,7 +61633,7 @@ SessionBuilder.prototype = {
}.bind(this)).then(function() {
session = record.getSessionByBaseKey(message.baseKey);
if (session) {
console.log("Duplicate PreKeyMessage for session");
// console.log("Duplicate PreKeyMessage for session");
return;
}

Expand All @@ -61653,7 +61654,7 @@ SessionBuilder.prototype = {
record.archiveCurrentState();
}
if (message.preKeyId && !preKeyPair) {
console.log('Invalid prekey id', message.preKeyId);
// console.log('Invalid prekey id', message.preKeyId);
}
return this.initSession(false, preKeyPair, signedPreKeyPair,
message.identityKey.toArrayBuffer(),
Expand Down Expand Up @@ -61997,7 +61998,7 @@ SessionCipher.prototype = {
return Promise.reject(new Error("No session found to decrypt message from " + this.remoteAddress.toString()));
}
if (session.indexInfo.closed != -1) {
console.log('decrypting message for closed session');
// console.log('decrypting message for closed session');
}

return this.maybeStepRatchet(session, remoteEphemeralKey, message.previousCounter).then(function() {
Expand Down Expand Up @@ -62036,7 +62037,7 @@ SessionCipher.prototype = {
},
fillMessageKeys: function(chain, counter) {
if (Object.keys(chain.messageKeys).length >= 1000) {
console.log("Too many message keys for chain");
// console.log("Too many message keys for chain");
return Promise.resolve(); // Stalker, much?
}

Expand Down Expand Up @@ -62066,7 +62067,7 @@ SessionCipher.prototype = {
return Promise.resolve();
}

console.log('New remote ephemeral key');
// console.log('New remote ephemeral key');
var ratchet = session.currentRatchet;

return Promise.resolve().then(function() {
Expand Down Expand Up @@ -62294,7 +62295,7 @@ var SessionRecord = function() {
getSessionByBaseKey: function(baseKey) {
var session = this._sessions[util.toString(baseKey)];
if (session && session.indexInfo.baseKeyType === BaseKeyType.OURS) {
console.log("Tried to lookup a session using our basekey");
// console.log("Tried to lookup a session using our basekey");
return undefined;
}
return session;
Expand Down Expand Up @@ -62410,7 +62411,7 @@ var SessionRecord = function() {
if (session.indexInfo.closed > -1) {
return;
}
console.log('closing session', session.indexInfo.baseKey);
// console.log('closing session', session.indexInfo.baseKey);

// After this has run, we can still receive messages on ratchet chains which
// were already open (unless we know we dont need them),
Expand Down Expand Up @@ -62442,7 +62443,7 @@ var SessionRecord = function() {
index = i;
}
}
console.log("Deleting chain closed at", oldest.added);
// console.log("Deleting chain closed at", oldest.added);
delete session[util.toString(oldest.ephemeralKey)];
session.oldRatchetList.splice(index, 1);
}
Expand All @@ -62460,7 +62461,7 @@ var SessionRecord = function() {
oldestSession = session;
}
}
console.log("Deleting session closed at", oldestSession.indexInfo.closed);
// console.log("Deleting session closed at", oldestSession.indexInfo.closed);
delete sessions[util.toString(oldestBaseKey)];
}
},
Expand Down Expand Up @@ -62544,8 +62545,14 @@ myCrypto.crypto = {
return array.buffer;
},
encrypt: function(key, data, iv) {
return crypto.subtle.importKey('raw', key, {name: 'AES-CBC'}, false, ['encrypt']).then(function(key) {
return crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array(iv)}, key, data);
return crypto.subtle.importKey('raw', key, {
name: 'AES-CBC'
}, false, ['encrypt'])
.then(function(key) {
return crypto.subtle.encrypt({
name: 'AES-CBC',
iv: new Uint8Array(iv)
}, key, data);
});
},
decrypt: function(key, data, iv) {
Expand Down Expand Up @@ -62625,8 +62632,8 @@ myCrypto.verifyMAC = function(data, key, mac, length) {
result = result | (a[i] ^ b[i]);
}
if (result !== 0) {
console.log('Our MAC ', dcodeIO.ByteBuffer.wrap(calculated_mac).toHex());
console.log('Their MAC', dcodeIO.ByteBuffer.wrap(mac).toHex());
// console.log('Our MAC ', dcodeIO.ByteBuffer.wrap(calculated_mac).toHex());
// console.log('Their MAC', dcodeIO.ByteBuffer.wrap(mac).toHex());
throw new Error("Bad MAC");
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/SessionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ SessionBuilder.prototype = {
}.bind(this)).then(function() {
session = record.getSessionByBaseKey(message.baseKey);
if (session) {
console.log("Duplicate PreKeyMessage for session");
// console.log("Duplicate PreKeyMessage for session");
return;
}

Expand All @@ -100,7 +100,7 @@ SessionBuilder.prototype = {
record.archiveCurrentState();
}
if (message.preKeyId && !preKeyPair) {
console.log('Invalid prekey id', message.preKeyId);
// console.log('Invalid prekey id', message.preKeyId);
}
return this.initSession(false, preKeyPair, signedPreKeyPair,
message.identityKey.toArrayBuffer(),
Expand Down
6 changes: 3 additions & 3 deletions src/SessionCipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ SessionCipher.prototype = {
return Promise.reject(new Error("No session found to decrypt message from " + this.remoteAddress.toString()));
}
if (session.indexInfo.closed != -1) {
console.log('decrypting message for closed session');
// console.log('decrypting message for closed session');
}

return this.maybeStepRatchet(session, remoteEphemeralKey, message.previousCounter).then(function() {
Expand Down Expand Up @@ -251,7 +251,7 @@ SessionCipher.prototype = {
},
fillMessageKeys: function(chain, counter) {
if (Object.keys(chain.messageKeys).length >= 1000) {
console.log("Too many message keys for chain");
// console.log("Too many message keys for chain");
return Promise.resolve(); // Stalker, much?
}

Expand Down Expand Up @@ -281,7 +281,7 @@ SessionCipher.prototype = {
return Promise.resolve();
}

console.log('New remote ephemeral key');
// console.log('New remote ephemeral key');
var ratchet = session.currentRatchet;

return Promise.resolve().then(function() {
Expand Down
8 changes: 4 additions & 4 deletions src/SessionRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var SessionRecord = function() {
getSessionByBaseKey: function(baseKey) {
var session = this._sessions[util.toString(baseKey)];
if (session && session.indexInfo.baseKeyType === BaseKeyType.OURS) {
console.log("Tried to lookup a session using our basekey");
// console.log("Tried to lookup a session using our basekey");
return undefined;
}
return session;
Expand Down Expand Up @@ -209,7 +209,7 @@ var SessionRecord = function() {
if (session.indexInfo.closed > -1) {
return;
}
console.log('closing session', session.indexInfo.baseKey);
// console.log('closing session', session.indexInfo.baseKey);

// After this has run, we can still receive messages on ratchet chains which
// were already open (unless we know we dont need them),
Expand Down Expand Up @@ -241,7 +241,7 @@ var SessionRecord = function() {
index = i;
}
}
console.log("Deleting chain closed at", oldest.added);
// console.log("Deleting chain closed at", oldest.added);
delete session[util.toString(oldest.ephemeralKey)];
session.oldRatchetList.splice(index, 1);
}
Expand All @@ -259,7 +259,7 @@ var SessionRecord = function() {
oldestSession = session;
}
}
console.log("Deleting session closed at", oldestSession.indexInfo.closed);
// console.log("Deleting session closed at", oldestSession.indexInfo.closed);
delete sessions[util.toString(oldestBaseKey)];
}
},
Expand Down
5 changes: 2 additions & 3 deletions src/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ myCrypto.crypto = {
return array.buffer;
},
encrypt: function(key, data, iv) {
// console.log('input data is', data)
return crypto.subtle.importKey('raw', key, {
name: 'AES-CBC'
}, false, ['encrypt'])
Expand Down Expand Up @@ -118,8 +117,8 @@ myCrypto.verifyMAC = function(data, key, mac, length) {
result = result | (a[i] ^ b[i]);
}
if (result !== 0) {
console.log('Our MAC ', dcodeIO.ByteBuffer.wrap(calculated_mac).toHex());
console.log('Their MAC', dcodeIO.ByteBuffer.wrap(mac).toHex());
// console.log('Our MAC ', dcodeIO.ByteBuffer.wrap(calculated_mac).toHex());
// console.log('Their MAC', dcodeIO.ByteBuffer.wrap(mac).toHex());
throw new Error("Bad MAC");
}
});
Expand Down
Loading

0 comments on commit 79f7037

Please sign in to comment.