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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 532728097e0c8c242d1dae95337412e9aedda7d4
|
4
|
+
data.tar.gz: e177f5bc2ea49371ef4e4b5dfa7ae0cc26d5337d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad87349174e6de3a2b9d0dbe611b1a63e2f7800052d710bfef2ad2d9e3c9fdb3106ce8808e6dd5815cc28fc3349f21c8900e62aa06c4eeb2407beb107755540a
|
7
|
+
data.tar.gz: ccc33a58e6146f1497a5967c5d74e4cb079ae8c5d5db62e9862e323820362179f4b1b8143be6abccb0a58b63d34966ddf14a5e046102e560987c80f70f61aea7
|
@@ -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
|
data/lib/simbiotes/server.rb
CHANGED
@@ -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(
|
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(
|
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
|
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
|
data/lib/simbiotes/version.rb
CHANGED
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.
|
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-
|
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.
|
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.
|