Mercurial > sat_docs
annotate scripts/minifier/otr/otr.js @ 20:703a394b9780
script: dbus-launch script
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 21 Sep 2014 21:43:47 +0200 |
parents | 1596660ddf72 |
children |
rev | line source |
---|---|
12
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1 /*! |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 otr.js v0.2.12 - 2014-04-15 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 (c) 2014 - Arlo Breault <arlolra@gmail.com> |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 Freely distributed under the MPL v2.0 license. |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 This file is concatenated for the browser. |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 Please see: https://github.com/arlolra/otr |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 */ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 ;(function (root, factory) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 if (typeof define === 'function' && define.amd) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 define([ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 "bigint" |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 , "crypto" |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 , "eventemitter" |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 ], function (BigInt, CryptoJS, EventEmitter) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 var root = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 BigInt: BigInt |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 , CryptoJS: CryptoJS |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 , EventEmitter: EventEmitter |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 , OTR: {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 , DSA: {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 return factory.call(root) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 root.OTR = {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 root.DSA = {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 factory.call(root) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 }(this, function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
36 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 ;(function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 "use strict"; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 var root = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 var CONST = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 // diffie-heilman |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
45 N : 'FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 , G : '2' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 // otr message states |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 , MSGSTATE_PLAINTEXT : 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 , MSGSTATE_ENCRYPTED : 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
51 , MSGSTATE_FINISHED : 2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
53 // otr auth states |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
54 , AUTHSTATE_NONE : 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 , AUTHSTATE_AWAITING_DHKEY : 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 , AUTHSTATE_AWAITING_REVEALSIG : 2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 , AUTHSTATE_AWAITING_SIG : 3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 // whitespace tags |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 , WHITESPACE_TAG : '\x20\x09\x20\x20\x09\x09\x09\x09\x20\x09\x20\x09\x20\x09\x20\x20' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
61 , WHITESPACE_TAG_V2 : '\x20\x20\x09\x09\x20\x20\x09\x20' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 , WHITESPACE_TAG_V3 : '\x20\x20\x09\x09\x20\x20\x09\x09' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
64 // otr tags |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 , OTR_TAG : '?OTR' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 , OTR_VERSION_1 : '\x00\x01' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 , OTR_VERSION_2 : '\x00\x02' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
68 , OTR_VERSION_3 : '\x00\x03' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
70 // smp machine states |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 , SMPSTATE_EXPECT0 : 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 , SMPSTATE_EXPECT1 : 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 , SMPSTATE_EXPECT2 : 2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 , SMPSTATE_EXPECT3 : 3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 , SMPSTATE_EXPECT4 : 4 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 // unstandard status codes |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 , STATUS_SEND_QUERY : 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
79 , STATUS_AKE_INIT : 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
80 , STATUS_AKE_SUCCESS : 2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
81 , STATUS_END_OTR : 3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
82 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
83 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
84 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
85 if (typeof module !== 'undefined' && module.exports) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
86 module.exports = CONST |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
87 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
88 root.OTR.CONST = CONST |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
89 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
90 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
91 }).call(this) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 ;(function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
93 "use strict"; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
94 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
95 var root = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
96 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
97 var HLP = {}, CryptoJS, BigInt |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
98 if (typeof module !== 'undefined' && module.exports) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
99 module.exports = HLP = {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 CryptoJS = require('../vendor/crypto.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
101 BigInt = require('../vendor/bigint.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
103 if (root.OTR) root.OTR.HLP = HLP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 if (root.DSA) root.DSA.HLP = HLP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
105 CryptoJS = root.CryptoJS |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
106 BigInt = root.BigInt |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
107 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
108 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
109 // data types (byte lengths) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
110 var DTS = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 BYTE : 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
112 , SHORT : 2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
113 , INT : 4 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
114 , CTR : 8 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
115 , MAC : 20 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
116 , SIG : 40 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
117 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
118 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
119 // otr message wrapper begin and end |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
120 var WRAPPER_BEGIN = "?OTR" |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
121 , WRAPPER_END = "." |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
122 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
123 var TWO = BigInt.str2bigInt('2', 10) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
124 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
125 HLP.debug = function (msg) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
126 // used as HLP.debug.call(ctx, msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 if ( this.debug && |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
128 typeof this.debug !== 'function' && |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
129 typeof console !== 'undefined' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
130 ) console.log(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
131 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
132 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
133 HLP.extend = function (child, parent) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 for (var key in parent) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
135 if (Object.hasOwnProperty.call(parent, key)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
136 child[key] = parent[key] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
137 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 function Ctor() { this.constructor = child } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
139 Ctor.prototype = parent.prototype |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
140 child.prototype = new Ctor() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 child.__super__ = parent.prototype |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
142 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
143 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
144 // constant-time string comparison |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
145 HLP.compare = function (str1, str2) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 if (str1.length !== str2.length) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 return false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 var i = 0, result = 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 for (; i < str1.length; i++) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 result |= str1[i].charCodeAt(0) ^ str2[i].charCodeAt(0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
151 return result === 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
153 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 HLP.randomExponent = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
155 return BigInt.randBigInt(1536) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
156 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 HLP.smpHash = function (version, fmpi, smpi) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
159 var sha256 = CryptoJS.algo.SHA256.create() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
160 sha256.update(CryptoJS.enc.Latin1.parse(HLP.packBytes(version, DTS.BYTE))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
161 sha256.update(CryptoJS.enc.Latin1.parse(HLP.packMPI(fmpi))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
162 if (smpi) sha256.update(CryptoJS.enc.Latin1.parse(HLP.packMPI(smpi))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
163 var hash = sha256.finalize() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
164 return HLP.bits2bigInt(hash.toString(CryptoJS.enc.Latin1)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
165 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
167 HLP.makeMac = function (aesctr, m) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
168 var pass = CryptoJS.enc.Latin1.parse(m) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
169 var mac = CryptoJS.HmacSHA256(CryptoJS.enc.Latin1.parse(aesctr), pass) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
170 return HLP.mask(mac.toString(CryptoJS.enc.Latin1), 0, 160) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
171 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
172 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 HLP.make1Mac = function (aesctr, m) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 var pass = CryptoJS.enc.Latin1.parse(m) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 var mac = CryptoJS.HmacSHA1(CryptoJS.enc.Latin1.parse(aesctr), pass) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
176 return mac.toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
177 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
178 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 HLP.encryptAes = function (msg, c, iv) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
180 var opts = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
181 mode: CryptoJS.mode.CTR |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
182 , iv: CryptoJS.enc.Latin1.parse(iv) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
183 , padding: CryptoJS.pad.NoPadding |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
184 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
185 var aesctr = CryptoJS.AES.encrypt( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
186 msg |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
187 , CryptoJS.enc.Latin1.parse(c) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
188 , opts |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
189 ) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 var aesctr_decoded = CryptoJS.enc.Base64.parse(aesctr.toString()) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
191 return CryptoJS.enc.Latin1.stringify(aesctr_decoded) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
192 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
193 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 HLP.decryptAes = function (msg, c, iv) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
195 msg = CryptoJS.enc.Latin1.parse(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
196 var opts = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
197 mode: CryptoJS.mode.CTR |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
198 , iv: CryptoJS.enc.Latin1.parse(iv) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
199 , padding: CryptoJS.pad.NoPadding |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
200 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
201 return CryptoJS.AES.decrypt( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
202 CryptoJS.enc.Base64.stringify(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
203 , CryptoJS.enc.Latin1.parse(c) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
204 , opts |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
205 ) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
207 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 HLP.multPowMod = function (a, b, c, d, e) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
209 return BigInt.multMod(BigInt.powMod(a, b, e), BigInt.powMod(c, d, e), e) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
210 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
211 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
212 HLP.ZKP = function (v, c, d, e) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
213 return BigInt.equals(c, HLP.smpHash(v, d, e)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
214 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
215 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
216 // greater than, or equal |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 HLP.GTOE = function (a, b) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
218 return (BigInt.equals(a, b) || BigInt.greater(a, b)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
219 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
220 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
221 HLP.between = function (x, a, b) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
222 return (BigInt.greater(x, a) && BigInt.greater(b, x)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
223 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
224 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
225 HLP.checkGroup = function (g, N_MINUS_2) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
226 return HLP.GTOE(g, TWO) && HLP.GTOE(N_MINUS_2, g) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
228 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
229 HLP.h1 = function (b, secbytes) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 var sha1 = CryptoJS.algo.SHA1.create() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
231 sha1.update(CryptoJS.enc.Latin1.parse(b)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
232 sha1.update(CryptoJS.enc.Latin1.parse(secbytes)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
233 return (sha1.finalize()).toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
234 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
236 HLP.h2 = function (b, secbytes) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
237 var sha256 = CryptoJS.algo.SHA256.create() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
238 sha256.update(CryptoJS.enc.Latin1.parse(b)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
239 sha256.update(CryptoJS.enc.Latin1.parse(secbytes)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
240 return (sha256.finalize()).toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
241 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
242 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
243 HLP.mask = function (bytes, start, n) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
244 return bytes.substr(start / 8, n / 8) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
245 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
246 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
247 var _toString = String.fromCharCode; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
248 HLP.packBytes = function (val, bytes) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
249 val = val.toString(16) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
250 var nex, res = '' // big-endian, unsigned long |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 for (; bytes > 0; bytes--) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
252 nex = val.length ? val.substr(-2, 2) : '0' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
253 val = val.substr(0, val.length - 2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
254 res = _toString(parseInt(nex, 16)) + res |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
255 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
256 return res |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
257 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
258 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
259 HLP.packINT = function (d) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
260 return HLP.packBytes(d, DTS.INT) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
261 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
262 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
263 HLP.packCtr = function (d) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
264 return HLP.padCtr(HLP.packBytes(d, DTS.CTR)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
265 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
266 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
267 HLP.padCtr = function (ctr) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
268 return ctr + '\x00\x00\x00\x00\x00\x00\x00\x00' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
269 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
270 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
271 HLP.unpackCtr = function (d) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
272 d = HLP.toByteArray(d.substring(0, 8)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
273 return HLP.unpack(d) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
274 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
275 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
276 HLP.unpack = function (arr) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
277 var val = 0, i = 0, len = arr.length |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
278 for (; i < len; i++) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
279 val = (val * 256) + arr[i] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
280 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
281 return val |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
282 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
284 HLP.packData = function (d) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
285 return HLP.packINT(d.length) + d |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
286 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
287 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
288 HLP.bits2bigInt = function (bits) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
289 bits = HLP.toByteArray(bits) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
290 return BigInt.ba2bigInt(bits) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
291 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
292 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
293 HLP.packMPI = function (mpi) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
294 return HLP.packData(BigInt.bigInt2bits(BigInt.trim(mpi, 0))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
295 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
296 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
297 HLP.packSHORT = function (short) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
298 return HLP.packBytes(short, DTS.SHORT) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
299 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
300 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
301 HLP.unpackSHORT = function (short) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
302 short = HLP.toByteArray(short) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
303 return HLP.unpack(short) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
304 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
305 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
306 HLP.packTLV = function (type, value) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
307 return HLP.packSHORT(type) + HLP.packSHORT(value.length) + value |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
308 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
309 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
310 HLP.readLen = function (msg) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
311 msg = HLP.toByteArray(msg.substring(0, 4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
312 return HLP.unpack(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
313 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
314 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
315 HLP.readData = function (data) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
316 var n = HLP.unpack(data.splice(0, 4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
317 return [n, data] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
318 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
319 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
320 HLP.readMPI = function (data) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
321 data = HLP.toByteArray(data) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
322 data = HLP.readData(data) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
323 return BigInt.ba2bigInt(data[1]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
324 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
325 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
326 HLP.packMPIs = function (arr) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
327 return arr.reduce(function (prv, cur) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
328 return prv + HLP.packMPI(cur) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
329 }, '') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
330 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
331 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
332 HLP.unpackMPIs = function (num, mpis) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
333 var i = 0, arr = [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
334 for (; i < num; i++) arr.push('MPI') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
335 return (HLP.splitype(arr, mpis)).map(function (m) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
336 return HLP.readMPI(m) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
337 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
338 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
339 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
340 HLP.wrapMsg = function (msg, fs, v3, our_it, their_it) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
341 msg = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Latin1.parse(msg)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
342 msg = WRAPPER_BEGIN + ":" + msg + WRAPPER_END |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
343 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 var its |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
345 if (v3) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
346 its = '|' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
347 its += (HLP.readLen(our_it)).toString(16) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
348 its += '|' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
349 its += (HLP.readLen(their_it)).toString(16) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
350 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
351 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
352 if (!fs) return [null, msg] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
353 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 var n = Math.ceil(msg.length / fs) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
355 if (n > 65535) return ['Too many fragments'] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
356 if (n == 1) return [null, msg] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
357 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
358 var k, bi, ei, frag, mf, mfs = [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
359 for (k = 1; k <= n; k++) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
360 bi = (k - 1) * fs |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 ei = k * fs |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
362 frag = msg.slice(bi, ei) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
363 mf = WRAPPER_BEGIN |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
364 if (v3) mf += its |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
365 mf += ',' + k + ',' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
366 mf += n + ',' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
367 mf += frag + ',' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
368 mfs.push(mf) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
369 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
370 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
371 return [null, mfs] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
372 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
373 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
374 HLP.splitype = function splitype(arr, msg) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
375 var data = [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
376 arr.forEach(function (a) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
377 var str |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
378 switch (a) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
379 case 'PUBKEY': |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
380 str = splitype(['SHORT', 'MPI', 'MPI', 'MPI', 'MPI'], msg).join('') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
381 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
382 case 'DATA': // falls through |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
383 case 'MPI': |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
384 str = msg.substring(0, HLP.readLen(msg) + 4) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
385 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
386 default: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
387 str = msg.substring(0, DTS[a]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
388 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
389 data.push(str) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
390 msg = msg.substring(str.length) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
391 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
392 return data |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
393 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
394 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
395 // https://github.com/msgpack/msgpack-javascript/blob/master/msgpack.js |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
396 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
397 var _bin2num = (function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
398 var i = 0, _bin2num = {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
399 for (; i < 0x100; ++i) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
400 _bin2num[String.fromCharCode(i)] = i // "\00" -> 0x00 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
401 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
402 for (i = 0x80; i < 0x100; ++i) { // [Webkit][Gecko] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
403 _bin2num[String.fromCharCode(0xf700 + i)] = i // "\f780" -> 0x80 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
404 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
405 return _bin2num |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
406 }()) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
407 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
408 HLP.toByteArray = function (data) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
409 var rv = [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
410 , ary = data.split("") |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
411 , i = -1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
412 , iz = ary.length |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
413 , remain = iz % 8 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
414 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
415 while (remain--) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
416 ++i |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
417 rv[i] = _bin2num[ary[i]] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
418 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
419 remain = iz >> 3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
420 while (remain--) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
421 rv.push(_bin2num[ary[++i]], _bin2num[ary[++i]], |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
422 _bin2num[ary[++i]], _bin2num[ary[++i]], |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
423 _bin2num[ary[++i]], _bin2num[ary[++i]], |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
424 _bin2num[ary[++i]], _bin2num[ary[++i]]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
425 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
426 return rv |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
427 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
428 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
429 }).call(this) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
430 ;(function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
431 "use strict"; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
432 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
433 var root = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
434 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
435 var CryptoJS, BigInt, Worker, WWPath, HLP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
436 if (typeof module !== 'undefined' && module.exports) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
437 module.exports = DSA |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
438 CryptoJS = require('../vendor/crypto.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
439 BigInt = require('../vendor/bigint.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
440 WWPath = require('path').join(__dirname, '/dsa-webworker.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
441 HLP = require('./helpers.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
442 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
443 // copy over and expose internals |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
444 Object.keys(root.DSA).forEach(function (k) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
445 DSA[k] = root.DSA[k] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
446 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
447 root.DSA = DSA |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
448 CryptoJS = root.CryptoJS |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
449 BigInt = root.BigInt |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
450 Worker = root.Worker |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
451 WWPath = 'dsa-webworker.js' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
452 HLP = DSA.HLP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
453 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
454 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
455 var ZERO = BigInt.str2bigInt('0', 10) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
456 , ONE = BigInt.str2bigInt('1', 10) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
457 , TWO = BigInt.str2bigInt('2', 10) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
458 , KEY_TYPE = '\x00\x00' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
459 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
460 var DEBUG = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
461 function timer() { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
462 var start = (new Date()).getTime() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
463 return function (s) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
464 if (!DEBUG || typeof console === 'undefined') return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
465 var t = (new Date()).getTime() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
466 console.log(s + ': ' + (t - start)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
467 start = t |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
468 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
469 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
470 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
471 function makeRandom(min, max) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
472 var c = BigInt.randBigInt(BigInt.bitSize(max)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
473 if (!HLP.between(c, min, max)) return makeRandom(min, max) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
474 return c |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
475 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
476 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
477 // altered BigInt.randProbPrime() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
478 // n rounds of Miller Rabin (after trial division with small primes) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
479 var rpprb = [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
480 function isProbPrime(k, n) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
481 var i, B = 30000, l = BigInt.bitSize(k) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
482 var primes = BigInt.primes |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
483 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
484 if (primes.length === 0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
485 primes = BigInt.findPrimes(B) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
486 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
487 if (rpprb.length != k.length) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
488 rpprb = BigInt.dup(k) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
489 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
490 // check ans for divisibility by small primes up to B |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
491 for (i = 0; (i < primes.length) && (primes[i] <= B); i++) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
492 if (BigInt.modInt(k, primes[i]) === 0 && !BigInt.equalsInt(k, primes[i])) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
493 return 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
494 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
495 // do n rounds of Miller Rabin, with random bases less than k |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
496 for (i = 0; i < n; i++) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
497 BigInt.randBigInt_(rpprb, l, 0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
498 while(!BigInt.greater(k, rpprb)) // pick a random rpprb that's < k |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
499 BigInt.randBigInt_(rpprb, l, 0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
500 if (!BigInt.millerRabin(k, rpprb)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
501 return 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
502 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
503 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
504 return 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
505 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
506 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
507 var bit_lengths = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
508 '1024': { N: 160, repeat: 40 } // 40x should give 2^-80 confidence |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
509 , '2048': { N: 224, repeat: 56 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
510 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
511 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
512 var primes = {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
513 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
514 // follows go lang http://golang.org/src/pkg/crypto/dsa/dsa.go |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
515 // fips version was removed in 0c99af0df3e7 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
516 function generatePrimes(bit_length) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
517 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
518 var t = timer() // for debugging |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
519 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
520 // number of MR tests to perform |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
521 var repeat = bit_lengths[bit_length].repeat |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
522 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
523 var N = bit_lengths[bit_length].N |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
524 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
525 var LM1 = BigInt.twoToThe(bit_length - 1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
526 var bl4 = 4 * bit_length |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
527 var brk = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
528 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
529 var q, p, rem, counter |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
530 for (;;) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
531 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
532 q = BigInt.randBigInt(N, 1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
533 q[0] |= 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
534 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
535 if (!isProbPrime(q, repeat)) continue |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
536 t('q') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
537 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
538 for (counter = 0; counter < bl4; counter++) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
539 p = BigInt.randBigInt(bit_length, 1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
540 p[0] |= 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
541 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
542 rem = BigInt.mod(p, q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
543 rem = BigInt.sub(rem, ONE) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
544 p = BigInt.sub(p, rem) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
545 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
546 if (BigInt.greater(LM1, p)) continue |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
547 if (!isProbPrime(p, repeat)) continue |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
548 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
549 t('p') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
550 primes[bit_length] = { p: p, q: q } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
551 brk = true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
552 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
553 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
554 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
555 if (brk) break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
556 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
557 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
558 var h = BigInt.dup(TWO) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
559 var pm1 = BigInt.sub(p, ONE) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
560 var e = BigInt.multMod(pm1, BigInt.inverseMod(q, p), p) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
561 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
562 var g |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
563 for (;;) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
564 g = BigInt.powMod(h, e, p) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
565 if (BigInt.equals(g, ONE)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
566 h = BigInt.add(h, ONE) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
567 continue |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
568 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
569 primes[bit_length].g = g |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
570 t('g') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
571 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
572 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
573 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
574 throw new Error('Unreachable!') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
575 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
576 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
577 function DSA(obj, opts) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
578 if (!(this instanceof DSA)) return new DSA(obj, opts) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
579 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
580 // options |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
581 opts = opts || {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
582 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
583 // inherit |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
584 if (obj) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
585 var self = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
586 ;['p', 'q', 'g', 'y', 'x'].forEach(function (prop) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
587 self[prop] = obj[prop] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
588 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
589 this.type = obj.type || KEY_TYPE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
590 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
591 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
592 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
593 // default to 1024 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
594 var bit_length = parseInt(opts.bit_length ? opts.bit_length : 1024, 10) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
595 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
596 if (!bit_lengths[bit_length]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
597 throw new Error('Unsupported bit length.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
598 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
599 // set primes |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
600 if (!primes[bit_length]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
601 generatePrimes(bit_length) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
602 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
603 this.p = primes[bit_length].p |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
604 this.q = primes[bit_length].q |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
605 this.g = primes[bit_length].g |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
606 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
607 // key type |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
608 this.type = KEY_TYPE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
609 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
610 // private key |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
611 this.x = makeRandom(ZERO, this.q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
612 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
613 // public keys (p, q, g, y) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
614 this.y = BigInt.powMod(this.g, this.x, this.p) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
615 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
616 // nocache? |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
617 if (opts.nocache) primes[bit_length] = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
618 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
619 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
620 DSA.prototype = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
621 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
622 constructor: DSA, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
623 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
624 packPublic: function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
625 var str = this.type |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
626 str += HLP.packMPI(this.p) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
627 str += HLP.packMPI(this.q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
628 str += HLP.packMPI(this.g) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
629 str += HLP.packMPI(this.y) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
630 return str |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
631 }, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
632 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
633 packPrivate: function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
634 var str = this.packPublic() + HLP.packMPI(this.x) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
635 str = CryptoJS.enc.Latin1.parse(str) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
636 return str.toString(CryptoJS.enc.Base64) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
637 }, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
638 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
639 // http://www.imperialviolet.org/2013/06/15/suddendeathentropy.html |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
640 generateNonce: function (m) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
641 var priv = BigInt.bigInt2bits(BigInt.trim(this.x, 0)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
642 var rand = BigInt.bigInt2bits(BigInt.randBigInt(256)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
643 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
644 var sha256 = CryptoJS.algo.SHA256.create() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
645 sha256.update(CryptoJS.enc.Latin1.parse(priv)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
646 sha256.update(m) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
647 sha256.update(CryptoJS.enc.Latin1.parse(rand)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
648 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
649 var hash = sha256.finalize() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
650 hash = HLP.bits2bigInt(hash.toString(CryptoJS.enc.Latin1)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
651 BigInt.rightShift_(hash, 256 - BigInt.bitSize(this.q)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
652 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
653 return HLP.between(hash, ZERO, this.q) ? hash : this.generateNonce(m) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
654 }, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
655 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
656 sign: function (m) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
657 m = CryptoJS.enc.Latin1.parse(m) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
658 var b = BigInt.str2bigInt(m.toString(CryptoJS.enc.Hex), 16) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
659 var k, r = ZERO, s = ZERO |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
660 while (BigInt.isZero(s) || BigInt.isZero(r)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
661 k = this.generateNonce(m) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
662 r = BigInt.mod(BigInt.powMod(this.g, k, this.p), this.q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
663 if (BigInt.isZero(r)) continue |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
664 s = BigInt.inverseMod(k, this.q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
665 s = BigInt.mult(s, BigInt.add(b, BigInt.mult(this.x, r))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
666 s = BigInt.mod(s, this.q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
667 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
668 return [r, s] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
669 }, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
670 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
671 fingerprint: function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
672 var pk = this.packPublic() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
673 if (this.type === KEY_TYPE) pk = pk.substring(2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
674 pk = CryptoJS.enc.Latin1.parse(pk) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
675 return CryptoJS.SHA1(pk).toString(CryptoJS.enc.Hex) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
676 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
677 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
678 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
679 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
680 DSA.parsePublic = function (str, priv) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
681 var fields = ['SHORT', 'MPI', 'MPI', 'MPI', 'MPI'] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
682 if (priv) fields.push('MPI') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
683 str = HLP.splitype(fields, str) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
684 var obj = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
685 type: str[0] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
686 , p: HLP.readMPI(str[1]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
687 , q: HLP.readMPI(str[2]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
688 , g: HLP.readMPI(str[3]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
689 , y: HLP.readMPI(str[4]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
690 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
691 if (priv) obj.x = HLP.readMPI(str[5]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
692 return new DSA(obj) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
693 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
694 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
695 function tokenizeStr(str) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
696 var start, end |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
697 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
698 start = str.indexOf("(") |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
699 end = str.lastIndexOf(")") |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
700 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
701 if (start < 0 || end < 0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
702 throw new Error("Malformed S-Expression") |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
703 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
704 str = str.substring(start + 1, end) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
705 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
706 var splt = str.search(/\s/) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
707 var obj = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
708 type: str.substring(0, splt) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
709 , val: [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
710 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
711 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
712 str = str.substring(splt + 1, end) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
713 start = str.indexOf("(") |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
714 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
715 if (start < 0) obj.val.push(str) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
716 else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
717 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
718 var i, len, ss, es |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
719 while (start > -1) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
720 i = start + 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
721 len = str.length |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
722 for (ss = 1, es = 0; i < len && es < ss; i++) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
723 if (str[i] === "(") ss++ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
724 if (str[i] === ")") es++ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
725 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
726 obj.val.push(tokenizeStr(str.substring(start, ++i))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
727 str = str.substring(++i) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
728 start = str.indexOf("(") |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
729 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
730 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
731 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
732 return obj |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
733 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
734 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
735 function parseLibotr(obj) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
736 if (!obj.type) throw new Error("Parse error.") |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
737 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
738 var o, val |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
739 if (obj.type === "privkeys") { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
740 o = [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
741 obj.val.forEach(function (i) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
742 o.push(parseLibotr(i)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
743 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
744 return o |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
745 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
746 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
747 o = {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
748 obj.val.forEach(function (i) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
749 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
750 val = i.val[0] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
751 if (typeof val === "string") { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
752 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
753 if (val.indexOf("#") === 0) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
754 val = val.substring(1, val.lastIndexOf("#")) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
755 val = BigInt.str2bigInt(val, 16) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
756 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
757 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
758 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
759 val = parseLibotr(i) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
760 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
761 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
762 o[i.type] = val |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
763 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
764 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
765 return o |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
766 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
767 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
768 DSA.parsePrivate = function (str, libotr) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
769 if (!libotr) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
770 str = CryptoJS.enc.Base64.parse(str) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
771 str = str.toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
772 return DSA.parsePublic(str, true) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
773 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
774 // only returning the first key found |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
775 return parseLibotr(tokenizeStr(str))[0]["private-key"].dsa |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
776 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
777 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
778 DSA.verify = function (key, m, r, s) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
779 if (!HLP.between(r, ZERO, key.q) || !HLP.between(s, ZERO, key.q)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
780 return false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
781 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
782 var hm = CryptoJS.enc.Latin1.parse(m) // CryptoJS.SHA1(m) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
783 hm = BigInt.str2bigInt(hm.toString(CryptoJS.enc.Hex), 16) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
784 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
785 var w = BigInt.inverseMod(s, key.q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
786 var u1 = BigInt.multMod(hm, w, key.q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
787 var u2 = BigInt.multMod(r, w, key.q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
788 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
789 u1 = BigInt.powMod(key.g, u1, key.p) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
790 u2 = BigInt.powMod(key.y, u2, key.p) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
791 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
792 var v = BigInt.mod(BigInt.multMod(u1, u2, key.p), key.q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
793 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
794 return BigInt.equals(v, r) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
795 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
796 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
797 DSA.createInWebWorker = function (options, cb) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
798 var opts = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
799 path: WWPath |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
800 , seed: BigInt.getSeed |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
801 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
802 if (options && typeof options === 'object') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
803 Object.keys(options).forEach(function (k) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
804 opts[k] = options[k] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
805 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
806 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
807 // load optional dep. in node |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
808 if (typeof module !== 'undefined' && module.exports) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
809 Worker = require('webworker-threads').Worker |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
810 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
811 var worker = new Worker(opts.path) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
812 worker.onmessage = function (e) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
813 var data = e.data |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
814 switch (data.type) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
815 case "debug": |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
816 if (!DEBUG || typeof console === 'undefined') return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
817 console.log(data.val) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
818 break; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
819 case "data": |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
820 worker.terminate() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
821 cb(DSA.parsePrivate(data.val)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
822 break; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
823 default: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
824 throw new Error("Unrecognized type.") |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
825 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
826 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
827 worker.postMessage({ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
828 seed: opts.seed() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
829 , imports: opts.imports |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
830 , debug: DEBUG |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
831 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
832 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
833 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
834 }).call(this) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
835 ;(function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
836 "use strict"; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
837 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
838 var root = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
839 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
840 var Parse = {}, CryptoJS, CONST, HLP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
841 if (typeof module !== 'undefined' && module.exports) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
842 module.exports = Parse |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
843 CryptoJS = require('../vendor/crypto.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
844 CONST = require('./const.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
845 HLP = require('./helpers.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
846 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
847 root.OTR.Parse = Parse |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
848 CryptoJS = root.CryptoJS |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
849 CONST = root.OTR.CONST |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
850 HLP = root.OTR.HLP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
851 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
852 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
853 // whitespace tags |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
854 var tags = {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
855 tags[CONST.WHITESPACE_TAG_V2] = CONST.OTR_VERSION_2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
856 tags[CONST.WHITESPACE_TAG_V3] = CONST.OTR_VERSION_3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
857 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
858 Parse.parseMsg = function (otr, msg) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
859 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
860 var ver = [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
861 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
862 // is this otr? |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
863 var start = msg.indexOf(CONST.OTR_TAG) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
864 if (!~start) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
865 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
866 // restart fragments |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
867 this.initFragment(otr) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
868 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
869 // whitespace tags |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
870 ind = msg.indexOf(CONST.WHITESPACE_TAG) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
871 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
872 if (~ind) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
873 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
874 msg = msg.split('') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
875 msg.splice(ind, 16) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
876 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
877 var tag, len = msg.length |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
878 for (; ind < len;) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
879 tag = msg.slice(ind, ind + 8).join('') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
880 if (Object.hasOwnProperty.call(tags, tag)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
881 msg.splice(ind, 8) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
882 ver.push(tags[tag]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
883 continue |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
884 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
885 ind += 8 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
886 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
887 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
888 msg = msg.join('') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
889 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
890 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
891 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
892 return { msg: msg, ver: ver } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
893 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
894 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
895 var ind = start + CONST.OTR_TAG.length |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
896 var com = msg[ind] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
897 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
898 // message fragment |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
899 if (com === ',' || com === '|') { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
900 return this.msgFragment(otr, msg.substring(ind + 1), (com === '|')) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
901 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
902 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
903 this.initFragment(otr) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
904 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
905 // query message |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
906 if (~['?', 'v'].indexOf(com)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
907 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
908 // version 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
909 if (msg[ind] === '?') { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
910 ver.push(CONST.OTR_VERSION_1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
911 ind += 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
912 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
913 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
914 // other versions |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
915 var vers = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
916 '2': CONST.OTR_VERSION_2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
917 , '3': CONST.OTR_VERSION_3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
918 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
919 var qs = msg.substring(ind + 1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
920 var qi = qs.indexOf('?') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
921 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
922 if (qi >= 1) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
923 qs = qs.substring(0, qi).split('') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
924 if (msg[ind] === 'v') { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
925 qs.forEach(function (q) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
926 if (Object.hasOwnProperty.call(vers, q)) ver.push(vers[q]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
927 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
928 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
929 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
930 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
931 return { cls: 'query', ver: ver } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
932 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
933 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
934 // otr message |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
935 if (com === ':') { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
936 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
937 ind += 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
938 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
939 var info = msg.substring(ind, ind + 4) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
940 if (info.length < 4) return { msg: msg } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
941 info = CryptoJS.enc.Base64.parse(info).toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
942 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
943 var version = info.substring(0, 2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
944 var type = info.substring(2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
945 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
946 // supporting otr versions 2 and 3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
947 if (!otr['ALLOW_V' + HLP.unpackSHORT(version)]) return { msg: msg } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
948 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
949 ind += 4 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
950 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
951 var end = msg.substring(ind).indexOf('.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
952 if (!~end) return { msg: msg } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
953 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
954 msg = CryptoJS.enc.Base64.parse(msg.substring(ind, ind + end)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
955 msg = CryptoJS.enc.Latin1.stringify(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
956 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
957 // instance tags |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
958 var instance_tags |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
959 if (version === CONST.OTR_VERSION_3) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
960 instance_tags = msg.substring(0, 8) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
961 msg = msg.substring(8) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
962 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
963 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
964 var cls |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
965 if (~['\x02', '\x0a', '\x11', '\x12'].indexOf(type)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
966 cls = 'ake' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
967 } else if (type === '\x03') { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
968 cls = 'data' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
969 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
970 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
971 return { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
972 version: version |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
973 , type: type |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
974 , msg: msg |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
975 , cls: cls |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
976 , instance_tags: instance_tags |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
977 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
978 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
979 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
980 // error message |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
981 if (msg.substring(ind, ind + 7) === ' Error:') { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
982 if (otr.ERROR_START_AKE) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
983 otr.sendQueryMsg() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
984 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
985 return { msg: msg.substring(ind + 7), cls: 'error' } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
986 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
987 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
988 return { msg: msg } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
989 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
990 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
991 Parse.initFragment = function (otr) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
992 otr.fragment = { s: '', j: 0, k: 0 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
993 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
994 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
995 Parse.msgFragment = function (otr, msg, v3) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
996 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
997 msg = msg.split(',') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
998 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
999 // instance tags |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1000 if (v3) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1001 var its = msg.shift().split('|') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1002 var their_it = HLP.packINT(parseInt(its[0], 16)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1003 var our_it = HLP.packINT(parseInt(its[1], 16)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1004 if (otr.checkInstanceTags(their_it + our_it)) return // ignore |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1005 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1006 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1007 if (msg.length < 4 || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1008 isNaN(parseInt(msg[0], 10)) || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1009 isNaN(parseInt(msg[1], 10)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1010 ) return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1011 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1012 var k = parseInt(msg[0], 10) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1013 var n = parseInt(msg[1], 10) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1014 msg = msg[2] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1015 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1016 if (n < k || n === 0 || k === 0) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1017 this.initFragment(otr) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1018 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1019 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1020 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1021 if (k === 1) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1022 this.initFragment(otr) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1023 otr.fragment = { k: 1, n: n, s: msg } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1024 } else if (n === otr.fragment.n && k === (otr.fragment.k + 1)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1025 otr.fragment.s += msg |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1026 otr.fragment.k += 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1027 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1028 this.initFragment(otr) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1029 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1030 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1031 if (n === k) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1032 msg = otr.fragment.s |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1033 this.initFragment(otr) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1034 return this.parseMsg(otr, msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1035 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1036 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1037 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1038 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1039 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1040 }).call(this) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1041 ;(function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1042 "use strict"; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1043 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1044 var root = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1045 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1046 var CryptoJS, BigInt, CONST, HLP, DSA |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1047 if (typeof module !== 'undefined' && module.exports) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1048 module.exports = AKE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1049 CryptoJS = require('../vendor/crypto.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1050 BigInt = require('../vendor/bigint.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1051 CONST = require('./const.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1052 HLP = require('./helpers.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1053 DSA = require('./dsa.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1054 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1055 root.OTR.AKE = AKE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1056 CryptoJS = root.CryptoJS |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1057 BigInt = root.BigInt |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1058 CONST = root.OTR.CONST |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1059 HLP = root.OTR.HLP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1060 DSA = root.DSA |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1061 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1062 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1063 // diffie-hellman modulus |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1064 // see group 5, RFC 3526 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1065 var N = BigInt.str2bigInt(CONST.N, 16) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1066 var N_MINUS_2 = BigInt.sub(N, BigInt.str2bigInt('2', 10)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1067 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1068 function hMac(gx, gy, pk, kid, m) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1069 var pass = CryptoJS.enc.Latin1.parse(m) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1070 var hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, pass) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1071 hmac.update(CryptoJS.enc.Latin1.parse(HLP.packMPI(gx))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1072 hmac.update(CryptoJS.enc.Latin1.parse(HLP.packMPI(gy))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1073 hmac.update(CryptoJS.enc.Latin1.parse(pk)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1074 hmac.update(CryptoJS.enc.Latin1.parse(kid)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1075 return (hmac.finalize()).toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1076 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1077 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1078 // AKE constructor |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1079 function AKE(otr) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1080 if (!(this instanceof AKE)) return new AKE(otr) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1081 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1082 // otr instance |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1083 this.otr = otr |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1084 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1085 // our keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1086 this.our_dh = otr.our_old_dh |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1087 this.our_keyid = otr.our_keyid - 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1088 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1089 // their keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1090 this.their_y = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1091 this.their_keyid = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1092 this.their_priv_pk = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1093 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1094 // state |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1095 this.ssid = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1096 this.transmittedRS = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1097 this.r = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1098 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1099 // bind methods |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1100 var self = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1101 ;['sendMsg'].forEach(function (meth) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1102 self[meth] = self[meth].bind(self) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1103 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1104 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1105 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1106 AKE.prototype = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1107 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1108 constructor: AKE, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1109 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1110 createKeys: function(g) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1111 var s = BigInt.powMod(g, this.our_dh.privateKey, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1112 var secbytes = HLP.packMPI(s) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1113 this.ssid = HLP.mask(HLP.h2('\x00', secbytes), 0, 64) // first 64-bits |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1114 var tmp = HLP.h2('\x01', secbytes) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1115 this.c = HLP.mask(tmp, 0, 128) // first 128-bits |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1116 this.c_prime = HLP.mask(tmp, 128, 128) // second 128-bits |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1117 this.m1 = HLP.h2('\x02', secbytes) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1118 this.m2 = HLP.h2('\x03', secbytes) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1119 this.m1_prime = HLP.h2('\x04', secbytes) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1120 this.m2_prime = HLP.h2('\x05', secbytes) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1121 }, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1122 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1123 verifySignMac: function (mac, aesctr, m2, c, their_y, our_dh_pk, m1, ctr) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1124 // verify mac |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1125 var vmac = HLP.makeMac(aesctr, m2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1126 if (!HLP.compare(mac, vmac)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1127 return ['MACs do not match.'] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1128 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1129 // decrypt x |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1130 var x = HLP.decryptAes(aesctr.substring(4), c, ctr) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1131 x = HLP.splitype(['PUBKEY', 'INT', 'SIG'], x.toString(CryptoJS.enc.Latin1)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1132 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1133 var m = hMac(their_y, our_dh_pk, x[0], x[1], m1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1134 var pub = DSA.parsePublic(x[0]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1135 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1136 var r = HLP.bits2bigInt(x[2].substring(0, 20)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1137 var s = HLP.bits2bigInt(x[2].substring(20)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1138 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1139 // verify sign m |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1140 if (!DSA.verify(pub, m, r, s)) return ['Cannot verify signature of m.'] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1141 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1142 return [null, HLP.readLen(x[1]), pub] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1143 }, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1144 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1145 makeM: function (their_y, m1, c, m2) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1146 var pk = this.otr.priv.packPublic() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1147 var kid = HLP.packINT(this.our_keyid) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1148 var m = hMac(this.our_dh.publicKey, their_y, pk, kid, m1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1149 m = this.otr.priv.sign(m) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1150 var msg = pk + kid |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1151 msg += BigInt.bigInt2bits(m[0], 20) // pad to 20 bytes |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1152 msg += BigInt.bigInt2bits(m[1], 20) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1153 msg = CryptoJS.enc.Latin1.parse(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1154 var aesctr = HLP.packData(HLP.encryptAes(msg, c, HLP.packCtr(0))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1155 var mac = HLP.makeMac(aesctr, m2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1156 return aesctr + mac |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1157 }, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1158 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1159 akeSuccess: function (version) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1160 HLP.debug.call(this.otr, 'success') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1161 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1162 if (BigInt.equals(this.their_y, this.our_dh.publicKey)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1163 return this.otr.error('equal keys - we have a problem.', true) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1164 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1165 this.otr.our_old_dh = this.our_dh |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1166 this.otr.their_priv_pk = this.their_priv_pk |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1167 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1168 if (!( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1169 (this.their_keyid === this.otr.their_keyid && |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1170 BigInt.equals(this.their_y, this.otr.their_y)) || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1171 (this.their_keyid === (this.otr.their_keyid - 1) && |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1172 BigInt.equals(this.their_y, this.otr.their_old_y)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1173 )) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1174 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1175 this.otr.their_y = this.their_y |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1176 this.otr.their_old_y = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1177 this.otr.their_keyid = this.their_keyid |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1178 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1179 // rotate keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1180 this.otr.sessKeys[0] = [ new this.otr.DHSession( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1181 this.otr.our_dh |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1182 , this.otr.their_y |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1183 ), null ] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1184 this.otr.sessKeys[1] = [ new this.otr.DHSession( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1185 this.otr.our_old_dh |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1186 , this.otr.their_y |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1187 ), null ] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1188 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1189 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1190 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1191 // ake info |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1192 this.otr.ssid = this.ssid |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1193 this.otr.transmittedRS = this.transmittedRS |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1194 this.otr_version = version |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1195 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1196 // go encrypted |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1197 this.otr.authstate = CONST.AUTHSTATE_NONE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1198 this.otr.msgstate = CONST.MSGSTATE_ENCRYPTED |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1199 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1200 // null out values |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1201 this.r = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1202 this.myhashed = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1203 this.dhcommit = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1204 this.encrypted = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1205 this.hashed = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1206 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1207 this.otr.trigger('status', [CONST.STATUS_AKE_SUCCESS]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1208 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1209 // send stored msgs |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1210 this.otr.sendStored() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1211 }, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1212 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1213 handleAKE: function (msg) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1214 var send, vsm, type |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1215 var version = msg.version |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1216 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1217 switch (msg.type) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1218 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1219 case '\x02': |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1220 HLP.debug.call(this.otr, 'd-h key message') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1221 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1222 msg = HLP.splitype(['DATA', 'DATA'], msg.msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1223 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1224 if (this.otr.authstate === CONST.AUTHSTATE_AWAITING_DHKEY) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1225 var ourHash = HLP.readMPI(this.myhashed) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1226 var theirHash = HLP.readMPI(msg[1]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1227 if (BigInt.greater(ourHash, theirHash)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1228 type = '\x02' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1229 send = this.dhcommit |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1230 break // ignore |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1231 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1232 // forget |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1233 this.our_dh = this.otr.dh() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1234 this.otr.authstate = CONST.AUTHSTATE_NONE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1235 this.r = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1236 this.myhashed = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1237 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1238 } else if ( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1239 this.otr.authstate === CONST.AUTHSTATE_AWAITING_SIG |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1240 ) this.our_dh = this.otr.dh() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1241 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1242 this.otr.authstate = CONST.AUTHSTATE_AWAITING_REVEALSIG |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1243 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1244 this.encrypted = msg[0].substring(4) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1245 this.hashed = msg[1].substring(4) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1246 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1247 type = '\x0a' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1248 send = HLP.packMPI(this.our_dh.publicKey) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1249 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1250 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1251 case '\x0a': |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1252 HLP.debug.call(this.otr, 'reveal signature message') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1253 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1254 msg = HLP.splitype(['MPI'], msg.msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1255 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1256 if (this.otr.authstate !== CONST.AUTHSTATE_AWAITING_DHKEY) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1257 if (this.otr.authstate === CONST.AUTHSTATE_AWAITING_SIG) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1258 if (!BigInt.equals(this.their_y, HLP.readMPI(msg[0]))) return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1259 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1260 return // ignore |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1261 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1262 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1263 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1264 this.otr.authstate = CONST.AUTHSTATE_AWAITING_SIG |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1265 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1266 this.their_y = HLP.readMPI(msg[0]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1267 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1268 // verify gy is legal 2 <= gy <= N-2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1269 if (!HLP.checkGroup(this.their_y, N_MINUS_2)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1270 return this.otr.error('Illegal g^y.', true) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1271 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1272 this.createKeys(this.their_y) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1273 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1274 type = '\x11' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1275 send = HLP.packMPI(this.r) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1276 send += this.makeM(this.their_y, this.m1, this.c, this.m2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1277 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1278 this.m1 = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1279 this.m2 = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1280 this.c = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1281 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1282 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1283 case '\x11': |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1284 HLP.debug.call(this.otr, 'signature message') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1285 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1286 if (this.otr.authstate !== CONST.AUTHSTATE_AWAITING_REVEALSIG) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1287 return // ignore |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1288 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1289 msg = HLP.splitype(['DATA', 'DATA', 'MAC'], msg.msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1290 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1291 this.r = HLP.readMPI(msg[0]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1292 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1293 // decrypt their_y |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1294 var key = CryptoJS.enc.Hex.parse(BigInt.bigInt2str(this.r, 16)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1295 key = CryptoJS.enc.Latin1.stringify(key) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1296 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1297 var gxmpi = HLP.decryptAes(this.encrypted, key, HLP.packCtr(0)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1298 gxmpi = gxmpi.toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1299 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1300 this.their_y = HLP.readMPI(gxmpi) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1301 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1302 // verify hash |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1303 var hash = CryptoJS.SHA256(CryptoJS.enc.Latin1.parse(gxmpi)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1304 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1305 if (!HLP.compare(this.hashed, hash.toString(CryptoJS.enc.Latin1))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1306 return this.otr.error('Hashed g^x does not match.', true) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1307 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1308 // verify gx is legal 2 <= g^x <= N-2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1309 if (!HLP.checkGroup(this.their_y, N_MINUS_2)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1310 return this.otr.error('Illegal g^x.', true) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1311 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1312 this.createKeys(this.their_y) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1313 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1314 vsm = this.verifySignMac( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1315 msg[2] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1316 , msg[1] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1317 , this.m2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1318 , this.c |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1319 , this.their_y |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1320 , this.our_dh.publicKey |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1321 , this.m1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1322 , HLP.packCtr(0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1323 ) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1324 if (vsm[0]) return this.otr.error(vsm[0], true) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1325 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1326 // store their key |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1327 this.their_keyid = vsm[1] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1328 this.their_priv_pk = vsm[2] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1329 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1330 send = this.makeM( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1331 this.their_y |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1332 , this.m1_prime |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1333 , this.c_prime |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1334 , this.m2_prime |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1335 ) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1336 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1337 this.m1 = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1338 this.m2 = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1339 this.m1_prime = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1340 this.m2_prime = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1341 this.c = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1342 this.c_prime = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1343 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1344 this.sendMsg(version, '\x12', send) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1345 this.akeSuccess(version) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1346 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1347 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1348 case '\x12': |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1349 HLP.debug.call(this.otr, 'data message') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1350 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1351 if (this.otr.authstate !== CONST.AUTHSTATE_AWAITING_SIG) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1352 return // ignore |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1353 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1354 msg = HLP.splitype(['DATA', 'MAC'], msg.msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1355 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1356 vsm = this.verifySignMac( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1357 msg[1] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1358 , msg[0] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1359 , this.m2_prime |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1360 , this.c_prime |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1361 , this.their_y |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1362 , this.our_dh.publicKey |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1363 , this.m1_prime |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1364 , HLP.packCtr(0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1365 ) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1366 if (vsm[0]) return this.otr.error(vsm[0], true) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1367 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1368 // store their key |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1369 this.their_keyid = vsm[1] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1370 this.their_priv_pk = vsm[2] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1371 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1372 this.m1_prime = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1373 this.m2_prime = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1374 this.c_prime = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1375 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1376 this.transmittedRS = true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1377 this.akeSuccess(version) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1378 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1379 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1380 default: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1381 return // ignore |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1382 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1383 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1384 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1385 this.sendMsg(version, type, send) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1386 }, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1387 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1388 sendMsg: function (version, type, msg) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1389 var send = version + type |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1390 var v3 = (version === CONST.OTR_VERSION_3) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1391 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1392 // instance tags for v3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1393 if (v3) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1394 HLP.debug.call(this.otr, 'instance tags') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1395 send += this.otr.our_instance_tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1396 send += this.otr.their_instance_tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1397 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1398 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1399 send += msg |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1400 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1401 // fragment message if necessary |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1402 send = HLP.wrapMsg( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1403 send |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1404 , this.otr.fragment_size |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1405 , v3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1406 , this.otr.our_instance_tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1407 , this.otr.their_instance_tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1408 ) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1409 if (send[0]) return this.otr.error(send[0]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1410 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1411 this.otr.io(send[1]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1412 }, |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1413 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1414 initiateAKE: function (version) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1415 HLP.debug.call(this.otr, 'd-h commit message') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1416 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1417 this.otr.trigger('status', [CONST.STATUS_AKE_INIT]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1418 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1419 this.otr.authstate = CONST.AUTHSTATE_AWAITING_DHKEY |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1420 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1421 var gxmpi = HLP.packMPI(this.our_dh.publicKey) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1422 gxmpi = CryptoJS.enc.Latin1.parse(gxmpi) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1423 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1424 this.r = BigInt.randBigInt(128) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1425 var key = CryptoJS.enc.Hex.parse(BigInt.bigInt2str(this.r, 16)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1426 key = CryptoJS.enc.Latin1.stringify(key) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1427 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1428 this.myhashed = CryptoJS.SHA256(gxmpi) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1429 this.myhashed = HLP.packData(this.myhashed.toString(CryptoJS.enc.Latin1)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1430 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1431 this.dhcommit = HLP.packData(HLP.encryptAes(gxmpi, key, HLP.packCtr(0))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1432 this.dhcommit += this.myhashed |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1433 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1434 this.sendMsg(version, '\x02', this.dhcommit) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1435 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1436 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1437 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1438 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1439 }).call(this) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1440 ;(function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1441 "use strict"; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1442 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1443 var root = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1444 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1445 var CryptoJS, BigInt, EventEmitter, CONST, HLP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1446 if (typeof module !== 'undefined' && module.exports) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1447 module.exports = SM |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1448 CryptoJS = require('../vendor/crypto.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1449 BigInt = require('../vendor/bigint.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1450 EventEmitter = require('../vendor/eventemitter.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1451 CONST = require('./const.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1452 HLP = require('./helpers.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1453 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1454 root.OTR.SM = SM |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1455 CryptoJS = root.CryptoJS |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1456 BigInt = root.BigInt |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1457 EventEmitter = root.EventEmitter |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1458 CONST = root.OTR.CONST |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1459 HLP = root.OTR.HLP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1460 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1461 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1462 // diffie-hellman modulus and generator |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1463 // see group 5, RFC 3526 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1464 var G = BigInt.str2bigInt(CONST.G, 10) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1465 var N = BigInt.str2bigInt(CONST.N, 16) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1466 var N_MINUS_2 = BigInt.sub(N, BigInt.str2bigInt('2', 10)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1467 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1468 // to calculate D's for zero-knowledge proofs |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1469 var Q = BigInt.sub(N, BigInt.str2bigInt('1', 10)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1470 BigInt.divInt_(Q, 2) // meh |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1471 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1472 function SM(reqs) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1473 if (!(this instanceof SM)) return new SM(reqs) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1474 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1475 this.version = 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1476 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1477 this.our_fp = reqs.our_fp |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1478 this.their_fp = reqs.their_fp |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1479 this.ssid = reqs.ssid |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1480 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1481 this.debug = !!reqs.debug |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1482 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1483 // initial state |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1484 this.init() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1485 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1486 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1487 // inherit from EE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1488 HLP.extend(SM, EventEmitter) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1489 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1490 // set the initial values |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1491 // also used when aborting |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1492 SM.prototype.init = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1493 this.smpstate = CONST.SMPSTATE_EXPECT1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1494 this.secret = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1495 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1496 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1497 SM.prototype.makeSecret = function (our, secret) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1498 var sha256 = CryptoJS.algo.SHA256.create() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1499 sha256.update(CryptoJS.enc.Latin1.parse(HLP.packBytes(this.version, 1))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1500 sha256.update(CryptoJS.enc.Hex.parse(our ? this.our_fp : this.their_fp)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1501 sha256.update(CryptoJS.enc.Hex.parse(our ? this.their_fp : this.our_fp)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1502 sha256.update(CryptoJS.enc.Latin1.parse(this.ssid)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1503 sha256.update(CryptoJS.enc.Latin1.parse(secret)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1504 var hash = sha256.finalize() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1505 this.secret = HLP.bits2bigInt(hash.toString(CryptoJS.enc.Latin1)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1506 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1507 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1508 SM.prototype.makeG2s = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1509 this.a2 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1510 this.a3 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1511 this.g2a = BigInt.powMod(G, this.a2, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1512 this.g3a = BigInt.powMod(G, this.a3, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1513 if ( !HLP.checkGroup(this.g2a, N_MINUS_2) || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1514 !HLP.checkGroup(this.g3a, N_MINUS_2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1515 ) this.makeG2s() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1516 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1517 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1518 SM.prototype.computeGs = function (g2a, g3a) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1519 this.g2 = BigInt.powMod(g2a, this.a2, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1520 this.g3 = BigInt.powMod(g3a, this.a3, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1521 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1522 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1523 SM.prototype.computePQ = function (r) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1524 this.p = BigInt.powMod(this.g3, r, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1525 this.q = HLP.multPowMod(G, r, this.g2, this.secret, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1526 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1527 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1528 SM.prototype.computeR = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1529 this.r = BigInt.powMod(this.QoQ, this.a3, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1530 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1531 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1532 SM.prototype.computeRab = function (r) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1533 return BigInt.powMod(r, this.a3, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1534 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1535 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1536 SM.prototype.computeC = function (v, r) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1537 return HLP.smpHash(v, BigInt.powMod(G, r, N)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1538 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1539 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1540 SM.prototype.computeD = function (r, a, c) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1541 return BigInt.subMod(r, BigInt.multMod(a, c, Q), Q) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1542 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1543 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1544 // the bulk of the work |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1545 SM.prototype.handleSM = function (msg) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1546 var send, r2, r3, r7, t1, t2, t3, t4, rab, tmp2, cR, d7, ms, trust |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1547 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1548 var expectStates = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1549 2: CONST.SMPSTATE_EXPECT1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1550 , 3: CONST.SMPSTATE_EXPECT2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1551 , 4: CONST.SMPSTATE_EXPECT3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1552 , 5: CONST.SMPSTATE_EXPECT4 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1553 , 7: CONST.SMPSTATE_EXPECT1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1554 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1555 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1556 if (msg.type === 6) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1557 this.init() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1558 this.trigger('abort') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1559 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1560 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1561 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1562 // abort! there was an error |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1563 if (this.smpstate !== expectStates[msg.type]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1564 return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1565 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1566 switch (this.smpstate) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1567 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1568 case CONST.SMPSTATE_EXPECT1: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1569 HLP.debug.call(this, 'smp tlv 2') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1570 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1571 // user specified question |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1572 var ind, question |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1573 if (msg.type === 7) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1574 ind = msg.msg.indexOf('\x00') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1575 question = msg.msg.substring(0, ind) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1576 msg.msg = msg.msg.substring(ind + 1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1577 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1578 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1579 // 0:g2a, 1:c2, 2:d2, 3:g3a, 4:c3, 5:d3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1580 ms = HLP.readLen(msg.msg.substr(0, 4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1581 if (ms !== 6) return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1582 msg = HLP.unpackMPIs(6, msg.msg.substring(4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1583 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1584 if ( !HLP.checkGroup(msg[0], N_MINUS_2) || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1585 !HLP.checkGroup(msg[3], N_MINUS_2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1586 ) return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1587 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1588 // verify znp's |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1589 if (!HLP.ZKP(1, msg[1], HLP.multPowMod(G, msg[2], msg[0], msg[1], N))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1590 return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1591 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1592 if (!HLP.ZKP(2, msg[4], HLP.multPowMod(G, msg[5], msg[3], msg[4], N))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1593 return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1594 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1595 this.g3ao = msg[3] // save for later |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1596 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1597 this.makeG2s() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1598 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1599 // zero-knowledge proof that the exponents |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1600 // associated with g2a & g3a are known |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1601 r2 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1602 r3 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1603 this.c2 = this.computeC(3, r2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1604 this.c3 = this.computeC(4, r3) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1605 this.d2 = this.computeD(r2, this.a2, this.c2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1606 this.d3 = this.computeD(r3, this.a3, this.c3) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1607 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1608 this.computeGs(msg[0], msg[3]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1609 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1610 this.smpstate = CONST.SMPSTATE_EXPECT0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1611 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1612 // assume utf8 question |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1613 question = CryptoJS.enc.Latin1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1614 .parse(question) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1615 .toString(CryptoJS.enc.Utf8) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1616 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1617 // invoke question |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1618 this.trigger('question', [question]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1619 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1620 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1621 case CONST.SMPSTATE_EXPECT2: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1622 HLP.debug.call(this, 'smp tlv 3') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1623 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1624 // 0:g2a, 1:c2, 2:d2, 3:g3a, 4:c3, 5:d3, 6:p, 7:q, 8:cP, 9:d5, 10:d6 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1625 ms = HLP.readLen(msg.msg.substr(0, 4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1626 if (ms !== 11) return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1627 msg = HLP.unpackMPIs(11, msg.msg.substring(4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1628 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1629 if ( !HLP.checkGroup(msg[0], N_MINUS_2) || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1630 !HLP.checkGroup(msg[3], N_MINUS_2) || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1631 !HLP.checkGroup(msg[6], N_MINUS_2) || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1632 !HLP.checkGroup(msg[7], N_MINUS_2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1633 ) return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1634 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1635 // verify znp of c3 / c3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1636 if (!HLP.ZKP(3, msg[1], HLP.multPowMod(G, msg[2], msg[0], msg[1], N))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1637 return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1638 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1639 if (!HLP.ZKP(4, msg[4], HLP.multPowMod(G, msg[5], msg[3], msg[4], N))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1640 return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1641 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1642 this.g3ao = msg[3] // save for later |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1643 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1644 this.computeGs(msg[0], msg[3]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1645 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1646 // verify znp of cP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1647 t1 = HLP.multPowMod(this.g3, msg[9], msg[6], msg[8], N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1648 t2 = HLP.multPowMod(G, msg[9], this.g2, msg[10], N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1649 t2 = BigInt.multMod(t2, BigInt.powMod(msg[7], msg[8], N), N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1650 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1651 if (!HLP.ZKP(5, msg[8], t1, t2)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1652 return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1653 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1654 var r4 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1655 this.computePQ(r4) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1656 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1657 // zero-knowledge proof that P & Q |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1658 // were generated according to the protocol |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1659 var r5 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1660 var r6 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1661 var tmp = HLP.multPowMod(G, r5, this.g2, r6, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1662 var cP = HLP.smpHash(6, BigInt.powMod(this.g3, r5, N), tmp) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1663 var d5 = this.computeD(r5, r4, cP) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1664 var d6 = this.computeD(r6, this.secret, cP) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1665 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1666 // store these |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1667 this.QoQ = BigInt.divMod(this.q, msg[7], N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1668 this.PoP = BigInt.divMod(this.p, msg[6], N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1669 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1670 this.computeR() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1671 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1672 // zero-knowledge proof that R |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1673 // was generated according to the protocol |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1674 r7 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1675 tmp2 = BigInt.powMod(this.QoQ, r7, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1676 cR = HLP.smpHash(7, BigInt.powMod(G, r7, N), tmp2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1677 d7 = this.computeD(r7, this.a3, cR) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1678 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1679 this.smpstate = CONST.SMPSTATE_EXPECT4 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1680 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1681 send = HLP.packINT(8) + HLP.packMPIs([ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1682 this.p |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1683 , this.q |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1684 , cP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1685 , d5 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1686 , d6 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1687 , this.r |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1688 , cR |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1689 , d7 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1690 ]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1691 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1692 // TLV |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1693 send = HLP.packTLV(4, send) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1694 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1695 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1696 case CONST.SMPSTATE_EXPECT3: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1697 HLP.debug.call(this, 'smp tlv 4') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1698 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1699 // 0:p, 1:q, 2:cP, 3:d5, 4:d6, 5:r, 6:cR, 7:d7 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1700 ms = HLP.readLen(msg.msg.substr(0, 4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1701 if (ms !== 8) return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1702 msg = HLP.unpackMPIs(8, msg.msg.substring(4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1703 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1704 if ( !HLP.checkGroup(msg[0], N_MINUS_2) || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1705 !HLP.checkGroup(msg[1], N_MINUS_2) || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1706 !HLP.checkGroup(msg[5], N_MINUS_2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1707 ) return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1708 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1709 // verify znp of cP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1710 t1 = HLP.multPowMod(this.g3, msg[3], msg[0], msg[2], N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1711 t2 = HLP.multPowMod(G, msg[3], this.g2, msg[4], N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1712 t2 = BigInt.multMod(t2, BigInt.powMod(msg[1], msg[2], N), N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1713 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1714 if (!HLP.ZKP(6, msg[2], t1, t2)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1715 return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1716 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1717 // verify znp of cR |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1718 t3 = HLP.multPowMod(G, msg[7], this.g3ao, msg[6], N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1719 this.QoQ = BigInt.divMod(msg[1], this.q, N) // save Q over Q |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1720 t4 = HLP.multPowMod(this.QoQ, msg[7], msg[5], msg[6], N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1721 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1722 if (!HLP.ZKP(7, msg[6], t3, t4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1723 return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1724 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1725 this.computeR() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1726 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1727 // zero-knowledge proof that R |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1728 // was generated according to the protocol |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1729 r7 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1730 tmp2 = BigInt.powMod(this.QoQ, r7, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1731 cR = HLP.smpHash(8, BigInt.powMod(G, r7, N), tmp2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1732 d7 = this.computeD(r7, this.a3, cR) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1733 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1734 send = HLP.packINT(3) + HLP.packMPIs([ this.r, cR, d7 ]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1735 send = HLP.packTLV(5, send) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1736 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1737 rab = this.computeRab(msg[5]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1738 trust = !!BigInt.equals(rab, BigInt.divMod(msg[0], this.p, N)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1739 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1740 this.trigger('trust', [trust, 'answered']) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1741 this.init() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1742 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1743 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1744 case CONST.SMPSTATE_EXPECT4: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1745 HLP.debug.call(this, 'smp tlv 5') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1746 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1747 // 0:r, 1:cR, 2:d7 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1748 ms = HLP.readLen(msg.msg.substr(0, 4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1749 if (ms !== 3) return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1750 msg = HLP.unpackMPIs(3, msg.msg.substring(4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1751 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1752 if (!HLP.checkGroup(msg[0], N_MINUS_2)) return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1753 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1754 // verify znp of cR |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1755 t3 = HLP.multPowMod(G, msg[2], this.g3ao, msg[1], N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1756 t4 = HLP.multPowMod(this.QoQ, msg[2], msg[0], msg[1], N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1757 if (!HLP.ZKP(8, msg[1], t3, t4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1758 return this.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1759 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1760 rab = this.computeRab(msg[0]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1761 trust = !!BigInt.equals(rab, this.PoP) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1762 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1763 this.trigger('trust', [trust, 'asked']) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1764 this.init() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1765 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1766 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1767 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1768 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1769 this.sendMsg(send) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1770 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1771 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1772 // send a message |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1773 SM.prototype.sendMsg = function (send) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1774 this.trigger('send', [this.ssid, '\x00' + send]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1775 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1776 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1777 SM.prototype.rcvSecret = function (secret, question) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1778 HLP.debug.call(this, 'receive secret') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1779 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1780 var fn, our = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1781 if (this.smpstate === CONST.SMPSTATE_EXPECT0) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1782 fn = this.answer |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1783 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1784 fn = this.initiate |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1785 our = true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1786 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1787 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1788 this.makeSecret(our, secret) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1789 fn.call(this, question) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1790 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1791 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1792 SM.prototype.answer = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1793 HLP.debug.call(this, 'smp answer') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1794 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1795 var r4 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1796 this.computePQ(r4) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1797 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1798 // zero-knowledge proof that P & Q |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1799 // were generated according to the protocol |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1800 var r5 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1801 var r6 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1802 var tmp = HLP.multPowMod(G, r5, this.g2, r6, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1803 var cP = HLP.smpHash(5, BigInt.powMod(this.g3, r5, N), tmp) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1804 var d5 = this.computeD(r5, r4, cP) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1805 var d6 = this.computeD(r6, this.secret, cP) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1806 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1807 this.smpstate = CONST.SMPSTATE_EXPECT3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1808 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1809 var send = HLP.packINT(11) + HLP.packMPIs([ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1810 this.g2a |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1811 , this.c2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1812 , this.d2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1813 , this.g3a |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1814 , this.c3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1815 , this.d3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1816 , this.p |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1817 , this.q |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1818 , cP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1819 , d5 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1820 , d6 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1821 ]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1822 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1823 this.sendMsg(HLP.packTLV(3, send)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1824 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1825 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1826 SM.prototype.initiate = function (question) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1827 HLP.debug.call(this, 'smp initiate') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1828 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1829 if (this.smpstate !== CONST.SMPSTATE_EXPECT1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1830 this.abort() // abort + restart |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1831 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1832 this.makeG2s() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1833 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1834 // zero-knowledge proof that the exponents |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1835 // associated with g2a & g3a are known |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1836 var r2 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1837 var r3 = HLP.randomExponent() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1838 this.c2 = this.computeC(1, r2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1839 this.c3 = this.computeC(2, r3) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1840 this.d2 = this.computeD(r2, this.a2, this.c2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1841 this.d3 = this.computeD(r3, this.a3, this.c3) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1842 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1843 // set the next expected state |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1844 this.smpstate = CONST.SMPSTATE_EXPECT2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1845 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1846 var send = '' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1847 var type = 2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1848 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1849 if (question) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1850 send += question |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1851 send += '\x00' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1852 type = 7 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1853 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1854 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1855 send += HLP.packINT(6) + HLP.packMPIs([ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1856 this.g2a |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1857 , this.c2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1858 , this.d2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1859 , this.g3a |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1860 , this.c3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1861 , this.d3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1862 ]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1863 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1864 this.sendMsg(HLP.packTLV(type, send)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1865 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1866 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1867 SM.prototype.abort = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1868 this.init() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1869 this.sendMsg(HLP.packTLV(6, '')) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1870 this.trigger('abort') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1871 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1872 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1873 }).call(this) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1874 ;(function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1875 "use strict"; |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1876 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1877 var root = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1878 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1879 var CryptoJS, BigInt, EventEmitter, Worker, SMWPath |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1880 , CONST, HLP, Parse, AKE, SM, DSA |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1881 if (typeof module !== 'undefined' && module.exports) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1882 module.exports = OTR |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1883 CryptoJS = require('../vendor/crypto.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1884 BigInt = require('../vendor/bigint.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1885 EventEmitter = require('../vendor/eventemitter.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1886 SMWPath = require('path').join(__dirname, '/sm-webworker.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1887 CONST = require('./const.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1888 HLP = require('./helpers.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1889 Parse = require('./parse.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1890 AKE = require('./ake.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1891 SM = require('./sm.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1892 DSA = require('./dsa.js') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1893 // expose CONST for consistency with docs |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1894 OTR.CONST = CONST |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1895 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1896 // copy over and expose internals |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1897 Object.keys(root.OTR).forEach(function (k) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1898 OTR[k] = root.OTR[k] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1899 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1900 root.OTR = OTR |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1901 CryptoJS = root.CryptoJS |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1902 BigInt = root.BigInt |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1903 EventEmitter = root.EventEmitter |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1904 Worker = root.Worker |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1905 SMWPath = 'sm-webworker.js' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1906 CONST = OTR.CONST |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1907 HLP = OTR.HLP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1908 Parse = OTR.Parse |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1909 AKE = OTR.AKE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1910 SM = OTR.SM |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1911 DSA = root.DSA |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1912 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1913 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1914 // diffie-hellman modulus and generator |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1915 // see group 5, RFC 3526 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1916 var G = BigInt.str2bigInt(CONST.G, 10) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1917 var N = BigInt.str2bigInt(CONST.N, 16) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1918 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1919 // JavaScript integers |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1920 var MAX_INT = Math.pow(2, 53) - 1 // doubles |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1921 var MAX_UINT = Math.pow(2, 31) - 1 // bitwise operators |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1922 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1923 // OTR contructor |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1924 function OTR(options) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1925 if (!(this instanceof OTR)) return new OTR(options) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1926 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1927 // options |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1928 options = options || {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1929 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1930 // private keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1931 if (options.priv && !(options.priv instanceof DSA)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1932 throw new Error('Requires long-lived DSA key.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1933 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1934 this.priv = options.priv ? options.priv : new DSA() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1935 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1936 this.fragment_size = options.fragment_size || 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1937 if (this.fragment_size < 0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1938 throw new Error('Fragment size must be a positive integer.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1939 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1940 this.send_interval = options.send_interval || 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1941 if (this.send_interval < 0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1942 throw new Error('Send interval must be a positive integer.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1943 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1944 this.outgoing = [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1945 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1946 // instance tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1947 this.our_instance_tag = options.instance_tag || OTR.makeInstanceTag() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1948 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1949 // debug |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1950 this.debug = !!options.debug |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1951 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1952 // smp in webworker options |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1953 // this is still experimental and undocumented |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1954 this.smw = options.smw |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1955 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1956 // init vals |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1957 this.init() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1958 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1959 // bind methods |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1960 var self = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1961 ;['sendMsg', 'receiveMsg'].forEach(function (meth) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1962 self[meth] = self[meth].bind(self) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1963 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1964 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1965 EventEmitter.call(this) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1966 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1967 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1968 // inherit from EE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1969 HLP.extend(OTR, EventEmitter) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1970 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1971 // add to prototype |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1972 OTR.prototype.init = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1973 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1974 this.msgstate = CONST.MSGSTATE_PLAINTEXT |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1975 this.authstate = CONST.AUTHSTATE_NONE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1976 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1977 this.ALLOW_V2 = true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1978 this.ALLOW_V3 = true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1979 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1980 this.REQUIRE_ENCRYPTION = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1981 this.SEND_WHITESPACE_TAG = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1982 this.WHITESPACE_START_AKE = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1983 this.ERROR_START_AKE = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1984 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1985 Parse.initFragment(this) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1986 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1987 // their keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1988 this.their_y = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1989 this.their_old_y = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1990 this.their_keyid = 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1991 this.their_priv_pk = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1992 this.their_instance_tag = '\x00\x00\x00\x00' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1993 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1994 // our keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1995 this.our_dh = this.dh() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1996 this.our_old_dh = this.dh() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1997 this.our_keyid = 2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1998 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1999 // session keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2000 this.sessKeys = [ new Array(2), new Array(2) ] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2001 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2002 // saved |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2003 this.storedMgs = [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2004 this.oldMacKeys = [] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2005 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2006 // smp |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2007 this.sm = null // initialized after AKE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2008 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2009 // when ake is complete |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2010 // save their keys and the session |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2011 this._akeInit() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2012 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2013 // receive plaintext message since switching to plaintext |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2014 // used to decide when to stop sending pt tags when SEND_WHITESPACE_TAG |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2015 this.receivedPlaintext = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2016 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2017 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2018 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2019 OTR.prototype._akeInit = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2020 this.ake = new AKE(this) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2021 this.transmittedRS = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2022 this.ssid = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2023 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2024 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2025 // smp over webworker |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2026 OTR.prototype._SMW = function (otr, reqs) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2027 this.otr = otr |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2028 var opts = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2029 path: SMWPath |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2030 , seed: BigInt.getSeed |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2031 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2032 if (typeof otr.smw === 'object') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2033 Object.keys(otr.smw).forEach(function (k) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2034 opts[k] = otr.smw[k] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2035 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2036 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2037 // load optional dep. in node |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2038 if (typeof module !== 'undefined' && module.exports) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2039 Worker = require('webworker-threads').Worker |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2040 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2041 this.worker = new Worker(opts.path) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2042 var self = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2043 this.worker.onmessage = function (e) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2044 var d = e.data |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2045 if (!d) return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2046 self.trigger(d.method, d.args) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2047 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2048 this.worker.postMessage({ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2049 type: 'seed' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2050 , seed: opts.seed() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2051 , imports: opts.imports |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2052 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2053 this.worker.postMessage({ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2054 type: 'init' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2055 , reqs: reqs |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2056 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2057 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2058 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2059 // inherit from EE |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2060 HLP.extend(OTR.prototype._SMW, EventEmitter) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2061 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2062 // shim sm methods |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2063 ;['handleSM', 'rcvSecret', 'abort'].forEach(function (m) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2064 OTR.prototype._SMW.prototype[m] = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2065 this.worker.postMessage({ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2066 type: 'method' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2067 , method: m |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2068 , args: Array.prototype.slice.call(arguments, 0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2069 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2070 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2071 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2072 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2073 OTR.prototype._smInit = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2074 var reqs = { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2075 ssid: this.ssid |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2076 , our_fp: this.priv.fingerprint() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2077 , their_fp: this.their_priv_pk.fingerprint() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2078 , debug: this.debug |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2079 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2080 if (this.smw) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2081 if (this.sm) this.sm.worker.terminate() // destroy prev webworker |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2082 this.sm = new this._SMW(this, reqs) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2083 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2084 this.sm = new SM(reqs) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2085 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2086 var self = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2087 ;['trust', 'abort', 'question'].forEach(function (e) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2088 self.sm.on(e, function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2089 self.trigger('smp', [e].concat(Array.prototype.slice.call(arguments))) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2090 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2091 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2092 this.sm.on('send', function (ssid, send) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2093 if (self.ssid === ssid) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2094 send = self.prepareMsg(send) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2095 self.io(send) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2096 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2097 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2098 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2099 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2100 OTR.prototype.io = function (msg, meta) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2101 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2102 // buffer |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2103 msg = ([].concat(msg)).map(function(m){ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2104 return { msg: m, meta: meta } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2105 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2106 this.outgoing = this.outgoing.concat(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2107 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2108 var self = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2109 ;(function send(first) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2110 if (!first) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2111 if (!self.outgoing.length) return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2112 var elem = self.outgoing.shift() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2113 self.trigger('io', [elem.msg, elem.meta]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2114 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2115 setTimeout(send, first ? 0 : self.send_interval) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2116 }(true)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2117 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2118 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2119 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2120 OTR.prototype.dh = function dh() { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2121 var keys = { privateKey: BigInt.randBigInt(320) } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2122 keys.publicKey = BigInt.powMod(G, keys.privateKey, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2123 return keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2124 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2125 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2126 // session constructor |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2127 OTR.prototype.DHSession = function DHSession(our_dh, their_y) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2128 if (!(this instanceof DHSession)) return new DHSession(our_dh, their_y) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2129 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2130 // shared secret |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2131 var s = BigInt.powMod(their_y, our_dh.privateKey, N) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2132 var secbytes = HLP.packMPI(s) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2133 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2134 // session id |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2135 this.id = HLP.mask(HLP.h2('\x00', secbytes), 0, 64) // first 64-bits |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2136 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2137 // are we the high or low end of the connection? |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2138 var sq = BigInt.greater(our_dh.publicKey, their_y) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2139 var sendbyte = sq ? '\x01' : '\x02' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2140 var rcvbyte = sq ? '\x02' : '\x01' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2141 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2142 // sending and receiving keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2143 this.sendenc = HLP.mask(HLP.h1(sendbyte, secbytes), 0, 128) // f16 bytes |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2144 this.sendmac = CryptoJS.SHA1(CryptoJS.enc.Latin1.parse(this.sendenc)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2145 this.sendmac = this.sendmac.toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2146 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2147 this.rcvenc = HLP.mask(HLP.h1(rcvbyte, secbytes), 0, 128) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2148 this.rcvmac = CryptoJS.SHA1(CryptoJS.enc.Latin1.parse(this.rcvenc)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2149 this.rcvmac = this.rcvmac.toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2150 this.rcvmacused = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2151 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2152 // extra symmetric key |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2153 this.extra_symkey = HLP.h2('\xff', secbytes) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2154 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2155 // counters |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2156 this.send_counter = 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2157 this.rcv_counter = 0 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2158 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2159 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2160 OTR.prototype.rotateOurKeys = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2161 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2162 // reveal old mac keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2163 var self = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2164 this.sessKeys[1].forEach(function (sk) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2165 if (sk && sk.rcvmacused) self.oldMacKeys.push(sk.rcvmac) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2166 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2167 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2168 // rotate our keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2169 this.our_old_dh = this.our_dh |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2170 this.our_dh = this.dh() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2171 this.our_keyid += 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2172 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2173 this.sessKeys[1][0] = this.sessKeys[0][0] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2174 this.sessKeys[1][1] = this.sessKeys[0][1] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2175 this.sessKeys[0] = [ |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2176 this.their_y ? |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2177 new this.DHSession(this.our_dh, this.their_y) : null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2178 , this.their_old_y ? |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2179 new this.DHSession(this.our_dh, this.their_old_y) : null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2180 ] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2181 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2182 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2183 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2184 OTR.prototype.rotateTheirKeys = function (their_y) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2185 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2186 // increment their keyid |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2187 this.their_keyid += 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2188 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2189 // reveal old mac keys |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2190 var self = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2191 this.sessKeys.forEach(function (sk) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2192 if (sk[1] && sk[1].rcvmacused) self.oldMacKeys.push(sk[1].rcvmac) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2193 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2194 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2195 // rotate their keys / session |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2196 this.their_old_y = this.their_y |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2197 this.sessKeys[0][1] = this.sessKeys[0][0] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2198 this.sessKeys[1][1] = this.sessKeys[1][0] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2199 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2200 // new keys / sessions |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2201 this.their_y = their_y |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2202 this.sessKeys[0][0] = new this.DHSession(this.our_dh, this.their_y) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2203 this.sessKeys[1][0] = new this.DHSession(this.our_old_dh, this.their_y) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2204 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2205 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2206 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2207 OTR.prototype.prepareMsg = function (msg, esk) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2208 if (this.msgstate !== CONST.MSGSTATE_ENCRYPTED || this.their_keyid === 0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2209 return this.error('Not ready to encrypt.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2210 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2211 var sessKeys = this.sessKeys[1][0] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2212 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2213 if (sessKeys.send_counter >= MAX_INT) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2214 return this.error('Should have rekeyed by now.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2215 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2216 sessKeys.send_counter += 1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2217 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2218 var ctr = HLP.packCtr(sessKeys.send_counter) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2219 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2220 var send = this.ake.otr_version + '\x03' // version and type |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2221 var v3 = (this.ake.otr_version === CONST.OTR_VERSION_3) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2222 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2223 if (v3) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2224 send += this.our_instance_tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2225 send += this.their_instance_tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2226 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2227 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2228 send += '\x00' // flag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2229 send += HLP.packINT(this.our_keyid - 1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2230 send += HLP.packINT(this.their_keyid) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2231 send += HLP.packMPI(this.our_dh.publicKey) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2232 send += ctr.substring(0, 8) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2233 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2234 if (Math.ceil(msg.length / 8) >= MAX_UINT) // * 16 / 128 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2235 return this.error('Message is too long.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2236 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2237 var aes = HLP.encryptAes( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2238 CryptoJS.enc.Latin1.parse(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2239 , sessKeys.sendenc |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2240 , ctr |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2241 ) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2242 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2243 send += HLP.packData(aes) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2244 send += HLP.make1Mac(send, sessKeys.sendmac) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2245 send += HLP.packData(this.oldMacKeys.splice(0).join('')) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2246 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2247 send = HLP.wrapMsg( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2248 send |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2249 , this.fragment_size |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2250 , v3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2251 , this.our_instance_tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2252 , this.their_instance_tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2253 ) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2254 if (send[0]) return this.error(send[0]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2255 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2256 // emit extra symmetric key |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2257 if (esk) this.trigger('file', ['send', sessKeys.extra_symkey, esk]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2258 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2259 return send[1] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2260 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2261 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2262 OTR.prototype.handleDataMsg = function (msg) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2263 var vt = msg.version + msg.type |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2264 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2265 if (this.ake.otr_version === CONST.OTR_VERSION_3) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2266 vt += msg.instance_tags |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2267 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2268 var types = ['BYTE', 'INT', 'INT', 'MPI', 'CTR', 'DATA', 'MAC', 'DATA'] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2269 msg = HLP.splitype(types, msg.msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2270 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2271 // ignore flag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2272 var ign = (msg[0] === '\x01') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2273 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2274 if (this.msgstate !== CONST.MSGSTATE_ENCRYPTED || msg.length !== 8) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2275 if (!ign) this.error('Received an unreadable encrypted message.', true) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2276 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2277 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2278 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2279 var our_keyid = this.our_keyid - HLP.readLen(msg[2]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2280 var their_keyid = this.their_keyid - HLP.readLen(msg[1]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2281 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2282 if (our_keyid < 0 || our_keyid > 1) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2283 if (!ign) this.error('Not of our latest keys.', true) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2284 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2285 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2286 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2287 if (their_keyid < 0 || their_keyid > 1) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2288 if (!ign) this.error('Not of your latest keys.', true) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2289 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2290 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2291 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2292 var their_y = their_keyid ? this.their_old_y : this.their_y |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2293 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2294 if (their_keyid === 1 && !their_y) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2295 if (!ign) this.error('Do not have that key.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2296 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2297 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2298 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2299 var sessKeys = this.sessKeys[our_keyid][their_keyid] |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2300 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2301 var ctr = HLP.unpackCtr(msg[4]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2302 if (ctr <= sessKeys.rcv_counter) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2303 if (!ign) this.error('Counter in message is not larger.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2304 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2305 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2306 sessKeys.rcv_counter = ctr |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2307 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2308 // verify mac |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2309 vt += msg.slice(0, 6).join('') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2310 var vmac = HLP.make1Mac(vt, sessKeys.rcvmac) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2311 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2312 if (!HLP.compare(msg[6], vmac)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2313 if (!ign) this.error('MACs do not match.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2314 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2315 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2316 sessKeys.rcvmacused = true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2317 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2318 var out = HLP.decryptAes( |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2319 msg[5].substring(4) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2320 , sessKeys.rcvenc |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2321 , HLP.padCtr(msg[4]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2322 ) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2323 out = out.toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2324 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2325 if (!our_keyid) this.rotateOurKeys() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2326 if (!their_keyid) this.rotateTheirKeys(HLP.readMPI(msg[3])) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2327 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2328 // parse TLVs |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2329 var ind = out.indexOf('\x00') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2330 if (~ind) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2331 this.handleTLVs(out.substring(ind + 1), sessKeys) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2332 out = out.substring(0, ind) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2333 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2334 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2335 out = CryptoJS.enc.Latin1.parse(out) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2336 return out.toString(CryptoJS.enc.Utf8) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2337 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2338 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2339 OTR.prototype.handleTLVs = function (tlvs, sessKeys) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2340 var type, len, msg |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2341 for (; tlvs.length; ) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2342 type = HLP.unpackSHORT(tlvs.substr(0, 2)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2343 len = HLP.unpackSHORT(tlvs.substr(2, 2)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2344 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2345 msg = tlvs.substr(4, len) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2346 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2347 // TODO: handle pathological cases better |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2348 if (msg.length < len) break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2349 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2350 switch (type) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2351 case 1: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2352 // Disconnected |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2353 this.msgstate = CONST.MSGSTATE_FINISHED |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2354 this.trigger('status', [CONST.STATUS_END_OTR]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2355 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2356 case 2: case 3: case 4: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2357 case 5: case 6: case 7: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2358 // SMP |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2359 if (this.msgstate !== CONST.MSGSTATE_ENCRYPTED) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2360 if (this.sm) this.sm.abort() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2361 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2362 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2363 if (!this.sm) this._smInit() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2364 this.sm.handleSM({ msg: msg, type: type }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2365 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2366 case 8: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2367 // utf8 filenames |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2368 msg = msg.substring(4) // remove 4-byte indication |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2369 msg = CryptoJS.enc.Latin1.parse(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2370 msg = msg.toString(CryptoJS.enc.Utf8) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2371 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2372 // Extra Symkey |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2373 this.trigger('file', ['receive', sessKeys.extra_symkey, msg]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2374 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2375 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2376 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2377 tlvs = tlvs.substring(4 + len) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2378 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2379 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2380 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2381 OTR.prototype.smpSecret = function (secret, question) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2382 if (this.msgstate !== CONST.MSGSTATE_ENCRYPTED) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2383 return this.error('Must be encrypted for SMP.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2384 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2385 if (typeof secret !== 'string' || secret.length < 1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2386 return this.error('Secret is required.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2387 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2388 if (!this.sm) this._smInit() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2389 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2390 // utf8 inputs |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2391 secret = CryptoJS.enc.Utf8.parse(secret).toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2392 question = CryptoJS.enc.Utf8.parse(question).toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2393 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2394 this.sm.rcvSecret(secret, question) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2395 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2396 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2397 OTR.prototype.sendQueryMsg = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2398 var versions = {} |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2399 , msg = CONST.OTR_TAG |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2400 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2401 if (this.ALLOW_V2) versions['2'] = true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2402 if (this.ALLOW_V3) versions['3'] = true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2403 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2404 // but we don't allow v1 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2405 // if (versions['1']) msg += '?' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2406 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2407 var vs = Object.keys(versions) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2408 if (vs.length) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2409 msg += 'v' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2410 vs.forEach(function (v) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2411 if (v !== '1') msg += v |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2412 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2413 msg += '?' |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2414 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2415 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2416 this.io(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2417 this.trigger('status', [CONST.STATUS_SEND_QUERY]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2418 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2419 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2420 OTR.prototype.sendMsg = function (msg, meta) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2421 if ( this.REQUIRE_ENCRYPTION || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2422 this.msgstate !== CONST.MSGSTATE_PLAINTEXT |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2423 ) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2424 msg = CryptoJS.enc.Utf8.parse(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2425 msg = msg.toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2426 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2427 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2428 switch (this.msgstate) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2429 case CONST.MSGSTATE_PLAINTEXT: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2430 if (this.REQUIRE_ENCRYPTION) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2431 this.storedMgs.push({msg: msg, meta: meta}) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2432 this.sendQueryMsg() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2433 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2434 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2435 if (this.SEND_WHITESPACE_TAG && !this.receivedPlaintext) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2436 msg += CONST.WHITESPACE_TAG // 16 byte tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2437 if (this.ALLOW_V3) msg += CONST.WHITESPACE_TAG_V3 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2438 if (this.ALLOW_V2) msg += CONST.WHITESPACE_TAG_V2 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2439 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2440 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2441 case CONST.MSGSTATE_FINISHED: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2442 this.storedMgs.push({msg: msg, meta: meta}) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2443 this.error('Message cannot be sent at this time.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2444 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2445 case CONST.MSGSTATE_ENCRYPTED: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2446 msg = this.prepareMsg(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2447 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2448 default: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2449 throw new Error('Unknown message state.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2450 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2451 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2452 if (msg) this.io(msg, meta) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2453 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2454 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2455 OTR.prototype.receiveMsg = function (msg) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2456 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2457 // parse type |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2458 msg = Parse.parseMsg(this, msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2459 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2460 if (!msg) return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2461 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2462 switch (msg.cls) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2463 case 'error': |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2464 this.error(msg.msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2465 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2466 case 'ake': |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2467 if ( msg.version === CONST.OTR_VERSION_3 && |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2468 this.checkInstanceTags(msg.instance_tags) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2469 ) return // ignore |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2470 this.ake.handleAKE(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2471 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2472 case 'data': |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2473 if ( msg.version === CONST.OTR_VERSION_3 && |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2474 this.checkInstanceTags(msg.instance_tags) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2475 ) return // ignore |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2476 msg.msg = this.handleDataMsg(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2477 msg.encrypted = true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2478 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2479 case 'query': |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2480 if (this.msgstate === CONST.MSGSTATE_ENCRYPTED) this._akeInit() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2481 this.doAKE(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2482 break |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2483 default: |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2484 // check for encrypted |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2485 if ( this.REQUIRE_ENCRYPTION || |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2486 this.msgstate !== CONST.MSGSTATE_PLAINTEXT |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2487 ) this.error('Received an unencrypted message.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2488 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2489 // received a plaintext message |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2490 // stop sending the whitespace tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2491 this.receivedPlaintext = true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2492 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2493 // received a whitespace tag |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2494 if (this.WHITESPACE_START_AKE && msg.ver.length > 0) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2495 this.doAKE(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2496 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2497 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2498 if (msg.msg) this.trigger('ui', [msg.msg, !!msg.encrypted]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2499 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2500 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2501 OTR.prototype.checkInstanceTags = function (it) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2502 var their_it = HLP.readLen(it.substr(0, 4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2503 var our_it = HLP.readLen(it.substr(4, 4)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2504 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2505 if (our_it && our_it !== HLP.readLen(this.our_instance_tag)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2506 return true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2507 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2508 if (HLP.readLen(this.their_instance_tag)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2509 if (HLP.readLen(this.their_instance_tag) !== their_it) return true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2510 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2511 if (their_it < 100) return true |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2512 this.their_instance_tag = HLP.packINT(their_it) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2513 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2514 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2515 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2516 OTR.prototype.doAKE = function (msg) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2517 if (this.ALLOW_V3 && ~msg.ver.indexOf(CONST.OTR_VERSION_3)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2518 this.ake.initiateAKE(CONST.OTR_VERSION_3) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2519 } else if (this.ALLOW_V2 && ~msg.ver.indexOf(CONST.OTR_VERSION_2)) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2520 this.ake.initiateAKE(CONST.OTR_VERSION_2) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2521 } else { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2522 // is this an error? |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2523 this.error('OTR conversation requested, ' + |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2524 'but no compatible protocol version found.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2525 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2526 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2527 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2528 OTR.prototype.error = function (err, send) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2529 if (send) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2530 if (!this.debug) err = "An OTR error has occurred." |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2531 err = '?OTR Error:' + err |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2532 this.io(err) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2533 return |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2534 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2535 this.trigger('error', [err]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2536 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2537 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2538 OTR.prototype.sendStored = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2539 var self = this |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2540 ;(this.storedMgs.splice(0)).forEach(function (elem) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2541 var msg = self.prepareMsg(elem.msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2542 self.io(msg, elem.meta) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2543 }) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2544 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2545 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2546 OTR.prototype.sendFile = function (filename) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2547 if (this.msgstate !== CONST.MSGSTATE_ENCRYPTED) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2548 return this.error('Not ready to encrypt.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2549 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2550 if (this.ake.otr_version !== CONST.OTR_VERSION_3) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2551 return this.error('Protocol v3 required.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2552 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2553 if (!filename) return this.error('Please specify a filename.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2554 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2555 // utf8 filenames |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2556 var l1name = CryptoJS.enc.Utf8.parse(filename) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2557 l1name = l1name.toString(CryptoJS.enc.Latin1) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2558 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2559 if (l1name.length >= 65532) return this.error('filename is too long.') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2560 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2561 var msg = '\x00' // null byte |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2562 msg += '\x00\x08' // type 8 tlv |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2563 msg += HLP.packSHORT(4 + l1name.length) // length of value |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2564 msg += '\x00\x00\x00\x01' // four bytes indicating file |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2565 msg += l1name |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2566 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2567 msg = this.prepareMsg(msg, filename) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2568 this.io(msg) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2569 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2570 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2571 OTR.prototype.endOtr = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2572 if (this.msgstate === CONST.MSGSTATE_ENCRYPTED) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2573 this.sendMsg('\x00\x00\x01\x00\x00') |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2574 if (this.sm) { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2575 if (this.smw) this.sm.worker.terminate() // destroy webworker |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2576 this.sm = null |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2577 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2578 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2579 this.msgstate = CONST.MSGSTATE_PLAINTEXT |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2580 this.receivedPlaintext = false |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2581 this.trigger('status', [CONST.STATUS_END_OTR]) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2582 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2583 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2584 // attach methods |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2585 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2586 OTR.makeInstanceTag = function () { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2587 var num = BigInt.randBigInt(32) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2588 if (BigInt.greater(BigInt.str2bigInt('100', 16), num)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2589 return OTR.makeInstanceTag() |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2590 return HLP.packINT(parseInt(BigInt.bigInt2str(num, 10), 10)) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2591 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2592 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2593 }).call(this) |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2594 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2595 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2596 return { |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2597 OTR: this.OTR |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2598 , DSA: this.DSA |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2599 } |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2600 |
1596660ddf72
Add minifier script for otr.js and its dependencies
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2601 })) |