Commit graph

13 commits

Author SHA1 Message Date
Hubert Chathi
ed94b56d16 fix compatibility with newer versions of emscripten 2022-10-06 13:14:38 -04:00
Hubert Chathi
8519ce0269 clear out random arrays 2021-12-10 16:15:22 -05:00
Hubert Chathi
ebc156e7c2 re-add null termination in javascript
because older versions of emscripten don't support the length argument to
UTF8ToString.
2019-04-08 15:54:02 -04:00
Damir Jelić
071029c201 javascript: Switch from deprecated Pointer_stringify() to UTF8toString().
The Pointer_stringify() function is deprecated and has a couple of
issues because it tries to guess the encoding of the buffer. In some
cases it can ignore the length parameter which could end up in
inconsistencies.

Switch to UTF8toString() that takes a length parameter and respects,
that way we don't need to allocate an additional byte for a NULL byte.
2019-04-08 15:18:28 -04:00
Hubert Chathi
93f764200e zero buffers in the JavaScript bindings 2018-10-16 17:50:34 -04:00
David Baker
122867c45c WebAssembly support!
Quite a lot going on in this PR:
 * Updates to support recent emscripten, switching to WASM which is now the default
 * Use emscripten's MODULARIZE option rather than wrapping it ourself, since doing
   so in pre-post js doesn't work anymore.
 * Most changes are moving the emscripten runtime functions to top-level
   calls rather than in the Module object.
 * Get rid of duplicated NULL_BYTE_PADDING_LENGTH
 * Fix ciphertext_length used without being declared
 * Fix things that caused the closure compiler to error, eg. using
   OLM_OPTIONS without a declaration.
 * Wait until module is inited to do OLM_ERROR = olm_error()

The main BREAKING CHANGE here is that the module now needs to initialise
asyncronously (because it has to load the wasm file). require()ing olm
now gives a function which needs to be called to create an instance.
The resulting object has a promise-like then() method that can be used
to detect when the module is ready. (We could use MODULARIZE_INSTANCE
to return the module directly as before, rather than the function,
but then we don't get the .then() method).
2018-09-21 16:01:51 +01:00
Richard van der Hoff
8e554ab5ef Avoid buffer overrun on encryption
Make sure we null-terminate encrypted strings before passing them to
UTF8ToString.

This used to work when we allocated the buffer on the stack, because it turns
out that allocate() zeroinits the returned memory. malloc(), of course, does
not.
2016-12-16 14:42:41 +00:00
Richard van der Hoff
8356fa37ad zero out plaintext buffers
Avoid leaving copies of the plaintext sitting around in the emscripten heap.
2016-12-15 13:37:34 +00:00
Richard van der Hoff
76610c0a3a Allocate memory for message blobs on the heap
Messages can be very large, so we don't really want to allocate them on the
stack. Switch to using the heap for them, and try to clean up some of the
string handling while we're at it.
2016-12-14 12:05:56 +00:00
Richard van der Hoff
50cd2b2a43 Clean up some typos
Remove redundant args from some js funcs, and fix a comment typo
2016-09-06 14:06:43 +01:00
Richard van der Hoff
c2b51207ee Fix error handling for group sessions
Fix a couple of places where we were using the wrong method to get the last
error.
2016-09-05 19:42:04 +01:00
Richard van der Hoff
1d4c13c798 Fix megolm decryption of UTF-8
Repeat the fix from b10f90d for megolm messages.

It turns out that the 'length' argument to 'Pointer_stringify' doesn't work if
the input includes characters >= 128.

Rather than try to figure out which methods can return UTF-8, and which always
return plain ascii, replace all uses of Pointer_stringify with a 'length'
argument with the version that expects a NULL-terminated input, and extend the
buffer by a byte to allow space for a null-terminator.

In the case of decrypt, we need to add the null ourself.

Fixes https://github.com/vector-im/vector-web/issues/2078.
2016-09-05 00:49:36 +01:00
Richard van der Hoff
013f27f3dc Javascript bindings for group sessions 2016-05-25 17:48:01 +01:00