diff options
author | gotoyuzo <gotoyuzo@ruby-lang.org> | 2007-12-24 07:31:23 +0000 |
---|---|---|
committer | gotoyuzo <gotoyuzo@ruby-lang.org> | 2007-12-24 07:31:23 +0000 |
commit | 893b9693878bbcf6f75f34a34f4e7e6505a9f965 (patch) | |
tree | ae251481bbadb5d5916ca516f3fee9478a195455 /sample/echo_cli.rb | |
parent | ce5c01d4ad2ce0a364a429a610b33d2060cb16cc (diff) | |
download | ruby-openssl-history-893b9693878bbcf6f75f34a34f4e7e6505a9f965.tar.gz |
* sample/openssl: reviewed and remove dependency on getopts.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/echo_cli.rb')
-rw-r--r-- | sample/echo_cli.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/sample/echo_cli.rb b/sample/echo_cli.rb index 29b356a..069a21e 100644 --- a/sample/echo_cli.rb +++ b/sample/echo_cli.rb @@ -2,15 +2,15 @@ require 'socket' require 'openssl' -require 'getopts' +require 'optparse' -getopts nil, "p:2000", "c:", "k:", "C:" +options = ARGV.getopts("p:c:k:C:") host = ARGV[0] || "localhost" -port = $OPT_p -cert_file = $OPT_c -key_file = $OPT_k -ca_path = $OPT_C +port = options["p"] || "2000" +cert_file = options["c"] +key_file = options["k"] +ca_path = options["C"] ctx = OpenSSL::SSL::SSLContext.new() if cert_file && key_file @@ -27,11 +27,18 @@ end s = TCPSocket.new(host, port) ssl = OpenSSL::SSL::SSLSocket.new(s, ctx) ssl.connect # start SSL session +p ssl.peer_cert +errors = Hash.new +OpenSSL::X509.constants.grep(/^V_(ERR_|OK)/).each do |name| + errors[OpenSSL::X509.const_get(name)] = name +end +p errors[ssl.verify_result] + ssl.sync_close = true # if true the underlying socket will be # closed in SSLSocket#close. (default: false) while line = $stdin.gets ssl.write line - print ssl.gets + puts ssl.gets.inspect end ssl.close |