Permalink
Browse files

namespace

  • Loading branch information...
1 parent f6ec569 commit dcbf9d51870a04f5388abe0d513e78af0c66b142 @arlolra committed Aug 25, 2012
Showing with 780 additions and 827 deletions.
  1. +571 −598 build/otr.js
  2. BIN build/otr.min.js
  3. +13 −12 grunt.js
  4. +4 −0 index.js
  5. +27 −32 lib/ake.js
  6. +8 −4 lib/{states.js → const.js}
  7. +0 −16 lib/dh.js
  8. +19 −21 lib/dsa.js
  9. +8 −10 lib/helpers.js
  10. +41 −42 lib/otr.js
  11. +17 −21 lib/parse.js
  12. +14 −17 lib/sm.js
  13. +1 −1 package.json
  14. +6 −1 readme.md
  15. +1 −1 test/browser.html
  16. +0 −1 test/spec/unit/data/keys.js
  17. +1 −1 test/spec/unit/dsa.js
  18. +21 −21 test/spec/unit/otr.js
  19. +22 −22 test/spec/unit/parse.js
  20. +5 −5 test/spec/unit/sm.js
  21. +1 −1 test/xmpp.js
View
1,169 build/otr.js

Large diffs are not rendered by default.

Oops, something went wrong.
View
Binary file not shown.
View
@@ -19,26 +19,27 @@ module.exports = function (grunt) {
pkg: '<json:package.json>'
, meta: {
banner:
- '/*!\n\n <%= pkg.name %>.js v<%= pkg.version %> - ' +
- '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
- ' (c) <%= grunt.template.today("yyyy") %> - <%= pkg.author %>\n' +
- ' Freely distributed under the <%= pkg.license %> license.\n\n' +
- ' This file is concatenated for the browser.\n' +
- ' Please see: <%= pkg.homepage %>' +
- '\n\n*/',
- cryptojs: 'module.exports = CryptoJS'
+ '/*!\n\n <%= pkg.name %>.js v<%= pkg.version %> - ' +
+ '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
+ ' (c) <%= grunt.template.today("yyyy") %> - <%= pkg.author %>\n' +
+ ' Freely distributed under the <%= pkg.license %> license.\n\n' +
+ ' This file is concatenated for the browser.\n' +
+ ' Please see: <%= pkg.homepage %>' +
+ '\n\n*/'
+ , cryptojs: 'module.exports = CryptoJS'
+ , globals: 'var OTR = {}, DSA = {}'
}
, concat: {
otr: {
src: [
'<banner:meta.banner>'
- , 'lib/dh.js'
- , 'lib/states.js'
+ , '<banner:meta.globals>'
+ , 'lib/const.js'
, 'lib/helpers.js'
, 'lib/dsa.js'
- , 'lib/sm.js'
- , 'lib/ake.js'
, 'lib/parse.js'
+ , 'lib/ake.js'
+ , 'lib/sm.js'
, 'lib/otr.js'
]
, dest: 'build/otr.js'
View
@@ -0,0 +1,4 @@
+module.exports = {
+ DSA: require('./lib/dsa.js')
+ , OTR: require('./lib/otr.js')
+}
View
@@ -2,32 +2,27 @@
var root = this
+ var CryptoJS, BigInt, CONST, HLP, DSA
if (typeof exports !== 'undefined') {
module.exports = AKE
+ CryptoJS = require('../vendor/crypto.js')
+ BigInt = require('../vendor/bigint.js')
+ CONST = require('./const.js')
+ HLP = require('./helpers.js')
+ DSA = require('./dsa.js')
} else {
- root.AKE = AKE
- }
-
- var CryptoJS = root.CryptoJS
- , BigInt = root.BigInt
- , DH = root.DH
- , HLP = root.HLP
- , DSA = root.DSA
- , STATES = root.STATES
-
- if (typeof require !== 'undefined') {
- CryptoJS || (CryptoJS = require('../vendor/crypto.js'))
- BigInt || (BigInt = require('../vendor/bigint.js'))
- DH || (DH = require('./dh.js'))
- HLP || (HLP = require('./helpers.js'))
- DSA || (DSA = require('./dsa.js'))
- STATES || (STATES = require('./states.js'))
+ root.OTR.AKE = AKE
+ CryptoJS = root.CryptoJS
+ BigInt = root.BigInt
+ CONST = root.OTR.CONST
+ HLP = root.OTR.HLP
+ DSA = root.DSA
}
// diffie-hellman modulus and generator
// see group 5, RFC 3526
- var G = BigInt.str2bigInt(DH.G, 10)
- var N = BigInt.str2bigInt(DH.N, 16)
+ var G = BigInt.str2bigInt(CONST.G, 10)
+ var N = BigInt.str2bigInt(CONST.N, 16)
var TWO = BigInt.str2bigInt('2', 10)
var N_MINUS_2 = BigInt.sub(N, TWO)
@@ -166,8 +161,8 @@
this.otr.smInit()
// go encrypted
- this.otr.authstate = STATES.AUTHSTATE_NONE
- this.otr.msgstate = STATES.MSGSTATE_ENCRYPTED
+ this.otr.authstate = CONST.AUTHSTATE_NONE
+ this.otr.msgstate = CONST.MSGSTATE_ENCRYPTED
// send stored msgs
this.otr.sendStored()
@@ -185,7 +180,7 @@
msg = HLP.splitype(['DATA', 'DATA'], msg.msg)
- if (this.otr.authstate === STATES.AUTHSTATE_AWAITING_DHKEY) {
+ if (this.otr.authstate === CONST.AUTHSTATE_AWAITING_DHKEY) {
var ourHash = HLP.readMPI(this.myhashed)
var theirHash = HLP.readMPI(msg[1])
if (BigInt.greater(ourHash, theirHash)) {
@@ -194,15 +189,15 @@
} else {
// forget
this.our_dh = this.otr.dh()
- this.otr.authstate = STATES.AUTHSTATE_NONE
+ this.otr.authstate = CONST.AUTHSTATE_NONE
this.r = null
this.myhashed = null
}
} else if (
- this.otr.authstate === STATES.AUTHSTATE_AWAITING_SIG
+ this.otr.authstate === CONST.AUTHSTATE_AWAITING_SIG
) this.our_dh = this.otr.dh()
- this.otr.authstate = STATES.AUTHSTATE_AWAITING_REVEALSIG
+ this.otr.authstate = CONST.AUTHSTATE_AWAITING_REVEALSIG
this.encrypted = msg[0].substring(4)
this.hashed = msg[1].substring(4)
@@ -218,15 +213,15 @@
msg = HLP.splitype(['MPI'], msg.msg)
- if (this.otr.authstate !== STATES.AUTHSTATE_AWAITING_DHKEY) {
- if (this.otr.authstate === STATES.AUTHSTATE_AWAITING_SIG) {
+ if (this.otr.authstate !== CONST.AUTHSTATE_AWAITING_DHKEY) {
+ if (this.otr.authstate === CONST.AUTHSTATE_AWAITING_SIG) {
if (!BigInt.equals(this.their_y, HLP.readMPI(msg[0]))) return
} else {
return // ignore
}
}
- this.otr.authstate = STATES.AUTHSTATE_AWAITING_SIG
+ this.otr.authstate = CONST.AUTHSTATE_AWAITING_SIG
this.their_y = HLP.readMPI(msg[0])
@@ -245,7 +240,7 @@
debug('signature message')
if ( !this.otr.ALLOW_V2 ||
- this.otr.authstate !== STATES.AUTHSTATE_AWAITING_REVEALSIG
+ this.otr.authstate !== CONST.AUTHSTATE_AWAITING_REVEALSIG
) return // ignore
msg = HLP.splitype(['DATA', 'DATA', 'MAC'], msg.msg)
@@ -303,7 +298,7 @@
debug('data message')
if ( !this.otr.ALLOW_V2 ||
- this.otr.authstate !== STATES.AUTHSTATE_AWAITING_SIG
+ this.otr.authstate !== CONST.AUTHSTATE_AWAITING_SIG
) return // ignore
msg = HLP.splitype(['DATA', 'MAC'], msg.msg)
@@ -337,7 +332,7 @@
},
sendMsg: function (msg) {
- msg = STATES.OTR_VERSION_2 + msg
+ msg = CONST.OTR_VERSION_2 + msg
msg = HLP.wrapMsg(msg, this.otr.fragment_size)
if (msg[0]) return this.otr.error(msg[0])
this.otr.sendMsg(msg[1], true)
@@ -349,7 +344,7 @@
// save in case we have to resend
this.dhcommit = '\x02'
- this.otr.authstate = STATES.AUTHSTATE_AWAITING_DHKEY
+ this.otr.authstate = CONST.AUTHSTATE_AWAITING_DHKEY
var gxmpi = HLP.packMPI(this.our_dh.publicKey)
@@ -2,10 +2,14 @@
var root = this
- var STATES = {
+ var CONST = {
+
+ // diffie-heilman
+ N : 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF'
+ , G : '2'
// otr message states
- MSGSTATE_PLAINTEXT : 0
+ , MSGSTATE_PLAINTEXT : 0
, MSGSTATE_ENCRYPTED : 1
, MSGSTATE_FINISHED : 2
@@ -26,9 +30,9 @@
}
if (typeof exports !== 'undefined') {
- module.exports = STATES
+ module.exports = CONST
} else {
- root.STATES = STATES
+ root.OTR.CONST = CONST
}
}).call(this)
View
@@ -1,16 +0,0 @@
-;(function () {
-
- var root = this
-
- var DH = {
- "N": "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF"
- , "G": "2"
- }
-
- if (typeof exports !== 'undefined') {
- module.exports = DH
- } else {
- root.DH = DH
- }
-
-}).call(this)
View
@@ -5,21 +5,21 @@
var root = this
- var DSA
+ var CryptoJS, BigInt, HLP
if (typeof exports !== 'undefined') {
- DSA = exports
+ module.exports = DSA
+ CryptoJS = require('../vendor/crypto.js')
+ BigInt = require('../vendor/bigint.js')
+ HLP = require('./helpers.js')
} else {
- DSA = root.DSA = {}
- }
-
- var BigInt = root.BigInt
- , CryptoJS = root.CryptoJS
- , HLP = root.HLP
-
- if (typeof require !== 'undefined') {
- BigInt || (BigInt = require('../vendor/bigint.js'))
- CryptoJS || (CryptoJS = require('../vendor/crypto.js'))
- HLP || (HLP = require('./helpers.js'))
+ // copy over and expose internals
+ Object.keys(root.DSA).forEach(function (k) {
+ DSA[k] = root.DSA[k]
+ })
+ root.DSA = DSA
+ CryptoJS = root.CryptoJS
+ BigInt = root.BigInt
+ HLP = DSA.HLP
}
var ZERO = BigInt.str2bigInt('0', 10)
@@ -52,10 +52,8 @@
return k
}
- DSA.Key = Key
-
- function Key() {
- if (!(this instanceof Key)) return new Key()
+ function DSA() {
+ if (!(this instanceof DSA)) return new DSA()
this.N = 160
this.L = 1024
@@ -69,9 +67,9 @@
this.y = BigInt.powMod(this.g, this.x, this.p)
}
- Key.prototype = {
+ DSA.prototype = {
- constructor: Key,
+ constructor: DSA,
makePQ: function() {
var g = this.N
@@ -217,8 +215,8 @@
}
DSA.inherit = function (key) {
- key.__proto__ = DSA.Key.prototype
- key.constructor = DSA.Key
+ key.__proto__ = DSA.prototype
+ key.constructor = DSA
key.type = '\x00\x00'
}
View
@@ -2,19 +2,17 @@
var root = this
- var HLP
+ var HLP, CryptoJS, BigInt
if (typeof exports !== 'undefined') {
HLP = exports
+ CryptoJS = require('../vendor/crypto.js')
+ BigInt = require('../vendor/bigint.js')
} else {
- HLP = root.HLP = {}
- }
-
- var BigInt = root.BigInt
- , CryptoJS = root.CryptoJS
-
- if (typeof require !== 'undefined') {
- BigInt || (BigInt = require('../vendor/bigint.js'))
- CryptoJS || (CryptoJS = require('../vendor/crypto.js'))
+ HLP = {}
+ if (root.OTR) root.OTR.HLP = HLP
+ if (root.DSA) root.DSA.HLP = HLP
+ CryptoJS = root.CryptoJS
+ BigInt = root.BigInt
}
// data types (byte lengths)
Oops, something went wrong.

0 comments on commit dcbf9d5

Please sign in to comment.