selfsdk 0.0.163 → 0.0.168
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 +2 -1
- data/lib/messages/authentication_message.rb +5 -1
- data/lib/messages/base.rb +4 -2
- data/lib/messages/fact_request.rb +6 -1
- data/lib/messages/fact_response.rb +5 -1
- data/lib/messages/message.rb +9 -7
- data/lib/messaging.rb +19 -4
- 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: ffcdce1f12b74a382540ad69d30e73e9f4b89316d10831c07917d59646c24764
|
4
|
+
data.tar.gz: 56c549de3f1cc8574760ded98e5ec1c790293e3555e2b3d0ac69376a124c39e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f9b6c16423ead39824635414bf1de2e5efdf80878b19d234f263663e003c90b8148411fb90498fdfa1525374bfdddf838a97bd28002aa5fcd67224a3b9ab990
|
7
|
+
data.tar.gz: e3143da9abc1cd2e17c0e1e0ed3253761af044a217246ca27978ed7321e542a5ae1c32499f6cf4e9f4ac380e889a096997774ee2ab95c18fedf78a3e8cc8b24a
|
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))
|
@@ -9,7 +9,7 @@ module SelfSDK
|
|
9
9
|
module Messages
|
10
10
|
class AuthenticationMessage < Base
|
11
11
|
|
12
|
-
def parse(input,
|
12
|
+
def parse(input, envelope=nil)
|
13
13
|
@input = input
|
14
14
|
@typ = @typ
|
15
15
|
@payload = get_payload input
|
@@ -21,6 +21,10 @@ module SelfSDK
|
|
21
21
|
@expires = ::Time.parse(payload[:exp])
|
22
22
|
@issued = ::Time.parse(payload[:iat])
|
23
23
|
@status = payload[:status]
|
24
|
+
if envelope
|
25
|
+
issuer = envelope.sender.split(":")
|
26
|
+
@from_device = issuer.last
|
27
|
+
end
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
data/lib/messages/base.rb
CHANGED
@@ -27,10 +27,12 @@ module SelfSDK
|
|
27
27
|
res
|
28
28
|
end
|
29
29
|
|
30
|
-
def send_message
|
30
|
+
def send_message(device_id = nil)
|
31
31
|
check_credits!
|
32
|
+
dds = devices
|
33
|
+
dds = [device_id] if device_id
|
32
34
|
res = []
|
33
|
-
|
35
|
+
dds.each do |d|
|
34
36
|
res << @messaging.send_message(proto(d))
|
35
37
|
SelfSDK.logger.info "asynchronously requested information to #{@to}:#{d}"
|
36
38
|
end
|
@@ -39,7 +39,7 @@ module SelfSDK
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def parse(input)
|
42
|
+
def parse(input, envelope=nil)
|
43
43
|
@input = input
|
44
44
|
@typ = MSG_TYPE
|
45
45
|
@payload = get_payload input
|
@@ -51,6 +51,11 @@ module SelfSDK
|
|
51
51
|
@description = @payload.include?(:description) ? @payload[:description] : nil
|
52
52
|
@facts = @payload[:facts]
|
53
53
|
@options = @payload[:options]
|
54
|
+
|
55
|
+
if envelope
|
56
|
+
issuer = envelope.sender.split(":")
|
57
|
+
@from_device = issuer.last
|
58
|
+
end
|
54
59
|
end
|
55
60
|
|
56
61
|
def build_response
|
@@ -13,7 +13,7 @@ module SelfSDK
|
|
13
13
|
|
14
14
|
attr_accessor :facts, :audience
|
15
15
|
|
16
|
-
def parse(input)
|
16
|
+
def parse(input, envelope=nil)
|
17
17
|
@input = input
|
18
18
|
@typ = MSG_TYPE
|
19
19
|
@payload = get_payload input
|
@@ -35,6 +35,10 @@ module SelfSDK
|
|
35
35
|
SelfSDK.logger.info e.message
|
36
36
|
end
|
37
37
|
end
|
38
|
+
if envelope
|
39
|
+
issuer = envelope.sender.split(":")
|
40
|
+
@from_device = issuer.last
|
41
|
+
end
|
38
42
|
end
|
39
43
|
|
40
44
|
def fact(name)
|
data/lib/messages/message.rb
CHANGED
@@ -10,11 +10,13 @@ require_relative "authentication_req"
|
|
10
10
|
module SelfSDK
|
11
11
|
module Messages
|
12
12
|
def self.parse(input, messaging, original=nil)
|
13
|
+
envelope = nil
|
13
14
|
body = if input.is_a? String
|
14
|
-
|
15
|
+
input
|
15
16
|
else
|
16
|
-
|
17
|
-
|
17
|
+
envelope = input
|
18
|
+
issuer = input.sender.split(":")
|
19
|
+
messaging.encryption_client.decrypt(input.ciphertext, issuer.first, issuer.last)
|
18
20
|
end
|
19
21
|
|
20
22
|
jwt = JSON.parse(body, symbolize_names: true)
|
@@ -23,16 +25,16 @@ module SelfSDK
|
|
23
25
|
case payload[:typ]
|
24
26
|
when "identities.facts.query.req"
|
25
27
|
m = FactRequest.new(messaging)
|
26
|
-
m.parse(body)
|
28
|
+
m.parse(body, envelope)
|
27
29
|
when "identities.facts.query.resp"
|
28
30
|
m = FactResponse.new(messaging)
|
29
|
-
m.parse(body)
|
31
|
+
m.parse(body, envelope)
|
30
32
|
when "identities.authenticate.resp"
|
31
33
|
m = AuthenticationResp.new(messaging)
|
32
|
-
m.parse(body)
|
34
|
+
m.parse(body, envelope)
|
33
35
|
when "identities.authenticate.req"
|
34
36
|
m = AuthenticationReq.new(messaging)
|
35
|
-
m.parse(body)
|
37
|
+
m.parse(body, envelope)
|
36
38
|
else
|
37
39
|
raise StandardError.new("Invalid message type.")
|
38
40
|
end
|
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,14 +415,18 @@ module SelfSDK
|
|
404
415
|
|
405
416
|
# Authenticates current client on the websocket server.
|
406
417
|
def authenticate
|
418
|
+
@auth_id = SecureRandom.uuid if @auth_id.nil?
|
419
|
+
|
407
420
|
SelfSDK.logger.info "authenticating"
|
408
421
|
send_raw Msgproto::Auth.new(
|
409
422
|
type: Msgproto::MsgType::AUTH,
|
410
|
-
id:
|
423
|
+
id: @auth_id,
|
411
424
|
token: @jwt.auth_token,
|
412
425
|
device: @device_id,
|
413
426
|
offset: @offset,
|
414
427
|
)
|
428
|
+
|
429
|
+
@auth_id = nil
|
415
430
|
end
|
416
431
|
|
417
432
|
def send_raw(msg)
|