selfsdk 0.0.167 → 0.0.172
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/crypto.rb +23 -1
- data/lib/messages/authentication_req.rb +1 -1
- data/lib/messages/base.rb +10 -1
- data/lib/messages/fact_request.rb +1 -1
- data/lib/messaging.rb +16 -13
- data/lib/signature_graph.rb +1 -1
- 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: 6e68f10b976ff9d53d2a5983300d48d1893ea831b18128198ee022e7191f9184
|
4
|
+
data.tar.gz: bf4d068f07d59e804700b278d1f12062301fdb4922960f71c7f6fbefd30a81fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b9d95c1241a0852ed1b8a11965fbab426f380929ffa27dbce41b2a761b6aacaa971fdc608aaeefc90d605646f03fa798bde4491def9b98dbbb01a2c1070289f
|
7
|
+
data.tar.gz: 93615191987f3bbce66d7f544afefc66869a740864a910666cb4b4374f580cd75dacd3a9b4a624b93c7569008ff73b1ffb598fd8fd775793b2a76ab58e268d59
|
data/lib/crypto.rb
CHANGED
@@ -24,7 +24,8 @@ module SelfSDK
|
|
24
24
|
keys = @account.otk['curve25519'].map{|k,v| {id: k, key: v}}.to_json
|
25
25
|
|
26
26
|
# 1b-iv) post those keys to POST /v1/identities/<selfid>/devices/1/pre_keys/
|
27
|
-
@client.post("/v1/apps/#{@client.jwt.id}/devices/#{@device}/pre_keys", keys)
|
27
|
+
res = @client.post("/v1/apps/#{@client.jwt.id}/devices/#{@device}/pre_keys", keys)
|
28
|
+
raise 'unable to push prekeys, please try in a few minutes' if res.code != 200
|
28
29
|
|
29
30
|
# 1b-v) store the account to a file
|
30
31
|
File.write(account_path, @account.to_pickle(storage_key))
|
@@ -89,6 +90,27 @@ module SelfSDK
|
|
89
90
|
|
90
91
|
# 7b-ii) use the initial message to create a session for bob or carol
|
91
92
|
session_with_bob = @account.inbound_session(m)
|
93
|
+
|
94
|
+
# 7b-iii) remove the session's prekey from the account
|
95
|
+
@account.remove_one_time_keys(session_with_bob)
|
96
|
+
|
97
|
+
current_one_time_keys = @account.otk['curve25519']
|
98
|
+
|
99
|
+
# 7b-iv) if the number of remaining prekeys is below a certain threshold, publish new keys
|
100
|
+
if current_one_time_keys.length < 10
|
101
|
+
@account.gen_otk(100)
|
102
|
+
|
103
|
+
keys = Array.new
|
104
|
+
|
105
|
+
@account.otk['curve25519'].each do |k,v|
|
106
|
+
keys.push({id: k, key: v}) if current_one_time_keys[k].nil?
|
107
|
+
end
|
108
|
+
|
109
|
+
res = @client.post("/v1/apps/#{@client.jwt.id}/devices/#{@device}/pre_keys", keys.to_json)
|
110
|
+
raise 'unable to push prekeys, please try in a few minutes' if res.code != 200
|
111
|
+
end
|
112
|
+
|
113
|
+
File.write(account_path, @account.to_pickle(@storage_key))
|
92
114
|
end
|
93
115
|
|
94
116
|
# 8) create a group session and set the identity of the account you're using
|
@@ -43,7 +43,7 @@ module SelfSDK
|
|
43
43
|
def proto(to_device)
|
44
44
|
Msgproto::Message.new(type: Msgproto::MsgType::MSG,
|
45
45
|
sender: "#{@jwt.id}:#{@messaging.device_id}",
|
46
|
-
id:
|
46
|
+
id: SecureRandom.uuid,
|
47
47
|
recipient: "#{@to}:#{to_device}",
|
48
48
|
ciphertext: encrypt_message(@jwt.prepare(body), @to, to_device))
|
49
49
|
end
|
data/lib/messages/base.rb
CHANGED
@@ -21,8 +21,13 @@ module SelfSDK
|
|
21
21
|
msgs = []
|
22
22
|
devices.each do |d|
|
23
23
|
msgs << proto(d)
|
24
|
-
SelfSDK.logger.info "synchronously messaging to #{@to}:#{d}"
|
25
24
|
end
|
25
|
+
current_devices.each do |d|
|
26
|
+
if d != @messaging.device_id
|
27
|
+
msgs << proto(d)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
SelfSDK.logger.info "synchronously messaging to #{@to}"
|
26
31
|
res = @messaging.send_and_wait_for_response(msgs, self)
|
27
32
|
res
|
28
33
|
end
|
@@ -84,6 +89,10 @@ module SelfSDK
|
|
84
89
|
@client.devices(@intermediary)
|
85
90
|
end
|
86
91
|
|
92
|
+
def current_devices
|
93
|
+
@client.devices(@jwt.id)
|
94
|
+
end
|
95
|
+
|
87
96
|
def check_credits!
|
88
97
|
app = @client.app(@jwt.id)
|
89
98
|
raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
|
data/lib/messaging.rb
CHANGED
@@ -101,15 +101,27 @@ module SelfSDK
|
|
101
101
|
# @param type [string] message type
|
102
102
|
# @param request [hash] original message requesing information
|
103
103
|
def send_custom(recipient, request_body)
|
104
|
-
|
105
|
-
|
106
|
-
send_message msg = Msgproto::Message.new(
|
104
|
+
@client.devices(recipient).each do |to_device|
|
105
|
+
send_message Msgproto::Message.new(
|
107
106
|
type: Msgproto::MsgType::MSG,
|
108
107
|
id: SecureRandom.uuid,
|
109
108
|
sender: "#{@jwt.id}:#{@device_id}",
|
110
|
-
recipient: "#{recipient}:#{
|
109
|
+
recipient: "#{recipient}:#{to_device}",
|
111
110
|
ciphertext: @jwt.prepare(request_body),
|
112
111
|
)
|
112
|
+
end
|
113
|
+
|
114
|
+
@client.devices(@jwt.id).each do |to_device|
|
115
|
+
if to-device != @device_id
|
116
|
+
send_message Msgproto::Message.new(
|
117
|
+
type: Msgproto::MsgType::MSG,
|
118
|
+
id: SecureRandom.uuid,
|
119
|
+
sender: "#{@jwt.id}:#{@device_id}",
|
120
|
+
recipient: "#{recipient}:#{to_device}",
|
121
|
+
ciphertext: @jwt.prepare(request_body),
|
122
|
+
)
|
123
|
+
end
|
124
|
+
end
|
113
125
|
end
|
114
126
|
|
115
127
|
# Allows incomming messages from the given identity
|
@@ -281,10 +293,6 @@ module SelfSDK
|
|
281
293
|
loop { sleep 10; clean_timeouts }
|
282
294
|
end
|
283
295
|
|
284
|
-
Thread.new do
|
285
|
-
loop { sleep 30; ping }
|
286
|
-
end
|
287
|
-
|
288
296
|
@mon.synchronize do
|
289
297
|
@acks[auth_id][:waiting_cond].wait_while { @acks[auth_id][:waiting] }
|
290
298
|
@acks.delete(auth_id)
|
@@ -351,11 +359,6 @@ module SelfSDK
|
|
351
359
|
end
|
352
360
|
end
|
353
361
|
|
354
|
-
# Pings the websocket server to keep the connection alive.
|
355
|
-
def ping
|
356
|
-
# SelfSDK.logger.info "ping"
|
357
|
-
@ws&.ping
|
358
|
-
end
|
359
362
|
|
360
363
|
# Process an event when it arrives through the websocket connection.
|
361
364
|
def on_message(event)
|
data/lib/signature_graph.rb
CHANGED
@@ -261,7 +261,7 @@ module SelfSDK
|
|
261
261
|
|
262
262
|
sk = @keys[operation.signing_key]
|
263
263
|
|
264
|
-
raise "operation specifies a signing key that does not exist" if
|
264
|
+
raise "operation specifies a signing key that does not exist" if sk.nil?
|
265
265
|
|
266
266
|
# if this is an account recovery, nuke all existing keys
|
267
267
|
if sk.type == KEY_TYPE_RECOVERY
|