examples/ssl_uc4_ciphers.rb in stomp-1.4.1 vs examples/ssl_uc4_ciphers.rb in stomp-1.4.2
- old
+ new
@@ -1,44 +1,47 @@
# -*- encoding: utf-8 -*-
#
# Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
#
-require "rubygems"
-require "stomp"
+if Kernel.respond_to?(:require_relative)
+ require_relative("./ssl_common")
+else
+ $LOAD_PATH << File.dirname(__FILE__)
+ require "ssl_common"
+end
+include SSLCommon
#
# == SSL Use Case 4 - User Supplied Ciphers
#
# If you need your own ciphers list, this is how.
# Stomp's default list will work in many cases. If you need to use this, you
# will know it because SSL connect will fail. In that case, determining
# _what_ should be in the list is your responsibility.
#
class ExampleSSL4C
# Initialize.
- def initialize
+ def initialize # Change the following as needed.
+ @host = ENV['STOMP_HOST'] ? ENV['STOMP_HOST'] : "localhost"
+ @port = ENV['STOMP_PORT'] ? ENV['STOMP_PORT'].to_i : 61612
end
# Run example.
def run
ciphers_list = [["DHE-RSA-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["DHE-DSS-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["AES256-SHA", "TLSv1/SSLv3", 256, 256], ["EDH-RSA-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["EDH-DSS-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DHE-RSA-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["DHE-DSS-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["AES128-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-MD5", "TLSv1/SSLv3", 128, 128], ["EDH-RSA-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56], ["EDH-DSS-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56], ["DES-CBC-SHA", "TLSv1/SSLv3", 56, 56], ["EXP-EDH-RSA-DES-CBC-SHA", "TLSv1/SSLv3", 40, 56], ["EXP-EDH-DSS-DES-CBC-SHA", "TLSv1/SSLv3", 40, 56], ["EXP-DES-CBC-SHA", "TLSv1/SSLv3", 40, 56], ["EXP-RC2-CBC-MD5", "TLSv1/SSLv3", 40, 128], ["EXP-RC4-MD5", "TLSv1/SSLv3", 40, 128]]
#
# SSL Use Case 4
#
- # Change the following:
- # * location of the client's private key
- # * location of the client's signed certificate
- # * location of the server's CA signed certificate
+ # Possibly change the cert file(s) name(s) here.
ssl_opts = Stomp::SSLParams.new(
- :key_file => "/home/gmallard/sslwork/2013/client.key", # The client's private key
- :cert_file => "/home/gmallard/sslwork/2013/client.crt", # The client's signed certificate
- :ts_files => "/home/gmallard/sslwork/2013/TestCA.crt", # The CA's signed sertificate
- :fsck => true, # Check that files exist first
- :ciphers => ciphers_list
+ :key_file => "#{cli_loc()}/#{pck()}", # the client's private key, private data
+ :cert_file => "#{cli_loc()}/#{cli_cert()}", # the client's signed certificate
+ :ts_files => "#{ca_loc()}/#{ca_cert()}", # The CA's signed sertificate
+ :fsck => true # Check that files exist first
)
#
hash = { :hosts => [
- {:login => 'guest', :passcode => 'guest', :host => 'localhost', :port => 61612, :ssl => ssl_opts},
+ {:login => 'guest', :passcode => 'guest', :host => @host, :port => @port, :ssl => ssl_opts},
],
:reliable => false, # YMMV, to test this in a sane manner
}
#
puts "Connect starts, SSL Use Case 4"
@@ -46,9 +49,16 @@
puts "Connect completed"
puts "SSL Verify Result: #{ssl_opts.verify_result}"
# puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
c.disconnect
end
+
+ private
+
+ def pck()
+ "client.key"
+ end
+
end
#
e = ExampleSSL4C.new
e.run