glumia / polito_dl

Command-line tool and library to download Polytechnic of Turin's online lessons from didattica.polito.it
GNU General Public License v3.0
2 stars 0 forks source link

urrlib3 and TLSv1 - Script not working #7

Closed glumia closed 4 years ago

glumia commented 4 years ago

There is an error with the login function (could be caused TLSv1 deprecation).

$polito_dl.py "https://didattica.polito.it/portal/pls/portal/sviluppo.videolezioni.vis?cor=464" --save-syllabus summary.txt
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in _validate_conn
    conn.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 344, in connect
    ssl_context=context)
  File "/usr/lib/python3/dist-packages/urllib3/util/ssl_.py", line 344, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/usr/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/usr/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='login.didattica.polito.it', port=443): Max retries exceeded with url: /secure/ShibLogin.php (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gius/polito_dl/polito_dl.py", line 400, in <module>
    login_cookie = get_login_cookie(user, passw)
  File "/home/gius/polito_dl/polito_dl.py", line 69, in get_login_cookie
    r = s.post('https://login.didattica.polito.it/secure/ShibLogin.php')
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 581, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='login.didattica.polito.it', port=443): Max retries exceeded with url: /secure/ShibLogin.php (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)')))
glumia commented 4 years ago

Yes, I looked in the source code of requests and urllib3, it's caused by TSLv1 (used by PoliTo for logins without a browser supporting javascript). Since it isn't specified urrlib3 tries by default a connection using at minimum TLSv1.2 and this obviously fails.