diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2018-10-19 11:34:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-19 11:34:55 -0400 |
commit | c4c3055f838092aa5503253363faa55b44d7c0a5 (patch) | |
tree | bccae67b64e716b98c103e9f9c3c836286fed287 /javascript/olm_outbound_group_session.js | |
parent | 1d880f9711e0f1b084e63221899f7da2e1087e28 (diff) | |
parent | 93f764200ef47cf6ad683216c21d98b438897ead (diff) |
Merge pull request #71 from matrix-org/js_sanitising
zero buffers in the JavaScript bindings
Diffstat (limited to 'javascript/olm_outbound_group_session.js')
-rw-r--r-- | javascript/olm_outbound_group_session.js | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/javascript/olm_outbound_group_session.js b/javascript/olm_outbound_group_session.js index e232883..f1ccd3d 100644 --- a/javascript/olm_outbound_group_session.js +++ b/javascript/olm_outbound_group_session.js @@ -29,9 +29,17 @@ OutboundGroupSession.prototype['pickle'] = restore_stack(function(key) { )(this.ptr); var key_buffer = stack(key_array); var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH); - outbound_group_session_method(Module['_olm_pickle_outbound_group_session'])( - this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length - ); + try { + outbound_group_session_method(Module['_olm_pickle_outbound_group_session'])( + this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length + ); + } finally { + // clear out copies of the pickle key + bzero(key_buffer, key_array.length) + for (var i = 0; i < key_array.length; i++) { + key_array[i] = 0; + } + } return Pointer_stringify(pickle_buffer); }); @@ -40,10 +48,18 @@ OutboundGroupSession.prototype['unpickle'] = restore_stack(function(key, pickle) var key_buffer = stack(key_array); var pickle_array = array_from_string(pickle); var pickle_buffer = stack(pickle_array); - outbound_group_session_method(Module['_olm_unpickle_outbound_group_session'])( - this.ptr, key_buffer, key_array.length, pickle_buffer, - pickle_array.length - ); + try { + outbound_group_session_method(Module['_olm_unpickle_outbound_group_session'])( + this.ptr, key_buffer, key_array.length, pickle_buffer, + pickle_array.length + ); + } finally { + // clear out copies of the pickle key + bzero(key_buffer, key_array.length) + for (var i = 0; i < key_array.length; i++) { + key_array[i] = 0; + } + } }); OutboundGroupSession.prototype['create'] = restore_stack(function() { @@ -116,7 +132,9 @@ OutboundGroupSession.prototype['session_key'] = restore_stack(function() { outbound_group_session_method(Module['_olm_outbound_group_session_key'])( this.ptr, key, key_length ); - return Pointer_stringify(key); + var key_str = Pointer_stringify(key); + bzero(key, key_length); // clear out our copy of the key + return key_str; }); OutboundGroupSession.prototype['message_index'] = function() { |