selfsdk 0.0.162 → 0.0.167
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/messages/authentication_message.rb +5 -1
- data/lib/messages/base.rb +4 -2
- data/lib/messages/fact_request.rb +7 -3
- data/lib/messages/fact_response.rb +6 -3
- 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: 425117eb38ae08f2a8d3e65e1ba7ba772b06a4cbc378d17cbe5870a5598d2cb2
|
4
|
+
data.tar.gz: a638bc535a0e81732c7f48e11a779fe7ac08a8ea7f5239b0600af087030df65f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69c5dd8b994ddcc2ba6432baac35fb20e03d810d927b991956ae878efa3546a988e617aa12bb831897656fa4a8adb8c6e1180f09934d110703b938cbe3d3e5cf
|
7
|
+
data.tar.gz: 300df2dbe461f01666943f29a5d137e9bc254fc6dbdbdb80763bfaad302b3eca1dc63e35682afcba06a4364f74f7a5f674dccccae7ab6fa69d035af54bcffb59
|
@@ -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,17 +39,23 @@ 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
|
46
46
|
@id = @payload[:cid]
|
47
47
|
@from = @payload[:iss]
|
48
48
|
@to = @payload[:sub]
|
49
|
+
@audience = payload[:aud]
|
49
50
|
@expires = @payload[:exp]
|
50
51
|
@description = @payload.include?(:description) ? @payload[:description] : nil
|
51
52
|
@facts = @payload[:facts]
|
52
53
|
@options = @payload[:options]
|
54
|
+
|
55
|
+
if envelope
|
56
|
+
issuer = envelope.sender.split(":")
|
57
|
+
@from_device = issuer.last
|
58
|
+
end
|
53
59
|
end
|
54
60
|
|
55
61
|
def build_response
|
@@ -59,8 +65,6 @@ module SelfSDK
|
|
59
65
|
m.to = @from
|
60
66
|
m.sub = @to
|
61
67
|
m.audience = @from
|
62
|
-
m.to_device = @messaging.device_id
|
63
|
-
m.from_device = @to_device
|
64
68
|
m.facts = @facts
|
65
69
|
m
|
66
70
|
end
|
@@ -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)
|
@@ -81,8 +85,7 @@ module SelfSDK
|
|
81
85
|
protected
|
82
86
|
|
83
87
|
def proto(to_device)
|
84
|
-
|
85
|
-
|
88
|
+
@to_device = to_device
|
86
89
|
Msgproto::Message.new(
|
87
90
|
type: Msgproto::MsgType::MSG,
|
88
91
|
id: SecureRandom.uuid,
|
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)
|