Project

General

Profile

Backport #5233 » openssl_write_failure.rb

A sample script showing the problem - niklasb (Niklas Baumstark), 08/26/2011 08:45 PM

 
1
#!/usr/bin/env ruby
2
# -*- coding: utf-8 -*-
3

    
4
require 'socket'
5
require 'openssl'
6

    
7
# set up SSL server
8
server = TCPServer.new("127.0.0.1", 4433)
9

    
10
key = OpenSSL::PKey::RSA.new(File.read("server.pem"))
11
cert = OpenSSL::X509::Certificate.new(File.read("server.pem"))
12
ssl_ctx = OpenSSL::SSL::SSLContext.new
13
ssl_ctx.key = key
14
ssl_ctx.cert = cert
15
server = OpenSSL::SSL::SSLServer.new(server, ssl_ctx)
16

    
17
Thread.start(server) do |server|
18
  server.listen(1)
19
  conn = server.accept
20
  str = "ä"*100000
21
  # uncomment the following line as a workaround
22
  #str.force_encoding "ascii"
23
  conn.write(str)
24
  conn.close
25
end
26

    
27
socket = TCPSocket.new("127.0.0.1", 4433)
28
ssl_ctx = OpenSSL::SSL::SSLContext.new
29
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_ctx)
30
ssl_socket.sync_close = true
31
ssl_socket.connect
32
str = ssl_socket.read
33
str.force_encoding "utf-8"
34

    
35
puts "str.size is %i (expecting 100000)" % str.size