Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit ab9ab6aaac629de2e192488b0dad3ff7367a6e5e @thoughtless committed Mar 15, 2012
Showing with 211 additions and 0 deletions.
  1. +1 −0 certs/594f1775.0
  2. +1 −0 certs/c38dbb03.0
  3. +1 −0 certs/d9b7a851.0
  4. +21 −0 certs/google-ca.pem
  5. +17 −0 certs/google-inter.pem
  6. +19 −0 certs/google-root.pem
  7. +3 −0 coolio/Gemfile
  8. +16 −0 coolio/Gemfile.lock
  9. +48 −0 coolio/request.rb
  10. +84 −0 em/client.rb
1 certs/594f1775.0
1 certs/c38dbb03.0
1 certs/d9b7a851.0
21 certs/google-ca.pem
@@ -0,0 +1,21 @@
+-----BEGIN CERTIFICATE-----
+MIIDdzCCAuCgAwIBAgIKfg/iLAADAABLzjANBgkqhkiG9w0BAQUFADBGMQswCQYD
+VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu
+dGVybmV0IEF1dGhvcml0eTAeFw0xMjAzMDgwODQ1MjNaFw0xMzAzMDgwODU1MjNa
+MGUxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N
+b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRQwEgYDVQQDFAsqLmdv
+b2dsZS5jYTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAqWGblRmyr3iEpYBF
+8C0Btob+FjPpCrSsZmZSbQ57OHU6oEYYyNKbrvgFASKLylqa3Zvoh/g4qSyI/6b7
+p+jeOifAnUznYjHbB5CNRcyXV7YOrCJBq5OEW8r+4FsZlgH3W4ZtvRdGyFXJKJiG
+YdIokHNaVrvxXZ3/T8SUAdFGZ8MCAwEAAaOCAUswggFHMB0GA1UdJQQWMBQGCCsG
+AQUFBwMBBggrBgEFBQcDAjAdBgNVHQ4EFgQUiQq7vtL0ePyrZ4pjmWFueXPd3h8w
+HwY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1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kC
+AwEAAaOCAQkwggEFMHAGA1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQ
+MA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlm
+aWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoGA1UdEAQTMBGBDzIwMTgw
+ODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvSspXXR9gj
+IBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQF
+MAMBAf8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUA
+A4GBAFjOKer89961zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y
+7qj/WsjTVbJmcVfewCHrPSqnI0kBBIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh
+1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee9570+sB3c4
+-----END CERTIFICATE-----
3 coolio/Gemfile
@@ -0,0 +1,3 @@
+source 'http://rubygems.org'
+
+gem 'cool.io-http'
16 coolio/Gemfile.lock
@@ -0,0 +1,16 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ cool.io (1.1.0)
+ iobuffer (>= 1.0.0)
+ cool.io-http (0.3.1)
+ cool.io
+ mime-types
+ iobuffer (1.1.2)
+ mime-types (1.17.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ cool.io-http
48 coolio/request.rb
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+
+
+require 'cool.io/http'
+
+class Coolio::Http
+ def self.verify_ssl_request opts={}, &block
+
+ method = opts[:method] || opts['method'] || :get
+ url = opts[:url] || opts['url']
+ payload = opts[:payload] || opts['payload'] || {}
+ headers = opts[:headers] || opts['headers'] || {}
+ query = opts[:query] || opts['query'] || {}
+ loop = opts[:loop] || opts['loop'] || Coolio::Loop.default
+
+ uri = URI.parse(url)
+ path = if uri.path.strip.empty? then '/' else uri.path end
+ q = (uri.query || '').split('&').inject({}){ |r, i|
+ k, v = i.split('=')
+ r[k] = v
+ r}.merge(query.inject({}){ |r, (k, v)| r[k.to_s] = v.to_s; r })
+ p = Payload.generate(payload)
+
+ http = connect(uri.host, uri.port, uri.scheme.downcase == 'https').attach(loop)
+
+ http.ssl_context.set_params(
+ :verify_mode => OpenSSL::SSL::VERIFY_PEER,
+ :ca_path => File.expand_path(File.join(File.dirname(__FILE__), '..', 'certs'))
+ )
+
+ http.request(method.to_s.upcase, path, :query => q,
+ :head => p.headers.merge(headers),
+ :body => p.read, &block)
+ end
+end
+
+url = 'https://www.yahoo.com'
+#url = 'https://www.example.com'
+#url = 'https://google.com'
+#Coolio::Http.request(:url => url){ |response|
+Coolio::Http.verify_ssl_request(:url => url){ |response|
+ puts "Response: #{response.body}"
+ puts
+ puts " Headers: #{response.headers}"
+ puts " Status: #{response.status}"
+}
+
+Coolio::Loop.default.run
84 em/client.rb
@@ -0,0 +1,84 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'eventmachine'
+
+module HttpHeaders
+ def initialize
+ end
+
+ def post_init
+ send_data "GET / HTTP/1.0\n\n"
+ @data = ""
+ end
+
+ def receive_data(data)
+ @data << data
+ end
+
+ def unbind
+ puts @data
+
+ EventMachine::stop_event_loop
+ end
+end
+
+
+# @ssl_context = OpenSSL::SSL::SSLContext.new
+# @ssl_context.set_params(
+# :verify_mode => OpenSSL::SSL::VERIFY_PEER,
+# :ca_path => File.expand_path(File.join(File.dirname(__FILE__), '..', 'certs'))
+# )
+# @tcp_client = TCPSocket.new 'www.google.ca', 443
+# @ssl_client = OpenSSL::SSL::SSLSocket.new @tcp_client, @context
+
+#EventMachine::run do
+# #EventMachine::connect 'www.google.ca', 443, HttpHeaders
+# EventMachine::attach @tcp_client, HttpHeaders
+#end
+
+#@ssl_client.connect
+#
+#@ssl_client.puts "GET /\r\n\n"
+#puts @ssl_client.gets
+
+# http://www.braintreepayments.com/devblog/sslsocket-verify_mode-doesnt-verify
+
+require 'socket'
+require 'openssl'
+require 'net/protocol'
+
+def verify_ssl_certificate(preverify_ok, ssl_context)
+ if preverify_ok != true || ssl_context.error != 0
+ err_msg = "SSL Verification failed -- Preverify: #{preverify_ok}, Error: #{ssl_context.error_string} (#{ssl_context.error})"
+ raise OpenSSL::SSL::SSLError.new(err_msg)
+ end
+ true
+end
+
+socket = TCPSocket.new('google.ca', 443)
+
+ssl_context = OpenSSL::SSL::SSLContext.new
+ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
+ssl_context.verify_callback = proc do |preverify_ok, ssl_context|
+ verify_ssl_certificate(preverify_ok, ssl_context)
+end
+ssl_context.ca_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'certs'))
+
+ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
+ssl_socket.sync_close = true
+ssl_socket.connect
+
+#ssl_socket.puts("GET / HTTP/1.0")
+#ssl_socket.puts("")
+#while line = ssl_socket.gets
+# puts line
+#end
+
+buffered_io = Net::BufferedIO.new(ssl_socket)
+
+
+EventMachine::run do
+ #EventMachine::connect 'www.google.ca', 443, HttpHeaders
+ EventMachine::attach buffered_io, HttpHeaders
+end

0 comments on commit ab9ab6a

Please sign in to comment.
Something went wrong with that request. Please try again.