2014-04-04 4 views
2

Python 스크립트를 사용하여 학술 서비스 제공 업체 (SP)가 호스팅하는 저널 기사에 액세스하려고합니다.Python을 사용한 SSL 오류 Shibboleth 인증 서버에 대한 액세스 요청

서버는 Shibboleth 로그인을 사용하여 인증합니다. Logging into SAML/Shibboleth authenticated server using python을 읽고 Python Requests로 로그인을 구현하려고했습니다.

스크립트는 내 IDP 기관으로 연결되는 링크를 SP에 쿼리하여 시작하며 IDP와 자동으로 인증됩니다. 첫 번째 부분은 작동하지만 IDP 링크를 따라 가면 SSL 오류가 발생합니다.

import requests 
import lxml.html 

LOGINLINK = 'https://www.jsave.org/action/showLogin?redirectUri=%2F' 
USERAGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0' 

s = requests.session() 
s.headers.update({'User-Agent' : USERAGENT}) 

# getting the page where you can search for your IDP 
# need to get the cookies so we can continue 
response = s.get(LOGINLINK) 
rtext = response.text 
print('Don\'t see your school?' in rtext) # prints True 

# POSTing the name of my institution 
data = { 
    'institutionName' : 'tubingen', 
    'submitForm' : 'Search', 
    'currUrl' : '%2Faction%2FshowBasicSearch', 
    'redirectUri' : '%2F', 
    'activity' : 'isearch' 
} 
response = s.post(BASEURL + '/action/showLogin', data=data) 
rtext = response.text 
print('university of tubingen' in rtext) # prints True 

# get the link that leads to the IDP 
tree = lxml.html.fromstring(rtext) 
loginlinks = tree.cssselect('a.extLogin') 
if (loginlinks): 
    loginlink = loginlinks[0].get('href') 
else: 
    exit(1) 

print('continuing to IDP') 
response = s.get(loginlink) 
rtext = response.text 
print('zentrale Anmeldeseite' in rtext) 

이 수율 : s.get를 사용

continuing to IDP... 

2014-04-04 10:04:06,010 - INFO - Starting new HTTPS connection (1): idp.uni-tuebingen.de 
Traceback (most recent call last): 

File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 480, in urlopen 
body=body, headers=headers) 

File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 285, in _make_request 
conn.request(method, url, **httplib_request_kw) 

File "/usr/lib/python3.4/http/client.py", line 1066, in request 
self._send_request(method, url, body, headers) 

File "/usr/lib/python3.4/http/client.py", line 1104, in _send_request 
self.endheaders(body) 

File "/usr/lib/python3.4/http/client.py", line 1062, in endheaders 
self._send_output(message_body) 

File "/usr/lib/python3.4/http/client.py", line 907, in _send_output 
self.send(msg) 

File "/usr/lib/python3.4/http/client.py", line 842, in send 
self.connect() 

File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 164, in connect 
ssl_version=resolved_ssl_version) 

File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/util.py", line 639, in ssl_wrap_socket 
return context.wrap_socket(sock, server_hostname=server_hostname) 

File "/usr/lib/python3.4/ssl.py", line 344, in wrap_socket 
_context=self) 

File "/usr/lib/python3.4/ssl.py", line 540, in __init__ 
self.do_handshake() 

File "/usr/lib/python3.4/ssl.py", line 767, in do_handshake 
self._sslobj.do_handshake() 

ssl.SSLError: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:598) 


During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 

File "/usr/lib/python3.4/site-packages/requests/adapters.py", line 330, in send 
timeout=timeout 

File "/usr/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 504, in urlopen 
raise SSLError(e) 

requests.packages.urllib3.exceptions.SSLError: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:598) 


During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
File "./try.py", line 154, in <module> 
response = s.get(loginlink) 

File "/usr/lib/python3.4/site-packages/requests/sessions.py", line 395, in get 
return self.request('GET', url, **kwargs) 

File "/usr/lib/python3.4/site-packages/requests/sessions.py", line 383, in request 
resp = self.send(prep, **send_kwargs) 

File "/usr/lib/python3.4/site-packages/requests/sessions.py", line 486, in send 
r = adapter.send(request, **kwargs) 

File "/usr/lib/python3.4/site-packages/requests/adapters.py", line 385, in send 
raise SSLError(e) 

requests.exceptions.SSLError: [SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:598) 

을 (LOGINLINK = 거짓을 확인) 정확히 같은 오류를 얻을 수 여기 내가 사용하는 것입니다. 간단히 urllib.request.urlopen (loginlink)을 사용하는 것도 마찬가지입니다.

Firefox로 링크를 인쇄하여 붙여 넣는 것은 정상적으로 작동합니다.

답변

1

openssl s_client과 같이 시도한 후 대상 idp.uni-tuebingen.de:443은 SSLv3 만 지원하며 더 새로운 버전은 오작동하는 것처럼 보입니다. SSLv3에 하나를 강제로 가져옵니다

openssl s_client -connect idp.uni-tuebingen.de:443 
CONNECTED(00000003) 
140493591938752:error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error:s23_clnt.c:741: 

그래서 당신이 연결을위한 SSLv3에 강제 할 수있는 방법을 찾을 필요가 :

$ openssl s_client -connect idp.uni-tuebingen.de:443 -ssl3 
CONNECTED(00000003) 
depth=3 C = DE, O = Deutsche Telekom AG, OU = T-TeleSec Trust Center, CN = Deutsche Telekom Root CA 2 
... 

그러나 기본 설정 또는 TLv1 강제로

이 (-tls1)에만 경고를 반환 . 나는이 시점에서 파이썬에 익숙하지 않지만 어쩌면 http://docs.python-requests.org/en/latest/user/advanced/ 장의 "예 : 특정 SSL 버전"장이 도움이됩니다.

그리고 Firefox와 호환되는 이유 : 안전한 버전으로 연결하지 않으면 브라우저는 일반적으로 다운 그레이드 된 SSL 버전으로 다시 시도합니다. 예 : 모두 깨진 물건을 해결하려고 노력하고 있습니다. (

+0

고맙습니다. 필자의 조언과 http : // lukasa에 따라 Python Requests에서 일하게되어 대단히 감사합니다. co.uk/2013/01/Choosing_SSL_Version_In_Requests/ "ssl_version = ssl.PROTOCOL_SSLv3"을 강제하는 어댑터 클래스가 추가되었습니다. – user3497169