{"action":"created","issue":{"url":"https://api.github.com/repos/gevent/gevent/issues/584","labels_url":"https://api.github.com/repos/gevent/gevent/issues/584/labels{/name}","comments_url":"https://api.github.com/repos/gevent/gevent/issues/584/comments","events_url":"https://api.github.com/repos/gevent/gevent/issues/584/events","html_url":"https://github.com/gevent/gevent/issues/584","id":90081924,"number":584,"title":"tcp ssl hung on connect using 2.7.9","user":{"login":"SuiperLolo","id":12999515,"avatar_url":"https://avatars.githubusercontent.com/u/12999515?v=3","gravatar_id":"","url":"https://api.github.com/users/SuiperLolo","html_url":"https://github.com/SuiperLolo","followers_url":"https://api.github.com/users/SuiperLolo/followers","following_url":"https://api.github.com/users/SuiperLolo/following{/other_user}","gists_url":"https://api.github.com/users/SuiperLolo/gists{/gist_id}","starred_url":"https://api.github.com/users/SuiperLolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SuiperLolo/subscriptions","organizations_url":"https://api.github.com/users/SuiperLolo/orgs","repos_url":"https://api.github.com/users/SuiperLolo/repos","events_url":"https://api.github.com/users/SuiperLolo/events{/privacy}","received_events_url":"https://api.github.com/users/SuiperLolo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-22T12:11:45Z","updated_at":"2015-06-23T22:11:32Z","closed_at":null,"body":"Hello,\r\n\r\nusing gevent 1.0.2 :\r\n\r\n- on python 2.7.6, this code is working.\r\n- on python 2.7.9, this is not working, got a ssl handshake that never exit at client side + on_connect never called at server side.\r\n=> python2.7/site-packages/gevent/_sslgte279.py\", line 511, in do_handshake\r\n    return self._sslobj.do_handshake()\r\n\r\nnote : you need server.crt & server.key files.\r\n\r\nThanks for feedback.\r\n\r\n********************\r\n*** 2.7.6 code\r\n********************\r\n```\r\n\r\nfrom __future__ import print_function\r\nfrom gevent import pywsgi\r\nimport gevent\r\n\r\nfrom gevent import monkey\r\nfrom gevent._ssl2 import SSLSocket\r\n\r\nmonkey.patch_all()\r\n\r\n\r\ndef on_connect(env, start_response):\r\n    \"\"\"\r\n    Doc\r\n    :param env:\r\n    :param start_response:\r\n    :return:\r\n    \"\"\"\r\n    print(\"Connected\")\r\n\r\n\r\ndef serve():\r\n    \"\"\"\r\n    Test\r\n    :return:\r\n    \"\"\"\r\n    server = pywsgi.WSGIServer(('0.0.0.0', 8443), on_connect,\r\n                               keyfile='server.key', certfile='server.crt')\r\n    server.serve_forever()\r\n\r\n\r\ndef connect():\r\n    \"\"\"\r\n    Test\r\n    \"\"\"\r\n    # 2-tuple (host, port)\r\n    address = (\"127.0.0.1\", 8443)\r\n\r\n    # Socket\r\n    current_socket = gevent.socket.socket()\r\n\r\n    # Wrap\r\n    current_socket = SSLSocket(current_socket)\r\n\r\n    # Connect\r\n    current_socket.connect(address)\r\n    while True:\r\n        print(\"Connected\")\r\n        gevent.sleep(1.0)\r\n\r\n\r\nprint(\"Serving\")\r\ngevent.spawn(serve)\r\nprint(\"Serving : done\")\r\n\r\nprint(\"Connecting\")\r\ngevent.spawn(connect)\r\n\r\nwhile True:\r\n    print(\"Serving...\")\r\n    gevent.sleep(5.0)\r\n```\r\n********************\r\n*** 2.7.9 code\r\n********************\r\n```\r\nfrom __future__ import print_function\r\nfrom gevent import pywsgi\r\nimport gevent\r\n\r\nfrom gevent import monkey\r\nfrom gevent._sslgte279 import SSLSocket\r\n\r\nmonkey.patch_all()\r\n\r\n\r\ndef on_connect(env, start_response):\r\n    \"\"\"\r\n    Doc\r\n    :param env:\r\n    :param start_response:\r\n    :return:\r\n    \"\"\"\r\n    print(\"Connected\")\r\n\r\n\r\ndef serve():\r\n    \"\"\"\r\n    Test\r\n    :return:\r\n    \"\"\"\r\n    server = pywsgi.WSGIServer(('0.0.0.0', 8443), on_connect,\r\n                               keyfile='server.key', certfile='server.crt')\r\n    server.serve_forever()\r\n\r\n\r\ndef connect():\r\n    \"\"\"\r\n    Test\r\n    \"\"\"\r\n\r\n    # 2-tuple (host, port)\r\n    address = (\"127.0.0.1\", 8443)\r\n\r\n    # Socket\r\n    current_socket = gevent.socket.socket()\r\n\r\n    # Wrap\r\n    current_socket = SSLSocket(current_socket)\r\n\r\n    # Connect\r\n    current_socket.connect(address)\r\n    while True:\r\n        print(\"Connected\")\r\n        gevent.sleep(1.0)\r\n\r\nprint(\"Serving\")\r\ngevent.spawn(serve)\r\nprint(\"Serving : done\")\r\n\r\nprint(\"Connecting\")\r\ngevent.spawn(connect)\r\n\r\nwhile True:\r\n    print(\"Serving...\")\r\n    gevent.sleep(5.0)\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/gevent/gevent/issues/comments/114656541","html_url":"https://github.com/gevent/gevent/issues/584#issuecomment-114656541","issue_url":"https://api.github.com/repos/gevent/gevent/issues/584","id":114656541,"user":{"login":"SuiperLolo","id":12999515,"avatar_url":"https://avatars.githubusercontent.com/u/12999515?v=3","gravatar_id":"","url":"https://api.github.com/users/SuiperLolo","html_url":"https://github.com/SuiperLolo","followers_url":"https://api.github.com/users/SuiperLolo/followers","following_url":"https://api.github.com/users/SuiperLolo/following{/other_user}","gists_url":"https://api.github.com/users/SuiperLolo/gists{/gist_id}","starred_url":"https://api.github.com/users/SuiperLolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SuiperLolo/subscriptions","organizations_url":"https://api.github.com/users/SuiperLolo/orgs","repos_url":"https://api.github.com/users/SuiperLolo/repos","events_url":"https://api.github.com/users/SuiperLolo/events{/privacy}","received_events_url":"https://api.github.com/users/SuiperLolo/received_events","type":"User","site_admin":false},"created_at":"2015-06-23T22:11:32Z","updated_at":"2015-06-23T22:11:32Z","body":"note : this is with a self-signed certificate.\r\n\r\ni tried to regen it (openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem)\r\n& add it to root certs (update-ca-certificates --fresh), failed\r\neven forcing stuff, no success...\r\n\r\n```\r\n    server = pywsgi.WSGIServer(('0.0.0.0', 8443), on_connect,\r\n                               keyfile='server.key', certfile='server.crt',\r\n                               ca_certs=\"/etc/ssl/certs/ca-certificates.crt\",\r\n                               cert_reqs=CERT_REQUIRED,\r\n                               ssl_version=PROTOCOL_SSLv23)\r\n```\r\n\r\nAt the end, with ca_certs / cert_reqs disabled or enabled :\r\n- old certif + PROTOCOL_SSLv23 : SSLError: [SSL] EVP lib (_ssl.c:581)\r\n- old certif + PROTOCOL_TLSv1 : SSLEOFError: EOF occurred in violation of protocol (_ssl.c:581)\r\n- new certif + PROTOCOL_SSLv23 : SSLEOFError: EOF occurred in violation of protocol (_ssl.c:581)\r\n- new certif + PROTOCOL_TLSv1 : SSLEOFError: EOF occurred in violation of protocol (_ssl.c:581)\r\n\r\nrunning debian 8, OpenSSL 1.0.1k 8 Jan 2015, Python 2.7.9, gevent 1.0.2\r\n\r\nSSL hell... after https, tcp....\r\n"}}