selfsdk 0.0.139 → 0.0.144
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/client.rb +20 -8
- data/lib/crypto.rb +27 -13
- data/lib/messages/authentication_req.rb +3 -0
- data/lib/messages/fact_request.rb +3 -0
- data/lib/messages/message.rb +1 -1
- 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: d9d49a7cde97a88c5c56c6233b964b72c66d9b046b2521cac189475646be55f2
|
4
|
+
data.tar.gz: 600b68b342c99830aba799eb13da1650d02cecd4bd824aeb38f51c768c77a13a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c7989e1245b7b2993e4c5784373d05c25870a1e4e695da1a49571e5ada8d779fb90c5d5f37fd9174e3cef51b054655c9efdb8470f573a98bdfa10ea950d1d8c
|
7
|
+
data.tar.gz: 8e30b0e94b496efdc80f6dc4d5bdb655e8236ff098880bf28f46bc8433f08182fe7bfca3942abe893cfd698f8be720ae598611ae24ea6c98b4adfac2db1c9c5b
|
data/lib/client.rb
CHANGED
@@ -66,19 +66,31 @@ module SelfSDK
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def post(endpoint, body)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
res = nil
|
70
|
+
loop do
|
71
|
+
res = HTTParty.post("#{@self_url}#{endpoint}",
|
72
|
+
headers: {
|
73
|
+
'Content-Type' => 'application/json',
|
74
|
+
'Authorization' => "Bearer #{@jwt.auth_token}"
|
75
|
+
},
|
76
|
+
body: body)
|
77
|
+
break if res.code != 503
|
78
|
+
sleep 2
|
79
|
+
end
|
80
|
+
return res
|
75
81
|
end
|
76
82
|
|
77
83
|
def get(endpoint)
|
78
|
-
|
84
|
+
res = nil
|
85
|
+
loop do
|
86
|
+
res = HTTParty.get("#{@self_url}#{endpoint}", headers: {
|
79
87
|
'Content-Type' => 'application/json',
|
80
88
|
'Authorization' => "Bearer #{@jwt.auth_token}"
|
81
|
-
|
89
|
+
})
|
90
|
+
break if res.code != 503
|
91
|
+
sleep 2
|
92
|
+
end
|
93
|
+
return res
|
82
94
|
end
|
83
95
|
|
84
96
|
# Lists all public keys stored on self for the given ID
|
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
|
@@ -55,9 +55,6 @@ module SelfSDK
|
|
55
55
|
|
56
56
|
# 2b-iv) create the session with bob
|
57
57
|
session_with_bob = @account.outbound_session(curve25519_identity_key, one_time_key)
|
58
|
-
|
59
|
-
# 2b-v) store the session to a file
|
60
|
-
File.write(session_file_name, session_with_bob.to_pickle(@storage_key))
|
61
58
|
end
|
62
59
|
|
63
60
|
# 3) create a group session and set the identity of the account youre using
|
@@ -67,11 +64,16 @@ module SelfSDK
|
|
67
64
|
gs.add_participant("#{recipient}:#{recipient_device}", session_with_bob)
|
68
65
|
|
69
66
|
# 5) encrypt a message
|
70
|
-
gs.encrypt(message).to_s
|
67
|
+
ct = gs.encrypt(message).to_s
|
68
|
+
|
69
|
+
# 6) store the session to a file
|
70
|
+
File.write(session_file_name, session_with_bob.to_pickle(@storage_key))
|
71
|
+
|
72
|
+
ct
|
71
73
|
end
|
72
74
|
|
73
75
|
def decrypt(message, sender, sender_device)
|
74
|
-
session_file_name =
|
76
|
+
session_file_name = session_path(sender, sender_device)
|
75
77
|
|
76
78
|
if File.exist?(session_file_name)
|
77
79
|
# 7a) if carol's session file exists load the pickle from the file
|
@@ -84,9 +86,6 @@ module SelfSDK
|
|
84
86
|
|
85
87
|
# 7b-ii) use the initial message to create a session for bob or carol
|
86
88
|
session_with_bob = @account.inbound_session(m)
|
87
|
-
|
88
|
-
# 7b-iii) store the session to a file
|
89
|
-
File.write(session_file_name, session_with_bob.to_pickle(@storage_key))
|
90
89
|
end
|
91
90
|
|
92
91
|
# 8) create a group session and set the identity of the account you're using
|
@@ -96,7 +95,22 @@ module SelfSDK
|
|
96
95
|
gs.add_participant("#{sender}:#{sender_device}", session_with_bob)
|
97
96
|
|
98
97
|
# 10) decrypt the message ciphertext
|
99
|
-
gs.decrypt("#{sender}:#{sender_device}", message).to_s
|
98
|
+
pt = gs.decrypt("#{sender}:#{sender_device}", message).to_s
|
99
|
+
|
100
|
+
# 11) store the session to a file
|
101
|
+
File.write(session_file_name, session_with_bob.to_pickle(@storage_key))
|
102
|
+
|
103
|
+
pt
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def account_path
|
109
|
+
"#{@storage_folder}/account.pickle"
|
110
|
+
end
|
111
|
+
|
112
|
+
def session_path(selfid, device)
|
113
|
+
"#{@storage_folder}/#{selfid}:#{device}-session.pickle"
|
100
114
|
end
|
101
115
|
end
|
102
116
|
end
|
@@ -39,6 +39,9 @@ module SelfSDK
|
|
39
39
|
protected
|
40
40
|
|
41
41
|
def proto
|
42
|
+
app = @client.app(@jwt.id)
|
43
|
+
raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
|
44
|
+
|
42
45
|
@to_device = @client.devices(@to).first
|
43
46
|
Msgproto::Message.new(type: Msgproto::MsgType::MSG,
|
44
47
|
sender: "#{@jwt.id}:#{@messaging.device_id}",
|
@@ -86,6 +86,9 @@ module SelfSDK
|
|
86
86
|
protected
|
87
87
|
|
88
88
|
def proto
|
89
|
+
app = @client.app(@jwt.id)
|
90
|
+
raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
|
91
|
+
|
89
92
|
devices = if @intermediary.nil?
|
90
93
|
@client.devices(@to)
|
91
94
|
else
|
data/lib/messages/message.rb
CHANGED
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
|