Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gajim-plugins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
gajim
gajim-plugins
Commits
2e8c5a5a
Commit
2e8c5a5a
authored
6 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
[omemo] Add sqlite identity key converter
parent
16234036
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
omemo/backend/liteaxolotlstore.py
+13
-7
13 additions, 7 deletions
omemo/backend/liteaxolotlstore.py
omemo/backend/util.py
+11
-0
11 additions, 0 deletions
omemo/backend/util.py
with
24 additions
and
7 deletions
omemo/backend/liteaxolotlstore.py
+
13
−
7
View file @
2e8c5a5a
...
...
@@ -33,6 +33,7 @@ from axolotl.util.medium import Medium
from
axolotl.util.keyhelper
import
KeyHelper
from
omemo.backend.util
import
Trust
from
omemo.backend.util
import
IdentityKeyExtended
from
omemo.backend.util
import
DEFAULT_PREKEY_AMOUNT
...
...
@@ -42,8 +43,14 @@ log = logging.getLogger('gajim.plugin_system.omemo')
def
_convert_to_string
(
text
):
return
text
.
decode
()
def
_convert_identity_key
(
key
):
if
not
key
:
return
return
IdentityKeyExtended
(
DjbECPublicKey
(
key
[
1
:]))
sqlite3
.
register_converter
(
'
jid
'
,
_convert_to_string
)
sqlite3
.
register_converter
(
'
pk
'
,
_convert_identity_key
)
class
LiteAxolotlStore
(
AxolotlStore
):
...
...
@@ -399,13 +406,12 @@ class LiteAxolotlStore(AxolotlStore):
self
.
storePreKey
(
pre_key
.
getId
(),
pre_key
)
def
getIdentityKeyPair
(
self
):
query
=
'''
SELECT public_key
, private_key FROM identities
WHERE recipient_id = -1
'''
query
=
'''
SELECT public_key
as
"
public_key [pk]
"
, private_key
FROM identities
WHERE recipient_id = -1
'''
result
=
self
.
_con
.
execute
(
query
).
fetchone
()
return
IdentityKeyPair
(
IdentityKey
(
DjbECPublicKey
(
result
.
public_key
[
1
:])),
DjbECPrivateKey
(
result
.
private_key
))
return
IdentityKeyPair
(
result
.
public_key
,
DjbECPrivateKey
(
result
.
private_key
))
def
getLocalRegistrationId
(
self
):
query
=
'
SELECT registration_id FROM identities WHERE recipient_id = -1
'
...
...
@@ -460,12 +466,12 @@ class LiteAxolotlStore(AxolotlStore):
def
getFingerprints
(
self
,
jid
):
query
=
'''
SELECT _id, recipient_id as
"
recipient_id [jid]
"
,
public_key, trust FROM identities
public_key
as
"
public_key [pk]
"
, trust FROM identities
WHERE recipient_id =? ORDER BY trust ASC
'''
return
self
.
_con
.
execute
(
query
,
(
jid
,)).
fetchall
()
def
getTrustedFingerprints
(
self
,
jid
):
query
=
'''
SELECT public_key FROM identities
query
=
'''
SELECT public_key
as
"
public_key [pk]
"
FROM identities
WHERE recipient_id = ? AND trust = ?
'''
result
=
self
.
_con
.
execute
(
query
,
(
jid
,
Trust
.
TRUSTED
)).
fetchall
()
return
[
row
.
public_key
for
row
in
result
]
...
...
This diff is collapsed.
Click to expand it.
omemo/backend/util.py
+
11
−
0
View file @
2e8c5a5a
...
...
@@ -18,6 +18,8 @@ import binascii
import
textwrap
from
enum
import
IntEnum
from
axolotl.identitykey
import
IdentityKey
DEFAULT_PREKEY_AMOUNT
=
100
MIN_PREKEY_AMOUNT
=
80
SPK_ARCHIVE_TIME
=
86400
*
15
# 15 Days
...
...
@@ -43,3 +45,12 @@ def get_fingerprint(identity_key, formatted=False):
buf
+=
'
{0}
'
.
format
(
fingerprint
[
w
:
w
+
wordsize
])
buf
=
textwrap
.
fill
(
buf
,
width
=
36
)
return
buf
.
rstrip
().
upper
()
class
IdentityKeyExtended
(
IdentityKey
):
def
__hash__
(
self
):
return
hash
(
self
.
publicKey
.
serialize
())
def
get_fingerprint
(
self
,
formatted
=
False
):
return
get_fingerprint
(
self
,
formatted
=
formatted
)
\ No newline at end of file
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