Commit 18ba56bc authored by JC Brand's avatar JC Brand

Remove duplicated crypto code and fixed crypto dependencies on non_amd.html page

parent f90fa641
......@@ -13,8 +13,8 @@
}
if (typeof define === 'function' && define.amd) {
define("converse", [
"crypto",
"otr",
"crypto.aes",
"locales",
"backbone.localStorage",
"jquery.tinysort",
......@@ -23,13 +23,13 @@
"strophe.roster",
"strophe.vcard",
"strophe.disco"
], function(otr, crypto) {
], function(CryptoJS, otr) {
// Use Mustache style syntax for variable interpolation
_.templateSettings = {
evaluate : /\{\[([\s\S]+?)\]\}/g,
interpolate : /\{\{([\s\S]+?)\}\}/g
};
return factory(jQuery, _, crypto, otr, console);
return factory(jQuery, _, CryptoJS, otr.OTR, otr.DSA, console);
}
);
} else {
......@@ -38,9 +38,9 @@
evaluate : /\{\[([\s\S]+?)\]\}/g,
interpolate : /\{\{([\s\S]+?)\}\}/g
};
root.converse = factory(jQuery, _, crypto, otr, console || {log: function(){}});
root.converse = factory(jQuery, _, CryptoJS, OTR, DSA, console || {log: function(){}});
}
}(this, function ($, _, crypto, otr, console) {
}(this, function ($, _, CryptoJS, OTR, DSA, console) {
var converse = {};
converse.initialize = function (settings, callback) {
var converse = this;
......@@ -447,14 +447,14 @@
// user alert is required here...
var saved_key = window.sessionStorage[hex_sha1(this.id+'priv_key')];
var instance_tag = window.sessionStorage[hex_sha1(this.id+'instance_tag')];
var cipher = crypto.lib.PasswordBasedCipher;
var cipher = CryptoJS.lib.PasswordBasedCipher;
var pass = converse.connection.pass;
var pass_check = this.get('pass_check');
var result, key;
if (saved_key && instance_tag && typeof pass_check !== 'undefined') {
var decrypted = cipher.decrypt(crypto.algo.AES, saved_key, pass);
key = otr.DSA.parsePrivate(decrypted.toString(crypto.enc.Latin1));
if (cipher.decrypt(crypto.algo.AES, pass_check, pass).toString(crypto.enc.Latin1) === 'match') {
var decrypted = cipher.decrypt(CryptoJS.algo.AES, saved_key, pass);
key = DSA.parsePrivate(decrypted.toString(CryptoJS.enc.Latin1));
if (cipher.decrypt(CryptoJS.algo.AES, pass_check, pass).toString(CryptoJS.enc.Latin1) === 'match') {
// Verified that the user's password is still the same
this.trigger('showHelpMessages', [__('Re-establishing encrypted session')]);
return {
......@@ -465,16 +465,16 @@
}
// We need to generate a new key and instance tag
result = alert(__('Your browser needs to generate a private key, which will be used in your encrypted chat session. This can take up to 30 seconds during which your browser might freeze and become unresponsive.'));
instance_tag = otr.OTR.makeInstanceTag();
key = new otr.DSA();
instance_tag = OTR.makeInstanceTag();
key = new DSA();
// Encrypt the key and set in sessionStorage. Also store
// instance tag
window.sessionStorage[hex_sha1(this.id+'priv_key')] =
cipher.encrypt(crypto.algo.AES, key.packPrivate(), pass).toString();
cipher.encrypt(CryptoJS.algo.AES, key.packPrivate(), pass).toString();
window.sessionStorage[hex_sha1(this.id+'instance_tag')] = instance_tag;
this.trigger('showHelpMessages', [__('Private key generated.')]);
this.save({'pass_check': cipher.encrypt(crypto.algo.AES, 'match', pass).toString()});
this.save({'pass_check': cipher.encrypt(CryptoJS.algo.AES, 'match', pass).toString()});
return {
'key': key,
'instance_tag': instance_tag
......@@ -483,15 +483,15 @@
updateOTRStatus: function (state) {
switch (state) {
case otr.OTR.CONST.STATUS_AKE_SUCCESS:
if (this.otr.msgstate === otr.OTR.CONST.MSGSTATE_ENCRYPTED) {
case OTR.CONST.STATUS_AKE_SUCCESS:
if (this.otr.msgstate === OTR.CONST.MSGSTATE_ENCRYPTED) {
this.save({'otr_status': UNVERIFIED});
}
break;
case otr.OTR.CONST.STATUS_END_OTR:
if (this.otr.msgstate === otr.OTR.CONST.MSGSTATE_FINISHED) {
case OTR.CONST.STATUS_END_OTR:
if (this.otr.msgstate === OTR.CONST.MSGSTATE_FINISHED) {
this.save({'otr_status': FINISHED});
} else if (this.otr.msgstate === otr.OTR.CONST.MSGSTATE_PLAINTEXT) {
} else if (this.otr.msgstate === OTR.CONST.MSGSTATE_PLAINTEXT) {
this.save({'otr_status': UNENCRYPTED});
}
break;
......@@ -532,7 +532,7 @@
// send the query message to them.
this.save({'otr_status': UNENCRYPTED});
var session = this.getSession();
this.otr = new otr.OTR({
this.otr = new OTR({
fragment_size: 140,
send_interval: 200,
priv: session.key,
......
;(function (root, factory) {
if (typeof define === "function" && define.amd) {
define([
"crypto.core",
"crypto.enc-base64",
"crypto.md5",
"crypto.evpkdf",
"crypto.cipher-core",
"crypto.aes",
"crypto.sha1",
"crypto.sha256",
"crypto.hmac",
"crypto.pad-nopadding",
"crypto.mode-ctr"
], function() {
return CryptoJS;
}
);
} else {
root.CryptoJS = factory();
}
}(this));
......@@ -11,12 +11,22 @@ require.config({
"strophe.roster": "components/strophe.roster/index",
"strophe.vcard": "components/strophe.vcard/index",
"strophe.disco": "components/strophe.disco/index",
"otr": "components/otr/build/otr",
"salsa20": "components/otr/build/dep/salsa20",
"bigint": "components/otr/build/dep/bigint",
"crypto": "components/otr/build/dep/crypto",
"crypto.core": "components/otr/vendor/cryptojs/core",
"crypto.enc-base64": "components/otr/vendor/cryptojs/enc-base64",
"crypto.md5": "components/crypto-js/src/md5",
"crypto.evpkdf": "components/crypto-js/src/evpkdf",
"crypto.cipher-core": "components/otr/vendor/cryptojs/cipher-core",
"crypto.aes": "components/otr/vendor/cryptojs/aes",
"crypto.sha1": "components/otr/vendor/cryptojs/sha1",
"crypto.sha256": "components/otr/vendor/cryptojs/sha256",
"crypto.hmac": "components/otr/vendor/cryptojs/hmac",
"crypto.pad-nopadding": "components/otr/vendor/cryptojs/pad-nopadding",
"crypto.mode-ctr": "components/otr/vendor/cryptojs/mode-ctr",
"crypto": "crypto",
"eventemitter": "components/otr/build/dep/eventemitter",
"salsa20": "components/otr/build/dep/salsa20",
"crypto.aes": "components/crypto-js/build/rollups/aes"
"otr": "components/otr/build/otr"
},
// define module dependencies for modules not using define
......
......@@ -8,6 +8,23 @@
<link rel="stylesheet" type="text/css" media="screen" href="converse.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="components/otr/build/dep/salsa20.js"></script>
<script type="text/javascript" src="components/otr/build/dep/bigint.js"></script>
<!-- CryptoJS -->
<script type="text/javascript" src="components/otr/vendor/cryptojs/core.js"></script>
<script type="text/javascript" src="components/otr/vendor/cryptojs/enc-base64.js"></script>
<script type="text/javascript" src="components/crypto-js/src/md5.js"></script>
<script type="text/javascript" src="components/crypto-js/src/evpkdf.js"></script>
<script type="text/javascript" src="components/otr/vendor/cryptojs/cipher-core.js"></script>
<script type="text/javascript" src="components/otr/vendor/cryptojs/aes.js"></script>
<script type="text/javascript" src="components/otr/vendor/cryptojs/sha1.js"></script>
<script type="text/javascript" src="components/otr/vendor/cryptojs/sha256.js"></script>
<script type="text/javascript" src="components/otr/vendor/cryptojs/hmac.js"></script>
<script type="text/javascript" src="components/otr/vendor/cryptojs/pad-nopadding.js"></script>
<script type="text/javascript" src="components/otr/vendor/cryptojs/mode-ctr.js"></script>
<!-- until here -->
<script type="text/javascript" src="components/otr/build/dep/eventemitter.js"></script>
<script type="text/javascript" src="components/otr/build/otr.js"></script>
<script type="text/javascript" src="components/strophe/strophe.js"></script>
<script type="text/javascript" src="components/strophe.roster/index.js"></script>
<script type="text/javascript" src="components/strophe.muc/index.js"></script>
......@@ -163,14 +180,7 @@
</footer>
</div>
<div id="conversejs">
<div id="collective-xmpp-chat-data"></div>
<div id="toggle-controlbox">
<a href="#" class="chat toggle-online-users">
<strong class="conn-feedback">Toggle chat</strong> <strong style="display: none" id="online-count">(0)</strong>
</a>
</div>
</div>
<div id="conversejs"></div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
......
......@@ -11,12 +11,22 @@ require.config({
"strophe.roster": "components/strophe.roster/index",
"strophe.vcard": "components/strophe.vcard/index",
"strophe.disco": "components/strophe.disco/index",
"otr": "components/otr/build/otr",
"salsa20": "components/otr/build/dep/salsa20",
"bigint": "components/otr/build/dep/bigint",
"crypto": "components/otr/build/dep/crypto",
"crypto.core": "components/otr/vendor/cryptojs/core",
"crypto.enc-base64": "components/otr/vendor/cryptojs/enc-base64",
"crypto.md5": "components/crypto-js/src/md5",
"crypto.evpkdf": "components/crypto-js/src/evpkdf",
"crypto.cipher-core": "components/otr/vendor/cryptojs/cipher-core",
"crypto.aes": "components/otr/vendor/cryptojs/aes",
"crypto.sha1": "components/otr/vendor/cryptojs/sha1",
"crypto.sha256": "components/otr/vendor/cryptojs/sha256",
"crypto.hmac": "components/otr/vendor/cryptojs/hmac",
"crypto.pad-nopadding": "components/otr/vendor/cryptojs/pad-nopadding",
"crypto.mode-ctr": "components/otr/vendor/cryptojs/mode-ctr",
"crypto": "crypto",
"eventemitter": "components/otr/build/dep/eventemitter",
"salsa20": "components/otr/build/dep/salsa20",
"crypto.aes": "components/crypto-js/build/rollups/aes",
"otr": "components/otr/build/otr",
// Extra test dependencies
"mock": "tests/mock",
"utils": "tests/utils",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment