relp 0.1.2 → 0.2.0

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: f7f83efde74951f5183dc18758bd7d92de7f0d47
4
- data.tar.gz: b582704d3e53d7dce8712d78809e1798680bbebf
3
+ metadata.gz: 1eedad03bc936d4d6853527e61ad522606daa54c
4
+ data.tar.gz: fe0c593c39cf33c06e0b19e60477dc40805c8d82
5
5
  SHA512:
6
- metadata.gz: cbf9e4b9037041a69397d9dd57fe742e2c7af1e76ec062633110f47e393fd8634182026b4e636f2c9a86da86a843e5b470519f3ff83ef21fecbe6df806fc0e71
7
- data.tar.gz: 6353f83c40e2cae9ccd5fc6da7660f220dbd9fea6a3ac7746a16fb9ffd90cf3ac45390cc01d63dd525ad4a7483a0ac59abfa62689a2fde632aaa22dce7df3d8c
6
+ metadata.gz: 01e1d1bba7a58febbab70bbc55a2f824199dc24eafc584506cf7c6121ccedf1cc82f44d12cd0d27c55731c58b593dd80c099e1dac7eb6869fdf7a66a2e83c869
7
+ data.tar.gz: fef50599502268f20e910d7cf5f135a5b6373688298e11fe69f4eda63e9a4c9b319b2a5c900b3b8c23d30315242c8ccda21d232c9b9962fb5fe07da4e9573eda
@@ -5,10 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.2.0] - 2017-09-11
9
+ ### Changed
10
+ - Server side - new arguments sequence `(port, callback, host = '0.0.0.0' , tls_context = nil, logger = nil)`
11
+ - Improved RELP frame checking
8
12
  ## [Unreleased]
9
13
  ### Added
10
- - Started writing this changelog
11
- - This repo transferred to ViaQ org
14
+ - Changelog
15
+ - This repo transferred to ViaQ organization
12
16
 
13
17
  ## [0.1.1] - 2017-06-23
14
18
  ### Changed
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RELP
2
2
 
3
- This library contains native implementation of [RELP protocol](http://www.rsyslog.com/doc/relp.html) in ruby. At the moment only server-side
3
+ This library contains native implementation of [RELP protocol](http://www.rsyslog.com/doc/relp.html) in ruby with TLS support. At the moment only server-side
4
4
  is properly implemented and (to some extent) tested.
5
5
 
6
6
  ## Installation
@@ -23,16 +23,8 @@ Or install it yourself as:
23
23
 
24
24
  ### Server
25
25
 
26
- To run server just creat instance of `Relp::RelpServer.new(host, port, logger = nil, callback)`
27
- and than call method run on instance of server e.g. `server.run`
28
-
29
- `host`
30
- * This is a required setting.
31
- * Value type is string
32
- * There is no default value for this setting.
33
- * Specifies address you want to bind to, use "0.0.0.0" to bind to any address
34
-
35
-
26
+ To run server just create instance of `Relp::RelpServer.new(port, callback, host, tls_context, logger)`
27
+ and then call method run on instance of server e.g. `server.run`
36
28
 
37
29
  `port`
38
30
 
@@ -41,19 +33,37 @@ and than call method run on instance of server e.g. `server.run`
41
33
  * There is no default value for this setting.
42
34
  * Sets on which port you want to listen for incoming RELP connections
43
35
 
44
-
36
+ `callback`
37
+ * This is a required setting.
38
+ * Method you want to be executed upon successfully accepted message, it has only one :string parameter, which is message itself.
39
+
40
+ `host`
41
+ * This is a required setting.
42
+ * Value type is string
43
+ * Default value is "0.0.0.0' to bind any address
44
+ * Specifies address you want to bind to, use "0.0.0.0" to bind to any address
45
+
46
+ `tls_context`
47
+ * Value type is SSL_context_object = OpenSSL::SSL::SSLContext.new See -> OpenSSL <a href="http://ruby-doc.org/stdlib-2.0.0/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html">homepage</a>
48
+ * If is not set - server runs without TLS or SSL encryption
49
+ * Example of TLS/SSL context object:
50
+ ```ruby
51
+ sslContext = OpenSSL::SSL::SSLContext.new
52
+ sslContext.cert = OpenSSL::X509::Certificate.new(File.open("path/to/certificate/cert.pem"))
53
+ sslContext.key = OpenSSL::PKey::RSA.new(File.open("path/to/key/key.pem"))
54
+ sslContext.ca_file = 'path/to/certificate/authority/ca.pem'
55
+ sslContext.verify_mode = OpenSSL::SSL::VERIFY_PEER #only if you want verify peer
56
+ ```
57
+
45
58
  `logger`
46
59
 
47
60
  * This is optional setting
48
61
  * Value type is logger object
49
62
  * If is not set - default is `Logger.new(STDOUT)` with all levels of logging
50
63
 
51
- `callback`
52
- * This is a required setting.
53
- * Method you want to be executed upon successfully accepted message, it has only one :Hash parameter, which is message itself.
54
-
64
+
55
65
  #### Important Methods
56
- * `run` Start connceting clients
66
+ * `run` Start connecting clients
57
67
  * `server_shutdown` Close connection to all clients and shutdown server
58
68
 
59
69
  ### Client
@@ -13,4 +13,7 @@ module Relp
13
13
 
14
14
  class InvalidCommand < RelpProtocolError
15
15
  end
16
- end
16
+
17
+ class MissingData < RelpProtocolError
18
+ end
19
+ end
@@ -1,9 +1,19 @@
1
1
  require 'relp/exceptions'
2
2
  require 'socket'
3
+ require "openssl"
4
+
3
5
  module Relp
4
6
  class RelpProtocol
5
7
  @@relp_version = '0'
6
8
  @@relp_software = 'librelp,1.2.13,http://librelp.adiscon.com'
9
+
10
+ def create_frame(txnr, command, message)
11
+ frame = {:txnr => txnr,
12
+ :command => command,
13
+ :message => message
14
+ }
15
+ end
16
+
7
17
  def frame_write(socket, frame)
8
18
  raw_data=[
9
19
  frame[:txnr],
@@ -24,9 +34,10 @@ module Relp
24
34
  frame = Hash.new
25
35
  if match = socket_content.match(/(^[0-9]+) ([\S]*) (\d+)([\s\S]*)/)
26
36
  frame[:txnr], frame[:command], frame[:data_length], frame[:message] = match.captures
37
+ check_message_length(frame)
27
38
  frame[:message].lstrip! #message could be empty
28
39
  else
29
- raise raise Relp::FrameReadException.new('Problem with reading RELP frame')
40
+ raise Relp::FrameReadException.new('Problem with reading RELP frame')
30
41
  end
31
42
  @logger.debug "Reading Frame #{frame.inspect}"
32
43
  rescue IOError
@@ -54,5 +65,17 @@ module Relp
54
65
  def extract_message_information(message)
55
66
  informations = Hash[message.scan(/^(.*)=(.*)$/).map { |(key, value)| [key.to_sym, value] }]
56
67
  end
68
+
69
+ def check_message_length(frame)
70
+ if frame[:command] == "close"
71
+ real_length = frame[:message].length
72
+ else
73
+ real_length = frame[:message].length - 2
74
+ end
75
+ if real_length != frame[:data_length].to_i
76
+ @logger.error 'Lost data'
77
+ raise Relp::MissingData.new('Data length is not same as received data')
78
+ end
79
+ end
57
80
  end
58
81
  end
@@ -1,10 +1,11 @@
1
1
  require 'relp/relp_protocol'
2
2
  require 'logger'
3
3
  require 'thread'
4
+ require "openssl"
4
5
 
5
6
  module Relp
6
7
  class RelpServer < RelpProtocol
7
- def initialize(host, port, logger = nil, callback)
8
+ def initialize(port, callback, host = '0.0.0.0' , tls_context = nil, logger = nil)
8
9
  @logger = logger
9
10
  @logger = Logger.new(STDOUT) if logger.nil?
10
11
  @socket_list = Array.new
@@ -12,8 +13,13 @@ module Relp
12
13
  @required_command = 'syslog'
13
14
 
14
15
  begin
15
- @server = TCPServer.new(host, port)
16
- @logger.info "Starting #{self.class} on %s:%i" % @server.local_address.ip_unpack
16
+ @server = TCPServer.new host, port
17
+ if tls_context
18
+ @logger.info "Starting #{self.class} with SSL enabled on %s:%i" % @server.local_address.ip_unpack
19
+ @server = OpenSSL::SSL::SSLServer.new(@server, tls_context)
20
+ else
21
+ @logger.info "Starting #{self.class} on %s:%i" % @server.local_address.ip_unpack
22
+ end
17
23
  rescue Errno::EADDRINUSE
18
24
  @logger.error "ERROR Could not start relp server: Port #{port} in use"
19
25
  raise Errno::EADDRINUSE
@@ -42,6 +48,8 @@ module Relp
42
48
  @logger.info "Connection closed"
43
49
  rescue Relp::RelpProtocolError => err
44
50
  @logger.warn 'Relp error: ' + err.class.to_s + ' ' + err.message
51
+ rescue OpenSSL::SSL::SSLError => ssl_error
52
+ @logger.error "SSL Error", :exception => ssl_error
45
53
  rescue Exception => e
46
54
  @logger.debug e
47
55
  ensure
@@ -65,13 +73,6 @@ module Relp
65
73
  end
66
74
  end
67
75
 
68
- def create_frame(txnr, command, message)
69
- frame = {:txnr => txnr,
70
- :command => command,
71
- :message => message
72
- }
73
- end
74
-
75
76
  def ack_frame(socket, txnr)
76
77
  frame = {:txnr => txnr,
77
78
  :command => 'rsp',
@@ -82,7 +83,7 @@ module Relp
82
83
 
83
84
  def server_close_message(socket)
84
85
  Hash.new frame = {:txnr => 0,
85
- :command => 'serverclose',
86
+ :command => 'close',
86
87
  :message => '0'
87
88
  }
88
89
  begin
@@ -1,3 +1,3 @@
1
1
  module Relp
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jiří Vymazal
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-18 00:00:00.000000000 Z
12
+ date: 2017-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -76,6 +76,7 @@ files:
76
76
  - lib/relp/version.rb
77
77
  - test/RELP_test.rb
78
78
  - test/test_helper.rb
79
+ - test/unit/relp_protocol_test.rb
79
80
  homepage: https://github.com/ViaQ/Relp
80
81
  licenses:
81
82
  - MIT
@@ -96,10 +97,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
97
  version: '0'
97
98
  requirements: []
98
99
  rubyforge_project:
99
- rubygems_version: 2.6.6
100
+ rubygems_version: 2.5.2
100
101
  signing_key:
101
102
  specification_version: 4
102
103
  summary: Ruby implementation of RELP (Reliable Event Logging Protocol) protocol.
103
104
  test_files:
104
- - test/test_helper.rb
105
105
  - test/RELP_test.rb
106
+ - test/unit/relp_protocol_test.rb
107
+ - test/test_helper.rb