Project

General

Profile

Feature #9830 » gost_ssl_example_with_certs.rb

Test script: connecting to GOST HTTPS with certificate auth - Envek (Andrey Novikov), 05/11/2014 08:27 PM

 
require 'openssl'
require 'socket'

OpenSSL::Engine.load
gost_engine = OpenSSL::Engine.by_id('gost')
gost_engine.set_default(0xFFFF) # It's required, but I don't know why

socket = TCPSocket.open('ssl-gost.envek.name', 443)
ssl_context = OpenSSL::SSL::SSLContext.new()
ssl_context.cert = OpenSSL::X509::Certificate.new(File.read('gost_r_34_10_2001_certificate.pem'))
ssl_context.key = OpenSSL::PKey.read(File.read('gost_r_34_10_2001_private_key.pem'))
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
ssl_socket.sync_close = true
ssl_socket.connect

request = <<-EOR
GET / HTTP/1.1
Host: ssl-gost.envek.name
Connection: close

EOR
# Don't remove blank line above!

ssl_socket.puts(request)
puts ssl_socket.read
ssl_socket.close
(5-5/6)