Commit Graph

474 Commits (9dc406dc8ddbea43df1819fe34f284f7bcda56cc)

Author SHA1 Message Date
lilia 7b1268e5f7 Log incoming invalid attachment urls also
Same as previous commit but for incoming.

// FREEBIE
9 years ago
lilia fe7505c050 Log invalid attachment urls
// FREEBIE
9 years ago
lilia 9c59dfda93 Remove duplicate case statement
This line was never being hit due to the duplicate one above (#L166).
Peeking at the server code shows that 403 is only given in response to
registration attempts, where it does in fact indicate an invalid code.

// FREEBIE
9 years ago
lilia 2f469835d9 Handle group quit sync messages
Previously, we would incorrectly reject group updates originating from a
linked device instructing us to remove ourselves from the group.

// FREEBIE
9 years ago
lilia edcb28aebb Don't save a MessageCounterError
Fixes #446

// FREEBIE
9 years ago
lilia b00d5289cf Save message timestamp for resending
Fix bug where resending due to failed network connection would fail
silently.

Broken in 7b6820 refactor which changed arguments to transmitMessage

// FREEBIE
10 years ago
lilia e9949152bb Always return a promise from sendSyncMessage
// FREEBIE
10 years ago
lilia acae4afce3 Handle invalid responses better
Depending on the response code, returning an HTTPError here will let us
retry later, if appropriate.

// FREEBIE
10 years ago
lilia 52b039a900 Remove unused function
This is now used only internally in libaxolotl, which provides its own
definition.

// FREEBIE
10 years ago
lilia 6445581594 Update libaxolotl
isEqual added to internal helper module

// FREEBIE
10 years ago
lilia 63cd3b2788 Use constant time mac comparison
In libtextsecure and in libaxolotl.

// FREEBIE
10 years ago
lilia 61439a886f Validate json responses
Perform lightweight validation on json responses from the server. Ensure
that the attributes we depend on have the right type.

// FREEBIE
10 years ago
lilia b0d4370c2c Remove unused variable
// FREEBIE
10 years ago
lilia 07702c4ee5 Let the application layer send sync messages
Previously, libtextsecure would send a sync message automatically
when appropriate. This fails if any recipient has a key conflict
or if our network connection fails mid-send.

Instead, when appropriate, return a the DataMessage encoded as an array
buffer for later syncing. This lets the application choose when to send
it, which we now do after any successful send to a recipient, rather
than after all recipients are successfully sent to.

Eventually we should move the DataMessage protobuf construction and
group sending logic to the application layer entirely, in which case
we wouldn't need libtextsecure to construct the sync message either.

Fixes #408
10 years ago
lilia 5c37c3d6ce Change return type from sending messages
Pass the whole result from the outgoing message callback on to the
caller, and preserve the names of the members.

// FREEBIE
10 years ago
lilia 7b6820d2ac Refactor messageSender/OutgoingMessage
Move encrypt and transmit to OutgoingMessage
Restore per-number queueing to messageSender

// FREEBIE
10 years ago
lilia adf8445b85 Populate registrationIds on deviceObjects
Saves us from doing so later.

// FREEBIE
10 years ago
lilia cf85c5e25e Fix key conflict with self after master device re-install
Fix bug where re-installing would cause sync messages to fail and
produce unresolvable error indicators on messages that were actually
sent.

// FREEBIE
10 years ago
lilia 4cc6b1ff9a Validate attachment urls
// FREEBIE
10 years ago
lilia f006bd9ddc Update libaxolotl
Removes webcrypto, fixes padding calc

// FREEBIE
10 years ago
lilia 641a7dbc6d Update libaxolotl
encryptMessageFor now requires an array buffer instead of a protobuf.

By converting the message to an array buffer outside the Promise.all, we
avoid allocating a new copy for each device.

// FREEBIE
10 years ago
codedust 5e255e9df0 Remove 'Textsecure' from error message in api.js 10 years ago
lilia 70bde5f4fa Update libaxolotl
// FREEBIE
10 years ago
lilia 596188a630 Fix protocol version check
Fixes #392

// FREEBIE
10 years ago
lilia 847fa43520 Save group members when creating groups from non-updates
Follow up to b0da4910. When inferring membership of the sender in an
unknown group, remember to save and return the group members.

Generally, this should only effect standalone clients unless someone
managed to clear their groups db table, since linked clients get group
info synced at registration.

// FREEBIE
10 years ago
lilia a3d29a92bb Reject messages sent to groups with no members
If you're the last member of the group, it doesn't make sense to send
messages to it. Previously, we would wait forever for a callback,
causing a stuck pending state indicator.

// FREEBIE
10 years ago
lilia 675be2b569 Don't reconnect if close was called
Fixes a bug during re-registration where we continue to re-open
the socket using old credentials.

// FREEBIE
10 years ago
lilia f863616785 Remove api TODO comments
// FREEBIE
10 years ago
lilia 80d32103d1 Clear session store when re-registering
When we re-register, our deviceId might change, which makes our sessions
are no longer valid since the recipient will see us as a new device.

Fixes #388
10 years ago
lilia a52d35bb1b Refactor and fixup key requests
Fix a bad loop scope bug in getKeysForNumber by using forEach.
Refactor the initial process of establishing key material for devices
that do not have open sessions.

// FREEBIE
10 years ago
lilia b18cfd75de Check for device keys in memory before requesting more
// FREEBIE
10 years ago
lilia 2b9d039837 Serialize requests for keys
Fixes #383

// FREEBIE
10 years ago
lilia a644b7a674 Update libaxolotl
// FREEBIE
10 years ago
lilia 1065502770 Change key conflict error message
Include the contact's number in the message for more helpful debug log
output.

// FREEBIE
10 years ago
lilia f8fd613669 Update libaxolotl
// FREEBIE
10 years ago
lilia ac7c95fed0 Validate argument lengths in crypto.js
These functions accept an array buffer and extract an AES and MAC key
from it without verifying it has the appropriate length. Ciphertext
messages are similarly dissected. The slice function does not raise an
error on out of bounds accesses but instead returns an empty or
partially-filled array. Empty or short arrays will be passed through to
the window.crypto.subtle API, where they will raise an error. We should
not rely on the Web Crypto API to validate key lengths or for MAC checks
to fail. Instead, validate the lengths of given parameters before
extracting their components.

// FREEBIE
10 years ago
lilia ec6898f1ab Process incoming messages in order
This may increase processing latency a bit, particularly with large
attachments, but will ensure that messages are dispatched in the order
they are received.

It would be nice to enforce ordering on only the dispatch step, so that
we could, for example, decrypt the next websocket message while waiting
for an attachment to download, but that will require a more complicated
refactor. Will stick with the quick fix for now and revisit later.

Fixes #342

// FREEBIE
10 years ago
lilia 9b12d8a978 Reconnect provisioning socket
If the provisioning socket closes, reconnect and generate a new qr code.
Fixes #371

// FREEBIE
10 years ago
lilia 01e85b68ef Handle exceptions when fetching keys for devices
It's rare that we get in a state where we have a device record without a
session, but we should handle errors gracefully in that case. Catch them
and register them, except for identity key errors which are registered
in handleResult.

// FREEBIE

fixup error handling // FREEBIE
10 years ago
lilia 12276e691b Refactor contents of sendMessageProto
This function dynamically declares a bunch of functions which bind to
its input arguments. Instead, use a new prototypal class to define
these functions within the context of a particular message.

// FREEBIE
10 years ago
lilia a2c7ac0df9 Serialize message sending per-recipient
Add a pendingMessages object to MessageSender. This object holds
one promise per recipient number. We init this promise with
Promise.resolve(), and chain on promises for message sending, replacing
the previous promise with the newly chained promise each time. If the
current promise resolves and finds that it is still the last promise
in the chain, it removes itself.
10 years ago
lilia 9be5efc571 Simplify keepalive resets
Websocket resources should have their keepalive timers reset whenever a
message comes in. This is a nicety that slightly reduces the amount of
traffic we send when actively messaging.

Previously this was handled by MessageReceiver, but it's a bit cleaner
to just have the WebsocketResource add an extra 'message' event handler.

// FREEBIE
10 years ago
lilia b9b01330fe Move jquery from libtextsecure components
Jquery is not required by libtextsecure, but our test coverage tool,
blanket, depends on it.

// FREEBIE
10 years ago
lilia 7414828bb3 Disable keepalive tests
These are failing because MockSocket doesn't implement an EventTarget
interface like an actual WebSocket does, so we get an exception when
trying to call addEventListener on it. :(

// FREEBIE
10 years ago
lilia 81ebc5ffd7 Improve stack traces on HTTPErrors
Save stack even earlier, outside the promise.

// FREEBIE
10 years ago
lilia c062fe3060 Automatically retry failed http requests
If we failed to reach the server, wait a second and try again up to 3
times.

// FREEBIE
10 years ago
lilia 816a206892 Refactor sendMessageToDevices
Split into separate encrypt and transmit functions. Let the encryption
function also handle all wire formatting (ie, jsonification and base64
encoding), which simplifes TextSecureServer.sendMessages, removes a
TODO, and lets us save fewer params to make network errors replayable.

// FREEBIE
10 years ago
lilia e9bc39bc56 Add parens and line breaks
// FREEBIE
10 years ago
lilia 0ff38e41c2 Let keepalive listen to socket events
Wait until the socket connects before starting the keepalive timer.
Automatically stop the keepalive when the socket is closed.

// FREEBIE
10 years ago
lilia 1345899253 Use reject instead of throw
This ensures that the containing promise is rejected without triggering
the side effects of an uncaught exception, such as causing the debugger
to pause.

// FREEBIE
10 years ago
lilia a32f3ff1f6 More work on replayable errors
Expose a button that does that retries outgoing messages if possible.

// FREEBIE
10 years ago
lilia 5eabfa2559 Fix libtextsecure tests
// FREEBIE
10 years ago
lilia 5bf608598c Fix MessageSender prototype
// FREEBIE
10 years ago
lilia b0da491025 Don't throw on unknown groups
// FREEBIE
10 years ago
lilia 8f003ea69d Don't throw if sender is not a group member
This could happen if we simply failed to process an earlier group
update correctly.

// FREEBIE
10 years ago
lilia 4a1d0ebdb9 Pass bytebuffer to axolotlInstance
// FREEBIE
10 years ago
lilia 46c9a7fafb Fix tryMessageAgain
// FREEBIE
10 years ago
lilia 9872b59355 Simplify filter predicate
Untangle a double negative to make this line shorter and easier to read.

// FREEBIE
10 years ago
lilia 0fa1069a93 Don't throw on duplicate members in a group update
Fixes #364

// FREEBIE
10 years ago
lilia 1aee065c2c Fix registration
Previously would fail to register keys by using the wrong username.
The username should be <number>.<deviceid> once we've confirmed our
account and received a deviceId from the server.

// FREEBIE
10 years ago
lilia 978b3d1a98 DRY up tryMessageAgain
// FREEBIE
10 years ago
lilia fbb65d1988 Add replayable network errors
Support for manual message retry.

// FREEBIE
10 years ago
lilia bc03bdbfc4 Move tryMessageAgain to MessageReceiver
`tryMessageAgain` is the routine called when re-trying a message that
failed to decrypt due to an IncomingIdentityKeyError. This handling
needs to move to MessageReceiver because it depends on
`processDecrypted` to handle incoming message protos, which depends
on a server instance in order to download attachments.

// FREEBIE
10 years ago
lilia 0fc673f25f Refactor sendmessage for prototypality
// FREEBIE
10 years ago
lilia 868695558d Throw on bad server url
// FREEBIE
10 years ago
lilia c8a1e090d2 Move handleAttachment and processDecrypted
Make these internal methods on MessageReceiver. Todo: refactor
identity key errors to use a given message receiver.

// FREEBIE
10 years ago
lilia a8f4bac2f7 Let makeAttachmentPointer resolve falsey arguments
Internalizing this pattern to the makeAttachmentPointer function lets us
DRY it up throughout the file.

// FREEBIE
10 years ago
lilia 9de23a967b Fix dropping the first websocket message 10 years ago
lilia 3fcd980c23 Add websocket error and close event handlers 10 years ago
lilia 78956ede2f Disable keepalive if we disconnect the socket 10 years ago
lilia 9e9d767a30 Add MessageSender
textsecure.MessageSender takes server url and credentials and returns
a message sending interface configured for that server.

Used a wrapper function to insert a TextSecureServer instance into
sendmessage.js code at runtime. This will result in function duplication
between different MessageSender objects, pending further refactoring to
use prototypal inheritence.

// FREEBIE
10 years ago
lilia 98aa5156b0 Refactor TextSecureServer for storage
Following the pattern from previous commit, let the server class accept
a url and login credentials from the caller. Then integrate into
MessageReceiver and AccountManager.

// FREEBIE
10 years ago
lilia 09bd6c7824 Lint
// FREEBIE
10 years ago
lilia 37ff3cf5a8 Change http logging
Printing method + url again makes it easier to match requests to
responses when scanning logs.

// FREEBIE
10 years ago
lilia b8536679b3 Stop keepalive when socket closes
// FREEBIE
10 years ago
lilia 04c5f83485 Un-nest libtextsecure errors
Fix inconsistency in error format, where we sometimes get an unexpected
Error object and sometimes get a wrapper object containing an Error.

Also start saving network errors.

// FREEBIE
10 years ago
lilia 1879e73c76 Allow one more retry if we get a 409
Handle cases where we get a 409 (missing/extra devices), handle it, then
get a 410 (stale devices by registration id).

// FREEBIE
10 years ago
lilia c8e51563a0 Refactor initial sync codepath to application layer
To reduce dependence on the message sending module, AccountManager
should send no sync requests itself.
10 years ago
lilia 6123c419d0 Remove refreshGroup
1. This is nonstandard behavior, not supported by any other clients. It
   may help sometimes but will also cause bugs (see 2)

2. iOS doesn't handle group updates with missing fields. all fields must
   be populated, and libtextsecure doesn't have any knowledge of the group
   name or avatar, so these updates will clobber group state on iOS.

// FREEBIE
10 years ago
lilia 94e1c2d123 Remove check for .humanError property
This property is no longer used by any of our errors.

// FREEBIE
10 years ago
lilia 6547538458 Use foreach instead of a loop
This syntax makes plain that the function is not used anywhere else,
and increases linearity/readability.

// FREEBIE
10 years ago
lilia acaf7b8de2 Refactor relay consistency check
Check the device list for relay consitency and throw an exception before
attempting to encrypt to any of the mismatched devices.

// FREEBIE
10 years ago
lilia bafc61600c Refactor sendMessageToDevices
Leverage map and Promise.all for more concise and linear code flow.
10 years ago
lilia 62c90e3925 Don't save/log websocket error
It's a generic error Event and doesn't actually contain anything useful.

// FREEBIE
10 years ago
lilia 289b82d1dc Expose messageReceiver.close
// FREEBIE
10 years ago
lilia 1d370857fc Remove unused callback arguments
Unused since d0fd3e94 afaict.

// FREEBIE
10 years ago
lilia 2204ef863d Fix event name
We successfully retry after a websocket connection closes, but this typo
prevented us from retrying if the websocket simply never opened.

// FREEBIE
10 years ago
lilia ce49d14d85 Fix leave group bug
This one's been around since forever, but only manifests when someone
leaves the group and comes back. In that case we fail to reinit their
numberRegistrationId object, which causes a npe when we try to send
send them group messages.

Affected parties must ask their fickle friends to leave/join again.

// FREEBIE
10 years ago
lilia c8a76ab38e Fix websocket event handler name
// FREEBIE
10 years ago
lilia 823f570955 Add more websocket debug logging
// FREEBIE
10 years ago
lilia f70e844cef Include url in http response logging
Otherwise it's impossible to tell which is which, especially when
sending group messages.

// FREEBIE
10 years ago
lilia 2243c09fea MessageReceiver is an event target
Rather than asking for a global target, the message receiver implements
the EventTarget interface itself. It does not expose the dispatchEvent
method, however. This ensures that events can only be triggered from
within the internal MessageReceiver class, which means we no longer need
to namespace them.

// FREEBIE
10 years ago
lilia a925027cd2 Refactor MessageReceiver for storage/server independence
Let the libtextsecure consumer pass in their own server url, username,
password, and signaling key, as with libtextsecure-java.

Also brings reconnect logic up into the MessageReceiver class, which
is the only place it should apply.
10 years ago
lilia e59a5792d5 Don't hardcode the attachment host 10 years ago
lilia 184e37383c Don't auto-populate the relay field
According to server api docs, relay is optional when it is the same as
our own server.

// FREEBIE
10 years ago
lilia 7d9cf0c167 Pass the signaling key into decryptWebSocketMessage
De-couple this file from dependency on storage.
10 years ago
lilia 537f0ceef0 Log all http requests at start and end
// FREEBIE
10 years ago
lilia 04c8796bd3 Disable socket level reconnect
This is now handled at a higher level by the message receiver with the
aid of http requests for diagnosing the disconnect.

// FREEBIE
10 years ago
lilia 6b483195cb Fix reconnect bugs from previous commit
Forgot to bind the socket event handler, and the then() handler should
come before the catch() handler or else it will execute every time the
catch handler executes.

// FREEBIE
10 years ago
lilia 16de5aa3d3 Improve reconnect logic
Always test connectivity with an http request after a websocket closes,
regardless of what code/error it closed with. If that request succeeds,
automatically reconnect the socket.

// FREEBIE
10 years ago
lilia f764445c86 Remove erroneous license file and headers
We only use GPLV3 around here.

// FREEBIE
10 years ago
lilia 0b98043c1c Add a worker
Offload all the asm.js code to a second thread. This is usually the
source of intermittent frontend freezes when running single-threaded.
10 years ago
lilia c3d3ec125d Wait for contact sync before opening inbox
Use a canned bootstrap progress animation in lieu of better design.

Fix #271 // FREEBIE
10 years ago
lilia 4f1ce4c493 Assume unknown recipients are single-device
Start by requesting keys for only the master device, then handle 410 as
needed. Single-device users are the more common case and this strategy
lets us avoid requesting/expending one of our own device keys when
establishing a session with sibling devices.

// FREEBIE
10 years ago
lilia f3f084398f Handle identity key errors when retrying decrypt
After setting a new identity key as trusted, we retry decryption on all
pending conflicts for that contact. If their identity changed twice in a
row, we can still get a conflict the second time, and should handle it
appropriately.
10 years ago
lilia 4fc4573de4 Don't try to sync after single device registration
There's no other device to sync to. :p
10 years ago
lilia b3d93ab334 Request group sync when pairing
Whoops, missed a step. Fixes #319. Fixes #276.

// FREEBIE
10 years ago
lilia 56b6375f97 Use new provisioning socket keepalive path
This new endpoint should always issue a response to a provisioning
socket so if we don't receive one we should assume the connection has
been lost.

Closes #318
10 years ago
lilia 2b563212b4 Change default for keepalive autodisconnect config
By default, automatically disconnect if no response. This is preferable
because we can sometimes lose connectivity without receiving a close
event from the socket, but it's also possible that the endpoint may not
support responses.

// FREEBIE
10 years ago
lilia ebca58b282 Fix multiple calls to done
Triggered by multiple keepalives.
10 years ago
lilia 7c0eb5e080 Add keepalive reset test 10 years ago
lilia 01ca1be24e Fix test 10 years ago
lilia 1a06cb5cbe Update consumers of WebsocketResources 10 years ago
lilia 1af8bd16b7 Add default response message to websocketresources
// FREEBIE
10 years ago
lilia 44b7b32385 Update tests 10 years ago
lilia 637cbcbf99 Make handleRequest optional in WebSocketResources
If no request handler is provided, respond with 404 to any incoming
requests.
10 years ago
lilia cd363bd84d Integrate keepalives into websocket resources 10 years ago
lilia 7d2b41db11 Add auto-disconnect config to keepalive constructor
Disconnects on no keepalive response by default.

// FREEBIE
10 years ago
lilia d9fe783488 Accept close code/message via websocket/resources 10 years ago
lilia 8170a7baae WebSocketResource exposes socket.close()
Allows for simplification of the keepalive construct.
10 years ago
lilia 98edd3939b Fix up websocket options handling 10 years ago
lilia 4c9d69094d Work on message receiver tests
Not quite working yet

// FREEBIE
10 years ago
lilia d9d4e281cc Keepalive provisioning socket
Fixes #315

// FREEBIE
10 years ago
lilia 0d0bdbf998 Don't auto-reconnect provisioning socket
// FREEBIE
10 years ago
lilia 15cd348bf2 Remove nonexistant variable 10 years ago
lilia 1f8856fa69 MessageReceiver accepts a server websocket url
// FREEBIE
10 years ago
lilia 17e515f886 Add identity key conflict tests 10 years ago
lilia c05be725b3 Move makeAttachmentPointer
Clean up unnecessary pre-declaration of `var makeAttachmentPointer`.
10 years ago
lilia 67f25214d3 Refactor outgoing identity key conflict handling
saveKeysToDeviceObject is the detector of outgoing identity key errors.
Catch these key errors closer to the source by pulling the
getKeysForNumber into the context of sendMessageToDevices, which lets
it access registerError and the message protobuf.

Previously identity key errors would be uncaught if all existing
sessions with a recipient were closed/deleted, since we would
preemptively fetch the new identity key. The old error handling only
kicked in after a 409/410 response from the server when posting a
message encrypted for a stale session.

// FREEBIE
10 years ago
lilia 27016e1919 Let textsecure devices throw on identity key change
Restore error format, accidentally removed in 43d6efcd

// FREEBIE
10 years ago
lilia 4e88d4a5cf Add missing semicolons 10 years ago
lilia c28b5408ab Plumb keys into outgoing conflicts 10 years ago
lilia cc303e0802 Update libaxolotl, handle untrusted identitykey
Previously we had no access to the new untrusted identity
for verification purposes.

// FREEBIE
10 years ago
lilia af48ca9e4b Update libaxolotl, remove one string conversion
Previously we would convert a bytebuffer to a string, pass it to
libaxolotl where it would be parsed back into a bytebuffer.

Ideally we would just pass the bytebuffer, but it turns out that
libaxolotl's bytebyffer class is identical but separate from
libtextsecure's bytebuffer class. ¯\_(ツ)_/¯

So instead we pass the underlying array buffer, which is handled
more or less the same way as a bytebuffer, and most importantly,
does not involve any copying.

// FREEBIE
10 years ago
lilia 1ab5af338a Update libaxolotl, un-revert b790f82849
Accidentally reverted in d3c158f
10 years ago
lilia 7d3d634a2d Move/refactor keepalive logic and add disconnect timer
We now disconnect ourselves if we don't get the server's response to a
keepalive request within 30s. This way we will eventually disconnect if
the network goes away but the socket is not closed.*

* See code.google.com/p/chromium/issues/detail?id=197841 and
https://stackoverflow.com/questions/11755605/chrome-websocket-connection-not-closed-when-browser-closed

We will then try to reconnect once a minute (See 8a10c96);

Keepalives belong at this level anyway, since the format is defined by
both the websocket resource protocol and our specific server url
structure.

// FREEBIE
10 years ago
lilia a3ae3cab79 Use Promise.reject for simplicity
The following are equivalent, except that the first is longer and
invokes an extra function call.

```
return new Promise(function(resolve, reject) {
  reject(new Error("Unknown Group"));
});

return Promise.reject(new Error("Unknown Group"));
```
10 years ago
lilia 20586e2dcc Namespace events
Naming conflict was firing the error handler twice.

// FREEBIE
10 years ago
lilia 6e74ac9e28 Dispatch all network errors, not just auth errors
Also streamline the onError handler.
10 years ago
lilia b40a8696b7 DRY up Promise creation in api.js
Since calls to ajax() are always wrapped in promises, we can internalize
that pattern in the ajax function itself.

// FREEBIE
10 years ago
lilia 3711e0a6cd Convert throwHumanError to custom error type
Now with 200% more helpful stack traces.

// FREEBIE
10 years ago
lilia 8745424d3a Fix outgoing identity key conflict handling
// FREEBIE
10 years ago
lilia 66ae3689c1 Fix decrypt error handling
This rejection-handler was resolving its promise rather than allowing
the rejection to bubble up.
10 years ago
lilia f8ae5556d9 Fix standalone registration 10 years ago
lilia 5242108e15 Fix group update avatar handling
The avatar handler was being added to the list of promises too late,
so we were storing the raw avatar protobuf (Long id, bytes key) rather
than the downloaded/decrypted attachment data.

Fixes #280
10 years ago
lilia 4c40861728 Fix reinstalls
Delay saving of new account info until we confirm with the server.
Explicitly delete old account info beforehand.

// FREEBIE
10 years ago
lilia db31835f68 Handle group sync for existing groups
// FREEBIE
10 years ago
lilia 5925c2fe84 Support for group sync
Protocol and handling is all analogous to contact sync: Multiple
GroupDetails structs are packed into a single attachment blob and parsed
on our end. We don't display the synced groups in the conversation list
until a new message is sent to one of them.

// FREEBIE
10 years ago
lilia f126e3b21b Work on auth error handling / reinstall 10 years ago
lilia 2f935dfd5e Add contact sync request protocol 10 years ago
lilia f32ff58953 Add support for device name 10 years ago
lilia 8dc4e34aaf Bug and test fixes for contact sync
Closes #135

// FREEBIE
10 years ago
lilia b0603bc91a Wrap message receiver for minimum api exposure
Initializing a message receiver opens the socket and starts listening
right away rather than requiring a separate call to connect. The only
other publicly accessible method is to query the socket status.

// FREEBIE
10 years ago
lilia 316838cfe9 Add tests and bug fixes for ContactBuffer 10 years ago
lilia 6d9854f456 Remove plaintext message test case
Support for the PLAINTEXT message type is not present in the latest
protobuf definitions. Leaving it out for now since we don't have any use
case for it currently.
10 years ago
lilia 228ffe901d Update json formatting for legacy message requests
Legacy DataMessages are sent using the `body` field, new Content
messages are sent using the `content` field.

// FREEBIE
10 years ago
lilia a833d62a71 Implement sync protocol changes
Update protobuf definitions and refactor message receive and decrypt
codepath to support new protocol, including various flavors of sync
messages (sent messages, contacts, and groups).

Also cleans up background.js and lets libtextsecure internalize
textsecure.processDecrypted and ensure that it is called before handing
DataMessages off to the application.

The Envelope structure now has a generic content field and a
legacyMessage field for backwards compatibility. We'll send outgoing
messages as legacy messages, and sync messages as "content" while
continuing to support both legacy and non-legacy messages on the receive
side until old clients have a chance to transition.
10 years ago
lilia 061d57c95a Fix string vs number comparison
Fix bug in device storage causing duplicate device messages after a 410.
10 years ago
lilia a9549e2e0f Fix 410 handling
We need to close the existing session with an old registrationId.
10 years ago
lilia 7d08e1132d Fix close session 10 years ago
lilia 7e8b1319a5 Ignore sync contexts on messages not from ourselves
But process the rest of the message normally.
10 years ago
lilia 090cc84452 Do not include destination on group sync messages 10 years ago
lilia d1bcafad65 Update libaxolotl 10 years ago
lilia 029c9754f0 Fix tests 10 years ago
lilia 704c6ce779 Signaling key is now an array buffer 10 years ago
lilia d230df5622 Move local identitykey and registrationid to indexeddb 10 years ago
lilia fe1d78b5fa Load protobufs asynchronously. Fixes #223 10 years ago
lilia 7799bef86c Tweak key conflict error messages
Be generic, because sometimes it's not TextSecure, but Signal.
10 years ago
lilia 359b4a15a2 Move group storage to axolotl store
Add async get/put/removeGroup to axolotl store and let libtextsecure
use it for group state storage.
10 years ago
lilia 748f32022a Fix up refreshGroup 10 years ago
lilia f774047935 Make libtextsecure group storage asynchronous 10 years ago
lilia 37c496f4f0 Close the provisioning socket 10 years ago
lilia 43d6efcd9e Don't save device objects to disk
Generate them from session and identity data. Save/delete pending prekey
data in an in-memory store and attach it to outgoing device objects.
10 years ago
lilia f413f03a6b Add getDeviceIds to axolotlstore
And add tests for getDeviceIds and removeAllSessions
10 years ago
lilia 121671c99f Store identity keys in indexeddb
Let device storage request them from axolotl store rather than storing a
copy.
10 years ago
lilia 7eda48f755 Move Session Storage to indexedDB 10 years ago
lilia 20ebc3f890 Move identity key storage functions to axolotl store 10 years ago
lilia f38b18ef63 Move Session storage to axolotlstore 10 years ago
lilia 9de1572ba6 Convert all storage.devices methods to be asynchronous 10 years ago
lilia 71715c95bc Async remove identity 10 years ago
lilia 26f1aa4db5 Async putSessionsForDevice 10 years ago
lilia 666f6baaca Async getSessionsForNumber 10 years ago
lilia 9e7d8c0a08 Rename textsecure.api and make it internal-only 10 years ago
lilia 45a61780af Fixup refreshPreKeys and call it whenever a prekey is deleted 10 years ago
lilia 7d0aeac8cb Use a worker to facilitate key generation 10 years ago
lilia f465bdddbf Add textsecure.AccountManager
This class should be used for account registration and for refreshing
prekeys for your account.
10 years ago
lilia a960acacc6 Add textsecure.refreshKeys
This helper checks the server for the number of remaining prekeys, then
generates more if there are fewer than 10 remaining.

// FREEBIE
10 years ago
lilia 96eafc7750 Integrate libaxolotl async storage changes
* Session records are now opaque strings, so treat them that way:
  - no more cross checking identity key and session records
  - Move hasOpenSession to axolotl wrapper
  - Remote registration ids must be fetched async'ly via protocol wrapper
* Implement async AxolotlStore using textsecure.storage
* Add some db stores and move prekeys and signed keys to indexeddb
* Add storage tests
* Rename identityKey storage key from libaxolotl25519KeyidentityKey to
  simply identityKey, since it's no longer hardcoded in libaxolotl
* Rework registration and key-generation, keeping logic in libtextsecure
  and rendering in options.js.
* Remove key_worker since workers are handled at the libaxolotl level
  now
10 years ago
lilia 8304aa903a Update libaxololt to a087b9e746e67995f16e077183cc0 10 years ago
lilia 2ff954d2f8 Fix api.js 10 years ago
lilia e4b49bde51 Add more websocket tests 10 years ago
lilia cc6a44f35d Fix tests 10 years ago
lilia 3ea254d0db Add TextSecureWebSocket tests 10 years ago
lilia 849a407433 Add mock-socket for testing socket stuff 10 years ago
lilia da34b8e0f8 Rename textsecure.websocket and make it internal-only 10 years ago
lilia 89c24cd2fa Move throwHumanError to api.js
It is only used there.
10 years ago
lilia 36b1e87214 Add textsecure.MessageReceiver
Encapsulate the websocket resources and socket setup process in a
friendly OO class. The MessageReceiver constructor expects an instance
of EventTarget on which to fire message events asynchronously. The
provider of the EventTarget can then add/remove listeners as desired.
10 years ago
lilia 37e09da1cc Remove unsued argument from getDeviceObject
Last usage of the `returnIdentityKey` argument was removed in 8b9a16852.
10 years ago
lilia bdecf5cc44 Generate key_worker.js
Instead of calling importScripts, which is prone to relative path
issues, generate the worker script with everything it needs included.
10 years ago
lilia 7af42a27c5 Fix registerKeys using array indices for key ids
preKeys is an array whose indices may or may not be keyId-based. Since
we have an inline keyId property, use that instead.
10 years ago
lilia bfe23d86aa Run key generation in a worker
Ground work for a smoother registration flow. Overall UX still needs
some polish but at least now we can have a progress gif or animation or
whatever. Also adds the phonenumber-confirmation step as a simple alert
box, which will be replaced with a nice dialogue in a later commit.
10 years ago
Matt Corallo 8b9a168524 Store session information separately 10 years ago
Matt Corallo e33c6fddda Do not rely on deviceObject.sessions anywhere in sendmessage 10 years ago
Matt Corallo 6c0f3ff1f0 Move session-storage logic to storage/devices from axolotl_wrapper 10 years ago
Matt Corallo 169097a409 Remove stale comments in axolotl_wrapper 10 years ago
Matt Corallo 89fefe4323 Create a textsecure.storage.impl to be overriden if desired 10 years ago
Matt Corallo 56bffdcfd3 Prefix libaxolotl-stored objects with "libaxolotl" 10 years ago
Matt Corallo 00cb420d37 Merge (un)encrypted storage layers 10 years ago
Matt Corallo 454b4726bd Replace load/decode/index around our own number with helpers 10 years ago
lilia 3759fe46e9 Account for -1 HTTPError code 10 years ago
lilia e52224e481 Remove libtextsecure's jquery dependency
Use only the finest, hand-crafted, artisanal XMLHttpRequests.
10 years ago
lilia 857eee5003 Divorce identity wipe from tryAgain functions
We'd like to live in a world where we can retry all the pending
conflicts in a conversation as a batch, which means we don't want to
wipe the identity key before processing each message. Thus, remove that
step from these handlers and encapsulate in a method on the conversation
model.
10 years ago
lilia c642854ddf Extract app-level logic from libtextsecure
Ensure that both tryAgain functions return promises, allowing the
application to take appropriate action in the result of success or
failure. This lets us remove all dependency from libtextsecure on
app-level constructs like message objects/ids and the `extenion.trigger`
function.

Corresponding frontend changes to follow in another commit.
10 years ago
lilia e88d4d8170 Tweak replayable errors
1. Return the value returned by the registered function, to expose the
underlying promise to the caller.

2. Stop accepting extra arguments to the replay function. The caller
should be able to do what they want with the returned promise instead.

3. Add a timestamp argument to the outgoing case, needed to re-try
sending a message.
10 years ago
Matt Corallo d3c158f4cf Move libaxolotl out-of-tree 10 years ago
Matt Corallo e2e06b2d3c Remove axolotl.storage usage from libtextsecure 10 years ago
lilia b790f82849 Remove libaxolotl dependency on textsecure/errors.js
Let libaxolotl throw a generic error instead of a replayable error, and
add an helper function in libtextsecure's axolotl_wrapper to catch and
convert from the generic error to the replayable one. This allows the
ReplayableError to remain a libtextsecure-level concept only.

Somewhat unrelatedly, but nearby, fix some whitespace and add missing
semicolon.
10 years ago
lilia 676ad04958 Add device storage method to wipe an identity 10 years ago
lilia 9e04910124 Recompile curve25519 with emcc 1.29.0
Now with actual malloc/free implementations. Had to drop back to -O1
optimization because the ed25519 signature test broke with -O2. :(

Closes #153

The toolchain install and build process, for reference:
```
wget https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz
tar xvfz emsdk-portable.tar.gz
cd emsdk-portable
./emsdk update
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
cd ../TextSecure-Browser
grunt build
```
10 years ago
lilia b9969b14b6 Always reconnect the socket except when there is an error
Turns out we can get ABNORMAL_CODE (1006) for disconnects where (for
instance) we pause the background page too long. However, in these cases
there is no preceeding ErrorEvent. In contrast, when we have bad
authentication credentials, there is an ErrorEvent. Thus, this change
ensures that we only reconnect if there was no Error.
10 years ago
lilia 0cbad730ce Don't send keepalive if socket has closed
Also shorten the timeout to see if it improves websocket connection
reliability.
10 years ago
lilia 2b073f3365 Reset keepalive timer if we're about to send
No sense in sending more keepalives than necessary.
10 years ago
lilia 7e5e558ad5 Bump keepalive to 60s 10 years ago
lilia fd6e2954f7 Curtail over-zealous websocket reconnects
Closes #173

Previously, in the event of a failed websocket auth, we would attempt to
reconnect once a second ad infinitum. This changeset ensures that we
only reconnect automatically if the socket closed 'normally' as
indicated by the code on the socket's CloseEvent. Otherwise, show a
'Websocket closed' error on the inbox view.

Ideally we would show a more contextual error (ie, 'Unauthorized'), but
unfortunately the actual server response code is not available to our
code. It can be observed in the console output from the background page,
but programmatically, we only receive the WebSocket CloseEvent codes
listed here:
https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes

The websocket error message is displayed by a normally-hidden but ever
present socket status element. Clicking this element will immediately
refresh the background page, which will try again to open the websocket
connection.
10 years ago
Matt Corallo 2277b41639 Remove non-existant device messages 10 years ago
Matt Corallo 5abf3073d5 Check END_SESSION messages in processDecrypted 10 years ago
Matt Corallo 29192edcb8 Ignore END_SESSION on messages with a sync context 10 years ago
Matt Corallo 9c3f8a1868 Dont send group-update right before we quit the group
Fixes #166
10 years ago
lilia b1035c23e5 Preserve whitespace in _concat files
This is a whitespace-only change. The diff is best viewed
with the `--patience` flag.

Some component library sources include trailing whitespace and carriage
returns which were excluded from these compiled files, (but somehow
still included in the final libtextsecure build). Although superfluous,
excluding these characters from these files means that I end up with
spurious changes whenever I rebuild them.
10 years ago
Matt Corallo f2853d00e6 Merge pull request #167 from WhisperSystems/sync
Sync outgoing individual and group messages
10 years ago
lilia f860cb4492 Return end session messages to the frontend
So we can save them in the message history, and because the caller
expects a promise.
10 years ago
lilia 40351fcc54 Sync outgoing messages
When sending an constrct a copy of the PushMessageContent protobuf, add
a SyncMessageContext, and send it to ourselves. Do this for all kinds of
group messages, and individual text/media messages, but not closeSession
messages as the latter are device-specific.

Do not sync messages if we are the primary device, which should only be
supported in development. Normal web clients must be paired with a
android or ios master device, and even in dev, a primary/standalone web
client does not support linking additional devices.
10 years ago
Matt Corallo b45c09470f Merge pull request #155 from WhisperSystems/closeSession
Fix textsecure.closeSession
10 years ago
lilia 0e8a5806a8 Fix textsecure.closeSession
sendIndividualProto requires a timestamp.
10 years ago
lilia 65c70a9117 Fix provisioning flow
Fix undefined axolotl.protobufs.ProvisionMessage, referenced in
libaxolotl/protocol.js
10 years ago
Matt Corallo 148410a826 Move jquery dep from libaxolotl to libaxolotl tests 10 years ago
Matt Corallo 44a094c324 Re-run concat 10 years ago
Matt Corallo 1e318a8293 Add missing TODO 10 years ago
Matt Corallo b356403061 De-duplicate registrationId in deviceObject 10 years ago
Matt Corallo 92d0de6837 [de]serialize sessions storage in device storage 10 years ago
Matt Corallo 1bef1ce5d3 Split out identity key storage from session storage 10 years ago
Matt Corallo 298c8624b2 Move test vectors to libaxolotl 10 years ago
Matt Corallo 7e3f1ef452 Actually store on removeDeviceIds 10 years ago
Matt Corallo 1806210b26 Rewrite most of the device storage stuff 10 years ago
Matt Corallo f1f5914879 Re-run concat 10 years ago
Matt Corallo bfb3e7751e Add missing validity check to device storage 10 years ago
Matt Corallo 30dd13e8e3 Return a function instead of a session in decryptWhisperMessage 10 years ago
Matt Corallo 3e648b0ea0 Move groups storage back to libtextsecure 10 years ago
Matt Corallo 04b2a13a75 Naively move device/session storage to wrapper 10 years ago
Matt Corallo 870e5dc9dc Remove all external non-test deps on libaxolotl/crypto 10 years ago