selfsdk 0.0.140 → 0.0.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/crypto.rb +15 -5
- data/lib/messaging.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fc84c8ad47b159c7f07f33226c1273bf30202f3b999ceba02ef51f6b35763fb
|
4
|
+
data.tar.gz: 4c88fbad5ffa05cc69977554d454ca7fcc796663400f2e74b770879afe05c2a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5f9b8cf446fb87a089d2094449691cd73806af84ce5d3f712a0357a0bdc5c4b2f7fef0dd6552591d56c4c5dd07fcaadcad02173b67b500f07ae80aec519fc2f
|
7
|
+
data.tar.gz: ee291b8ca0f22787067ae2edca5a59fee3fea4950a06cfd921c00c9d283d7c769cefeac7dd8bcee0bd2eeee7784fab307a52919d81f87942b8c8ccd4eff6d045
|
data/lib/crypto.rb
CHANGED
@@ -8,9 +8,9 @@ module SelfSDK
|
|
8
8
|
@storage_key = storage_key
|
9
9
|
@storage_folder = storage_folder
|
10
10
|
|
11
|
-
if File.exist?(
|
11
|
+
if File.exist?(account_path)
|
12
12
|
# 1a) if alice's account file exists load the pickle from the file
|
13
|
-
@account = SelfCrypto::Account.from_pickle(File.read(
|
13
|
+
@account = SelfCrypto::Account.from_pickle(File.read(account_path), @storage_key)
|
14
14
|
else
|
15
15
|
# 1b-i) if create a new account for alice if one doesn't exist already
|
16
16
|
@account = SelfCrypto::Account.from_seed(@client.jwt.key)
|
@@ -25,12 +25,12 @@ module SelfSDK
|
|
25
25
|
@client.post("/v1/apps/#{@client.jwt.id}/devices/#{@device}/pre_keys", keys)
|
26
26
|
|
27
27
|
# 1b-v) store the account to a file
|
28
|
-
File.write(
|
28
|
+
File.write(account_path, @account.to_pickle(storage_key))
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def encrypt(message, recipient, recipient_device)
|
33
|
-
session_file_name =
|
33
|
+
session_file_name = session_path(recipient, recipient_device)
|
34
34
|
|
35
35
|
if File.exist?(session_file_name)
|
36
36
|
# 2a) if bob's session file exists load the pickle from the file
|
@@ -71,7 +71,7 @@ module SelfSDK
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def decrypt(message, sender, sender_device)
|
74
|
-
session_file_name =
|
74
|
+
session_file_name = session_path(sender, sender_device)
|
75
75
|
|
76
76
|
if File.exist?(session_file_name)
|
77
77
|
# 7a) if carol's session file exists load the pickle from the file
|
@@ -98,5 +98,15 @@ module SelfSDK
|
|
98
98
|
# 10) decrypt the message ciphertext
|
99
99
|
gs.decrypt("#{sender}:#{sender_device}", message).to_s
|
100
100
|
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def account_path
|
105
|
+
"#{@storage_folder}/account.pickle"
|
106
|
+
end
|
107
|
+
|
108
|
+
def session_path(selfid, device)
|
109
|
+
"#{@storage_folder}/#{selfid}:#{device}-session.pickle"
|
110
|
+
end
|
101
111
|
end
|
102
112
|
end
|
data/lib/messaging.rb
CHANGED
@@ -30,7 +30,7 @@ module SelfSDK
|
|
30
30
|
# @params storage_folder [String] folder to perist messaging encryption
|
31
31
|
# @option opts [Bool] :auto_reconnect Automatically reconnects to websocket if connection is lost (defaults to true).
|
32
32
|
# @option opts [String] :device_id The device id to be used by the app defaults to "1".
|
33
|
-
def initialize(url, client, storage_key,
|
33
|
+
def initialize(url, client, storage_key, options = {})
|
34
34
|
@mon = Monitor.new
|
35
35
|
@url = url
|
36
36
|
@messages = {}
|
@@ -49,7 +49,7 @@ module SelfSDK
|
|
49
49
|
|
50
50
|
FileUtils.mkdir_p @storage_dir unless File.exist? @storage_dir
|
51
51
|
unless options.include? :no_crypto
|
52
|
-
@encryption_client = Crypto.new(@client, @device_id,
|
52
|
+
@encryption_client = Crypto.new(@client, @device_id, @storage_dir, storage_key)
|
53
53
|
end
|
54
54
|
|
55
55
|
if options.include? :ws
|