Commit Graph

103 Commits (7f04439b37309e32c90abb4574a162343fb57f2e)

Author SHA1 Message Date
lilia 7f04439b37 New websocket protocol 11 years ago
lilia 735737f0bc Merge Whisper.Messages into Whisper Threads
Eliminates the global Whisper.Messages object and consolidates shared
send/receive logic in Whisper.Threads.

To the latter end, note that the decrypted array buffer on an attachment
pointer is now named data instead of decrypted, in order to match the
format of outgoing attachments presented by
FileReader.readAsArrayBuffers and let us use the same handler to base64
encode them.
11 years ago
lilia 1ad898a62e Simplify webcrypto type conversion
Previously we'd get a WordArray and convert to string before converting
to array buffer. Instead, go directly to array buffer.
11 years ago
lilia e190582d9e Build CryptoJS components into webcrypto.js
We only depend on cryptojs for this webcrypto polyfill, so let Grunt
concatenate them into one file.

The reference in the getString helper isn't needed since we use the
built in string converters on CryptoJS's word arrays.
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 0a3c03025b Abstract nativeclient callback logic
The nativeclient.js module overrides
window.textsecure.registerOnLoadFunction with its own version. Otherwise
helpers will define a trivial placeholder for same.

The flag textsecure.NATIVE_CLIENT can be set anywhere ahead of
nativeclient.js, but is only acted on in nativeclient.js,
and crypto.js.
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 1c76c0b546 Move storage objects to their own files
Greatly reduce the size of the ignominiously named helpers.js.
11 years ago
lilia b92c5bb84e Unused function 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 211129475c Fix attachment ids
Parse attachment ids out of the attachment pointer url and return them
as strings because the copy parsed by JSON suffers a loss of precision.
Convert them to and from the format expected by the protobuf using
facilities from decodeIO.Long.
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 03cc667e48 Standardize some whitespace
The preferred style is 4 spaces.
11 years ago
lilia bbe57ef0bf Stringify incoming group ids
Otherwise when we try to make their local storage keys they look like:
"egroupByteBuffer(offset=4,markedOffset=-1,length=28,capacity=112)"
11 years ago
lilia 7e9c0e2394 Group ids should be strings (or stringables)
ArrayBuffer was a bad choice.
11 years ago
lilia 320d1f18ae Fix exception when protbuf-encoding groupIds
An exception is thrown when protobuf tries to encode a number as the
group id, which is declared to have type 'bytes'.

Fix by make it an ArrayBuffer instead, and increase the length to 16,
which is what the Android client uses:

c632b32ff8/src/org/thoughtcrime/securesms/database/GroupDatabase.java (L222)
11 years ago
lilia 5b0573293f Fix references to GroupContext Type ENUM values 11 years ago
lilia e89e691957 Fix bug in groupId generation
Previously, if calling createNewGroup with an undefined groupId,
no groupId was generated.

This occurred because no entry for "group" + undefined exists in
localStorage, which caused this code to think undefined was a
valid group id.

Fixed by adding `|| groupId == undefined` to the while clause.
Also decoupled the groupId collision check for clarity.
11 years ago
lilia 81e4af5827 Move phonenumbery utils to libphonenumber object
Slowly whittling away at helpers.js...
11 years ago
lilia 9fc14cfa30 Remove erroneous comment re: MDN copyright
In fact, the code samples we have copied from MDN are declared to be
public domain (see link below):

  "Code samples added on or after August 20, 2010 are in the public
  domain."

https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses

AFAICT we're using code from this page, last updated 10/4/14:
https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
11 years ago
lilia 266600e5ab There's no need to wrap this function inside a function afaict 11 years ago
Matt Corallo 28779e0b35 Fix tests by returning promises 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 c427da04f0 Add closeSession tests as Alice and fix re-requesting prekeys 11 years ago
Matt Corallo ebcfd4736e Fix session lookup in duplicate prekeymessage case 11 years ago
Matt Corallo 287b55120d First cut of ALICE test vectors 11 years ago
Matt Corallo a8908646aa Fix null flags in v3 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 4c3ee6f23b Compare equality w/o getString (in the future) 11 years ago
Matt Corallo b94ba6b726 USE_NACL = true 11 years ago
Marco 13a9329bcf improved number validation (based on google's libphonenumber) 11 years ago
Matt Corallo 1ec6b0aed6 Better TODO wording 11 years ago
Matt Corallo 12a849957a Refresh groups on (probably) new identity key (maybe more often?) 11 years ago
Matt Corallo 0f126fc0f8 Keep track of number->groups, add TODO to refresh, other tweaks 11 years ago
Matt Corallo e495e8e3db Group updates to match real protocol and get better checking 11 years ago
Matt Corallo c90b9a5c59 Some group update verification 11 years ago
Matt Corallo b1ec02fa92 Group API 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 8f49d201e6 Fix longstanding(?) attachment bug 11 years ago
Matt Corallo c2d1d816f2 Save sessions in deviceObjects, test using fake_api, minor tweaks 11 years ago
Matt Corallo 1724d122d3 More typos from me being too tired 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 753a950816 Redo registration process 11 years ago
Matt Corallo 2d12a33ead Fix decoding/protos/tests 11 years ago
Matt Corallo ac48d552fa Fix some bugs recently introduced 11 years ago
Matt Corallo 21b95ce1d3 Re-create some of d9bf0a4, which was broken and reverted in 1e6720 11 years ago