stomp 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +10 -0
- data/README.rdoc +24 -21
- data/Rakefile +2 -2
- data/examples/slogger.rb +39 -24
- data/lib/stomp/connection.rb +98 -79
- data/lib/stomp/constants.rb +1 -1
- data/lib/stomp/errors.rb +21 -0
- data/lib/stomp/sslparams.rb +63 -44
- data/lib/stomp/version.rb +1 -1
- data/stomp.gemspec +2 -2
- data/test/test_connection.rb +1 -1
- data/test/test_helper.rb +2 -1
- data/test/test_ssl.rb +30 -9
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 1.2.2 2012-24-03
|
2
|
+
|
3
|
+
* Major performance improvement for read of messages without content-length header
|
4
|
+
* Correct Stomp 1.1 failing test
|
5
|
+
* Update sample code to reflect removal of 'send'
|
6
|
+
* Add on_ssl_connectfail callback and allow clients to signal quit from the callback
|
7
|
+
* Ensure that SSL certificates and SSL related files exist and are readable
|
8
|
+
* Allow SSL file checks before connect using SSLParams.new(:fsck => true, ...)
|
9
|
+
* Correct a test for Windows compatibility
|
10
|
+
|
1
11
|
== 1.2.1 2012-13-03
|
2
12
|
|
3
13
|
* Robust SSL certificate support. See examples and: https://github.com/morellon/stomp/wiki/extended-ssl-overview
|
data/README.rdoc
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
==README
|
2
2
|
|
3
|
-
* (http://gitorious.org/projects/stomp/)
|
4
3
|
* (https://github.com/morellon/stomp/)
|
5
|
-
* (http://
|
4
|
+
* (http://gitorious.org/projects/stomp/)
|
6
5
|
|
7
6
|
===Overview
|
8
7
|
|
@@ -12,13 +11,17 @@ An implementation of the Stomp protocol for Ruby. See:
|
|
12
11
|
|
13
12
|
===New
|
14
13
|
|
15
|
-
|
14
|
+
* Gem version 1.2.2. Performance and more SSL enhancements.
|
15
|
+
* Full support of SSL certificates is announced as of gem version 1.2.1.
|
16
|
+
* Support of Stomp protocol level 1.1 is announced as of gem version 1.2.0.
|
17
|
+
|
18
|
+
See the change log for details.
|
16
19
|
|
17
20
|
===Example Usage
|
18
21
|
|
19
22
|
client = Stomp::Client.new("test", "user", "localhost", 61613)
|
20
|
-
client.send("/
|
21
|
-
client.subscribe("/
|
23
|
+
client.send("/queue/mine", "hello world!")
|
24
|
+
client.subscribe("/queue/mine") do |msg|
|
22
25
|
p msg
|
23
26
|
end
|
24
27
|
|
@@ -26,11 +29,11 @@ Support of Stomp protocol level 1.1 is announced as of gem version 1.2.0.
|
|
26
29
|
|
27
30
|
options = "initialReconnectDelay=5000&randomize=false&useExponentialBackOff=false"
|
28
31
|
|
29
|
-
#remotehost1 uses SSL, remotehost2 doesn't
|
32
|
+
# remotehost1 uses SSL, remotehost2 doesn't
|
30
33
|
client = Stomp::Client.new("failover:(stomp+ssl://login1:passcode1@remotehost1:61612,stomp://login2:passcode2@remotehost2:61613)?#{options}")
|
31
34
|
|
32
|
-
client.
|
33
|
-
client.subscribe("/
|
35
|
+
client.publish("/queue/mine", "hello world!")
|
36
|
+
client.subscribe("/queue/mine") do |msg|
|
34
37
|
p msg
|
35
38
|
end
|
36
39
|
|
@@ -63,26 +66,16 @@ Support of Stomp protocol level 1.1 is announced as of gem version 1.2.0.
|
|
63
66
|
connection = Stomp::Connection.new(hash)
|
64
67
|
|
65
68
|
|
66
|
-
===
|
69
|
+
===Hstorical Information
|
67
70
|
|
68
71
|
Up until March 2009 the project was maintained and primarily developed by Brian McCallister.
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
===Source Code
|
73
|
+
===Source Code and Project URLs
|
73
74
|
|
74
75
|
https://github.com/morellon/stomp/
|
75
76
|
http://gitorious.org/projects/stomp/
|
76
|
-
http://github.com/js/stomp/
|
77
|
-
|
78
|
-
===Project urls
|
79
|
-
|
80
|
-
Project Home :
|
81
|
-
|
82
|
-
http://gitorious.org/projects/stomp/
|
83
|
-
http://rubyforge.org/projects/stomp/
|
84
77
|
|
85
|
-
Stomp Protocol
|
78
|
+
===Stomp Protocol Information :
|
86
79
|
|
87
80
|
http://stomp.github.com/index.html
|
88
81
|
|
@@ -110,6 +103,16 @@ The following people have contributed to Stomp:
|
|
110
103
|
* Chris Needham
|
111
104
|
* R.I. Pienaar
|
112
105
|
* tworker
|
106
|
+
* James Pearson
|
107
|
+
|
108
|
+
= Announcements
|
109
|
+
|
110
|
+
In the next version of the gem, the dates in CHANGELOG.rdoc will be changed from:
|
111
|
+
|
112
|
+
* yyyy-dd-mm
|
113
|
+
|
114
|
+
to:
|
113
115
|
|
116
|
+
* ISO8601 format (yyyymmdd)
|
114
117
|
|
115
118
|
|
data/Rakefile
CHANGED
@@ -61,8 +61,8 @@ Rake::RDocTask.new do |rdoc|
|
|
61
61
|
rdoc.rdoc_dir = "doc"
|
62
62
|
rdoc.title = "Stomp"
|
63
63
|
rdoc.options += %w[ --line-numbers --inline-source --charset utf-8 ]
|
64
|
-
rdoc.rdoc_files.include("README.rdoc", "CHANGELOG.rdoc"
|
65
|
-
|
64
|
+
rdoc.rdoc_files.include("README.rdoc", "CHANGELOG.rdoc", "lib/**/*.rb", "examples/**/*.rb",
|
65
|
+
"test/**/*.rb")
|
66
66
|
end
|
67
67
|
|
68
68
|
Rake::TestTask.new do |t|
|
data/examples/slogger.rb
CHANGED
@@ -17,12 +17,27 @@ Optional callback methods:
|
|
17
17
|
on_subscribe: subscribe called
|
18
18
|
on_receive: receive called and successful
|
19
19
|
|
20
|
+
on_ssl_connecting: SSL connection starting
|
21
|
+
on_ssl_connected: successful SSL connect
|
22
|
+
on_ssl_connectfail: unsuccessful SSL connect (will usually be retried)
|
23
|
+
|
24
|
+
on_hbread_fail: unsuccessful Heartbeat read
|
25
|
+
on_hbwrite_fail: unsuccessful Heartbeat write
|
26
|
+
|
20
27
|
All methods are optional, at the user's requirements.
|
21
28
|
|
22
29
|
If a method is not provided, it is not called (of course.)
|
23
30
|
|
24
|
-
IMPORTANT NOTE: call back logging methods *
|
25
|
-
otherwise the underlying STOMP connection
|
31
|
+
IMPORTANT NOTE: in general, call back logging methods *SHOULD* not raise exceptions,
|
32
|
+
otherwise the underlying STOMP connection may fail in mysterious ways.
|
33
|
+
|
34
|
+
There are two useful exceptions to this rule for:
|
35
|
+
|
36
|
+
on_connectfail
|
37
|
+
on_ssl_connectfail
|
38
|
+
|
39
|
+
These two methods can raise a Stomp::Errors::LoggerConnectionError. If this
|
40
|
+
exception is raised, it is passed up the chain to the caller.
|
26
41
|
|
27
42
|
Callback parameters: are a copy of the @parameters instance variable for
|
28
43
|
the Stomp::Connection.
|
@@ -64,6 +79,11 @@ class Slogger
|
|
64
79
|
rescue
|
65
80
|
@log.debug "Connect Fail oops"
|
66
81
|
end
|
82
|
+
=begin
|
83
|
+
# An example LoggerConnectionError raise
|
84
|
+
@log.debug "Connect Fail, will raise"
|
85
|
+
raise Stomp::Error::LoggerConnectionError.new("quit from connect")
|
86
|
+
=end
|
67
87
|
end
|
68
88
|
|
69
89
|
# Log disconnect events
|
@@ -136,28 +156,6 @@ class Slogger
|
|
136
156
|
end
|
137
157
|
end
|
138
158
|
|
139
|
-
|
140
|
-
# Stomp 1.1+ - heart beat read (receive) failed
|
141
|
-
def on_hbread_fail(parms, ticker_data)
|
142
|
-
begin
|
143
|
-
@log.debug "Hbreadf Parms #{info(parms)}"
|
144
|
-
@log.debug "Hbreadf Result #{ticker_data}"
|
145
|
-
rescue
|
146
|
-
@log.debug "Hbreadf oops"
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
# Stomp 1.1+ - heart beat thread fires
|
151
|
-
def on_hbfire(parms, type, time)
|
152
|
-
begin
|
153
|
-
@log.debug "HBfire #{type} " + "=" * 30
|
154
|
-
@log.debug "HBfire #{type} Parms #{info(parms)}"
|
155
|
-
@log.debug "HBfire #{type} Time #{time}"
|
156
|
-
rescue
|
157
|
-
@log.debug "HBfire #{type} oops"
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
159
|
def on_ssl_connecting(parms)
|
162
160
|
begin
|
163
161
|
@log.debug "SSL Connecting Parms #{info(parms)}"
|
@@ -174,6 +172,20 @@ class Slogger
|
|
174
172
|
end
|
175
173
|
end
|
176
174
|
|
175
|
+
def on_ssl_connectfail(parms)
|
176
|
+
begin
|
177
|
+
@log.debug "SSL Connect Fail Parms #{info(parms)}"
|
178
|
+
@log.debug "SSL Connect Fail Excception #{parms[:ssl_exception]}, #{parms[:ssl_exception].message}"
|
179
|
+
rescue
|
180
|
+
@log.debug "SSL Connect Fail oops"
|
181
|
+
end
|
182
|
+
=begin
|
183
|
+
# An example LoggerConnectionError raise
|
184
|
+
@log.debug "SSL Connect Fail, will raise"
|
185
|
+
raise Stomp::Error::LoggerConnectionError.new("quit from SSL connect")
|
186
|
+
=end
|
187
|
+
end
|
188
|
+
|
177
189
|
private
|
178
190
|
|
179
191
|
def info(parms)
|
@@ -188,6 +200,9 @@ class Slogger
|
|
188
200
|
# parms[:cur_parseto]
|
189
201
|
# parms[:cur_conattempts]
|
190
202
|
#
|
203
|
+
# For the on_ssl_connectfail callback these are also available:
|
204
|
+
# parms[:ssl_exception]
|
205
|
+
#
|
191
206
|
"Host: #{parms[:cur_host]}, Port: #{parms[:cur_port]}, Login: Port: #{parms[:cur_login]}, Passcode: #{parms[:cur_passcode]}, ssl: #{parms[:cur_ssl]}"
|
192
207
|
end
|
193
208
|
end # of class
|
data/lib/stomp/connection.rb
CHANGED
@@ -141,8 +141,14 @@ module Stomp
|
|
141
141
|
@failure = $!
|
142
142
|
used_socket = nil
|
143
143
|
raise unless @reliable
|
144
|
+
raise if @failure.is_a?(Stomp::Error::LoggerConnectionError)
|
144
145
|
if @logger && @logger.respond_to?(:on_connectfail)
|
145
|
-
|
146
|
+
# on_connectfail may raise
|
147
|
+
begin
|
148
|
+
@logger.on_connectfail(log_params)
|
149
|
+
rescue Exception => aex
|
150
|
+
raise if aex.is_a?(Stomp::Error::LoggerConnectionError)
|
151
|
+
end
|
146
152
|
else
|
147
153
|
$stderr.print "connect to #{@host} failed: #{$!} will retry(##{@connection_attempts}) in #{@reconnect_delay}\n"
|
148
154
|
end
|
@@ -500,14 +506,14 @@ module Stomp
|
|
500
506
|
content_length = message_header.match /content-length\s?:\s?(\d+)\s?\n/
|
501
507
|
message_body = ''
|
502
508
|
|
503
|
-
# If
|
504
|
-
char = ''
|
509
|
+
# If content_length is present, read the specified amount of bytes
|
505
510
|
if content_length
|
506
511
|
message_body = read_socket.read content_length[1].to_i
|
507
512
|
raise Stomp::Error::InvalidMessageLength unless parse_char(read_socket.getc) == "\0"
|
508
|
-
# Else
|
513
|
+
# Else read the rest of the message until the first \0
|
509
514
|
else
|
510
|
-
message_body
|
515
|
+
message_body = read_socket.readline("\0")
|
516
|
+
message_body.chop!
|
511
517
|
end
|
512
518
|
|
513
519
|
# If the buffer isn't empty, reads trailing new lines.
|
@@ -629,93 +635,106 @@ module Stomp
|
|
629
635
|
|
630
636
|
def open_ssl_socket
|
631
637
|
require 'openssl' unless defined?(OpenSSL)
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
# If connecting with an SSLParams instance, and the _default_ Ruby
|
643
|
-
# ciphers list is required, use:
|
644
|
-
# * :ssl => Stomp::SSLParams.new(..., :use_ruby_ciphers => true)
|
645
|
-
#
|
646
|
-
# If a custom ciphers list is required, connect with:
|
647
|
-
# * :ssl => Stomp::SSLParams.new(..., :ciphers => custom_ciphers_list)
|
648
|
-
#
|
649
|
-
if @ssl != true
|
638
|
+
begin # Any raised SSL exceptions
|
639
|
+
ctx = OpenSSL::SSL::SSLContext.new
|
640
|
+
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE # Assume for now
|
641
|
+
#
|
642
|
+
# Note: if a client uses :ssl => true this results in the gem using
|
643
|
+
# the _default_ Ruby ciphers list. This is _known_ to fail in later
|
644
|
+
# Ruby releases. The gem provides a default cipher list that may
|
645
|
+
# function in these cases. To use this connect with:
|
646
|
+
# * :ssl => Stomp::SSLParams.new
|
647
|
+
# * :ssl => Stomp::SSLParams.new(..., :ciphers => Stomp::DEFAULT_CIPHERS)
|
650
648
|
#
|
651
|
-
#
|
652
|
-
#
|
653
|
-
#
|
649
|
+
# If connecting with an SSLParams instance, and the _default_ Ruby
|
650
|
+
# ciphers list is required, use:
|
651
|
+
# * :ssl => Stomp::SSLParams.new(..., :use_ruby_ciphers => true)
|
654
652
|
#
|
653
|
+
# If a custom ciphers list is required, connect with:
|
654
|
+
# * :ssl => Stomp::SSLParams.new(..., :ciphers => custom_ciphers_list)
|
655
|
+
#
|
656
|
+
if @ssl != true
|
657
|
+
#
|
658
|
+
# Here @ssl is:
|
659
|
+
# * an instance of Stomp::SSLParams
|
660
|
+
# Control would not be here if @ssl == false or @ssl.nil?.
|
661
|
+
#
|
662
|
+
|
663
|
+
# Back reference the SSLContext
|
664
|
+
@ssl.ctx = ctx
|
665
|
+
|
666
|
+
# Server authentication parameters if required
|
667
|
+
if @ssl.ts_files
|
668
|
+
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
669
|
+
truststores = OpenSSL::X509::Store.new
|
670
|
+
fl = @ssl.ts_files.split(",")
|
671
|
+
fl.each do |fn|
|
672
|
+
# Add next cert file listed
|
673
|
+
raise Stomp::Error::SSLNoTruststoreFileError if !File::exists?(fn)
|
674
|
+
raise Stomp::Error::SSLUnreadableTruststoreFileError if !File::readable?(fn)
|
675
|
+
truststores.add_file(fn)
|
676
|
+
end
|
677
|
+
ctx.cert_store = truststores
|
678
|
+
end
|
655
679
|
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
680
|
+
# Client authentication parameters
|
681
|
+
# Both cert file and key file must be present or not, it can not be a mix
|
682
|
+
raise Stomp::Error::SSLClientParamsError if @ssl.cert_file.nil? && !@ssl.key_file.nil?
|
683
|
+
raise Stomp::Error::SSLClientParamsError if !@ssl.cert_file.nil? && @ssl.key_file.nil?
|
684
|
+
if @ssl.cert_file # Any check will do here
|
685
|
+
raise Stomp::Error::SSLNoCertFileError if !File::exists?(@ssl.cert_file)
|
686
|
+
raise Stomp::Error::SSLUnreadableCertFileError if !File::readable?(@ssl.cert_file)
|
687
|
+
ctx.cert = OpenSSL::X509::Certificate.new(File.open(@ssl.cert_file))
|
688
|
+
raise Stomp::Error::SSLNoKeyFileError if !File::exists?(@ssl.key_file)
|
689
|
+
raise Stomp::Error::SSLUnreadableKeyFileError if !File::readable?(@ssl.key_file)
|
690
|
+
ctx.key = OpenSSL::PKey::RSA.new(File.open(@ssl.key_file))
|
691
|
+
end
|
692
|
+
|
693
|
+
# Cipher list
|
694
|
+
if !@ssl.use_ruby_ciphers # No Ruby ciphers (the default)
|
695
|
+
if @ssl.ciphers # User ciphers list?
|
696
|
+
ctx.ciphers = @ssl.ciphers # Accept user supplied ciphers
|
697
|
+
else
|
698
|
+
ctx.ciphers = Stomp::DEFAULT_CIPHERS # Just use Stomp defaults
|
699
|
+
end
|
668
700
|
end
|
669
|
-
ctx.cert_store = truststores
|
670
701
|
end
|
671
702
|
|
672
|
-
#
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
if @ssl.cert_file # Any check will do here
|
677
|
-
raise Stomp::Error::SSLNoCertFileError if !File::exists?(@ssl.cert_file)
|
678
|
-
ctx.cert = OpenSSL::X509::Certificate.new(File.open(@ssl.cert_file))
|
679
|
-
raise Stomp::Error::SSLNoKeyFileError if !File::exists?(@ssl.key_file)
|
680
|
-
ctx.key = OpenSSL::PKey::RSA.new(File.open(@ssl.key_file))
|
703
|
+
#
|
704
|
+
ssl = nil
|
705
|
+
if @logger && @logger.respond_to?(:on_ssl_connecting)
|
706
|
+
@logger.on_ssl_connecting(log_params)
|
681
707
|
end
|
682
708
|
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
709
|
+
Timeout::timeout(@connect_timeout, Stomp::Error::SocketOpenTimeout) do
|
710
|
+
ssl = OpenSSL::SSL::SSLSocket.new(open_tcp_socket, ctx)
|
711
|
+
end
|
712
|
+
def ssl.ready?
|
713
|
+
! @rbuffer.empty? || @io.ready?
|
714
|
+
end
|
715
|
+
ssl.connect
|
716
|
+
if @ssl != true
|
717
|
+
# Pass back results if possible
|
718
|
+
if RUBY_VERSION =~ /1\.8\.[56]/
|
719
|
+
@ssl.verify_result = "N/A for Ruby #{RUBY_VERSION}"
|
687
720
|
else
|
688
|
-
|
721
|
+
@ssl.verify_result = ssl.verify_result
|
689
722
|
end
|
723
|
+
@ssl.peer_cert = ssl.peer_cert
|
690
724
|
end
|
691
|
-
|
692
|
-
|
693
|
-
#
|
694
|
-
ssl = nil
|
695
|
-
if @logger && @logger.respond_to?(:on_ssl_connecting)
|
696
|
-
@logger.on_ssl_connecting(log_params)
|
697
|
-
end
|
698
|
-
|
699
|
-
Timeout::timeout(@connect_timeout, Stomp::Error::SocketOpenTimeout) do
|
700
|
-
ssl = OpenSSL::SSL::SSLSocket.new(open_tcp_socket, ctx)
|
701
|
-
end
|
702
|
-
def ssl.ready?
|
703
|
-
! @rbuffer.empty? || @io.ready?
|
704
|
-
end
|
705
|
-
ssl.connect
|
706
|
-
if @ssl != true
|
707
|
-
# Pass back results if possible
|
708
|
-
if RUBY_VERSION =~ /1\.8\.[56]/
|
709
|
-
@ssl.verify_result = "N/A for Ruby #{RUBY_VERSION}"
|
710
|
-
else
|
711
|
-
@ssl.verify_result = ssl.verify_result
|
725
|
+
if @logger && @logger.respond_to?(:on_ssl_connected)
|
726
|
+
@logger.on_ssl_connected(log_params)
|
712
727
|
end
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
728
|
+
ssl
|
729
|
+
rescue Exception => ex
|
730
|
+
if @logger && @logger.respond_to?(:on_ssl_connectfail)
|
731
|
+
lp = log_params.clone
|
732
|
+
lp[:ssl_exception] = ex
|
733
|
+
@logger.on_ssl_connectfail(lp)
|
734
|
+
end
|
735
|
+
#
|
736
|
+
raise # Reraise
|
717
737
|
end
|
718
|
-
ssl
|
719
738
|
end
|
720
739
|
|
721
740
|
def close_socket
|
data/lib/stomp/constants.rb
CHANGED
data/lib/stomp/errors.rb
CHANGED
@@ -104,18 +104,39 @@ module Stomp
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
+
class SSLUnreadableKeyFileError < RuntimeError
|
108
|
+
def message
|
109
|
+
"client key file can not be read"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
107
113
|
class SSLNoCertFileError < RuntimeError
|
108
114
|
def message
|
109
115
|
"client cert file does not exist"
|
110
116
|
end
|
111
117
|
end
|
112
118
|
|
119
|
+
class SSLUnreadableCertFileError < RuntimeError
|
120
|
+
def message
|
121
|
+
"client cert file can not be read"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
113
125
|
class SSLNoTruststoreFileError < RuntimeError
|
114
126
|
def message
|
115
127
|
"a client truststore file does not exist"
|
116
128
|
end
|
117
129
|
end
|
118
130
|
|
131
|
+
class SSLUnreadableTruststoreFileError < RuntimeError
|
132
|
+
def message
|
133
|
+
"a client truststore file can not be read"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
class LoggerConnectionError < RuntimeError
|
138
|
+
end
|
139
|
+
|
119
140
|
end # module Error
|
120
141
|
end # module Stomp
|
121
142
|
|
data/lib/stomp/sslparams.rb
CHANGED
@@ -1,50 +1,69 @@
|
|
1
|
-
#
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
module
|
4
|
-
#
|
5
|
-
# == Purpose
|
6
|
-
#
|
7
|
-
# Parameters for STOMP ssl connections.
|
8
|
-
#
|
9
|
-
class SSLParams
|
10
|
-
# The trust store files. Normally the certificate of the CA that signed
|
11
|
-
# the server's certificate. One file name, or a CSV list of file names.
|
12
|
-
attr_accessor :ts_files
|
13
|
-
# The client certificate file.
|
14
|
-
attr_accessor :cert_file
|
15
|
-
# The client private key file.
|
16
|
-
attr_accessor :key_file
|
17
|
-
# SSL Connect Verify Result. The result of the handshake.
|
18
|
-
attr_accessor :verify_result
|
19
|
-
# The certificate of the connection peer (the server), received during
|
20
|
-
# the handshake.
|
21
|
-
attr_accessor :peer_cert
|
22
|
-
# Optional list of SSL ciphers to be used. In the format documented for
|
23
|
-
# Ruby's OpenSSL.
|
24
|
-
attr_accessor :ciphers
|
25
|
-
# Abcolute command to use Ruby default ciphers
|
26
|
-
attr_reader :use_ruby_ciphers
|
27
|
-
# Back reference to the OpenSSL::SSL::SSLContext instance, gem sets before connect
|
28
|
-
attr_accessor :ctx # Set by the gem during connect, before the callbacks
|
3
|
+
module Stomp
|
29
4
|
#
|
30
|
-
|
5
|
+
# == Purpose
|
6
|
+
#
|
7
|
+
# Parameters for STOMP ssl connections.
|
8
|
+
#
|
9
|
+
class SSLParams
|
10
|
+
# The trust store files. Normally the certificate of the CA that signed
|
11
|
+
# the server's certificate. One file name, or a CSV list of file names.
|
12
|
+
attr_accessor :ts_files
|
13
|
+
# The client certificate file.
|
14
|
+
attr_accessor :cert_file
|
15
|
+
# The client private key file.
|
16
|
+
attr_accessor :key_file
|
17
|
+
# SSL Connect Verify Result. The result of the handshake.
|
18
|
+
attr_accessor :verify_result
|
19
|
+
# The certificate of the connection peer (the server), received during
|
20
|
+
# the handshake.
|
21
|
+
attr_accessor :peer_cert
|
22
|
+
# Optional list of SSL ciphers to be used. In the format documented for
|
23
|
+
# Ruby's OpenSSL.
|
24
|
+
attr_accessor :ciphers
|
25
|
+
# Abcolute command to use Ruby default ciphers
|
26
|
+
attr_reader :use_ruby_ciphers
|
27
|
+
# Back reference to the OpenSSL::SSL::SSLContext instance, gem sets before connect
|
28
|
+
attr_accessor :ctx # Set by the gem during connect, before the callbacks
|
29
|
+
# Client wants file existance check now. true/value or false/nil
|
30
|
+
attr_reader :fsck #
|
31
|
+
#
|
32
|
+
def initialize(opts={})
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
# Server authentication parameters
|
35
|
+
@ts_files = opts[:ts_files] # A trust store file, normally a CA's cert
|
36
|
+
# or a CSV list of cert file names
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
38
|
+
# Client authentication parameters
|
39
|
+
@cert_file = opts[:cert_file] # Client cert
|
40
|
+
@key_file = opts[:key_file] # Client key
|
41
|
+
#
|
42
|
+
raise Stomp::Error::SSLClientParamsError if @cert_file.nil? && !@key_file.nil?
|
43
|
+
raise Stomp::Error::SSLClientParamsError if !@cert_file.nil? && @key_file.nil?
|
44
|
+
#
|
45
|
+
@ciphers = opts[:ciphers]
|
46
|
+
@use_ruby_ciphers = opts[:use_ruby_ciphers] ? opts[:use_ruby_ciphers] : false
|
47
|
+
#
|
48
|
+
if opts[:fsck]
|
49
|
+
if @cert_file
|
50
|
+
raise Stomp::Error::SSLNoCertFileError if !File::exists?(@cert_file)
|
51
|
+
raise Stomp::Error::SSLUnreadableCertFileError if !File::readable?(@cert_file)
|
52
|
+
end
|
53
|
+
if @key_file
|
54
|
+
raise Stomp::Error::SSLNoKeyFileError if !File::exists?(@key_file)
|
55
|
+
raise Stomp::Error::SSLUnreadableKeyFileError if !File::readable?(@key_file)
|
56
|
+
end
|
57
|
+
if @ts_files
|
58
|
+
tsa = @ts_files.split(",")
|
59
|
+
tsa.each do |fn|
|
60
|
+
raise Stomp::Error::SSLNoTruststoreFileError if !File::exists?(fn)
|
61
|
+
raise Stomp::Error::SSLUnreadableTruststoreFileError if !File::readable?(fn)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end # of class SSLParams
|
48
67
|
|
49
|
-
end
|
68
|
+
end # of module Stomp
|
50
69
|
|
data/lib/stomp/version.rb
CHANGED
data/stomp.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{stomp}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian McCallister", "Marius Mathiesen", "Thiago Morello", "Guy M. Allard"]
|
12
|
-
s.date = %q{2012-03-
|
12
|
+
s.date = %q{2012-03-24}
|
13
13
|
s.description = %q{Ruby client for the Stomp messaging protocol. Note that this gem is no longer supported on rubyforge.}
|
14
14
|
s.email = ["brianm@apache.org", "marius@stones.com", "morellon@gmail.com", "allard.guy.m@gmail.com"]
|
15
15
|
s.executables = ["catstomp", "stompcat"]
|
data/test/test_connection.rb
CHANGED
@@ -23,7 +23,7 @@ class TestConnection < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_poll_async
|
26
|
-
@conn.subscribe("/queue/do.not.put.messages.on.this.queue")
|
26
|
+
@conn.subscribe("/queue/do.not.put.messages.on.this.queue", :id => "a.no.messages.queue")
|
27
27
|
# If the test 'hangs' here, Connection#poll is broken.
|
28
28
|
m = @conn.poll
|
29
29
|
assert m.nil?
|
data/test/test_helper.rb
CHANGED
@@ -56,8 +56,9 @@ module TestBase
|
|
56
56
|
|
57
57
|
def get_ssl_connection()
|
58
58
|
ch = get_conn_headers()
|
59
|
+
ssl_params = Stomp::SSLParams.new # S/B safe for all Ruby versions tested
|
59
60
|
hash = { :hosts => [
|
60
|
-
{:login => user, :passcode => passcode, :host => host, :port => ssl_port, :ssl =>
|
61
|
+
{:login => user, :passcode => passcode, :host => host, :port => ssl_port, :ssl => ssl_params},
|
61
62
|
],
|
62
63
|
:connect_headers => ch
|
63
64
|
}
|
data/test/test_ssl.rb
CHANGED
@@ -12,7 +12,7 @@ class TestSSL < Test::Unit::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def teardown
|
15
|
-
@conn.disconnect if @conn.open? # allow tests to disconnect
|
15
|
+
@conn.disconnect if @conn && @conn.open? # allow tests to disconnect
|
16
16
|
end
|
17
17
|
#
|
18
18
|
def test_ssl_0000
|
@@ -20,29 +20,50 @@ class TestSSL < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
#
|
23
|
-
def
|
23
|
+
def test_ssl_0010_parms
|
24
24
|
ssl_params = Stomp::SSLParams.new
|
25
25
|
assert ssl_params.ts_files.nil?
|
26
26
|
assert ssl_params.cert_file.nil?
|
27
27
|
assert ssl_params.key_file.nil?
|
28
|
+
assert ssl_params.fsck.nil?
|
28
29
|
end
|
29
30
|
|
30
31
|
#
|
31
|
-
def
|
32
|
+
def test_ssl_0020_noraise
|
33
|
+
assert_nothing_raised {
|
34
|
+
ssl_parms = Stomp::SSLParams.new(:cert_file => "dummy1", :key_file => "dummy2")
|
35
|
+
}
|
36
|
+
assert_nothing_raised {
|
37
|
+
ssl_parms = Stomp::SSLParams.new(:ts_files => "dummyts1")
|
38
|
+
}
|
39
|
+
assert_nothing_raised {
|
40
|
+
ssl_parms = Stomp::SSLParams.new(:ts_files => "dummyts1",
|
41
|
+
:cert_file => "dummy1", :key_file => "dummy2")
|
42
|
+
}
|
43
|
+
end
|
44
|
+
#
|
45
|
+
def test_ssl_0030_raise
|
32
46
|
assert_raise(Stomp::Error::SSLClientParamsError) {
|
33
47
|
ssl_parms = Stomp::SSLParams.new(:cert_file => "dummy1")
|
34
48
|
}
|
35
49
|
assert_raise(Stomp::Error::SSLClientParamsError) {
|
36
50
|
ssl_parms = Stomp::SSLParams.new(:key_file => "dummy2")
|
37
51
|
}
|
38
|
-
|
39
|
-
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
def test_ssl_0040_fsck
|
56
|
+
assert_raise(Stomp::Error::SSLNoCertFileError) {
|
57
|
+
ssl_parms = Stomp::SSLParams.new(:cert_file => "dummy1",
|
58
|
+
:key_file => "dummy2", :fsck => true)
|
40
59
|
}
|
41
|
-
|
42
|
-
ssl_parms = Stomp::SSLParams.new(:
|
60
|
+
assert_raise(Stomp::Error::SSLNoKeyFileError) {
|
61
|
+
ssl_parms = Stomp::SSLParams.new(:cert_file => __FILE__,
|
62
|
+
:key_file => "dummy2", :fsck => true)
|
43
63
|
}
|
44
|
-
|
45
|
-
ssl_parms = Stomp::SSLParams.new(:ts_files => "
|
64
|
+
assert_raise(Stomp::Error::SSLNoTruststoreFileError) {
|
65
|
+
ssl_parms = Stomp::SSLParams.new(:ts_files => "/tmp/not-likely-here.txt",
|
66
|
+
:fsck => true)
|
46
67
|
}
|
47
68
|
end
|
48
69
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stomp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 2
|
10
|
+
version: 1.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian McCallister
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2012-03-
|
21
|
+
date: 2012-03-24 00:00:00 -04:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|