selfsdk 0.0.153 → 0.0.158

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0c8f286f380ceb7e9ac8e066789832d4b9f197751505b940fd8cf746bde8428
4
- data.tar.gz: 49256177edb72bc4eb166ae7cd2d3310f60f9dab6b0a1c0380eb779adf05cf63
3
+ metadata.gz: 30ec6ed6d4c41d8a37d049f8d03a4fe91976ae19caf1eb3f8feb5418b12ed30a
4
+ data.tar.gz: 3f9262518a31f02865f2e77bbfa125c3fa23f8b56606cb0c3899ad9b1f5d4521
5
5
  SHA512:
6
- metadata.gz: 814615b35b65af67cbde61330523aa3ec43122b52b0048078ebe6a6ac895e5518ecb8dde154017a15e0190cdb3c9ad32a74ed09627824d49208cdf98748c79f5
7
- data.tar.gz: 3b37174d96dd2b6d4c050d496dd338a4ae0e1b9c36ef0b7d27b81c36f9cc1f74c58ce536e46e08a9e7c27a3449e1aab680b666f6e4ebbb1c8e2120df41ad4d55
6
+ metadata.gz: 86a6cbcd6a449683ae5cf16cfc9a6c55b8a284fe08ccfe9c038a9f75c14722cab0bc29bfff2797a62653382b7da7d3875eda66a700e68983ae45e0dce625983a
7
+ data.tar.gz: 3bd97ff20641571543c6f621472f6f736b067003c72fcd99a4f9c342bf996c4093c9291b54c122dc770fe9a03817c18efb8486a35d8531fe2a01d375010fb478
@@ -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
@@ -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,
@@ -17,7 +17,7 @@ module SelfSDK
17
17
 
18
18
  protected
19
19
 
20
- def proto
20
+ def proto(to_device)
21
21
  nil
22
22
  end
23
23
  end
@@ -72,7 +72,7 @@ module SelfSDK
72
72
 
73
73
  protected
74
74
 
75
- def proto
75
+ def proto(to_device)
76
76
  raise ::StandardError.new("must define this method")
77
77
  end
78
78
 
@@ -59,6 +59,7 @@ module SelfSDK
59
59
  m.to = @from
60
60
  m.audience = @from
61
61
  m.to_device = @messaging.device_id
62
+ m.from_device = @to_device
62
63
  m.facts = @facts
63
64
  m
64
65
  end
@@ -62,7 +62,7 @@ module SelfSDK
62
62
 
63
63
  protected
64
64
 
65
- def proto
65
+ def proto(to_device)
66
66
  encoded_facts = []
67
67
  @facts.each do |fact|
68
68
  encoded_facts.push(fact.to_hash)
@@ -85,7 +85,7 @@ module SelfSDK
85
85
  id: SecureRandom.uuid,
86
86
  sender: "#{@jwt.id}:#{@messaging.device_id}",
87
87
  recipient: "#{@to}:#{@to_device}",
88
- ciphertext: body,
88
+ ciphertext: encrypt_message(body, @to, @to_device)
89
89
  )
90
90
  end
91
91
  end
@@ -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
- @storage_dir = options.fetch(:storage_dir, DEFAULT_STORAGE_DIR)
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
- @encryption_client = Crypto.new(@client, @device_id, @storage_dir, storage_key)
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.unpack('q')[0]
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([offset].pack('q'))
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selfsdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.153
4
+ version: 0.0.158
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures