|
1 | 1 | /*!
|
2 | 2 |
|
3 |
| - otr.js v0.2.10 - 2014-02-04 |
| 3 | + otr.js v0.2.11 - 2014-03-24 |
4 | 4 | (c) 2014 - Arlo Breault <[email protected]>
|
5 | 5 | Freely distributed under the MPL v2.0 license.
|
6 | 6 |
|
|
1095 | 1095 | this.ssid = null
|
1096 | 1096 | this.transmittedRS = false
|
1097 | 1097 | this.r = null
|
1098 |
| - this.priv = otr.priv |
1099 | 1098 |
|
1100 | 1099 | // bind methods
|
1101 | 1100 | var self = this
|
|
1144 | 1143 | },
|
1145 | 1144 |
|
1146 | 1145 | makeM: function (their_y, m1, c, m2) {
|
1147 |
| - var pk = this.priv.packPublic() |
| 1146 | + var pk = this.otr.priv.packPublic() |
1148 | 1147 | var kid = HLP.packINT(this.our_keyid)
|
1149 | 1148 | var m = hMac(this.our_dh.publicKey, their_y, pk, kid, m1)
|
1150 |
| - m = this.priv.sign(m) |
| 1149 | + m = this.otr.priv.sign(m) |
1151 | 1150 | var msg = pk + kid
|
1152 | 1151 | msg += BigInt.bigInt2bits(m[0], 20) // pad to 20 bytes
|
1153 | 1152 | msg += BigInt.bigInt2bits(m[1], 20)
|
|
1409 | 1408 | )
|
1410 | 1409 | if (send[0]) return this.otr.error(send[0])
|
1411 | 1410 |
|
1412 |
| - this.otr._sendMsg(send[1], true) |
| 1411 | + this.otr.io(send[1]) |
1413 | 1412 | },
|
1414 | 1413 |
|
1415 | 1414 | initiateAKE: function (version) {
|
|
1556 | 1555 |
|
1557 | 1556 | if (msg.type === 6) {
|
1558 | 1557 | this.init()
|
1559 |
| - this.trigger('trust', [false]) |
| 1558 | + this.trigger('abort') |
1560 | 1559 | return
|
1561 | 1560 | }
|
1562 | 1561 |
|
|
2092 | 2091 | })
|
2093 | 2092 | this.sm.on('send', function (ssid, send) {
|
2094 | 2093 | if (self.ssid === ssid)
|
2095 |
| - self._sendMsg(send) |
| 2094 | + send = self.prepareMsg(send) |
| 2095 | + self.io(send) |
2096 | 2096 | })
|
2097 | 2097 | }
|
2098 | 2098 |
|
2099 |
| - OTR.prototype.io = function (msg) { |
| 2099 | + OTR.prototype.io = function (msg, meta) { |
2100 | 2100 |
|
2101 | 2101 | // buffer
|
| 2102 | + msg = ([].concat(msg)).map(function(m){ |
| 2103 | + return { msg: m, meta: meta } |
| 2104 | + }) |
2102 | 2105 | this.outgoing = this.outgoing.concat(msg)
|
2103 | 2106 |
|
2104 | 2107 | var self = this
|
2105 | 2108 | ;(function send(first) {
|
2106 | 2109 | if (!first) {
|
2107 | 2110 | if (!self.outgoing.length) return
|
2108 |
| - var msg = self.outgoing.shift() |
2109 |
| - self.trigger('io', [msg]) |
| 2111 | + var elem = self.outgoing.shift() |
| 2112 | + self.trigger('io', [elem.msg, elem.meta]) |
2110 | 2113 | }
|
2111 | 2114 | setTimeout(send, first ? 0 : self.send_interval)
|
2112 | 2115 | }(true))
|
|
2413 | 2416 | msg += '?'
|
2414 | 2417 | }
|
2415 | 2418 |
|
2416 |
| - this._sendMsg(msg, true) |
| 2419 | + this.io(msg) |
2417 | 2420 | this.trigger('status', [CONST.STATUS_SEND_QUERY])
|
2418 | 2421 | }
|
2419 | 2422 |
|
2420 |
| - OTR.prototype.sendMsg = function (msg) { |
| 2423 | + OTR.prototype.sendMsg = function (msg, meta) { |
2421 | 2424 | if ( this.REQUIRE_ENCRYPTION ||
|
2422 | 2425 | this.msgstate !== CONST.MSGSTATE_PLAINTEXT
|
2423 | 2426 | ) {
|
2424 | 2427 | msg = CryptoJS.enc.Utf8.parse(msg)
|
2425 | 2428 | msg = msg.toString(CryptoJS.enc.Latin1)
|
2426 | 2429 | }
|
2427 |
| - this._sendMsg(msg) |
2428 |
| - } |
2429 |
| - |
2430 |
| - OTR.prototype._sendMsg = function (msg, internal) { |
2431 |
| - if (!internal) { // a user or sm msg |
2432 | 2430 |
|
2433 |
| - switch (this.msgstate) { |
2434 |
| - case CONST.MSGSTATE_PLAINTEXT: |
2435 |
| - if (this.REQUIRE_ENCRYPTION) { |
2436 |
| - this.storedMgs.push(msg) |
2437 |
| - this.sendQueryMsg() |
2438 |
| - return |
2439 |
| - } |
2440 |
| - if (this.SEND_WHITESPACE_TAG && !this.receivedPlaintext) { |
2441 |
| - msg += CONST.WHITESPACE_TAG // 16 byte tag |
2442 |
| - if (this.ALLOW_V3) msg += CONST.WHITESPACE_TAG_V3 |
2443 |
| - if (this.ALLOW_V2) msg += CONST.WHITESPACE_TAG_V2 |
2444 |
| - } |
2445 |
| - break |
2446 |
| - case CONST.MSGSTATE_FINISHED: |
2447 |
| - this.storedMgs.push(msg) |
2448 |
| - this.error('Message cannot be sent at this time.') |
| 2431 | + switch (this.msgstate) { |
| 2432 | + case CONST.MSGSTATE_PLAINTEXT: |
| 2433 | + if (this.REQUIRE_ENCRYPTION) { |
| 2434 | + this.storedMgs.push({msg: msg, meta: meta}) |
| 2435 | + this.sendQueryMsg() |
2449 | 2436 | return
|
2450 |
| - default: |
2451 |
| - msg = this.prepareMsg(msg) |
2452 |
| - } |
2453 |
| - |
| 2437 | + } |
| 2438 | + if (this.SEND_WHITESPACE_TAG && !this.receivedPlaintext) { |
| 2439 | + msg += CONST.WHITESPACE_TAG // 16 byte tag |
| 2440 | + if (this.ALLOW_V3) msg += CONST.WHITESPACE_TAG_V3 |
| 2441 | + if (this.ALLOW_V2) msg += CONST.WHITESPACE_TAG_V2 |
| 2442 | + } |
| 2443 | + break |
| 2444 | + case CONST.MSGSTATE_FINISHED: |
| 2445 | + this.storedMgs.push({msg: msg, meta: meta}) |
| 2446 | + this.error('Message cannot be sent at this time.') |
| 2447 | + return |
| 2448 | + case CONST.MSGSTATE_ENCRYPTED: |
| 2449 | + msg = this.prepareMsg(msg) |
| 2450 | + break |
| 2451 | + default: |
| 2452 | + throw new Error('Unknown message state.') |
2454 | 2453 | }
|
2455 |
| - if (msg) this.io(msg) |
| 2454 | + |
| 2455 | + if (msg) this.io(msg, meta) |
2456 | 2456 | }
|
2457 | 2457 |
|
2458 | 2458 | OTR.prototype.receiveMsg = function (msg) {
|
|
2532 | 2532 | if (send) {
|
2533 | 2533 | if (!this.debug) err = "An OTR error has occurred."
|
2534 | 2534 | err = '?OTR Error:' + err
|
2535 |
| - this._sendMsg(err, true) |
| 2535 | + this.io(err) |
2536 | 2536 | return
|
2537 | 2537 | }
|
2538 | 2538 | this.trigger('error', [err])
|
2539 | 2539 | }
|
2540 | 2540 |
|
2541 | 2541 | OTR.prototype.sendStored = function () {
|
2542 | 2542 | var self = this
|
2543 |
| - ;(this.storedMgs.splice(0)).forEach(function (msg) { |
2544 |
| - self._sendMsg(msg) |
| 2543 | + ;(this.storedMgs.splice(0)).forEach(function (elem) { |
| 2544 | + var msg = self.prepareMsg(elem.msg) |
| 2545 | + self.io(msg, elem.meta) |
2545 | 2546 | })
|
2546 | 2547 | }
|
2547 | 2548 |
|
|
2567 | 2568 | msg += l1name
|
2568 | 2569 |
|
2569 | 2570 | msg = this.prepareMsg(msg, filename)
|
2570 |
| - if (msg) this._sendMsg(msg, true) |
| 2571 | + this.io(msg) |
2571 | 2572 | }
|
2572 | 2573 |
|
2573 | 2574 | OTR.prototype.endOtr = function () {
|
|
2594 | 2595 |
|
2595 | 2596 | }).call(this)
|
2596 | 2597 |
|
| 2598 | + |
2597 | 2599 | return {
|
2598 | 2600 | OTR: this.OTR
|
2599 | 2601 | , DSA: this.DSA
|
|
0 commit comments