simbiotes 0.1.11 → 0.1.12

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
  SHA1:
3
- metadata.gz: ea86cc934275ad9bee68dff9df9394f5a3c206b8
4
- data.tar.gz: 7a70964b49e63fe9c4f4d828967c36b0fa223719
3
+ metadata.gz: 532728097e0c8c242d1dae95337412e9aedda7d4
4
+ data.tar.gz: e177f5bc2ea49371ef4e4b5dfa7ae0cc26d5337d
5
5
  SHA512:
6
- metadata.gz: 961f8ba083b6d2fa0b78051ccb2c71c96dccf26b51c462bfd6ad2087d4603acd6b03adc883c6a875689ddf13b1b0d85f484ac76f82a6e5683948f30601db03d2
7
- data.tar.gz: aa0c4a2f70947fd66b06a37e071a7084c508af9f9bdc04e163595a55904a768af4cd3fa6c96b8dad57b3fb0d41197588f171c9325c5a6734c7c7f05286ab6e84
6
+ metadata.gz: ad87349174e6de3a2b9d0dbe611b1a63e2f7800052d710bfef2ad2d9e3c9fdb3106ce8808e6dd5815cc28fc3349f21c8900e62aa06c4eeb2407beb107755540a
7
+ data.tar.gz: ccc33a58e6146f1497a5967c5d74e4cb079ae8c5d5db62e9862e323820362179f4b1b8143be6abccb0a58b63d34966ddf14a5e046102e560987c80f70f61aea7
@@ -5,5 +5,6 @@ Simbiotes.configure do |config|
5
5
  config.server_port = 8000
6
6
  config.tls = true
7
7
  config.verify_peer = true
8
+ config.handshake = true
8
9
  config.local_logging = true
9
10
  end
@@ -1,7 +1,7 @@
1
1
  module Simbiotes
2
2
  class Configuration
3
3
 
4
- attr_accessor :public_key, :private_key, :local_logging, :targets, :local_port, :server, :server_port, :portal, :push, :tls, :verify_peer
4
+ attr_accessor :public_key, :private_key, :local_logging, :targets, :local_port, :server, :server_port, :portal, :push, :tls, :verify_peer, :handshake
5
5
 
6
6
  def initialize
7
7
  @public_key = nil
@@ -15,6 +15,7 @@ module Simbiotes
15
15
  @push = false
16
16
  @tls = true
17
17
  @verify_peer = true
18
+ @handshake = true
18
19
  end
19
20
 
20
21
  end
@@ -4,11 +4,33 @@
4
4
 
5
5
  require "socket"
6
6
  require 'openssl'
7
+ require 'json'
8
+
7
9
  module Simbiotes
8
10
  class Server
9
11
  def initialize
12
+ @error_msg = nil
13
+ rgs = SimbiotesSetting.find_by(key: "server")
14
+ rgs_port = SimbiotesSetting.find_by(key: "port")
15
+ if rgs == nil
16
+ server_details = Server.lookup
17
+ if server_details["status"] == "ok"
18
+ rgs = server_details["rgs"]
19
+ c = SimbiotesSetting.new
20
+ c.key = "server"
21
+ c.value = rgs
22
+ c.save
23
+ rgs_port = server_details["rgs_port"]
24
+ c = SimbiotesSetting.new
25
+ c.key = "port"
26
+ c.value = rgs_port
27
+ c.save
28
+ else
29
+ @error_msg = server_details["status_msg"]
30
+ end
31
+ end
10
32
  if Simbiotes.configuration.tls == true
11
- socket = TCPSocket.new(Simbiotes.configuration.server, Simbiotes.configuration.server_port)
33
+ socket = TCPSocket.new(rgs, rgs_port)
12
34
  context = OpenSSL::SSL::SSLContext.new
13
35
  context.key = Server.key
14
36
  context.cert = Server.cert
@@ -20,7 +42,11 @@ module Simbiotes
20
42
  server.sync_close = true
21
43
  server.connect
22
44
  else
23
- server = TCPSocket.open(Simbiotes.configuration.server, Simbiotes.configuration.server_port)
45
+ server = TCPSocket.open(rgs, rgs_port)
46
+ end
47
+ if Simbiotes.configuration.handshake == true
48
+ server.puts('{"action":"connect"}')
49
+ response = server.gets
24
50
  end
25
51
  @server = server
26
52
  @localport = Simbiotes.configuration.local_port
@@ -67,6 +93,10 @@ module Simbiotes
67
93
  loop do
68
94
  Thread.fork(server.accept) do |client|
69
95
  s = client.gets
96
+ if @error_msg != nil
97
+ string = '{"error":"' + error_msg + '"}'
98
+ client.puts(string)
99
+ end
70
100
  #puts s
71
101
  self.send(s)
72
102
  end
@@ -77,6 +107,29 @@ module Simbiotes
77
107
  end
78
108
  end
79
109
 
110
+ def self.lookup
111
+ if Simbiotes.configuration.tls == true
112
+ socket = TCPSocket.new(Simbiotes.configuration.server, Simbiotes.configuration.server_port)
113
+ context = OpenSSL::SSL::SSLContext.new
114
+ context.key = Server.key
115
+ context.cert = Server.cert
116
+ if Simbiotes.configuration.verify_peer == true
117
+ context.ca_file = Server.ca_cert
118
+ context.verify_mode = OpenSSL::SSL::VERIFY_PEER
119
+ end
120
+ server = OpenSSL::SSL::SSLSocket.new socket, context
121
+ server.sync_close = true
122
+ server.connect
123
+ else
124
+ server = TCPSocket.open(Simbiotes.configuration.server, Simbiotes.configuration.server_port)
125
+ end
126
+ server.puts('{"action":lookup}')
127
+ msg = server.gets
128
+ hash = JSON.parse(msg)
129
+ server.close
130
+ return hash
131
+ end
132
+
80
133
  def self.key
81
134
  key = SimbiotesSetting.find_by(key: "key")
82
135
  if key == nil
@@ -135,7 +188,7 @@ module Simbiotes
135
188
  def self.generate_cert(key, public_key)
136
189
  csr = OpenSSL::X509::Request.new
137
190
  csr.version = 0
138
- csr.subject = OpenSSL::X509::Name.parse 'CN=simbiotes.com'
191
+ csr.subject = OpenSSL::X509::Name.parse "CN=#{Simbiotes.configuration.public_key}:#{Simbiotes.configuration.private_key}"
139
192
  csr.public_key = key.public_key
140
193
  csr.sign key, OpenSSL::Digest::SHA1.new
141
194
  cert = Simbiotes::Portal.generate_certificate(csr)
@@ -157,5 +210,14 @@ module Simbiotes
157
210
  return ca_cert
158
211
  end
159
212
 
213
+ at_exit do
214
+ if Simbiotes.configuration.handshake == true
215
+ string = '{"action":"disconnect"}'
216
+ if @server != nil
217
+ @server.puts(string)
218
+ end
219
+ end
220
+ end
221
+
160
222
  end
161
223
  end
@@ -1,3 +1,3 @@
1
1
  module Simbiotes
2
- VERSION = '0.1.11'
2
+ VERSION = '0.1.12'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simbiotes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - MicroArx Corporation
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-02 00:00:00.000000000 Z
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  version: '0'
231
231
  requirements: []
232
232
  rubyforge_project:
233
- rubygems_version: 2.5.2
233
+ rubygems_version: 2.2.2
234
234
  signing_key:
235
235
  specification_version: 4
236
236
  summary: The easy way to integrate the IoT in your web app.