selfsdk 0.0.157 → 0.0.162

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: 591ba1fdd4152ea5346667256345644f78ddcc5307426f59d90bc2a7ac61cdcc
4
- data.tar.gz: 3e565f40abf9e8df6fdde236ba92bc65f780cbcc7554fc26316cc52b54dc2d69
3
+ metadata.gz: c7b7b3b844225f5fc4419a53bf28aa028e44c264a4ec3b298c269daaea4b05c5
4
+ data.tar.gz: 64c35eac74be284ab020e2412c27a338f856174e5d154c59dcab0e4625a65276
5
5
  SHA512:
6
- metadata.gz: 231048c700a31b8e0664a20b4afb212fd5f4b3da8cc91b02b18296153cd6e0d5c137d902f95133b32bf288bae815598270c0f0caf1271f791e34b9f4de79a115
7
- data.tar.gz: c44c480f4c5181e11c310345a8c81f99b17867877760edf927ab6bdcf3dc46805487533febca0e5f4208615c9a65fac463ee48ec73a02764bda52be2749e54f8
6
+ metadata.gz: 1dd9537fd6aa8021b8a2a5d5d3587fc447bd3a389460c5b4ea996f429a91b4a965cdb577673109f69514eb8056963c7f972a6e440edc764c06fbe5934ff9cc7b
7
+ data.tar.gz: d2cf23e278279d99cef701b0f74f8c31a6ed3ce4f1a44b87a8b648b8fb9e9029b84812431b53a4f7b4e2abf234a977cd7e59b57a1e53532e9ab0bc2f8230e2b3
@@ -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
@@ -57,6 +57,7 @@ module SelfSDK
57
57
  m.id = @id
58
58
  m.from = @to
59
59
  m.to = @from
60
+ m.sub = @to
60
61
  m.audience = @from
61
62
  m.to_device = @messaging.device_id
62
63
  m.from_device = @to_device
@@ -60,15 +60,13 @@ module SelfSDK
60
60
  end
61
61
  end
62
62
 
63
- protected
64
-
65
- def proto(to_device)
63
+ def body
66
64
  encoded_facts = []
67
65
  @facts.each do |fact|
68
66
  encoded_facts.push(fact.to_hash)
69
67
  end
70
- body = @jwt.prepare(
71
- typ: MSG_TYPE,
68
+
69
+ { typ: MSG_TYPE,
72
70
  iss: @jwt.id,
73
71
  sub: @sub || @to,
74
72
  aud: @audience,
@@ -77,15 +75,20 @@ module SelfSDK
77
75
  cid: @id,
78
76
  jti: SecureRandom.uuid,
79
77
  status: @status,
80
- facts: encoded_facts,
81
- )
78
+ facts: encoded_facts }
79
+ end
80
+
81
+ protected
82
+
83
+ def proto(to_device)
84
+
82
85
 
83
86
  Msgproto::Message.new(
84
87
  type: Msgproto::MsgType::MSG,
85
88
  id: SecureRandom.uuid,
86
89
  sender: "#{@jwt.id}:#{@messaging.device_id}",
87
90
  recipient: "#{@to}:#{@to_device}",
88
- ciphertext: encrypt_message(body, @to, @to_device)
91
+ ciphertext: encrypt_message(@jwt.prepare(body), @to, @to_device)
89
92
  )
90
93
  end
91
94
  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.157
4
+ version: 0.0.162
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures