Page MenuHomePhabricator

OAuth handshake can't complete for test.orain.org
Closed, ResolvedPublic

Description

Based on T102602 and use test.orain.org for testing.

> import pywikibot
> site = pywikibot.Site()
> from pywikibot.login import OauthLoginManager
> consumer_token = ('XXXXXXXXXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXX')
> login_manager = OauthLoginManager(consumer_token, site)
> login_manager.login()
Logging in to oraintest:en via OAuth consumer XXXXXXXXXXXXXXXXXXXXXXXXXX
Authenticate via web browser
Response query string: XXXXXXXXXXXXXXXXXXXXXXXXXX
ERROR: [('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')]

The exception is actually raised by complete function in mwoauth (use mwoauth 0.2.4):

def complete(mw_uri, consumer_token, request_token, response_qs):
    """
    Completes an OAuth handshake with MediaWiki by exchanging an

    :Parameters:
        mw_uri : `str`
            The base URI of the MediaWiki installation.  Note that the URI
            should end in ``"index.php"``.
        consumer_token : :class:`~mwoauth.ConsumerToken`
            A key/secret pair representing you, the consumer.
        request_token : :class:`~mwoauth.RequestToken`
            A temporary token representing the user.  Returned by
            `initiate()`.
        response_qs : `bytes`
            The query string of the URL that MediaWiki forwards the user back
            after authorization.

    :Returns:
        An `AccessToken` containing an authorized key/secret pair that
        can be stored and used by you.
    """

    ......

    # Construct a new auth with the verifier
    auth = OAuth1(consumer_token.key,
                  client_secret=consumer_token.secret,
                  resource_owner_key=request_token.key,
                  resource_owner_secret=request_token.secret,
                  verifier=verifier)

    # Send the verifier and ask for an authorized resource owner key/secret
    r = requests.post(url=mw_uri,
                      params={'title': "Special:OAuth/token"},
                      auth=auth)

    ......

The exception is raised by the last r = requests.post(...)sentence.
Also, the actual exception is hided because of T105767.

The issue may be related: https://github.com/kennethreitz/requests/issues/2022

Workaround

SNI is the reason for the error, like @Tgr mentioned in his comments:

Looking at the SSLLabs analyses:

the main differences are that Orain uses SNI and only supports elliptic ciphers, while Wikimedia crams all its domains in a single certificate and has a bunch of fallback ciphers. SNI could be the reason for the error: (1) (2) (3) (although the error messages mentioned there are different)

(1) of comments above mentions the solution: http://docs.python-requests.org/en/latest/community/faq/#what-are-hostname-doesn-t-match-errors

Event Timeline

VcamX raised the priority of this task from to Needs Triage.
VcamX updated the task description. (Show Details)
VcamX added subscribers: VcamX, jayvdb, Halfak.
VcamX set Security to None.

This seems like a generic SSL connection issue not specifically related to OAuth. You could test to make sure by trying to connect to some random page.

@Tgr I think you're right.

>>> import requests
>>>
>>> requests.get('https://test.orain.org/wiki/Main_Page')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/var/pyenv/versions/2.7.9/lib/python2.7/site-packages/requests/api.py", line 69, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/var/pyenv/versions/2.7.9/lib/python2.7/site-packages/requests/api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/usr/local/var/pyenv/versions/2.7.9/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/var/pyenv/versions/2.7.9/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/var/pyenv/versions/2.7.9/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')]

>>> requests.get('https://meta.orain.org/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/var/pyenv/versions/2.7.9/lib/python2.7/site-packages/requests/api.py", line 69, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/var/pyenv/versions/2.7.9/lib/python2.7/site-packages/requests/api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/usr/local/var/pyenv/versions/2.7.9/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/var/pyenv/versions/2.7.9/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/var/pyenv/versions/2.7.9/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')]

@jayvdb Maybe it's requests lib problem.

@VcamX it looks like it's the server you are hitting.

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.7.0'
>>> requests.get("https://test.orain.org/wiki/Main_Page")
/home/halfak/env/2.7/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/halfak/env/2.7/local/lib/python2.7/site-packages/requests/api.py", line 69, in get
    return request('get', url, params=params, **kwargs)
  File "/home/halfak/env/2.7/local/lib/python2.7/site-packages/requests/api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "/home/halfak/env/2.7/local/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/halfak/env/2.7/local/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/home/halfak/env/2.7/local/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno 1] _ssl.c:510: error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error
>>> requests.get("https://en.wikipedia.org/wiki/Main_Page")
/home/halfak/env/2.7/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
<Response [200]>

See also https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning

Per ssllabs (see the Configuration section) Orain does not support SSLv3 (nor SSL at all, in a strict technical sense, only TLS). That is a common setup - many organizations (including Wikimedia) dropped SSLv3 support in response to the POODLE attack. You are probably using an outdated or misconfigured library or OS which is not able to do protocol negotiation.

But en.wikipedia.org doesn't support SSL too and @Halfak got the error only on orain.org.

It looks more like to be the problem of orain.org... Does it have possibility that requests lib can't adapt to orain.org or the TLS configuration of orain.org?

But en.wikipedia.org doesn't support SSL too and @Halfak got the error only on orain.org.

Fair point. Looking at the SSLLabs analyses:

the main differences are that Orain uses SNI and only supports elliptic ciphers, while Wikimedia crams all its domains in a single certificate and has a bunch of fallback ciphers. SNI could be the reason for the error: (1) (2) (3) (although the error messages mentioned there are different)

@XZise I agree with @Tgr. Installing pyOpenSSL, ndg-httpsclient and pyasn1 works for me when using python 2.7.6.

Does ignoring ssl certificate verification work, without ndg-httpsclient?

@jayvdb, for python 2.7.6, it doesn't work.

VcamX renamed this task from OAuth handshake can't complete to OAuth handshake can't complete for test.orain.org.Aug 9 2015, 6:35 AM
VcamX updated the task description. (Show Details)
VcamX updated the task description. (Show Details)