Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
norstbox
gajim
Commits
43e94f50
Commit
43e94f50
authored
10 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
fix some encoding issues
parent
33e31953
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/common/stanza_session.py
+28
-24
28 additions, 24 deletions
src/common/stanza_session.py
with
28 additions
and
24 deletions
src/common/stanza_session.py
+
28
−
24
View file @
43e94f50
...
...
@@ -410,21 +410,21 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
c
=
stanza
.
NT
.
c
c
.
setNamespace
(
'
http://www.xmpp.org/extensions/xep-0200.html#ns
'
)
c
.
NT
.
data
=
base64
.
b64encode
(
m_final
)
c
.
NT
.
data
=
base64
.
b64encode
(
m_final
)
.
decode
(
'
utf-8
'
)
# FIXME check for rekey request, handle <key/> elements
m_content
=
''
.
join
(
map
(
str
,
c
.
getChildren
()))
m_content
=
(
''
.
join
(
map
(
str
,
c
.
getChildren
()))
).
encode
(
'
utf-8
'
)
c
.
NT
.
mac
=
base64
.
b64encode
(
self
.
hmac
(
self
.
km_s
,
m_content
+
\
crypto
.
encode_mpi
(
old_en_counter
)))
crypto
.
encode_mpi
(
old_en_counter
)))
.
decode
(
'
utf-8
'
)
msgtxt
=
'
[This is part of an encrypted session.
'
\
'
If you see this message, something went wrong.]
'
lang
=
os
.
getenv
(
'
LANG
'
)
if
lang
is
not
None
and
lang
!=
'
en
'
:
# we're not english
msgtxt
=
_
(
'
[This is part of an encrypted session.
'
'
If you see this message, something went wrong.]
'
)
+
'
(
'
+
\
msgtxt
+
'
)
'
'
If you see this message, something went wrong.]
'
)
+
'
(
'
+
\
msgtxt
+
'
)
'
stanza
.
setBody
(
msgtxt
)
return
stanza
...
...
@@ -473,6 +473,7 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
# contents of <c>, minus <mac>, minus whitespace
macable
=
''
.
join
(
str
(
x
)
for
x
in
c
.
getChildren
()
if
x
.
getName
()
!=
'
mac
'
)
macable
=
macable
.
encode
(
'
utf-8
'
)
received_mac
=
base64
.
b64decode
(
c
.
getTagData
(
'
mac
'
))
calculated_mac
=
self
.
hmac
(
self
.
km_o
,
macable
+
\
...
...
@@ -483,7 +484,7 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
m_final
=
base64
.
b64decode
(
c
.
getTagData
(
'
data
'
))
m_compressed
=
self
.
decrypt
(
m_final
)
plaintext
=
self
.
decompress
(
m_compressed
)
plaintext
=
self
.
decompress
(
m_compressed
)
.
decode
(
'
utf-8
'
)
try
:
parsed
=
nbxmpp
.
Node
(
node
=
'
<node>
'
+
plaintext
+
'
</node>
'
)
...
...
@@ -536,7 +537,7 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
if
i_o
==
'
a
'
and
self
.
sas_algs
==
'
sas28x5
'
:
# we don't need to calculate this if there's a verified retained secret
# (but we do anyways)
self
.
sas
=
crypto
.
sas_28x5
(
m_o
,
self
.
form_s
)
self
.
sas
=
crypto
.
sas_28x5
(
m_o
,
self
.
form_s
.
encode
(
'
utf-8
'
)
)
if
self
.
negotiated
[
'
recv_pubkey
'
]:
plaintext
=
self
.
decrypt
(
id_o
)
...
...
@@ -571,11 +572,11 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
content
=
self
.
n_s
+
self
.
n_o
+
crypto
.
encode_mpi
(
dh_i
)
+
pubkey_o
if
sigmai
:
self
.
form_o
=
c7l_form
self
.
form_o
=
c7l_form
.
encode
(
'
utf-8
'
)
content
+=
self
.
form_o
else
:
form_o2
=
c7l_form
content
+=
self
.
form_o
+
form_o2
form_o2
=
c7l_form
.
encode
(
'
utf-8
'
)
content
+=
self
.
form_o
.
encode
(
'
utf-8
'
)
+
form_o2
mac_o_calculated
=
self
.
hmac
(
self
.
ks_o
,
content
)
...
...
@@ -609,7 +610,7 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
old_c_s
=
self
.
c_s
content
=
self
.
n_o
+
self
.
n_s
+
crypto
.
encode_mpi
(
dh_i
)
+
pubkey_s
+
\
self
.
form_s
+
form_s2
self
.
form_s
.
encode
(
'
utf-8
'
)
+
form_s2
.
encode
(
'
utf-8
'
)
mac_s
=
self
.
hmac
(
self
.
ks_s
,
content
)
...
...
@@ -632,14 +633,16 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
if
self
.
status
==
'
requested-e2e
'
and
self
.
sas_algs
==
'
sas28x5
'
:
# we're alice; check for a retained secret
# if none exists, prompt the user with the SAS
self
.
sas
=
crypto
.
sas_28x5
(
m_s
,
self
.
form_o
)
self
.
sas
=
crypto
.
sas_28x5
(
m_s
,
self
.
form_o
.
encode
(
'
utf-8
'
)
)
if
self
.
sigmai
:
# FIXME save retained secret?
self
.
check_identity
(
tuple
)
return
(
nbxmpp
.
DataField
(
name
=
'
identity
'
,
value
=
base64
.
b64encode
(
id_s
)),
nbxmpp
.
DataField
(
name
=
'
mac
'
,
value
=
base64
.
b64encode
(
m_s
)))
return
(
nbxmpp
.
DataField
(
name
=
'
identity
'
,
value
=
base64
.
b64encode
(
id_s
).
decode
(
'
utf-8
'
)),
nbxmpp
.
DataField
(
name
=
'
mac
'
,
value
=
base64
.
b64encode
(
m_s
).
decode
(
'
utf-8
'
)))
def
negotiate_e2e
(
self
,
sigmai
):
self
.
negotiated
=
{}
...
...
@@ -695,7 +698,7 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
self
.
n_s
=
crypto
.
generate_nonce
()
x
.
addChild
(
node
=
nbxmpp
.
DataField
(
name
=
'
my_nonce
'
,
value
=
base64
.
b64encode
(
self
.
n_s
),
typ
=
'
hidden
'
))
value
=
base64
.
b64encode
(
self
.
n_s
)
.
decode
(
'
utf-8
'
)
,
typ
=
'
hidden
'
))
modp_options
=
[
int
(
g
)
for
g
in
gajim
.
config
.
get
(
'
esession_modp
'
).
split
(
'
,
'
)
]
...
...
@@ -826,7 +829,7 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
return
dhhashes
=
dhhashes_f
.
getValues
()
self
.
negotiated
[
'
He
'
]
=
base64
.
b64decode
(
dhhashes
[
group_order
].
encode
(
'
utf8
'
))
'
utf8
'
))
bytes
=
int
(
self
.
n
/
8
)
...
...
@@ -845,7 +848,7 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
'
nonce
'
:
self
.
n_o
}
for
name
in
to_add
:
b64ed
=
base64
.
b64encode
(
to_add
[
name
])
b64ed
=
base64
.
b64encode
(
to_add
[
name
])
.
decode
(
'
utf-8
'
)
x
.
addChild
(
node
=
nbxmpp
.
DataField
(
name
=
name
,
value
=
b64ed
))
self
.
form_o
=
''
.
join
(
nbxmpp
.
c14n
.
c14n
(
el
,
self
.
_is_buggy_gajim
())
for
\
...
...
@@ -935,7 +938,7 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
value
=
'
urn:xmpp:ssn
'
))
result
.
addChild
(
node
=
nbxmpp
.
DataField
(
name
=
'
accept
'
,
value
=
'
1
'
))
result
.
addChild
(
node
=
nbxmpp
.
DataField
(
name
=
'
nonce
'
,
value
=
base64
.
b64encode
(
self
.
n_o
)))
value
=
base64
.
b64encode
(
self
.
n_o
)
.
decode
(
'
utf-8
'
)
))
self
.
kc_s
,
self
.
km_s
,
self
.
ks_s
=
self
.
generate_initiator_keys
(
self
.
k
)
...
...
@@ -952,11 +955,12 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
rshash_size
=
self
.
hash_alg
().
digest_size
rshashes
.
append
(
crypto
.
random_bytes
(
rshash_size
))
rshashes
=
[
base64
.
b64encode
(
rshash
)
for
rshash
in
rshashes
]
rshashes
=
[
base64
.
b64encode
(
rshash
).
decode
(
'
utf-8
'
)
for
rshash
in
\
rshashes
]
result
.
addChild
(
node
=
nbxmpp
.
DataField
(
name
=
'
rshashes
'
,
value
=
rshashes
))
result
.
addChild
(
node
=
nbxmpp
.
DataField
(
name
=
'
dhkeys
'
,
value
=
base64
.
b64encode
(
crypto
.
encode_mpi
(
e
))))
value
=
base64
.
b64encode
(
crypto
.
encode_mpi
(
e
))
.
decode
(
'
utf-8
'
)
))
self
.
form_o
=
''
.
join
(
nbxmpp
.
c14n
.
c14n
(
el
,
self
.
_is_buggy_gajim
())
\
for
el
in
form
.
getChildren
())
...
...
@@ -1037,9 +1041,9 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
x
.
addChild
(
node
=
nbxmpp
.
DataField
(
name
=
'
FORM_TYPE
'
,
value
=
'
urn:xmpp:ssn
'
))
x
.
addChild
(
node
=
nbxmpp
.
DataField
(
name
=
'
nonce
'
,
value
=
base64
.
b64encode
(
self
.
n_o
)))
self
.
n_o
)
.
decode
(
'
utf-8
'
)
))
x
.
addChild
(
node
=
nbxmpp
.
DataField
(
name
=
'
srshash
'
,
value
=
base64
.
b64encode
(
srshash
)))
srshash
)
.
decode
(
'
utf-8
'
)
))
for
datafield
in
self
.
make_identity
(
x
,
self
.
d
):
x
.
addChild
(
node
=
datafield
)
...
...
@@ -1155,11 +1159,11 @@ class EncryptedStanzaSession(ArchivingStanzaSession):
self
.
es
[
modp
]
=
e
if
sigmai
:
dhs
.
append
(
base64
.
b64encode
(
crypto
.
encode_mpi
(
e
)))
dhs
.
append
(
base64
.
b64encode
(
crypto
.
encode_mpi
(
e
))
.
decode
(
'
utf-8
'
)
)
name
=
'
dhkeys
'
else
:
He
=
crypto
.
sha256
(
crypto
.
encode_mpi
(
e
))
dhs
.
append
(
base64
.
b64encode
(
He
))
dhs
.
append
(
base64
.
b64encode
(
He
)
.
decode
(
'
utf-8
'
)
)
name
=
'
dhhashes
'
return
nbxmpp
.
DataField
(
name
=
name
,
typ
=
'
hidden
'
,
value
=
dhs
)
...
...
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