ruby_home 0.1.22 → 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5c2472175346b490fafbd175e114227a9796e4304c472d5c3e5f4eb8734c76a
4
- data.tar.gz: 6930dac62338255403695f5369397daa26fd0c7853d9ab2784a7de084f092655
3
+ metadata.gz: 8a06fe406af9a2d18a8cd3083e97dd84d10cf6ccc447ff3d46527ea5882c22d1
4
+ data.tar.gz: 3893723e9f2ccf60561bc831a680b715f7216f32c1783bbc3b01bd290212d95a
5
5
  SHA512:
6
- metadata.gz: 18ebd83f029b7a1545d2f28331ca38be78ffe5a392026e598b93732b936dc5712b43e7b7b1c24088864709cc4fa45d6189bf3c9793220303d02b1fb86c336079
7
- data.tar.gz: cd1227d1e26ef5dd91c6fc91c1ce526cc8b8e257916161a8cc72814e68f5be522b33bdd8f4db3d46a5511ce98534261917c640dfe75e6cc9e23df2cc19efe391
6
+ metadata.gz: 613563189aaf7dedf4361b8bc8f3a59ed6b98527976c309ccd40ffafc6717cebfd1eb97d792507eddc751b151aaa5c1f047317038475e4a63c96c94da8012a7e
7
+ data.tar.gz: ac7e43d2580b305a97d8b1354b940cb909cd2a4763bcf629898cb2a59cc817c53b049bd4745c597a80aa84a8072e3157583f1ee9975a4e542b00cb5c37d92d72
@@ -40,7 +40,7 @@ module RubyHome
40
40
  def tlv(object)
41
41
  logger.debug "Response"
42
42
  logger.debug object.inspect
43
- HAP::TLV.encode(object)
43
+ TLV.encode(object)
44
44
  end
45
45
 
46
46
  def logger
@@ -65,7 +65,7 @@ module RubyHome
65
65
  end
66
66
 
67
67
  def _unpack_request
68
- HAP::TLV.read(request_body).tap do |request_tlv|
68
+ TLV.decode(request_body).tap do |request_tlv|
69
69
  logger.debug "Request"
70
70
  logger.debug request_tlv.inspect
71
71
  end
@@ -60,7 +60,7 @@ module RubyHome
60
60
 
61
61
  nonce = HexHelper.pad('PS-Msg05')
62
62
  decrypted_data = chacha20poly1305ietf.decrypt(nonce, encrypted_data)
63
- unpacked_decrypted_data = HAP::TLV.read(decrypted_data)
63
+ unpacked_decrypted_data = TLV.decode(decrypted_data)
64
64
 
65
65
  iosdevicepairingid = unpacked_decrypted_data[:identifier]
66
66
  iosdevicesignature = unpacked_decrypted_data[:signature]
@@ -53,7 +53,7 @@ module RubyHome
53
53
  chacha20poly1305ietf = HAP::Crypto::ChaCha20Poly1305.new(session.session_key)
54
54
  nonce = HexHelper.pad('PV-Msg03')
55
55
  decrypted_data = chacha20poly1305ietf.decrypt(nonce, encrypted_data)
56
- unpacked_decrypted_data = HAP::TLV.read(decrypted_data)
56
+ unpacked_decrypted_data = TLV.decode(decrypted_data)
57
57
 
58
58
  if accessory_info.paired_clients.any? {|h| h[:identifier] == unpacked_decrypted_data[:identifier]}
59
59
  shared_secret = HAP::Crypto::SessionKey.new(session.shared_secret)
@@ -1,3 +1,3 @@
1
1
  module RubyHome
2
- VERSION = '0.1.22'
2
+ VERSION = '0.1.23'
3
3
  end
data/lib/ruby_home.rb CHANGED
@@ -6,7 +6,8 @@ require 'nio'
6
6
  require 'oj'
7
7
  require 'rack'
8
8
  require 'rbnacl'
9
- require 'ruby_home-srp'
9
+ require 'ruby_home/srp'
10
+ require 'ruby_home/tlv'
10
11
  require 'securerandom'
11
12
  require 'sinatra/base'
12
13
  require 'socket'
data/rubyhome.gemspec CHANGED
@@ -33,7 +33,8 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency 'nio4r', '~> 2.3', '>= 2.3.1'
34
34
  spec.add_dependency 'oj', '3.7.9'
35
35
  spec.add_dependency 'rbnacl', '~> 6.0'
36
- spec.add_dependency 'ruby_home-srp', '~> 1.2'
36
+ spec.add_dependency 'ruby_home-srp', '~> 1.3'
37
+ spec.add_dependency 'ruby_home-tlv', '~> 0.1.0'
37
38
  spec.add_dependency 'sinatra', '2.0.5'
38
39
  spec.add_dependency 'wisper', '~> 2.0'
39
40
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_home
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Entwistle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-25 00:00:00.000000000 Z
11
+ date: 2019-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -126,14 +126,28 @@ dependencies:
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '1.2'
129
+ version: '1.3'
130
130
  type: :runtime
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: '1.2'
136
+ version: '1.3'
137
+ - !ruby/object:Gem::Dependency
138
+ name: ruby_home-tlv
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: 0.1.0
144
+ type: :runtime
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: 0.1.0
137
151
  - !ruby/object:Gem::Dependency
138
152
  name: sinatra
139
153
  requirement: !ruby/object:Gem::Requirement
@@ -283,7 +297,6 @@ files:
283
297
  - lib/ruby_home/hap/hap_response.rb
284
298
  - lib/ruby_home/hap/server.rb
285
299
  - lib/ruby_home/hap/session.rb
286
- - lib/ruby_home/hap/tlv.rb
287
300
  - lib/ruby_home/hap/values/base_value.rb
288
301
  - lib/ruby_home/hap/values/bool_value.rb
289
302
  - lib/ruby_home/hap/values/float_value.rb
@@ -1,102 +0,0 @@
1
- module RubyHome
2
- module HAP
3
- module TLV
4
- ERROR_TYPES = {
5
- unknown: 1,
6
- authentication: 2,
7
- backoff: 3,
8
- max_peers: 4,
9
- max_tries: 5,
10
- unavailable: 6,
11
- busy: 7,
12
- }.freeze
13
- TYPE_ERRORS = ERROR_TYPES.invert.freeze
14
-
15
- NAME_TYPES = {
16
- method: 0,
17
- identifier: 1,
18
- salt: 2,
19
- public_key: 3,
20
- proof: 4,
21
- encrypted_data: 5,
22
- state: 6,
23
- error: 7,
24
- retry_delay: 8,
25
- certificate: 9,
26
- signature: 10,
27
- permissions: 11,
28
- fragment_data: 12,
29
- fragment_last: 13,
30
- }.freeze
31
- TYPE_NAMES = NAME_TYPES.invert.freeze
32
-
33
- class Bytes < BinData::String; end
34
-
35
- class UTF8String < BinData::String
36
- def snapshot
37
- super.force_encoding('UTF-8')
38
- end
39
- end
40
-
41
- class Payload < BinData::Choice
42
- bytes :default, read_length: :len
43
-
44
- uint8 0, read_length: :len
45
- utf8_string 1, read_length: :len
46
- bytes 2, read_length: :len
47
- bytes 3, read_length: :len
48
- bytes 4, read_length: :len
49
- bytes 5, read_length: :len
50
- uint8 6, read_length: :len
51
- uint8 7, read_length: :len
52
- uint8 8, read_length: :len
53
- bytes 9, read_length: :len
54
- bytes 10, read_length: :len
55
- uint8 11, read_length: :len
56
- bytes 12, read_length: :len
57
- bytes 13, read_length: :len
58
- end
59
-
60
- class TLV < BinData::Record
61
- uint8 :type_id, read_length: 2
62
- uint8 :len, read_length: 2
63
- payload :val, selection: :type_id
64
- end
65
-
66
- READER = BinData::Array.new(type: :tlv, read_until: :eof)
67
-
68
- def self.read(input)
69
- READER.clear
70
- READER.read(input)
71
- READER.snapshot.each_with_object({}) do |(hash), memo|
72
- type = TYPE_NAMES[hash[:type_id]]
73
- next unless type
74
-
75
- if memo[type]
76
- memo[type] << hash[:val]
77
- else
78
- memo[type] = hash[:val]
79
- end
80
- end
81
- end
82
-
83
- def self.encode(hash)
84
- hash.to_hash.each_with_object(String.new) do |(key, value), memo|
85
- type_id = NAME_TYPES[key]
86
- next unless type_id
87
-
88
- if value.is_a?(String)
89
- value.scan(/.{1,255}/m)
90
- else
91
- [value]
92
- end.each do |frame_value|
93
- tlv = TLV.new(type_id: type_id, val: frame_value).tap do |tlv|
94
- tlv.len = tlv.val.to_binary_s.length
95
- end
96
- memo << tlv.to_binary_s
97
- end
98
- end
99
- end
100
- end
101
- end
102
- end