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
d036b0f6
Commit
d036b0f6
authored
6 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
[omemo] Move secret data into own table
parent
cfaa259a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
omemo/backend/devices.py
+2
-1
2 additions, 1 deletion
omemo/backend/devices.py
omemo/backend/liteaxolotlstore.py
+40
-11
40 additions, 11 deletions
omemo/backend/liteaxolotlstore.py
with
42 additions
and
12 deletions
omemo/backend/devices.py
+
2
−
1
View file @
d036b0f6
...
...
@@ -29,7 +29,8 @@ class DeviceManager:
reg_id
=
self
.
_storage
.
getLocalRegistrationId
()
if
reg_id
is
None
:
raise
ValueError
(
'
No own device found
'
)
self
.
__own_device
=
(
reg_id
%
2147483646
)
+
1
self
.
__own_device
=
reg_id
self
.
add_device
(
self
.
_own_jid
,
self
.
__own_device
)
self
.
_log
.
info
(
'
Our device id: %s
'
,
self
.
__own_device
)
...
...
This diff is collapsed.
Click to expand it.
omemo/backend/liteaxolotlstore.py
+
40
−
11
View file @
d036b0f6
...
...
@@ -95,7 +95,7 @@ class LiteAxolotlStore(AxolotlStore):
def
_generate_axolotl_keys
(
self
):
identity_key_pair
=
KeyHelper
.
generateIdentityKeyPair
()
registration_id
=
KeyHelper
.
ge
nerateRegistrationId
(
)
registration_id
=
KeyHelper
.
ge
tRandomSequence
(
max
=
2147483647
)
pre_keys
=
KeyHelper
.
generatePreKeys
(
KeyHelper
.
getRandomSequence
(),
DEFAULT_PREKEY_AMOUNT
)
self
.
storeLocalData
(
registration_id
,
identity_key_pair
)
...
...
@@ -115,9 +115,12 @@ class LiteAxolotlStore(AxolotlStore):
if
self
.
user_version
()
==
0
:
create_tables
=
'''
CREATE TABLE IF NOT EXISTS secret (
device_id INTEGER, public_key BLOB, private_key BLOB);
CREATE TABLE IF NOT EXISTS identities (
_id INTEGER PRIMARY KEY AUTOINCREMENT, recipient_id TEXT,
registration_id INTEGER, public_key BLOB,
private_key BLOB,
registration_id INTEGER, public_key BLOB,
timestamp INTEGER, trust INTEGER,
shown INTEGER DEFAULT 0);
...
...
@@ -145,7 +148,7 @@ class LiteAxolotlStore(AxolotlStore):
create_db_sql
=
"""
BEGIN TRANSACTION;
%s
PRAGMA user_version=
5
;
PRAGMA user_version=
6
;
END TRANSACTION;
"""
%
(
create_tables
)
self
.
_con
.
executescript
(
create_db_sql
)
...
...
@@ -218,6 +221,26 @@ class LiteAxolotlStore(AxolotlStore):
END TRANSACTION;
"""
%
(
add_timestamp
))
if
self
.
user_version
()
<
6
:
# Move secret data into own table
# We add +1 to registration id because we did that in other code in
# earlier versions. On this migration we correct this mistake now.
move
=
"""
CREATE TABLE IF NOT EXISTS secret (
device_id INTEGER, public_key BLOB, private_key BLOB);
INSERT INTO secret (device_id, public_key, private_key)
SELECT registration_id + 1, public_key, private_key
FROM identities
WHERE recipient_id = -1;
"""
self
.
_con
.
executescript
(
"""
BEGIN TRANSACTION;
%s
PRAGMA user_version=6;
END TRANSACTION;
"""
%
move
)
def
loadSignedPreKey
(
self
,
signedPreKeyId
):
query
=
'
SELECT record FROM signed_prekeys WHERE prekey_id = ?
'
result
=
self
.
_con
.
execute
(
query
,
(
signedPreKeyId
,
)).
fetchone
()
...
...
@@ -416,25 +439,31 @@ class LiteAxolotlStore(AxolotlStore):
def
getIdentityKeyPair
(
self
):
query
=
'''
SELECT public_key as
"
public_key [pk]
"
, private_key
FROM
identities WHERE recipient_id = -
1
'''
FROM
secret LIMIT
1
'''
result
=
self
.
_con
.
execute
(
query
).
fetchone
()
return
IdentityKeyPair
(
result
.
public_key
,
DjbECPrivateKey
(
result
.
private_key
))
def
getLocalRegistrationId
(
self
):
query
=
'
SELECT
registration_id FROM identities WHERE recipient_id = -
1
'
query
=
'
SELECT
device_id FROM secret LIMIT
1
'
result
=
self
.
_con
.
execute
(
query
).
fetchone
()
return
result
.
registration
_id
if
result
is
not
None
else
None
return
result
.
device
_id
if
result
is
not
None
else
None
def
storeLocalData
(
self
,
registrationId
,
identityKeyPair
):
query
=
'''
INSERT INTO identities(
recipient_id, registration_id, public_key, private_key)
VALUES(-1, ?, ?, ?)
'''
def
storeLocalData
(
self
,
device_id
,
identityKeyPair
):
query
=
'
SELECT * FROM secret
'
result
=
self
.
_con
.
execute
(
query
).
fetchone
()
if
result
is
not
None
:
self
.
_log
.
error
(
'
Trying to save secret key into
'
'
non-empty secret table
'
)
return
query
=
'''
INSERT INTO secret(device_id, public_key, private_key)
VALUES(?, ?, ?)
'''
public_key
=
identityKeyPair
.
getPublicKey
().
getPublicKey
().
serialize
()
private_key
=
identityKeyPair
.
getPrivateKey
().
serialize
()
self
.
_con
.
execute
(
query
,
(
registrationI
d
,
public_key
,
private_key
))
self
.
_con
.
execute
(
query
,
(
device_i
d
,
public_key
,
private_key
))
self
.
_con
.
commit
()
def
saveIdentity
(
self
,
recipientId
,
identityKey
):
...
...
This diff is collapsed.
Click to expand it.
Malte L
@maltel
mentioned in issue
#413 (closed)
·
5 years ago
mentioned in issue
#413 (closed)
mentioned in issue #413
Toggle commit list
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