Commit Graph

474 Commits (9dc406dc8ddbea43df1819fe34f284f7bcda56cc)

Author SHA1 Message Date
lilia 331ca46d75 Fix websocket event name
Fixes #798

// FREEBIE
9 years ago
lilia 15e964de81 Update libsignal-protocol v0.13.0
* libsignal.Curve is now a synchronous interface.
* libsignal.Curve.async is now the asynchronous interface.
* Fixes bugs in session management.

// FREEBIE
9 years ago
lilia f216262298 Update libsignal-protocol v0.12.0
Moves version byte check to protocol lib.

// FREEBIE
9 years ago
lilia 055c0c323e Remove unneeded property from device object
// FREEBIE
9 years ago
lilia f8e176fd40 Dedupe methods
Define textsecure.crypto in terms of libsignal.crypto.

// FREEBIE
9 years ago
lilia 58452066aa Move device storage methods to outgoing message
This is the only place they are called.

// FREEBIE
9 years ago
lilia daae664965 Remove unused function
// FREEBIE
9 years ago
lilia d32a352d8a Use deviceIds/addresses instead of encodedNumbers
The getDeviceObjectsForNumber method returns device objects that contain
nothing but the encodedNumber property. Instead, just deal in deviceIds
until a SignalProtocolAddress is constructed to manage both the number
and deviceId.

// FREEBIE
9 years ago
lilia 95935f70ee Remove relay check from sendmessage
We don't currently store any relay information about devices,
and

// FREEBIE
9 years ago
lilia f16803018c Update libsignal-protocol v0.11.0
* Changes return type from decryption functions
* Update components

// FREEBIE
9 years ago
lilia 148bd32671 Update libsignal-protocol v0.10.0
* Changes policy for old session deletion
* Renames putIdentityKey to saveIdentity
* Remove device messages

// FREEBIE
9 years ago
lilia ffa702c934 Update libsignal-protocol v0.9.0
* Exposes crypto APIs.
* Move worker methods to libsigna.worker.
* Move ProvisioningCipher to libtextsecure.
9 years ago
lilia cd2218ada7 Move hard-coded worker url out of libtextsecure
// FREEBIE
9 years ago
lilia d5f4665fa4 MessageReceiver uses SessionCipher to retry conflicts
// FREEBIE
9 years ago
lilia 9ecfe6acb0 Use SignalProtocolAddress in MessageReceiver constructor
// FREEBIE
9 years ago
lilia 213b44935d Update libsignal-protocol v0.8.0
Reorder identity key check
9 years ago
lilia eee93987f8 Update libsignal-protocol v0.7.0
Remove unused methods.

// FREEBIE
9 years ago
lilia 6266050a67 Remove unused jobqueue
// FREEBIE
9 years ago
lilia 050ea87aaf Get device ids instead of objects
// FREEBIE
9 years ago
lilia 7939b6ae98 Remove hasOpenSession from protocol_wrapper
// FREEBIE
9 years ago
lilia 0483fa2f97 Remove closeOpenSessionForDevice from protocol_wrapper
// FREEBIE
9 years ago
lilia 0d5ec60a7a Remove handlePreKeyWhisperMessage from protocol_wrapper
// FREEBIE
9 years ago
lilia 8010a09045 Remove decryptWhisperMessage from protocol_wrapper
// FREEBIE
9 years ago
lilia 891ddacd35 Remove processPreKey from protocol_wrapper
Use SessionBuilder directly instead of protocol_wrapper

// FREEBIE
9 years ago
lilia 843036f0ce Remove getRegistrationId and encryptMessageFor from protocol_wrapper
We can now use protocol classes like SessionCipher directly because it
supports per-device read/write serialization internally.

// FREEBIE
9 years ago
lilia 284cf5be3a Update libsignal-protocol v0.6.0
Adds session accessors on SessionCipher and an internal session lock to
replace the same implemented in protocol_wrapper.js

// FREEBIE
9 years ago
lilia 92293f9da9 Update libsignal-protocol v0.5.0
Renames libsignal.util to libsignal.KeyHelper.

// FREEBIE
9 years ago
lilia e68031019b Integrate libsignal.SessionCipher
Bypass the old protocolInstance wrapper methods and use the shiny new
SessionCipher class directly.

// FREEBIE
9 years ago
lilia 9e6ad27fc5 Update libsignal-protocol v0.4.0
// FREEBIE
9 years ago
lilia 418adff2a8 Rename device_storage_test.js
// FREEBIE
9 years ago
lilia 56238136ca Remove trivial wrapper method
// FREEBIE
9 years ago
lilia 78cdc0cb52 Remove tempKeys
Now that we simply establish and save a session via SessionBuilder
rather than saving the keys to pass in during encrypt, we can stop
caching them in memory in between the identity key check and the
encryption step.

// FREEBIE
9 years ago
lilia 519d3ec31b Update libsignal-protocol
// FREEBIE
9 years ago
lilia 9f871db48a Update libsignal-protocol / Update prekey format
Integrates change in prekey object formatting, which now matches more
conveniently with the representation rendered by the server.

// FREEBIE
9 years ago
lilia f173104c82 Tests for isTrustedIdentity
// FREEBIE
9 years ago
lilia b385b6e48e Update libsignal-protocol
SessionBuilder / SessionRecord refactor.

// FREEBIE
9 years ago
lilia e659104cbf Add isTrustedIdentity to SignalProtocolStore
Adds a new required storage method for the protocol library.

// FREEBIE
9 years ago
lilia 7dcaf721ca Add keepalive logging
// FREEBIE
9 years ago
lilia 91bdd37019 Fix tests
// FREEBIE
9 years ago
lilia b160556d6e Change filename
// FREEBIE
9 years ago
lilia 9a1a3bdf64 Rename axolotl to libsignal
// FREEBIE
9 years ago
lilia 6bffd50009 Fix comment
// FREEBIE
9 years ago
lilia 1d60dc38fb Rename axolotl storage
// FREEBIE
9 years ago
lilia ee3bc11e3c Rename axolotlInstance
// FREEBIE
9 years ago
lilia 0fe3497d0e Update libsignal-protocol
Remove remaining refs to axolotl from lsp.

// FREEBIE
9 years ago
lilia 4169336776 Update libsignal protobuf package name
// FREEBIE
9 years ago
lilia c1e1dd97ba Change libsignal-protocol filenames
// FREEBIE
9 years ago
lilia b1d370755a Rename AxolotlStore
// FREEBIE
9 years ago
lilia 1fe5d63015 Update protocol libs
Rename storage functions

// FREEBIE
9 years ago
lilia 6a928e3377 Fix reference error in MessageReceiver from fe82e4
Fix a reference error when resolving a key conflict on an incoming end
session message. See Signal-Android/5438.

// FREEBIE
9 years ago
lilia 2d6d2a92b9 Update libaxolotl
// FREEBIE
9 years ago
lilia af392c077d Update libaxolotl
// FREEBIE
9 years ago
lilia 7e2c6fd6bc Remove unused argument
// FREEBIE
9 years ago
lilia ddcdc9e2ff Log on prekey messages
// FREEBIE
9 years ago
lilia 960519d296 Add debug logging
// FREEBIE
9 years ago
lilia 2128ee63aa Update libaxolotl
// FREEBIE
9 years ago
lilia 84235ef58e Use forEach instead of loop
// FREEBIE
9 years ago
lilia c02054d5da Pass ciphertext as ArrayBuffer instead of string
// FREEBIE
9 years ago
lilia 6053fe67ba Use built-in string conversion on protobuf
In lieu of a global helper.

// FREEBIE
9 years ago
lilia 3e0bce2b21 Move, rename, and simplify toArrayBuffer helper
This function is only ever used to convert groupIds from strings to
array buffers in sendmessage.

// FREEBIE
9 years ago
lilia c22a205d2e Remove unnecessary conversion from test
// FREEBIE
9 years ago
lilia 7dff9ac51b Update libaxolotl
// FREEBIE
9 years ago
lilia 57d64fe669 Fix session corruption due to database races
Prevent races between encrypt and decrypt calls, and other read/write
operations on the session store by serializing session io ops per
device.

Possible fix for #535

// FREEBIE
9 years ago
lilia 5f07c74f1a Add log statement when opening provisioning socket
Make it more obvious via logs which server someone is attempting to
register with (i.e., to disambiguate staging from prod).

// FREEBIE
9 years ago
lilia 2b7cbef8b1 Rename a function
Avoid confusing this operation with actual receipts, which are something
else.

// FREEBIE
9 years ago
lilia 8fdf58971c Add missing semicolons
// FREEBIE
9 years ago
lilia c3bbdb393f Refactor media uploading step
Move this to its own function which encapsulates the error handling for
it.

// FREEBIE
9 years ago
lilia 44b1a6451d Add validation to Message class
// FREEBIE
9 years ago
lilia 781ada64ca Add libtextsecure support for syncing read messages
Plumbing for sending and receiving a new sync protobuf for marking
messages read on/from my other devices.

// FREEBIE
9 years ago
lilia 010297f4c5 Track groups I've left
// FREEBIE
9 years ago
lilia 7e82d1295c Handle attachment upload errors
Adds a new kind of replayable error that handles retry of pre-encryption
failures, e.g., attachment upload.

Fixes #485

// FREEBIE
9 years ago
lilia 910e37649a Let group messages use new Message class
// FREEBIE
9 years ago
lilia 3bffdd96f5 Add sendMessage to handle sending from Message class
// FREEBIE
9 years ago
lilia ecdfa09e97 Create a helper class for constructing messages
// FREEBIE
9 years ago
lilia b73a3aea80 Fix syntax error
// FREEBIE
9 years ago
lilia cee2b3163a Add missing bind in messageReceiver
// FREEBIE
9 years ago
lilia 7dcad67410 Fix handleSentMessage
Missing a bind in 27fe7e3.

// FREEBIE
9 years ago
lilia d4760452d1 Add signal agent to server requests
// FREEBIE
9 years ago
lilia 27fe7e355e Process end session flags in sync messages
Because remote clients will delete all sessions in response to an end
session message, regardless of which device it came from, when our
linked device sends an end session message, we must also end all
sessions with the destination.

This change moves the end session flag processing to processDecrypted,
which is shared between handlers of sent messages, data messages, and
messages which are re-tried after resolving identity conflicts.

// FREEBIE
9 years ago
lilia fe82e469f2 Make end session consistent with android
Close all the sessions for a number when receiving an end session
message.

// FREEBIE
9 years ago
lilia 86132a38a8 Log envelopes and session end events
Help debug bad session errors by logging some envelope info about the
message we are about to decrypt. With this, if there is a decryption
error (e.g., bad mac or no session) it is clear from the logs what
number and device message sent the bad message.

Also log when we send and receive end session messages and when we close
sessions for certain devices.

// FREEBIE
9 years ago
lilia 7c17c5fa54 Update chai
// FREEBIE
9 years ago
lilia 1ee6a2e43f Rebuild libtextsecure test components w/ new chai
// FREEBIE
9 years ago
lilia a9cba1471a Update our own key on re-install
Previously we would delete our own key from the trust store when
re-linking, in case it changed. We can also immediately take one step
further and store the new key. Typically this happens in the course of
requesting sync info from the master device, except in the case of
standalone clients.

Closes #596

// FREEBIE
9 years ago
lilia 30aa13079f Fix sync request argument check
Fixes #609

// FREEBIE
9 years ago
lilia d6da77b6f4 Throw exception on bad args to SyncRequest
// FREEBIE
9 years ago
lilia 1b68e652cc Fire group sync completion event despite errors
Sometimes an error is thrown while processing groups from a group sync
message. We still want to fire the groupsync event when we're done
handling all the data, even if some of it was bad.
9 years ago
lilia 75b2c9c5de Fix crash when removing a listener
// FREEBIE
9 years ago
lilia f7c4fd2fed DRY up event target implementations
Dedupe event target code and make it extensible.

// FREEBIE
9 years ago
lilia 925c1bdb33 Add SyncRequest class
Similar in function to an xhr request, a textsecure.SyncRequest object
is initialized from a message sender and receiver pair and initiates a
request for sync from the master device. It later fires a success event
when both contacts and groups are done syncing, or a timeout event after
one minute.

// FREEBIE
9 years ago
Karel Bilek d8381cfc47 Dispatch an event after processing a group sync
Related #521
9 years ago
lilia 96520e9fd4 Move envelope decode before ack
We should not ack envelope protobufs that fail to decode correctly. If
the server happens to send us such a thing it probably indicates a
protocol mismatch between it and the client, in which case the client
needs to update and re-receive the failed message.

// FREEBIE
9 years ago
lilia 44824df6cb Refactor for clarity
// FREEBIE
9 years ago
Matt Corallo dac084b604 Send message ACKs immediately after recv, instead of after process 9 years ago
lilia 093eb001ff Correct log statement
Although in practice, these timestamps are often the same, they needn't
be, and when they aren't, we want the sentMessage.timestamp here.

// FREEBIE
9 years ago
lilia d95f869d62 More logging
// FREEBIE
9 years ago
lilia d201c65f7c More verbose logging in message receiver
// FREEBIE
9 years ago
lilia bc576e18d5 Fix no delivery receipts on close session messages
// FREEBIE
9 years ago
lilia 9031b4c10c Update libaxolotl
Fixes #477

// FREEBIE
9 years ago
lilia ea980b4385 Don't surface invalid attachment urls to the user
Log them, but don't put display them in user-facing error ui.

// FREEBIE
9 years ago
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