selfsdk 0.0.165 → 0.0.170
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/messaging.rb +26 -19
- 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: 2ef1e4f98e83e8c056812dc7fe331a6e409f9e930f3764c2e1a5920f55f646fe
|
4
|
+
data.tar.gz: 1eb25590ddbad6f74edf8dac58f1374582905fc3bafe48fa732d3c2ef60dbb34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 304a87b8b1b9a01571befe77ff2acadcea0a5254cd7972c9072ea96fe60e21356160e82f98255f17c3df00ebe62c28dc032e7ee711c0d8fe488dc28d9010f48f
|
7
|
+
data.tar.gz: c8c8bca065193c65aa091aacfc727966c5921f502bb80f0d34f0d4716b1a733cb5caaccf6dee5d3d00b496df24bc7d3bb6ee3dd30c7f290cf07160664024c6aa
|
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
|
data/lib/messaging.rb
CHANGED
@@ -43,6 +43,7 @@ module SelfSDK
|
|
43
43
|
@client = client
|
44
44
|
@ack_timeout = 60 # seconds
|
45
45
|
@timeout = 120 # seconds
|
46
|
+
@auth_id = SecureRandom.uuid
|
46
47
|
@device_id = options.fetch(:device_id, DEFAULT_DEVICE)
|
47
48
|
@auto_reconnect = options.fetch(:auto_reconnect, DEFAULT_AUTO_RECONNECT)
|
48
49
|
@raw_storage_dir = options.fetch(:storage_dir, DEFAULT_STORAGE_DIR)
|
@@ -264,8 +265,10 @@ module SelfSDK
|
|
264
265
|
# Start sthe websocket listener
|
265
266
|
def start
|
266
267
|
SelfSDK.logger.info "starting"
|
268
|
+
auth_id = @auth_id.dup
|
269
|
+
|
267
270
|
@mon.synchronize do
|
268
|
-
@acks[
|
271
|
+
@acks[auth_id] = { waiting_cond: @mon.new_cond,
|
269
272
|
waiting: true,
|
270
273
|
timeout: SelfSDK::Time.now + @ack_timeout }
|
271
274
|
end
|
@@ -283,8 +286,16 @@ module SelfSDK
|
|
283
286
|
end
|
284
287
|
|
285
288
|
@mon.synchronize do
|
286
|
-
@acks[
|
287
|
-
@acks.delete(
|
289
|
+
@acks[auth_id][:waiting_cond].wait_while { @acks[auth_id][:waiting] }
|
290
|
+
@acks.delete(auth_id)
|
291
|
+
end
|
292
|
+
# In case this does not succeed start the process again.
|
293
|
+
if @acks.include? auth_id
|
294
|
+
if @acks[auth_id][:waiting]
|
295
|
+
close
|
296
|
+
start_connection
|
297
|
+
end
|
298
|
+
@acks.delete(auth_id)
|
288
299
|
end
|
289
300
|
end
|
290
301
|
|
@@ -404,22 +415,18 @@ module SelfSDK
|
|
404
415
|
|
405
416
|
# Authenticates current client on the websocket server.
|
406
417
|
def authenticate
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
SelfSDK.logger.info "authentication timed out, retrying ..."
|
421
|
-
close
|
422
|
-
start_connection
|
418
|
+
@auth_id = SecureRandom.uuid if @auth_id.nil?
|
419
|
+
|
420
|
+
SelfSDK.logger.info "authenticating"
|
421
|
+
send_raw Msgproto::Auth.new(
|
422
|
+
type: Msgproto::MsgType::AUTH,
|
423
|
+
id: @auth_id,
|
424
|
+
token: @jwt.auth_token,
|
425
|
+
device: @device_id,
|
426
|
+
offset: @offset,
|
427
|
+
)
|
428
|
+
|
429
|
+
@auth_id = nil
|
423
430
|
end
|
424
431
|
|
425
432
|
def send_raw(msg)
|
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
|