Browse Source

Renamed stuff to "EndToEndEncryption".

pull/225/head
Joachim Bauch 11 years ago
parent
commit
c33d2cb416
  1. 20
      static/js/mediastream/api.js
  2. 4
      static/js/services/api.js
  3. 76
      static/js/services/endtoendencryption.js
  4. 6
      static/js/services/services.js

20
static/js/mediastream/api.js

@ -22,19 +22,19 @@ @@ -22,19 +22,19 @@
"use strict";
define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
var Api = function(version, connector, encryption) {
var Api = function(version, connector, endToEndEncryption) {
this.e = $({});
this.version = version;
this.id = null;
this.sid = null;
this.session = {};
this.connector = connector;
if (!encryption.initialize(this)) {
if (!endToEndEncryption.initialize(this)) {
console.warn("Encryption services failed to initialize");
this.encryption = null;
this.endToEndEncryption = null;
} else {
console.log("Encryption services initialized");
this.encryption = encryption;
this.endToEndEncryption = endToEndEncryption;
}
this.iids= 0;
@ -118,11 +118,11 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) { @@ -118,11 +118,11 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
Api.prototype.sendEncrypted = function(type, data, noqueue) {
var to = data.To;
if (!to || !this.encryption) {
if (!to || !this.endToEndEncryption) {
return this.send(type, data, noqueue);
}
this.encryption.encrypt(to, type, data, _.bind(function(type, encrypted) {
this.endToEndEncryption.encrypt(to, type, data, _.bind(function(type, encrypted) {
encrypted.To = to
this.send(type, encrypted, noqueue);
}, this));
@ -152,11 +152,11 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) { @@ -152,11 +152,11 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
if (!obj.hasOwnProperty("sendEncrypted")) {
obj.sendEncrypted = _.bind(function(type, data) {
var to = data.To;
if (!to || !this.encryption) {
if (!to || !this.endToEndEncryption) {
return obj.send(type, data, type, data);
}
this.encryption.encrypt(to, type, data, _.bind(function(encryptedType, encrypted) {
this.endToEndEncryption.encrypt(to, type, data, _.bind(function(encryptedType, encrypted) {
encrypted.To = to
encrypted.Type = encryptedType
obj.send(encryptedType, encrypted, type, data);
@ -190,11 +190,11 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) { @@ -190,11 +190,11 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
}
if (dataType === "Encrypted") {
if (!this.encryption) {
if (!this.endToEndEncryption) {
console.log("Encryption is not supported, can't handle", data);
return;
}
this.encryption.decrypt(d.From, data, _.bind(function(decrypted) {
this.endToEndEncryption.decrypt(d.From, data, _.bind(function(decrypted) {
this.processReceived(d, decrypted.Type, decrypted[decrypted.Type]);
}, this));
return;

4
static/js/services/api.js

@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
define([
'mediastream/api'
], function(Api) {
return ["globalContext", "connector", "encryption", function(context, connector, encryption) {
return new Api(context.Cfg.Version, connector, encryption);
return ["globalContext", "connector", "endToEndEncryption", function(context, connector, endToEndEncryption) {
return new Api(context.Cfg.Version, connector, endToEndEncryption);
}];
});

76
static/js/services/encryption.js → static/js/services/endtoendencryption.js

@ -115,13 +115,13 @@ define([ @@ -115,13 +115,13 @@ define([
return JSON.stringify(data);
};
var LocalStorageDataStore = function(encryption) {
var LocalStorageDataStore = function(endToEndEncryption) {
this.e = $({});
this.encryption = encryption;
this.endToEndEncryption = endToEndEncryption;
this.userid = null;
this.id = encryption.api.sid;
this.id = endToEndEncryption.api.sid;
this.anonymous_storage = {};
encryption.api.e.on("received.self", _.bind(function(event, data) {
endToEndEncryption.api.e.on("received.self", _.bind(function(event, data) {
var userid = data.Suserid || null;
if (this.id === (userid || data.Sid) && this.userid === userid) {
return;
@ -132,7 +132,7 @@ define([ @@ -132,7 +132,7 @@ define([
this.userid = userid;
this.anonymous_storage = {};
}
this.encryption.resetStore();
this.endToEndEncryption.resetStore();
if (initial) {
this.e.triggerHandler("ready");
}
@ -231,7 +231,7 @@ define([ @@ -231,7 +231,7 @@ define([
return this.save("signed_pre_key_" + this.id + "_" + key.id, data);
};
var Encryption = function(api) {
var EndToEndEncryption = function(api) {
this.e = $({});
this.api = api;
// TODO(fancycode): Look into using IndexedDB as storage backend.
@ -271,11 +271,11 @@ define([ @@ -271,11 +271,11 @@ define([
this.resetStore();
};
Encryption.prototype.isSupported = function() {
EndToEndEncryption.prototype.isSupported = function() {
return !!this.store;
};
Encryption.prototype.resetStore = function() {
EndToEndEncryption.prototype.resetStore = function() {
// TODO(fancycode): We should process any pending messages before
// resetting everything.
this.identity_keypair = null;
@ -292,11 +292,11 @@ define([ @@ -292,11 +292,11 @@ define([
}
};
Encryption.prototype.getIdentityFingerprint = function() {
EndToEndEncryption.prototype.getIdentityFingerprint = function() {
return this.formatIdentityFingerprint(this.identity_keypair.public);
};
Encryption.prototype.formatIdentityFingerprint = function(public_key) {
EndToEndEncryption.prototype.formatIdentityFingerprint = function(public_key) {
// TODO(jojo): Change this to be the SHA-1 hash of a three-byte key
// id and the public key.
// See https://github.com/WhisperSystems/TextSecure/blob/08ed90c5ece49c92e35c492afb4e60160983015a/src/org/thoughtcrime/securesms/crypto/PublicKey.java#L95
@ -309,7 +309,7 @@ define([ @@ -309,7 +309,7 @@ define([
return fingerprint.substr(2);
};
Encryption.prototype.storePeerIdentity = function(peer, public_key) {
EndToEndEncryption.prototype.storePeerIdentity = function(peer, public_key) {
var fingerprint = this.formatIdentityFingerprint(public_key);
var existing = this.peer_identities[peer];
if (existing === fingerprint) {
@ -324,7 +324,7 @@ define([ @@ -324,7 +324,7 @@ define([
this.peer_identities[peer] = fingerprint;
};
Encryption.prototype.getReadyPromise = function() {
EndToEndEncryption.prototype.getReadyPromise = function() {
if (!this.ready_promise) {
// Load/create initial objects
this.ready_promise = this.loadData().then(_.bind(function() {
@ -356,7 +356,7 @@ define([ @@ -356,7 +356,7 @@ define([
return this.ready_promise;
};
Encryption.prototype.loadData = function() {
EndToEndEncryption.prototype.loadData = function() {
var deferred = $q.defer();
var doLoadData = _.bind(function() {
this.identity_keypair = this.store.loadKeypair();
@ -378,7 +378,7 @@ define([ @@ -378,7 +378,7 @@ define([
return deferred.promise;
};
Encryption.prototype.getLocalIdentityKeyPair = function() {
EndToEndEncryption.prototype.getLocalIdentityKeyPair = function() {
var deferred = $q.defer();
_.defer(_.bind(function() {
if (this.identity_keypair) {
@ -398,7 +398,7 @@ define([ @@ -398,7 +398,7 @@ define([
return deferred.promise;
};
Encryption.prototype.getLocalRegistrationId = function() {
EndToEndEncryption.prototype.getLocalRegistrationId = function() {
var deferred = $q.defer();
_.defer(_.bind(function() {
if (this.registration_id) {
@ -417,7 +417,7 @@ define([ @@ -417,7 +417,7 @@ define([
return deferred.promise;
};
Encryption.prototype.getLastResortPreKey = function() {
EndToEndEncryption.prototype.getLastResortPreKey = function() {
var deferred = $q.defer();
_.defer(_.bind(function() {
if (this.last_resort_pre_key) {
@ -437,7 +437,7 @@ define([ @@ -437,7 +437,7 @@ define([
return deferred.promise;
};
Encryption.prototype.getLocalSignedPreKeyPair = function(id) {
EndToEndEncryption.prototype.getLocalSignedPreKeyPair = function(id) {
var deferred = $q.defer();
_.defer(_.bind(function() {
var signed_pre_key;
@ -451,7 +451,7 @@ define([ @@ -451,7 +451,7 @@ define([
return deferred.promise;
};
Encryption.prototype.getSignedPreKey = function(id) {
EndToEndEncryption.prototype.getSignedPreKey = function(id) {
if (!id) {
id = this.next_signed_pre_key_id;
this.next_signed_pre_key_id++;
@ -475,7 +475,7 @@ define([ @@ -475,7 +475,7 @@ define([
return deferred.promise;
};
Encryption.prototype.apiSend = function(type, message) {
EndToEndEncryption.prototype.apiSend = function(type, message) {
var msg = {
"Type": type
};
@ -483,7 +483,7 @@ define([ @@ -483,7 +483,7 @@ define([
this.api.send(type, message);
};
Encryption.prototype.register = function() {
EndToEndEncryption.prototype.register = function() {
this.getReadyPromise().then(_.bind(function() {
var message = {
"RegistrationId": this.registration_id,
@ -500,7 +500,7 @@ define([ @@ -500,7 +500,7 @@ define([
}, this));
};
Encryption.prototype.processPendingMessages = function(peer) {
EndToEndEncryption.prototype.processPendingMessages = function(peer) {
var pending = this.pending_messages[peer];
if (pending && pending.length > 0) {
var msg = pending.shift();
@ -526,7 +526,7 @@ define([ @@ -526,7 +526,7 @@ define([
}
};
Encryption.prototype.requestKeyBundle = function(peer) {
EndToEndEncryption.prototype.requestKeyBundle = function(peer) {
this.getSignedPreKey().then(_.bind(function(signed_pre_key) {
var bundle = {
"To": peer,
@ -543,7 +543,7 @@ define([ @@ -543,7 +543,7 @@ define([
}, this));
};
Encryption.prototype.receivedKeyBundle = function(peer, data) {
EndToEndEncryption.prototype.receivedKeyBundle = function(peer, data) {
var bundle = {
"identityKey": deserializePublicKey(data.Identity),
"preKeyId": null,
@ -571,7 +571,7 @@ define([ @@ -571,7 +571,7 @@ define([
}, this));
};
Encryption.prototype.encrypt = function(peer, type, message, callback) {
EndToEndEncryption.prototype.encrypt = function(peer, type, message, callback) {
var msg = {"Type": type};
msg[type] = message;
message = JSON.stringify(msg);
@ -599,7 +599,7 @@ define([ @@ -599,7 +599,7 @@ define([
this.encryptWithSession(peer, session, message, callback);
};
Encryption.prototype.encryptWithSession = function(
EndToEndEncryption.prototype.encryptWithSession = function(
peer, session, message, callback) {
var buffer = ByteBuffer.fromUTF8(message).toArrayBuffer();
// TODO(fancycode): Add error handling.
@ -617,7 +617,7 @@ define([ @@ -617,7 +617,7 @@ define([
}, this));
};
Encryption.prototype.decrypt = function(peer, message, callback) {
EndToEndEncryption.prototype.decrypt = function(peer, message, callback) {
if (this.is_processing_messages[peer]) {
this.pending_messages[peer].push({
"type": "decrypt",
@ -632,7 +632,7 @@ define([ @@ -632,7 +632,7 @@ define([
this.decryptWithSession(peer, session, message, callback);
};
Encryption.prototype.decryptWithSession = function(
EndToEndEncryption.prototype.decryptWithSession = function(
peer, session, message, callback) {
var handle_decrypted = _.bind(function(decrypted) {
if (decrypted.identityKey) {
@ -662,38 +662,38 @@ define([ @@ -662,38 +662,38 @@ define([
}
};
var encryption;
var endToEndEncryption;
// Only export limited public encryption API.
var encryptionApi = {
var endToEndEncryptionApi = {
"initialize": function(api) {
if (encryption) {
if (endToEndEncryption) {
return true;
}
encryption = new Encryption(api);
if (!encryption.isSupported()) {
encryption = null;
endToEndEncryption = new EndToEndEncryption(api);
if (!endToEndEncryption.isSupported()) {
endToEndEncryption = null;
return false;
}
return true;
},
"encrypt": function(peer, type, message, callback) {
if (!encryption) {
if (!endToEndEncryption) {
callback(type, message);
return;
}
encryption.encrypt(peer, type, message, callback);
endToEndEncryption.encrypt(peer, type, message, callback);
},
"decrypt": function(peer, message, callback) {
if (!encryption) {
if (!endToEndEncryption) {
callback(message);
return;
}
encryption.decrypt(peer, message, callback);
endToEndEncryption.decrypt(peer, message, callback);
}
};
return encryptionApi;
return endToEndEncryptionApi;
}];

6
static/js/services/services.js

@ -71,7 +71,7 @@ define([ @@ -71,7 +71,7 @@ define([
'services/sandbox',
'services/dummystream',
'services/usermedia',
'services/encryption'], function(_,
'services/endtoendencryption'], function(_,
desktopNotify,
playSound,
safeApply,
@ -120,7 +120,7 @@ mediaDevices, @@ -120,7 +120,7 @@ mediaDevices,
sandbox,
dummyStream,
userMedia,
encryption) {
endToEndEncryption) {
var services = {
desktopNotify: desktopNotify,
@ -171,7 +171,7 @@ encryption) { @@ -171,7 +171,7 @@ encryption) {
sandbox: sandbox,
dummyStream: dummyStream,
userMedia: userMedia,
encryption: encryption
endToEndEncryption: endToEndEncryption
};
var initialize = function(angModule) {

Loading…
Cancel
Save