Commit Graph

76 Commits (8d56a1b24833596048bec01a3d690ad1293645ef)

Author SHA1 Message Date
lilia 2f58ea5f3a Fixup curve25519 module
Rename methods on the curve25519 interface to be a bit more high level.
Cleanup emscripten wrapper class, wrap long lines and such. Also add a
grunt task alias for building the emscripten compiled curve
implementation.
11 years ago
lilia a1a528ccdd Finish abstracting native client
Firstly, don't initialize textsecure.nativclient unless the browser
supports it. The mimetype-check trick is hewn from nacl-common.js.

Secondly, nativeclient crypto functions will all automatically wait for
the module to load before sending messages, so we needn't register any
onload callbacks outside nativeclient.js. (Previously, if you wanted to
do crypto with native client, you would have to register a call back and
wait for the module to load.) Now that the native client crypto is
encapsulated behind a nice interface, it can handle all that
onload-callback jazz internally: if the module isn't loaded when you
call a nativeclient function, return a promise that waits for the load
callback, and eventually resolves with the result of the requested
command. This removes the need for textsecure.registerOnLoadCallback.

Finally, although native client has its quirks, it's significantly
faster than the alternative (emscripten compiled js), so this commit
also lets the crypto backend use native client opportunistically, if
it's available, falling back to js if not, which should make us
compatible with older versions of chrome and chromium.
11 years ago
lilia b4f4f87a7c Add emscripten-compiled curve25519 module
Build with `grunt compile && grunt concat:curve25519` after installing
emscripten.

Enable by either (a) not loading nativeclient.js or (b) setting
`textsecure.NATIVE_CLIENT = false` before loading nativeclient.js.
11 years ago
lilia 69c52d51b3 Abstract out curve25519 tests
Also rename the internal variable in crypto.js to be a little more
explicit about which curve we're dealing with.
11 years ago
lilia 9f676af9bb Refactor crypto.js and native client interface
NB: this diff is best viewed with --ignore-whitespace

Distills crypto.js down to the hard cryptoey bones. It pulls from
webcrypto for aes and hmac, and from native client for curve25519 stuff
or potentially another object implementing the handful of needed
curve25519 functions.

Everything else formerly known as crypto, including session storage and
management, axolotl, etc.. is now protocol.js. The separation is not
quite perfect, but it's a big step.

nativeclient.js now enables talking to the native client module through
a high level interface as well as registering callbacks that will be
executed once the module is loaded. And it has tests!

Finally, this commit removes all references to the "testing_only"
object, preferring to run tests on textsecure.crypto instead.
11 years ago
lilia cd4b98d426 Remove 1mod8
27b5bf54cc
11 years ago
lilia db76c7e164 Initialize session.currentRatchet.previousCounter 11 years ago
lilia ddd6f1a944 remove another unused function 11 years ago
lilia 80e3fadcb1 Remove unused *MACWithVersionByte functions 11 years ago
lilia 39505c81b1 Finish up webcrypto integration, Fixes #72
We now correctly and opportunistically use the webcrypto API if
available, polyfilling if it's not detected. This change also includes a
layer of abstraction over the webcrypto interface so we no longer have
to deal with key-imports or algorithm names all over the place. Since we
no longer support AES-CTR, code outside this file can simply call
`textsecure.subtle.<encrypt|decrypt|sign>(key, data [, iv])`.
11 years ago
Matt Corallo da0c63fb1b Add (untested) AES-CBC switch from v3 (fs loss resulted in old tested version being lost) 11 years ago
lilia b69db59ad4 Fix buffer concatenation
TypedArray.prototype.set doesn't handle ArrayBuffers correctly (it
writes all zeros). Instead, wrap each ArrayBuffer in a typed array
for concatenation.
11 years ago
lilia 4675cdf3f2 Webcrypto won't go down without a fight
Turns out that assigning a new object to window.crypto.subtle
is not so easy. That's probably a good thing.
11 years ago
lilia 1023ea1732 Refactor textsecure.protos -> textsecure.protobuf
DRY up protobuf declarations and move to a slightly briefer naming
convention.

Also dropped some ArrayBuffer -> string conversions as
ProtoBuf.js handles ArrayBuffers just fine, and in fact, more
efficiently than strings.

Finally, dropped the btoa() wrappers, because that incurs an extra
string -> string conversion before the protobuf's internal string ->
array buffer conversion. In lieu of btoa, we can simply pass in the
optional string encoding argument to the protobuf's decode method,
which in these cases should be 'binary'.

Related: #17
11 years ago
lilia d7edfd4efb Remove reference to undefined function 11 years ago
Matt Corallo d6d17eaf19 Remove unused function 11 years ago
Matt Corallo f6f35c5b61 Fix a missing function and dont blow up on delivery receipts 11 years ago
Matt Corallo a6b0d1f84b Add entirely untested secondary device init 11 years ago
Matt Corallo 6455da5c9a Refactor a bunch of stuff re: session closing, add test cases 11 years ago
Matt Corallo c427da04f0 Add closeSession tests as Alice and fix re-requesting prekeys 11 years ago
Matt Corallo 6f3ee151f3 Add a BOB test-case around session closure 11 years ago
Matt Corallo a6426194ef Update BOB test cases 11 years ago
Matt Corallo 957587bd9a Add identity keys to MAC, begin updating test cases 11 years ago
Matt Corallo eab0911d3d I lied, there is no verification tag 11 years ago
Matt Corallo ebcfd4736e Fix session lookup in duplicate prekeymessage case 11 years ago
Matt Corallo 5040bfbe44 Fix pending verifications 11 years ago
Matt Corallo a76ae2f1f8 Add verification tags, make alice tests strict(ish) again 11 years ago
Matt Corallo 287b55120d First cut of ALICE test vectors 11 years ago
Matt Corallo 0d4ae6a8cb Fix undefined variable in for's (browser update to strict mode?) 11 years ago
Matt Corallo de83429962 v3 steps 11 years ago
Matt Corallo 66bf371aa7 Use staging server (ie update to server keys v2) and protocolv3 11 years ago
Matt Corallo 53f8ac9ad9 Generate signed keys (breaks registration) 11 years ago
Matt Corallo 4c3ee6f23b Compare equality w/o getString (in the future) 11 years ago
Matt Corallo 3190fe97f9 HMAC Update for Protov3 11 years ago
Matt Corallo b5c6e3d101 JS ed25519 11 years ago
Matt Corallo a2da4fffb0 Remove useless function 11 years ago
Matt Corallo 92514ad08f Fix missing baseKey 11 years ago
Matt Corallo ceca03c5d0 Close chainKey.key 11 years ago
Matt Corallo c953c6c16d closeSession 11 years ago
Matt Corallo d0fd3e94d8 sendMessage refactor, initial group stuff (breaks message storage) 11 years ago
Matt Corallo cf35b7056f Retry API, standardize <script> list 11 years ago
Matt Corallo c2d1d816f2 Save sessions in deviceObjects, test using fake_api, minor tweaks 11 years ago
Matt Corallo eb80a10ed1 Fix new function(){}() typo (thanks codedust on GitHub) 11 years ago
Matt Corallo aec36468bc Request new keys (largely untested) 11 years ago
Matt Corallo 68131a6e2a Add human readable version of errors 11 years ago
Matt Corallo 2d12a33ead Fix decoding/protos/tests 11 years ago
Matt Corallo 21b95ce1d3 Re-create some of d9bf0a4, which was broken and reverted in 1e6720 11 years ago
Matt Corallo d387cd22f5 s/getEncodedNumber// (with XXXs) 11 years ago
Matt Corallo 9aae93fc99 textsecure.protos 11 years ago
lilia 1e672030de Fix a couple things broken in d9bf0a4
Slight revert from said commit. We really do need the
IncomingPushMessageSignal protobuf at the UI layer, mostly because
it contains the 'source' attribute, without which we don't know
who sent the message.

Also fix a crash when there are no attachments on a message.
11 years ago