selfsdk 0.0.154 → 0.0.159
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 -2
- data/lib/messages/attestation.rb +3 -0
- data/lib/messages/fact_request.rb +1 -0
- data/lib/messages/fact_response.rb +1 -1
- data/lib/messaging.rb +30 -5
- 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: 1a1de83ae25387f6180432dd419f36568956a458bdbfd5df988ea9292588e50a
|
4
|
+
data.tar.gz: 55717411b03f983659ee503493a233d3ceea14f35fd991eec9494a6bc01fe9b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 291ba0d883273e9aa94eb61aa936014a1fd4a6031c9e921d0affc5da4064c39a4cc5b073bb68823ae73d53a33c2808f9cb4921eeac0e043308715d8eb37b9239
|
7
|
+
data.tar.gz: d73be5eb6086614300de7469026715881b640ea51fd9e9e5d8054a7b9c387b9d67f3cb21e72f358ff899833176bf9bb38962832405dd68461fc489e8d217d345
|
data/lib/crypto.rb
CHANGED
@@ -8,7 +8,7 @@ module SelfSDK
|
|
8
8
|
@client = client
|
9
9
|
@device = device
|
10
10
|
@storage_key = storage_key
|
11
|
-
@storage_folder = storage_folder
|
11
|
+
@storage_folder = "#{storage_folder}/#{@client.jwt.key_id}"
|
12
12
|
|
13
13
|
if File.exist?(account_path)
|
14
14
|
# 1a) if alice's account file exists load the pickle from the file
|
@@ -112,7 +112,7 @@ module SelfSDK
|
|
112
112
|
"#{@storage_folder}/account.pickle"
|
113
113
|
end
|
114
114
|
|
115
|
-
def session_path(selfid, device)
|
115
|
+
def session_path(selfid, device)
|
116
116
|
"#{@storage_folder}/#{selfid}:#{device}-session.pickle"
|
117
117
|
end
|
118
118
|
end
|
data/lib/messages/attestation.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
# frozen_string_literal: true
|
4
4
|
|
5
|
+
require_relative '../ntptime'
|
6
|
+
|
5
7
|
module SelfSDK
|
6
8
|
module Messages
|
7
9
|
class Attestation
|
@@ -42,6 +44,7 @@ module SelfSDK
|
|
42
44
|
o = {
|
43
45
|
sub: @to,
|
44
46
|
iss: @origin,
|
47
|
+
iat: SelfSDK::Time.now.strftime('%FT%TZ'),
|
45
48
|
source: @source,
|
46
49
|
fact: @fact_name,
|
47
50
|
expected_value: @expected_value,
|
data/lib/messaging.rb
CHANGED
@@ -45,13 +45,17 @@ module SelfSDK
|
|
45
45
|
@timeout = 120 # seconds
|
46
46
|
@device_id = options.fetch(:device_id, DEFAULT_DEVICE)
|
47
47
|
@auto_reconnect = options.fetch(:auto_reconnect, DEFAULT_AUTO_RECONNECT)
|
48
|
-
@
|
48
|
+
@raw_storage_dir = options.fetch(:storage_dir, DEFAULT_STORAGE_DIR)
|
49
|
+
@storage_dir = "#{@raw_storage_dir}/apps/#{@jwt.id}/devices/#{@device_id}"
|
50
|
+
FileUtils.mkdir_p @storage_dir unless File.exist? @storage_dir
|
49
51
|
@offset_file = "#{@storage_dir}/#{@jwt.id}:#{@device_id}.offset"
|
50
52
|
@offset = read_offset
|
53
|
+
migrate_old_storage_format
|
51
54
|
|
52
|
-
FileUtils.mkdir_p @storage_dir unless File.exist? @storage_dir
|
53
55
|
unless options.include? :no_crypto
|
54
|
-
|
56
|
+
crypto_path = "#{@storage_dir}/keys"
|
57
|
+
FileUtils.mkdir_p crypto_path unless File.exist? crypto_path
|
58
|
+
@encryption_client = Crypto.new(@client, @device_id, crypto_path, storage_key)
|
55
59
|
end
|
56
60
|
|
57
61
|
if options.include? :ws
|
@@ -439,15 +443,36 @@ module SelfSDK
|
|
439
443
|
return 0 unless File.exist? @offset_file
|
440
444
|
|
441
445
|
File.open(@offset_file, 'rb') do |f|
|
442
|
-
return f.read.
|
446
|
+
return f.read.to_i
|
443
447
|
end
|
444
448
|
end
|
445
449
|
|
446
450
|
def write_offset(offset)
|
447
451
|
File.open(@offset_file, 'wb') do |f|
|
448
452
|
f.flock(File::LOCK_EX)
|
449
|
-
f.write(
|
453
|
+
f.write(offset.to_s.rjust(19, "0"))
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
def migrate_old_storage_format
|
458
|
+
# Move the offset file
|
459
|
+
old_offset_file = "#{@raw_storage_dir}/#{@jwt.id}:#{@device_id}.offset"
|
460
|
+
if File.file?(old_offset_file)
|
461
|
+
File.open(old_offset_file, 'rb') do |f|
|
462
|
+
offset = f.read.unpack('q')[0]
|
463
|
+
write_offset(offset)
|
464
|
+
end
|
465
|
+
File.delete(old_offset_file)
|
466
|
+
end
|
467
|
+
|
468
|
+
# Move all pickle files
|
469
|
+
crypto_path = "#{@storage_dir}/keys/#{@jwt.key_id}"
|
470
|
+
FileUtils.mkdir_p crypto_path unless File.exist? crypto_path
|
471
|
+
Dir[File.join(@raw_storage_dir, "*.pickle")].each do |file|
|
472
|
+
filename = File.basename(file, ".pickle")
|
473
|
+
File.rename file, "#{crypto_path}/#{filename}.pickle"
|
450
474
|
end
|
475
|
+
|
451
476
|
end
|
452
477
|
end
|
453
478
|
end
|