Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
f2c283c9
Commit
f2c283c9
authored
Aug 04, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More work on decrypting messages
parent
be0eaecf
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
390 additions
and
164 deletions
+390
-164
dist/converse.js
dist/converse.js
+173
-66
spec/omemo.js
spec/omemo.js
+39
-10
src/converse-chatboxes.js
src/converse-chatboxes.js
+17
-13
src/converse-mam.js
src/converse-mam.js
+10
-6
src/converse-omemo.js
src/converse-omemo.js
+140
-67
src/utils/core.js
src/utils/core.js
+7
-2
tests/mock.js
tests/mock.js
+4
-0
No files found.
dist/converse.js
View file @
f2c283c9
This diff is collapsed.
Click to expand it.
spec/omemo.js
View file @
f2c283c9
...
...
@@ -10,13 +10,30 @@
describe
(
"
The OMEMO module
"
,
function
()
{
it
(
"
adds methods for encrypting and decrypting messages via AES GCM
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
let
iq_stanza
,
view
,
sent_stanza
;
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
test_utils
.
openChatBoxFor
(
_converse
,
contact_jid
)
.
then
((
view
)
=>
view
.
model
.
encryptMessage
(
'
This message will be encrypted
'
))
.
then
((
payload
)
=>
{
debugger
;
return
view
.
model
.
decryptMessage
(
payload
);
}).
then
(
done
);
}));
it
(
"
enables encrypted messages to be sent and received
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
,
'
chatBoxesFetched
'
],
{},
function
(
done
,
_converse
)
{
var
sent_stanza
;
let
iq_stanza
,
view
;
let
iq_stanza
,
view
,
sent_stanza
;
test_utils
.
createContacts
(
_converse
,
'
current
'
,
1
);
_converse
.
emit
(
'
rosterContactsFetched
'
);
const
contact_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
;
...
...
@@ -143,7 +160,7 @@
spyOn
(
_converse
.
connection
,
'
send
'
).
and
.
callFake
(
stanza
=>
{
sent_stanza
=
stanza
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
return
test_utils
.
waitUntil
(()
=>
sent_stanza
);
}).
then
(
function
()
{
}).
then
(
()
=>
{
expect
(
sent_stanza
.
toLocaleString
()).
toBe
(
`<message from='dummy@localhost/resource' to='max.frankfurter@localhost' `
+
`type='chat' id='
${
sent_stanza
.
nodeTree
.
getAttribute
(
'
id
'
)}
' xmlns='jabber:client'>`
+
...
...
@@ -154,10 +171,21 @@
`<key rid='555'>eyJ0eXBlIjoxLCJib2R5IjoiYzFwaDNSNzNYNyIsInJlZ2lzdHJhdGlvbklkIjoiMTMzNyJ9</key>`
+
`<iv>
${
sent_stanza
.
nodeTree
.
querySelector
(
'
iv
'
).
textContent
}
</iv>`
+
`</header>`
+
`<payload>
${
sent_stanza
.
nodeTree
.
querySelector
(
'
payload
'
).
textContent
}
</payload>`
+
`</encrypted>`
+
`</message>`
);
// Test reception of an encrypted message
return
view
.
model
.
encryptMessage
(
'
This is an encrypted message from the contact
'
)
}).
then
((
payload
)
=>
{
// XXX: Normally the key will be encrypted via libsignal.
// However, we're mocking libsignal in the tests, so we include
// it as plaintext in the message.
const
key
=
btoa
(
JSON
.
stringify
({
'
type
'
:
1
,
'
body
'
:
payload
.
key_str
+
payload
.
tag
,
'
registrationId
'
:
'
1337
'
}));
const
stanza
=
$msg
({
'
from
'
:
contact_jid
,
'
to
'
:
_converse
.
connection
.
jid
,
...
...
@@ -166,21 +194,22 @@
}).
c
(
'
body
'
).
t
(
'
This is a fallback message
'
).
up
()
.
c
(
'
encrypted
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
OMEMO
})
.
c
(
'
header
'
,
{
'
sid
'
:
'
555
'
})
.
c
(
'
key
'
,
{
'
rid
'
:
_converse
.
omemo_store
.
get
(
'
device_id
'
)}).
t
(
'
c1ph3R73X7
'
).
up
()
.
c
(
'
iv
'
).
t
(
'
1234
'
)
.
c
(
'
key
'
,
{
'
rid
'
:
_converse
.
omemo_store
.
get
(
'
device_id
'
)}).
t
(
key
).
up
()
.
c
(
'
iv
'
).
t
(
payload
.
iv
)
.
up
().
up
()
.
c
(
'
payload
'
).
t
(
'
M04R-c1ph3R73X7
'
);
.
c
(
'
payload
'
).
t
(
payload
.
ciphertext
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
return
test_utils
.
waitUntil
(()
=>
view
.
model
.
messages
.
length
>
1
);
}).
then
(()
=>
{
expect
(
view
.
model
.
messages
.
length
).
toBe
(
2
);
const
last_msg
=
view
.
model
.
messages
.
at
(
1
),
encrypted
=
last_msg
.
get
(
'
encrypted
'
);
expect
(
encrypted
instanceof
Object
).
toBe
(
true
);
expect
(
encrypted
.
device_id
).
toBe
(
'
555
'
);
expect
(
encrypted
.
iv
).
toBe
(
'
1234
'
);
expect
(
encrypted
.
key
).
toBe
(
'
c1ph3R73X7
'
);
expect
(
encrypted
.
payload
).
toBe
(
'
M04R-c1ph3R73X7
'
);
expect
(
encrypted
.
iv
).
toBe
(
btoa
(
'
1234
'
)
);
expect
(
encrypted
.
key
).
toBe
(
btoa
(
'
c1ph3R73X7
'
)
);
expect
(
encrypted
.
payload
).
toBe
(
btoa
(
'
M04R-c1ph3R73X7
'
)
);
done
();
});
}));
...
...
src/converse-chatboxes.js
View file @
f2c283c9
...
...
@@ -498,25 +498,29 @@
if
(
spoiler
)
{
attrs
.
spoiler_hint
=
spoiler
.
textContent
.
length
>
0
?
spoiler
.
textContent
:
''
;
}
return
attrs
;
return
Promise
.
resolve
(
attrs
)
;
},
createMessage
(
message
,
original_stanza
)
{
/* Create a Backbone.Message object inside this chat box
* based on the identified message stanza.
*/
const
attrs
=
this
.
getMessageAttributesFromStanza
(
message
,
original_stanza
);
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
getMessageAttributesFromStanza
(
message
,
original_stanza
)
.
then
((
attrs
)
=>
{
const
is_csn
=
u
.
isOnlyChatStateNotification
(
attrs
);
if
(
is_csn
&&
(
attrs
.
is_delayed
||
(
attrs
.
type
===
'
groupchat
'
&&
Strophe
.
getResourceFromJid
(
attrs
.
from
)
==
this
.
get
(
'
nick
'
))))
{
// XXX: MUC leakage
// No need showing delayed or our own CSN messages
return
;
resolve
()
;
}
else
if
(
!
is_csn
&&
!
attrs
.
file
&&
!
attrs
.
message
&&
!
attrs
.
oob_url
&&
attrs
.
type
!==
'
error
'
)
{
// TODO: handle <subject> messages (currently being done by ChatRoom)
return
;
resolve
()
;
}
else
{
return
this
.
messages
.
create
(
attrs
);
resolve
(
this
.
messages
.
create
(
attrs
)
);
}
});
});
},
isHidden
()
{
...
...
src/converse-mam.js
View file @
f2c283c9
...
...
@@ -129,12 +129,16 @@
// New functions which don't exist yet can also be added.
ChatBox
:
{
getMessageAttributesFromStanza
(
message
,
original_stanza
)
{
const
attrs
=
this
.
__super__
.
getMessageAttributesFromStanza
.
apply
(
this
,
arguments
);
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
__super__
.
getMessageAttributesFromStanza
.
apply
(
this
,
arguments
)
.
then
((
attrs
)
=>
{
const
archive_id
=
getMessageArchiveID
(
original_stanza
);
if
(
archive_id
)
{
attrs
.
archive_id
=
archive_id
;
}
return
attrs
;
resolve
(
attrs
);
}).
catch
(
reject
);
});
}
},
...
...
src/converse-omemo.js
View file @
f2c283c9
This diff is collapsed.
Click to expand it.
src/utils/core.js
View file @
f2c283c9
...
...
@@ -863,8 +863,8 @@
};
u
.
arrayBufferToString
=
function
(
ab
)
{
var
enc
=
new
TextDecoder
(
"
utf-8
"
);
return
enc
.
decode
(
new
Uint8Array
(
ab
)
);
const
enc
=
new
TextDecoder
(
"
utf-8
"
);
return
enc
.
decode
(
ab
);
};
u
.
arrayBufferToBase64
=
function
(
ab
)
{
...
...
@@ -872,6 +872,11 @@
.
reduce
((
data
,
byte
)
=>
data
+
String
.
fromCharCode
(
byte
),
''
));
};
u
.
stringToArrayBuffer
=
function
(
string
)
{
const
enc
=
new
TextEncoder
();
// always utf-8
return
enc
.
encode
(
string
);
};
u
.
base64ToArrayBuffer
=
function
(
b64
)
{
const
binary_string
=
window
.
atob
(
b64
),
len
=
binary_string
.
length
,
...
...
tests/mock.js
View file @
f2c283c9
...
...
@@ -6,6 +6,7 @@
var
Strophe
=
converse
.
env
.
Strophe
;
var
moment
=
converse
.
env
.
moment
;
var
$iq
=
converse
.
env
.
$iq
;
var
u
=
converse
.
env
.
utils
;
window
.
libsignal
=
{
'
SignalProtocolAddress
'
:
function
(
name
,
device_id
)
{
...
...
@@ -20,6 +21,9 @@
'
body
'
:
'
c1ph3R73X7
'
,
'
registrationId
'
:
'
1337
'
});
this
.
decryptWhisperMessage
=
(
key_and_tag
)
=>
{
return
Promise
.
resolve
(
u
.
stringToArrayBuffer
(
key_and_tag
));
}
},
'
SessionBuilder
'
:
function
(
storage
,
remote_address
)
{
this
.
processPreKey
=
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment