stomp 1.4.5 → 1.4.10

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.
@@ -40,6 +40,9 @@ class LoggerExample
40
40
  # //////////////////////////////////////////////////////////////////////////////
41
41
  # A hash type connect *MUST* be used to enable callback logging.
42
42
  # //////////////////////////////////////////////////////////////////////////////
43
+ # Note: running this example will generate a number of connect failures,
44
+ # because of the fake host in this connect hash.
45
+ # //////////////////////////////////////////////////////////////////////////////
43
46
  hash = { :hosts => [
44
47
  {:login => user, :passcode => password, :host => 'noonehome', :port => 2525,
45
48
  :ssl => so},
@@ -38,7 +38,7 @@ class FilePutGet
38
38
  conn = get_connection()
39
39
  puts "pgf005: Qname is: #{@qname}"
40
40
  # Try to gracefully handle files that exceed broker size limits.
41
- ph = {:presistent => true}
41
+ ph = {:persistent => true}
42
42
  ph['suppress_content_length'] = 'yes' if suppresscl()
43
43
  puts "pgf006: Headers are: #{ph.inspect}"
44
44
  begin
@@ -76,4 +76,4 @@ end
76
76
  #
77
77
  e = FilePutGet.new()
78
78
  e.doput()
79
- e.doget()
79
+ # e.doget()
@@ -0,0 +1,4 @@
1
+ #
2
+ require 'stomp'
3
+ #
4
+ puts Stomp::Version::STRING
@@ -120,7 +120,7 @@ Subcase B - When your broker _does_ require client authentication:
120
120
 
121
121
  * Expect connection failure (broker must be sent a valid client certificate).
122
122
 
123
- ### Use Case 3 - Authentification by broker, no authentification by broker
123
+ ### Use Case 3 - Authentification by broker, no authentification by client
124
124
 
125
125
  Subcase A - When your broker does _not_ require client authentication:
126
126
 
@@ -51,6 +51,30 @@ module SSLCommon
51
51
  ENV['CLI_KEY'] || pck() # The client private key File
52
52
  end
53
53
 
54
+ # Client cert file name. Change or specify.
55
+ # This is the author's default.
56
+ def cli_cert_text()
57
+ fake_cert = '------BEGIN CERTIFICATE-----
58
+ fake_cert
59
+ ------END CERTIFICATE-----'
60
+
61
+ # The client cert text is stored in environmental variable
62
+ ENV['CLI_CERT_TEXT'] || fake_cert
63
+
64
+ end
65
+
66
+ # Client private key . Change or specify.
67
+ # This is the author's default.
68
+ # This file should not be exposed to the outside world.
69
+ def cli_key_text()
70
+ fake_key = '-----BEGIN PRIVATE KEY-----
71
+ fake_key
72
+ -----END PRIVATE KEY-----'
73
+
74
+ # The client private key text is stored in environment variable
75
+ ENV['CLI_KEY_TEXT'] || fake_key
76
+ end
77
+
54
78
  # Server Data.
55
79
 
56
80
  # Server file location/directory. Change or specify.
@@ -0,0 +1,69 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ #
4
+ # Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
5
+ #
6
+ if Kernel.respond_to?(:require_relative)
7
+ require_relative("../ssl_common")
8
+ require_relative("../../stomp_common")
9
+ else
10
+ $LOAD_PATH << File.dirname(__FILE__)
11
+ require "../ssl_common"
12
+ require("../../stomp_common")
13
+ end
14
+ include SSLCommon
15
+ include Stomp1xCommon
16
+ #
17
+ # == SSL Use Case 3 - server *does* authenticate client, client does *not* authenticate server
18
+ #
19
+ # Subcase 3.A - Message broker configuration does *not* require client authentication
20
+ #
21
+ # - Expect connection success
22
+ # - Expect a verify result of 20 becuase the client did not authenticate the
23
+ # server's certificate.
24
+ #
25
+ # Subcase 3.B - Message broker configuration *does* require client authentication
26
+ #
27
+ # - Expect connection success if the server can authenticate the client certificate
28
+ # - Expect a verify result of 20 because the client did not authenticate the
29
+ # server's certificate.
30
+ #
31
+ class ExampleSSL3woFiles
32
+ # Initialize.
33
+ def initialize
34
+ # Change the following as needed.
35
+ @host = host()
36
+ # It is very likely that you will have to specify your specific port number.
37
+ # 61612 is currently my AMQ local port number for ssl client auth is required.
38
+ @port = ENV['STOMP_PORT'] ? ENV['STOMP_PORT'].to_i : 61612
39
+ end
40
+ # Run example.
41
+ def run
42
+ puts "SSLUC3 Connect host: #{@host}, port: #{@port}"
43
+
44
+ # Possibly change the cert file(s) name(s) here.
45
+ ssl_opts = Stomp::SSLParams.new(
46
+ :key_text => cli_key_text().to_s, # the client's private key, private data
47
+ :cert_text => cli_cert_text().to_s # the client's signed certificate
48
+ )
49
+ puts "SSLOPTS: #{ssl_opts.inspect}"
50
+ #
51
+ hash = { :hosts => [
52
+ {:login => login(), :passcode => passcode(), :host => @host, :port => @port, :ssl => ssl_opts},
53
+ ],
54
+ :reliable => false, # YMMV, to test this in a sane manner
55
+ }
56
+ #
57
+ puts "Connect starts, SSL Use Case 3"
58
+ c = Stomp::Connection.new(hash)
59
+ puts "Connect completed"
60
+ puts "SSL Verify Result: #{ssl_opts.verify_result}"
61
+ puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}" if showPeerCert()
62
+ c.disconnect()
63
+ end
64
+
65
+ end
66
+ #
67
+ e = ExampleSSL3woFiles.new()
68
+ e.run
69
+
@@ -0,0 +1,65 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ #
4
+ # Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
5
+ #
6
+ if Kernel.respond_to?(:require_relative)
7
+ require_relative("../ssl_common")
8
+ require_relative("../../stomp_common")
9
+ else
10
+ $LOAD_PATH << File.dirname(__FILE__)
11
+ require "../ssl_common"
12
+ require("../../stomp_common")
13
+ end
14
+ include SSLCommon
15
+ include Stomp1xCommon
16
+ #
17
+ # == SSL Use Case 3 - User Supplied Ciphers not from files
18
+ #
19
+ # If you need your own ciphers list, this is how.
20
+ # Stomp's default list will work in many cases. If you need to use this, you
21
+ # will know it because SSL connect will fail. In that case, determining
22
+ # _what_ should be in the list is your responsibility.
23
+ #
24
+ class ExampleSSLwoFiles3C
25
+ # Initialize.
26
+ def initialize # Change the following as needed.
27
+ @host = host()
28
+ # It is very likely that you will have to specify your specific port number.
29
+ # 61612 is currently my AMQ local port number for ssl client auth is required.
30
+ @port = ENV['STOMP_PORT'] ? ENV['STOMP_PORT'].to_i : 61612
31
+ end
32
+ # Run example.
33
+ def run
34
+ puts "SSLUC3C Connect host: #{@host}, port: #{@port}"
35
+ #
36
+ # SSL Use Case 3 without files
37
+ # certificate information will typically be stored in environmental variables
38
+ #
39
+ # Possibly change the cert file(s) name(s) here.
40
+ ssl_opts = Stomp::SSLParams.new(
41
+ :key_text => cli_key_text().to_s, # the client's private key, private data
42
+ :cert_text => cli_cert_text().to_s, # the client's signed certificate
43
+ :ciphers => ciphers_list() # The cipher list
44
+ )
45
+ #
46
+ puts "SSLOPTS: #{ssl_opts.inspect}"
47
+ hash = { :hosts => [
48
+ {:login => login(), :passcode => passcode(), :host => @host, :port => @port, :ssl => ssl_opts},
49
+ ],
50
+ :reliable => false, # YMMV, to test this in a sane manner
51
+ }
52
+ #
53
+ puts "Connect starts, SSL Use Case 3 without files"
54
+ c = Stomp::Connection.new(hash)
55
+ puts "Connect completed"
56
+ puts "SSL Verify Result: #{ssl_opts.verify_result}"
57
+ puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}" if showPeerCert()
58
+ c.disconnect()
59
+ end
60
+
61
+ end
62
+ #
63
+ e = ExampleSSLwoFiles3C.new()
64
+ e.run
65
+
@@ -55,6 +55,7 @@ module Stomp1xCommon
55
55
  ],
56
56
  :connect_headers => conn_hdrs,
57
57
  }
58
+ conn_hash[:stompconn] = ENV["STOMP_USESTOMP"] ? true : false
58
59
  conn = Stomp::Connection.new(conn_hash)
59
60
  end
60
61
 
@@ -175,6 +175,7 @@ module Stomp
175
175
  @replay_messages_by_txn = {}
176
176
 
177
177
  @listener_map = Hash.new do |message|
178
+ @failure = nil
178
179
  unless @connection.slog(:on_miscerr, @connection.log_params, "Received unknown frame type: '#{message.command}'\n")
179
180
  warn "Received unknown frame type: '#{message.command}'\n"
180
181
  end
@@ -164,7 +164,7 @@ module Stomp
164
164
  begin
165
165
  delta = curt - @lr
166
166
  if delta > sleeptime
167
- slog(:on_hbfire, log_params, "receive_heartbeat", {})
167
+ slog(:on_hbfire, log_params, "receive_heartbeat", {:delta => delta})
168
168
  # Client code could be off doing something else (that is, no reading of
169
169
  # the socket has been requested by the caller). Try to handle that case.
170
170
  lock = @read_semaphore.try_lock
@@ -61,14 +61,6 @@ module Stomp
61
61
  raise Stomp::Error::HandShakeDetectedError
62
62
  end
63
63
 
64
- # Check for a valid frame name from the server.
65
- frname = line.chomp
66
- p [ "_receive_frame_name_check", frname ] if drdbg
67
- unless SERVER_FRAMES[frname]
68
- sfex = Stomp::Error::ServerFrameNameError.new(frname)
69
- raise sfex
70
- end
71
-
72
64
  p [ "_receive_norm_lend", line, Time.now ] if drdbg
73
65
  line = _normalize_line_end(line) if @protocol >= Stomp::SPL_12
74
66
 
@@ -124,7 +116,7 @@ module Stomp
124
116
  #
125
117
  # Note: experiments with JRuby seem to show that socket.ready? never
126
118
  # returns true. It appears that in cases where Ruby returns true
127
- # that JRuby returns a Fixnum. We attempt to adjust for this
119
+ # that JRuby returns an Integer. We attempt to adjust for this
128
120
  # in the _is_ready? method.
129
121
  #
130
122
  # Note 2: the draining of new lines must be done _after_ a message
@@ -157,8 +149,15 @@ module Stomp
157
149
  p [ "_receive_new_message" ] if drdbg
158
150
  msg = Message.new(message_header + "\n" + message_body + "\0", @protocol >= Stomp::SPL_11)
159
151
  p [ "_receive_decode_headers", msg.command, msg.headers ] if drdbg
152
+ # Check for a valid frame name from the server.
153
+ p [ "_receive_frame_name_check", msg.command ] if drdbg
154
+ unless SERVER_FRAMES[msg.command]
155
+ sfex = Stomp::Error::ServerFrameNameError.new(msg.command)
156
+ raise sfex
157
+ end
160
158
  #
161
- if @protocol >= Stomp::SPL_11 && msg.command != Stomp::CMD_CONNECTED
159
+ # Always decode headers, even for 1.0. Issue #160.
160
+ if msg.command != Stomp::CMD_CONNECTED
162
161
  msg.headers = _decodeHeaders(msg.headers)
163
162
  end
164
163
  p [ "_receive_ends", msg.command, msg.headers ] if drdbg
@@ -172,16 +171,16 @@ module Stomp
172
171
  #
173
172
  def _is_ready?(s)
174
173
  rdy = s.ready?
175
- ### p [ "isr?", rdy ]
174
+ #p [ "isr?", rdy ]
176
175
  return rdy unless @jruby
177
- ### p [ "jrdychk", rdy.class ]
176
+ #p [ "jrdychk", rdy.class ]
178
177
  if rdy.class == NilClass
179
178
  # rdy = true
180
179
  rdy = false # A test
181
180
  else
182
- rdy = (rdy.class == Fixnum || rdy.class == TrueClass) ? true : false
181
+ rdy = (rdy.class == Integer || rdy.class == TrueClass) ? true : false
183
182
  end
184
- ### p [ "isr?_last", rdy ]
183
+ #p [ "isr?_last", rdy ]
185
184
  rdy
186
185
  end
187
186
 
@@ -229,9 +228,10 @@ module Stomp
229
228
  dtrdbg = ENV['DTRDBG'] ? true : false
230
229
  # p [ "wirewrite" ]
231
230
  # _dump_callstack()
232
-
231
+ p [ "_transmit_headers_in1", headers ] if dtrdbg
233
232
  if @protocol >= Stomp::SPL_11 && command != Stomp::CMD_CONNECT
234
233
  headers = _encodeHeaders(headers)
234
+ p [ "_transmit_headers_in2", headers ] if dtrdbg
235
235
  end
236
236
  @transmit_semaphore.synchronize do
237
237
  p [ "_transmit_lock", Thread::current() ] if dtrdbg
@@ -250,7 +250,9 @@ module Stomp
250
250
  # Lets send this header in the message, so it can maintain state when using unreceive
251
251
  headers[:'content-length'] = "#{body_length_bytes}" unless headers[:suppress_content_length]
252
252
  headers[:'content-type'] = "text/plain; charset=UTF-8" unless headers[:'content-type'] || headers[:suppress_content_type]
253
+ p [ "_transmit_command", command ] if dtrdbg
253
254
  _wire_write(used_socket,command)
255
+ p [ "_transmit_headers", headers ] if dtrdbg
254
256
  headers.each do |k,v|
255
257
  if v.is_a?(Array)
256
258
  v.each do |e|
@@ -260,8 +262,10 @@ module Stomp
260
262
  _wire_write(used_socket,"#{k}:#{v}")
261
263
  end
262
264
  end
265
+ p [ "_transmit_headers done" ] if dtrdbg
263
266
  _wire_write(used_socket,"")
264
267
  if body != ''
268
+ p [ "_transmit_body", body ] if dtrdbg
265
269
  if headers[:suppress_content_length]
266
270
  if tz = body.index("\00")
267
271
  used_socket.write body[0..tz-1]
@@ -273,7 +277,8 @@ module Stomp
273
277
  end
274
278
  end
275
279
  used_socket.write "\0"
276
- used_socket.flush if autoflush
280
+ used_socket.flush if @autoflush
281
+ # used_socket.flush
277
282
 
278
283
  if @protocol >= Stomp::SPL_11
279
284
  @ls = Time.now.to_f if @hbs
@@ -323,6 +328,7 @@ module Stomp
323
328
  # open_ssl_socket opens an SSL socket.
324
329
  def open_ssl_socket()
325
330
  require 'openssl' unless defined?(OpenSSL)
331
+ ossdbg = ENV['OSSDBG'] ? true : false
326
332
  begin # Any raised SSL exceptions
327
333
  ctx = @sslctx_newparm ? OpenSSL::SSL::SSLContext.new(@sslctx_newparm) : OpenSSL::SSL::SSLContext.new
328
334
  ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE # Assume for now
@@ -368,20 +374,66 @@ module Stomp
368
374
  end
369
375
  ctx.cert_store = truststores
370
376
  end
371
-
372
- # Client authentication parameters.
373
- # Both cert file and key file must be present or not, it can not be a mix.
374
- raise Stomp::Error::SSLClientParamsError if @ssl.cert_file.nil? && !@ssl.key_file.nil?
375
- raise Stomp::Error::SSLClientParamsError if !@ssl.cert_file.nil? && @ssl.key_file.nil?
376
- if @ssl.cert_file # Any check will do here
377
+ #
378
+ p [ "OSSL50", "old code starts" ] if ossdbg
379
+ usecert = nil
380
+ usekey = nil
381
+ # Client authentication
382
+ # If cert exists as a file, then it should not be input as text
383
+ raise Stomp::Error::SSLClientParamsError if !@ssl.cert_file.nil? &&
384
+ !@ssl.cert_text.nil?
385
+ # If cert exists as file, then key must exist, either as text or file
386
+ raise Stomp::Error::SSLClientParamsError if !@ssl.cert_file.nil? &&
387
+ @ssl.key_file.nil? && @ssl.key_text.nil?
388
+ if @ssl.cert_file
377
389
  raise Stomp::Error::SSLNoCertFileError if !File::exists?(@ssl.cert_file)
378
390
  raise Stomp::Error::SSLUnreadableCertFileError if !File::readable?(@ssl.cert_file)
379
- ctx.cert = OpenSSL::X509::Certificate.new(File.read(@ssl.cert_file))
391
+ p [ "OSSL51", "old code cert file read" ] if ossdbg
392
+ usecert = OpenSSL::X509::Certificate.new(File.read(@ssl.cert_file))
393
+ end
394
+ # If cert exists as file, then key must exist, either as text or file
395
+ raise Stomp::Error::SSLClientParamsError if !@ssl.cert_text.nil? &&
396
+ @ssl.key_file.nil? && @ssl.key_text.nil?
397
+ if @ssl.cert_text
398
+ p [ "OSSL52", "old code cert text get" ] if ossdbg
399
+ usecert = OpenSSL::X509::Certificate.new(@ssl.cert_text)
400
+ end
401
+
402
+ # If key exists as a text, then it should not be input as file
403
+ raise Stomp::Error::SSLClientParamsError if !@ssl.key_text.nil? &&
404
+ !@ssl.key_file.nil?
405
+ if @ssl.key_file
380
406
  raise Stomp::Error::SSLNoKeyFileError if !File::exists?(@ssl.key_file)
381
407
  raise Stomp::Error::SSLUnreadableKeyFileError if !File::readable?(@ssl.key_file)
382
- ctx.key = OpenSSL::PKey::RSA.new(File.read(@ssl.key_file), @ssl.key_password)
408
+ p [ "OSSL53", "old code key file read" ] if ossdbg
409
+ usekey = OpenSSL::PKey::RSA.new(File.read(@ssl.key_file), @ssl.key_password)
383
410
  end
384
411
 
412
+ if @ssl.key_text
413
+ nt = @ssl.key_text.gsub(/\t/, "")
414
+ p [ "OSSL54", "old code key text get" ] if ossdbg
415
+ usekey = OpenSSL::PKey::RSA.new(nt, @ssl.key_password)
416
+ end
417
+ #
418
+ # This style of code because: in newer Ruby versions the 'cert'
419
+ # and 'key' attributes are deprecated. It is suggested that the
420
+ # 'add_certificate' method be used instead.
421
+ #
422
+ if ctx.respond_to?(:add_certificate) # Newer Ruby version ??
423
+ p [ "OSSL55", "new code option", usecert, usekey ] if ossdbg
424
+ if !usecert.nil? && !usekey.nil?
425
+ p [ "OSSL55", "new code add_certificate" ] if ossdbg
426
+ ctx.add_certificate(usecert, usekey)
427
+ else
428
+ p [ "OSSL56", "new code SKIP add_certificate" ] if ossdbg
429
+ end
430
+ else
431
+ # Older Ruby versions
432
+ p [ "OSSL56", "old code option", usecert, usekey ] if ossdbg
433
+ ctx.cert = usecert
434
+ ctx.key = usekey
435
+ end
436
+ p [ "OSSL99", "old code ends" ] if ossdbg
385
437
  # Cipher list
386
438
  # As of this writing, there are numerous problems with supplying
387
439
  # cipher lists to jruby. So we do not attempt to do that here.
@@ -442,8 +494,8 @@ module Stomp
442
494
  ssl.close
443
495
  end
444
496
  #
445
- puts ex.backtrace
446
- $stdout.flush
497
+ puts ex.backtrace if ossdbg
498
+ $stdout.flush if ossdbg
447
499
  raise # Reraise
448
500
  end
449
501
  end
@@ -515,17 +567,17 @@ module Stomp
515
567
  if @protocol == Stomp::SPL_10 || (@protocol >= Stomp::SPL_11 && !@hbr)
516
568
  if @jruby
517
569
  # Handle JRuby specific behavior.
518
- ### p [ "ilrjr00", _is_ready?(read_socket), RUBY_VERSION ]
570
+ #p [ "ilrjr00", _is_ready?(read_socket), RUBY_VERSION ]
519
571
  if RUBY_VERSION < "2"
520
572
  while true
521
- ### p [ "ilrjr01A1", _is_ready?(read_socket) ]
573
+ #p [ "ilrjr01A1", _is_ready?(read_socket) ]
522
574
  line = _interruptible_gets(read_socket) # Data from wire
523
575
  break unless line == "\n"
524
576
  line = ''
525
577
  end
526
578
  else # RUBY_VERSION >= "2"
527
579
  while _is_ready?(read_socket)
528
- ### p [ "ilrjr01B2", _is_ready?(read_socket) ]
580
+ #p [ "ilrjr01B2", _is_ready?(read_socket) ]
529
581
  line = _interruptible_gets(read_socket) # Data from wire
530
582
  break unless line == "\n"
531
583
  line = ''