{"action":"created","issue":{"url":"https://api.github.com/repos/manastech/crystal/issues/664","labels_url":"https://api.github.com/repos/manastech/crystal/issues/664/labels{/name}","comments_url":"https://api.github.com/repos/manastech/crystal/issues/664/comments","events_url":"https://api.github.com/repos/manastech/crystal/issues/664/events","html_url":"https://github.com/manastech/crystal/issues/664","id":77040797,"number":664,"title":"Issue with OpenSSL (when not in :client mode)","user":{"login":"bararchy","id":1631073,"avatar_url":"https://avatars.githubusercontent.com/u/1631073?v=3","gravatar_id":"","url":"https://api.github.com/users/bararchy","html_url":"https://github.com/bararchy","followers_url":"https://api.github.com/users/bararchy/followers","following_url":"https://api.github.com/users/bararchy/following{/other_user}","gists_url":"https://api.github.com/users/bararchy/gists{/gist_id}","starred_url":"https://api.github.com/users/bararchy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bararchy/subscriptions","organizations_url":"https://api.github.com/users/bararchy/orgs","repos_url":"https://api.github.com/users/bararchy/repos","events_url":"https://api.github.com/users/bararchy/events{/privacy}","received_events_url":"https://api.github.com/users/bararchy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-16T13:34:52Z","updated_at":"2015-05-16T19:14:44Z","closed_at":null,"body":"This is the code:\r\n\r\n```ruby\r\nrequire \"openssl\"\r\nrequire \"socket\"\r\n\r\nbegin\r\n  tcp_server = TCPServer.new(55555)\r\nrescue e : Exception\r\n  puts \"Error in socket: #{e}\"\r\nend\r\n\r\nif tcp_server\r\n  context = OpenSSL::SSL::Context.default\r\n  context.private_key = (\"key.pem\")\r\n  context.certificate_chain = (\"cert.pem\")\r\n  begin\r\n    ssl_server = OpenSSL::SSL::Socket.new(tcp_server, mode = :server, context)\r\n  rescue e : Exception\r\n    puts \"Error in SSL socket: #{e.message}\\r\\nlog: #{e.backtrace}\"\r\n  end\r\nend\r\n```\r\n\r\nThis is the error:\r\n\r\n```\r\nError in SSL socket: Error reading file: Transport endpoint is not connected\r\nlog: [\"*Exception@Exception#initialize<Errno, String>:Array(String) +46 [0]\", \"*Errno#initialize<Errno, String>:Array(String) +139 [0]\", \"*Errno::new<String>:Errno +100 [0]\", \"*TCPServer@FileDescriptorIO#read<TCPServer, Slice(UInt8), Int32>:Int64 +210 [0]\", \"*TCPServer@IO#read<TCPServer, Slice(UInt8)>:Int64 +60 [0]\", \"~fun_literal_7 +111 [0]\", \"BIO_read +108 [0]\", \"ssl23_read_bytes +85 [0]\", \"ssl23_get_client_hello +1210 [0]\", \"ssl23_accept +456 [0]\", \"*OpenSSL::SSL::Socket#initialize<OpenSSL::SSL::Socket, TCPServer, Symbol, OpenSSL::SSL::Context>:Int32 +210 [0]\", \"*OpenSSL::SSL::Socket::new<TCPServer, Symbol, OpenSSL::SSL::Context>:OpenSSL::SSL::Socket +110 [0]\", \"__crystal_main +2433 [0]\", \"main +32 [0]\", \"__libc_start_main +240 [0]\", \"_start +41 [0]\", \" +41 [0]\"]\r\n```"},"comment":{"url":"https://api.github.com/repos/manastech/crystal/issues/comments/102667260","html_url":"https://github.com/manastech/crystal/issues/664#issuecomment-102667260","issue_url":"https://api.github.com/repos/manastech/crystal/issues/664","id":102667260,"user":{"login":"bararchy","id":1631073,"avatar_url":"https://avatars.githubusercontent.com/u/1631073?v=3","gravatar_id":"","url":"https://api.github.com/users/bararchy","html_url":"https://github.com/bararchy","followers_url":"https://api.github.com/users/bararchy/followers","following_url":"https://api.github.com/users/bararchy/following{/other_user}","gists_url":"https://api.github.com/users/bararchy/gists{/gist_id}","starred_url":"https://api.github.com/users/bararchy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bararchy/subscriptions","organizations_url":"https://api.github.com/users/bararchy/orgs","repos_url":"https://api.github.com/users/bararchy/repos","events_url":"https://api.github.com/users/bararchy/events{/privacy}","received_events_url":"https://api.github.com/users/bararchy/received_events","type":"User","site_admin":false},"created_at":"2015-05-16T19:14:44Z","updated_at":"2015-05-16T19:14:44Z","body":"Ok, I'm now quite sure there is an issue with opensl, this should run right ? well openssl it self thinks not XD \r\n\r\n```ruby\r\nrequire \"openssl\"\r\nrequire \"socket\"\r\n\r\nbegin\r\n  tcp_server = TCPServer.new(55555)\r\nrescue e : Exception\r\n  puts \"Error in socket: #{e}\"\r\nend\r\n\r\nif tcp_server\r\n  context = OpenSSL::SSL::Context.new\r\n  context.private_key = (\"key.pem\")\r\n  context.certificate_chain = (\"cert.pem\")\r\n  begin\r\n    loop do\r\n      tcp_server.accept do |client|\r\n        puts \"In loop! accepted connection\"\r\n        ssl_server = OpenSSL::SSL::Socket.new(client, mode = :server, context)\r\n        puts \"Upgraded to SSL\"\r\n        ssl_server.finalize\r\n        puts \"Done.\"\r\n      end\r\n    end\r\n  rescue e : Exception\r\n    puts \"Error in SSL socket: #{e.message}\\r\\nlog: #{e.backtrace}\"\r\n  end\r\nend\r\n```\r\n\r\nOpenSSL s_client:\r\n\r\n\r\n```\r\nopenssl s_client -host 127.0.0.1 -port 55555\r\nCONNECTED(00000003)\r\n139842411501200:error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure:s23_clnt.c:769:\r\n---\r\nno peer certificate available\r\n---\r\nNo client certificate CA names sent\r\n---\r\nSSL handshake has read 7 bytes and written 348 bytes\r\n---\r\nNew, (NONE), Cipher is (NONE)\r\nSecure Renegotiation IS NOT supported\r\nCompression: NONE\r\nExpansion: NONE\r\nNo ALPN negotiated\r\n---\r\n\r\n```"}}