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

 
1
require 'openssl'
2
require 'socket'
3

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

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

    
16
request = <<-EOR
17
GET / HTTP/1.1
18
Host: ssl-gost.envek.name
19
Connection: close
20

    
21
EOR
22
# Don't remove blank line above!
23

    
24
ssl_socket.puts(request)
25
puts ssl_socket.read
26
ssl_socket.close