aboutsummaryrefslogtreecommitdiff
path: root/javascript/olm_inbound_group_session.js
diff options
context:
space:
mode:
authorHubert Chathi <hubert@uhoreg.ca>2018-10-16 17:50:34 -0400
committerHubert Chathi <hubert@uhoreg.ca>2018-10-16 17:50:34 -0400
commit93f764200ef47cf6ad683216c21d98b438897ead (patch)
treead69f3ece758a8012424967d1cff1f86bd2a5f28 /javascript/olm_inbound_group_session.js
parent09dc3b602599c1d7305adb183e4d402665d79a8f (diff)
zero buffers in the JavaScript bindings
Diffstat (limited to 'javascript/olm_inbound_group_session.js')
-rw-r--r--javascript/olm_inbound_group_session.js62
1 files changed, 48 insertions, 14 deletions
diff --git a/javascript/olm_inbound_group_session.js b/javascript/olm_inbound_group_session.js
index 7d9e401..dd8e493 100644
--- a/javascript/olm_inbound_group_session.js
+++ b/javascript/olm_inbound_group_session.js
@@ -29,9 +29,17 @@ InboundGroupSession.prototype['pickle'] = restore_stack(function(key) {
)(this.ptr);
var key_buffer = stack(key_array);
var pickle_buffer = stack(pickle_length + NULL_BYTE_PADDING_LENGTH);
- inbound_group_session_method(Module['_olm_pickle_inbound_group_session'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer, pickle_length
- );
+ try {
+ inbound_group_session_method(Module['_olm_pickle_inbound_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,28 +48,52 @@ InboundGroupSession.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);
- inbound_group_session_method(Module['_olm_unpickle_inbound_group_session'])(
- this.ptr, key_buffer, key_array.length, pickle_buffer,
- pickle_array.length
- );
+ try {
+ inbound_group_session_method(Module['_olm_unpickle_inbound_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;
+ }
+ }
});
InboundGroupSession.prototype['create'] = restore_stack(function(session_key) {
var key_array = array_from_string(session_key);
var key_buffer = stack(key_array);
- inbound_group_session_method(Module['_olm_init_inbound_group_session'])(
- this.ptr, key_buffer, key_array.length
- );
+ try {
+ inbound_group_session_method(Module['_olm_init_inbound_group_session'])(
+ this.ptr, key_buffer, key_array.length
+ );
+ } finally {
+ // clear out copies of the key
+ bzero(key_buffer, key_array.length)
+ for (var i = 0; i < key_array.length; i++) {
+ key_array[i] = 0;
+ }
+ }
});
InboundGroupSession.prototype['import_session'] = restore_stack(function(session_key) {
var key_array = array_from_string(session_key);
var key_buffer = stack(key_array);
- inbound_group_session_method(Module['_olm_import_inbound_group_session'])(
- this.ptr, key_buffer, key_array.length
- );
+ try {
+ inbound_group_session_method(Module['_olm_import_inbound_group_session'])(
+ this.ptr, key_buffer, key_array.length
+ );
+ } finally {
+ // clear out copies of the key
+ bzero(key_buffer, key_array.length)
+ for (var i = 0; i < key_array.length; i++) {
+ key_array[i] = 0;
+ }
+ }
});
InboundGroupSession.prototype['decrypt'] = restore_stack(function(
@@ -140,7 +172,9 @@ InboundGroupSession.prototype['export_session'] = restore_stack(function(message
outbound_group_session_method(Module['_olm_export_inbound_group_session'])(
this.ptr, key, key_length, message_index
);
- return Pointer_stringify(key);
+ var key_str = Pointer_stringify(key);
+ bzero(key, key_length); // clear out a copy of the key
+ return key_str;
});
olm_exports['InboundGroupSession'] = InboundGroupSession;