Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Olm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
Olm
Commits
8356fa37
Commit
8356fa37
authored
8 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
zero out plaintext buffers
Avoid leaving copies of the plaintext sitting around in the emscripten heap.
parent
76610c0a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
javascript/olm_inbound_group_session.js
+4
-2
4 additions, 2 deletions
javascript/olm_inbound_group_session.js
javascript/olm_outbound_group_session.js
+4
-2
4 additions, 2 deletions
javascript/olm_outbound_group_session.js
javascript/olm_post.js
+15
-4
15 additions, 4 deletions
javascript/olm_post.js
with
23 additions
and
8 deletions
javascript/olm_inbound_group_session.js
+
4
−
2
View file @
8356fa37
...
...
@@ -64,7 +64,7 @@ InboundGroupSession.prototype['create'] = restore_stack(function(session_key) {
InboundGroupSession
.
prototype
[
'
decrypt
'
]
=
restore_stack
(
function
(
message
)
{
var
message_buffer
,
plaintext_buffer
;
var
message_buffer
,
plaintext_buffer
,
plaintext_length
;
try
{
message_buffer
=
malloc
(
message
.
length
);
...
...
@@ -80,7 +80,7 @@ InboundGroupSession.prototype['decrypt'] = restore_stack(function(
plaintext_buffer
=
malloc
(
max_plaintext_length
+
NULL_BYTE_PADDING_LENGTH
);
var
message_index
=
stack
(
4
);
var
plaintext_length
=
inbound_group_session_method
(
plaintext_length
=
inbound_group_session_method
(
Module
[
"
_olm_group_decrypt
"
]
)(
this
.
ptr
,
...
...
@@ -105,6 +105,8 @@ InboundGroupSession.prototype['decrypt'] = restore_stack(function(
free
(
message_buffer
);
}
if
(
plaintext_buffer
!==
undefined
)
{
// don't leave a copy of the plaintext in the heap.
bzero
(
plaintext_buffer
,
plaintext_length
+
NULL_BYTE_PADDING_LENGTH
);
free
(
plaintext_buffer
);
}
}
...
...
This diff is collapsed.
Click to expand it.
javascript/olm_outbound_group_session.js
+
4
−
2
View file @
8356fa37
...
...
@@ -64,9 +64,9 @@ OutboundGroupSession.prototype['create'] = restore_stack(function() {
});
OutboundGroupSession
.
prototype
[
'
encrypt
'
]
=
function
(
plaintext
)
{
var
plaintext_buffer
,
message_buffer
;
var
plaintext_buffer
,
message_buffer
,
plaintext_length
;
try
{
var
plaintext_length
=
Module
[
'
lengthBytesUTF8
'
](
plaintext
);
plaintext_length
=
Module
[
'
lengthBytesUTF8
'
](
plaintext
);
var
message_length
=
outbound_group_session_method
(
Module
[
'
_olm_group_encrypt_message_length
'
]
...
...
@@ -86,6 +86,8 @@ OutboundGroupSession.prototype['encrypt'] = function(plaintext) {
return
Module
[
'
UTF8ToString
'
](
message_buffer
);
}
finally
{
if
(
plaintext_buffer
!==
undefined
)
{
// don't leave a copy of the plaintext in the heap.
bzero
(
plaintext_buffer
,
plaintext_length
+
1
);
free
(
plaintext_buffer
);
}
if
(
message_buffer
!==
undefined
)
{
...
...
This diff is collapsed.
Click to expand it.
javascript/olm_post.js
+
15
−
4
View file @
8356fa37
...
...
@@ -42,6 +42,13 @@ function restore_stack(wrapped) {
}
}
/* set a memory area to zero */
function
bzero
(
ptr
,
n
)
{
while
(
n
--
>
0
)
{
Module
[
'
HEAP8
'
][
ptr
++
]
=
0
;
}
}
function
Account
()
{
var
size
=
Module
[
'
_olm_account_size
'
]();
this
.
buf
=
malloc
(
size
);
...
...
@@ -299,7 +306,7 @@ Session.prototype['matches_inbound_from'] = restore_stack(function(
Session
.
prototype
[
'
encrypt
'
]
=
restore_stack
(
function
(
plaintext
)
{
var
plaintext_buffer
,
message_buffer
;
var
plaintext_buffer
,
message_buffer
,
plaintext_length
;
try
{
var
random_length
=
session_method
(
Module
[
'
_olm_encrypt_random_length
'
]
...
...
@@ -308,7 +315,7 @@ Session.prototype['encrypt'] = restore_stack(function(
Module
[
'
_olm_encrypt_message_type
'
]
)(
this
.
ptr
);
var
plaintext_length
=
Module
[
'
lengthBytesUTF8
'
](
plaintext
);
plaintext_length
=
Module
[
'
lengthBytesUTF8
'
](
plaintext
);
var
message_length
=
session_method
(
Module
[
'
_olm_encrypt_message_length
'
]
)(
this
.
ptr
,
plaintext_length
);
...
...
@@ -334,6 +341,8 @@ Session.prototype['encrypt'] = restore_stack(function(
};
}
finally
{
if
(
plaintext_buffer
!==
undefined
)
{
// don't leave a copy of the plaintext in the heap.
bzero
(
plaintext_buffer
,
plaintext_length
+
1
);
free
(
plaintext_buffer
);
}
if
(
message_buffer
!==
undefined
)
{
...
...
@@ -345,13 +354,13 @@ Session.prototype['encrypt'] = restore_stack(function(
Session
.
prototype
[
'
decrypt
'
]
=
restore_stack
(
function
(
message_type
,
message
)
{
var
message_buffer
,
plaintext_buffer
;
var
message_buffer
,
plaintext_buffer
,
max_pliantext_length
;
try
{
message_buffer
=
malloc
(
message
.
length
);
Module
[
'
writeAsciiToMemory
'
](
message
,
message_buffer
,
true
);
var
max_plaintext_length
=
session_method
(
max_plaintext_length
=
session_method
(
Module
[
'
_olm_decrypt_max_plaintext_length
'
]
)(
this
.
ptr
,
message_type
,
message_buffer
,
message
.
length
);
...
...
@@ -379,6 +388,8 @@ Session.prototype['decrypt'] = restore_stack(function(
free
(
message_buffer
);
}
if
(
plaintext_buffer
!==
undefined
)
{
// don't leave a copy of the plaintext in the heap.
bzero
(
plaintext_buffer
,
max_plaintext_length
+
NULL_BYTE_PADDING_LENGTH
);
free
(
plaintext_buffer
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment