rxio 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/lib/rxio/client.rb +17 -1
- data/lib/rxio/service.rb +12 -2
- data/lib/rxio/version.rb +1 -1
- data/rxio.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c9ca3ae8857d65bc146a20200d72feba5876cfb
|
4
|
+
data.tar.gz: 411f6c8e7ea2a455d7ce261b4de5f4883f8ee205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 342d8d61b7240292c3925f8ab7e7447f80d40f6c12d73ae6df65004d4960cf3b8fdc5f3f74da0168c666e3317e5ccd845e93b102716318c1370a03d5cb28a188
|
7
|
+
data.tar.gz: 4c12c281829622777e8013f7bdc323516acef82004b83c5bc232005548e1d1fdfdad19045ca51f05545d11c9f79d53c3ccfe2df8b1f89b46547d5a6a397a90de
|
data/README.md
CHANGED
@@ -32,6 +32,38 @@ This will execute the service / client main loop. The handler module provides th
|
|
32
32
|
The _run_ method on both *Service* & *Client* is blocking and will only return after the main loop has terminated.
|
33
33
|
A _stop_ method is also provided to request the main loop to terminate.
|
34
34
|
|
35
|
+
### SSL Support
|
36
|
+
|
37
|
+
RxIO provides support for secure communication through [OpenSSL](https://www.openssl.org/).
|
38
|
+
To create a secure server, pass the ssl parameters to RxIO::Service.new:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
s = RxIO::Service.new 'localhost', 4444, ExampleServiceHandler, { cert: './certificate.pem', pkey: './private.key' }
|
42
|
+
s.startup
|
43
|
+
```
|
44
|
+
|
45
|
+
Creating a secure client is as simple as:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
c = RxIO::Client.new 'localhost', 4444, TestClientHandler, true
|
49
|
+
c.startup
|
50
|
+
```
|
51
|
+
|
52
|
+
#### SSL Params
|
53
|
+
|
54
|
+
When creating a secure client, the last argument to RxIO::Client.new is a hash through which the following can be specified:
|
55
|
+
|
56
|
+
* *verify_peer* - true/false (Verify the Peer Certificate)
|
57
|
+
|
58
|
+
#### Ignoring SSL Certificate Errors
|
59
|
+
|
60
|
+
Although strongly discouraged for obvious security reasons, the SSL Peer Certificate verification can be disabled:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
c = RxIO::Client.new 'localhost', port, TestClientHandler, true, verify_peer: false
|
64
|
+
c.startup
|
65
|
+
```
|
66
|
+
|
35
67
|
### Running in the background
|
36
68
|
|
37
69
|
While the _run_ / _stop_ methods offer a simple way to implement a single service/client within the current thread, some situations may require wrapping in a separate thread.
|
data/lib/rxio/client.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
# External Includes
|
5
5
|
require 'thread'
|
6
6
|
require 'socket'
|
7
|
+
require 'openssl'
|
7
8
|
require 'runify'
|
8
9
|
|
9
10
|
# Internal Includes
|
@@ -32,7 +33,15 @@ module RxIO
|
|
32
33
|
# @param [String] addr Address to which the client should connect
|
33
34
|
# @param [Fixnum] port Port on which the client should connect
|
34
35
|
# @param [Module] service_handler Module implementing service client logic
|
35
|
-
|
36
|
+
# @param [Boolean] ssl Create a secure client
|
37
|
+
# @param [Hash] ssl_params SSL Parameters - see README
|
38
|
+
def initialize addr, port, service_handler, ssl = false, ssl_params = { verify_peer: true }
|
39
|
+
|
40
|
+
# Set SSL Context
|
41
|
+
if ssl
|
42
|
+
@ssl_ctx = OpenSSL::SSL::SSLContext.new
|
43
|
+
@ssl_ctx.verify_mode = ssl_params[:verify_peer] ? OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT : OpenSSL::SSL::VERIFY_NONE
|
44
|
+
end
|
36
45
|
|
37
46
|
# Set Address & Port
|
38
47
|
@addr = addr
|
@@ -126,6 +135,13 @@ module RxIO
|
|
126
135
|
# Check Socket
|
127
136
|
return nil unless @sock
|
128
137
|
|
138
|
+
# Wrap into SSL Socket
|
139
|
+
if @ssl_ctx
|
140
|
+
@sock = OpenSSL::SSL::SSLSocket.new @sock, @ssl_ctx
|
141
|
+
@sock.sync_close
|
142
|
+
@sock.connect
|
143
|
+
end
|
144
|
+
|
129
145
|
# Reset Client Buffers
|
130
146
|
@client[:lock].synchronize { @client[:obuf] = '' }
|
131
147
|
@client[:ibuf] = ''
|
data/lib/rxio/service.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
# External Includes
|
5
5
|
require 'thread'
|
6
6
|
require 'socket'
|
7
|
+
require 'openssl'
|
7
8
|
require 'runify'
|
8
9
|
|
9
10
|
# Internal Includes
|
@@ -29,7 +30,15 @@ module RxIO
|
|
29
30
|
# @param [String] addr Address on which the service should listen
|
30
31
|
# @param [Fixnum] port Port on which the service should listen
|
31
32
|
# @param [Module] service_handler Module implementing the service logic
|
32
|
-
|
33
|
+
# @param [Hash] ssl_params Optional SSL Parameters ({ cert: '/path/to/cert', pkey: '/path/to/privatekey' }) - will create a secure server if not nil
|
34
|
+
def initialize addr, port, service_handler, ssl_params = nil
|
35
|
+
|
36
|
+
# Set SSL Params
|
37
|
+
if ssl_params
|
38
|
+
@ssl_ctx = OpenSSL::SSL::SSLContext.new
|
39
|
+
@ssl_ctx.cert = OpenSSL::X509::Certificate.new File.read(ssl_params[:cert])
|
40
|
+
@ssl_ctx.key = OpenSSL::PKey::RSA.new File.read(ssl_params[:pkey])
|
41
|
+
end
|
33
42
|
|
34
43
|
# Set Address & Port
|
35
44
|
@addr = addr
|
@@ -58,6 +67,7 @@ module RxIO
|
|
58
67
|
|
59
68
|
# Create TCP Socket Server
|
60
69
|
@serv = TCPServer.new @addr, @port
|
70
|
+
@serv = OpenSSL::SSL::SSLServer.new @serv, @ssl_ctx if @ssl_ctx
|
61
71
|
@socks << @serv
|
62
72
|
|
63
73
|
# Update Service
|
@@ -152,7 +162,7 @@ module RxIO
|
|
152
162
|
def acpt_sock s
|
153
163
|
|
154
164
|
# Accept
|
155
|
-
ns = s.
|
165
|
+
ns = s.accept rescue nil
|
156
166
|
|
157
167
|
# Register Client
|
158
168
|
add_client ns if ns
|
data/lib/rxio/version.rb
CHANGED
data/rxio.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rxio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eresse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: openssl
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: runify
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|