SSL 서버가 실행되고있어 JSON 객체를 허용하고 다른 JSON 객체로 응답 할 수 있습니다. 그러나 JSON 객체를 수행하기 전에 단순화 된 버전을 작성하기로 결정했으며 SSL로이 이상한 오류를 발견했습니다. 제가 잘못한 것을하지 않는 한, 인증서 생성에 대한 해결책이 제대로 작동하지 않았습니다.Python openSLL 서버 연결시 충돌 - 이상한 오류 메시지
파이썬 서버 키와 인증서의
import socket
import re
import ssl
# Standard socket stuff:
host = '' # do we need socket.gethostname() ?
port = 8080
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((host, port))
sock.listen(1) # don't queue up any requests
# Loop forever, listening for requests:
while True:
csock, caddr = sock.accept()
connstream = ssl.wrap_socket(csock,
server_side=True,
certfile="cert.pem",
keyfile="cert.pem",
ssl_version=ssl.PROTOCOL_SSLv23)
print "Connection from: " + `caddr`
dataBuf = connstream.recv(4096) # read what is there to read
extraData = connstream.recv(4096) #see if there is more
while len(extraData) != 0: #if something extra was read
dataBuf += extraData
extraData = connstream.recv(4096) #check again
print '--------'
print len(dataBuf), dataBuf
# Look in the first line of the request for a move command
# A move command should be e.g. 'http://server/move?a=90'
match = re.match('GET /move\?a=(\d+)\sHTTP/1', dataBuf)
if match:
angle = match.group(1)
print "ANGLE: " + angle + "\n"
connstream.sendall("HTTP/1.0 200 OK\r\n"+
"Content-Type: text/html\r\n"+
"Connection: close\r\n"+
"\r\n"+
"""<!DOCTYPE html>
<head>
<title>Success</title>
</head>
<body>
Boo!
</body>
</html>\r\n
""")
else:
# If there was no recognised command then return a 404 (page not found)
print "Returning 404"
connstream.sendall("HTTP/1.0 404 Not Found\r\n")
#connstream.shutdown(socket.SHUT_RDWR)
connstream.close()
세대 : 그래서 여기에 내가했던 모든 것 내가 아닌 내가 로컬 호스트를 제공하고 있습니다로 내가는 "일반 이름"부분에서 뭔가 잘못하고있는 중이 야 확실.
Country Name (2 letter code) [AU]:UK
State or Province Name (full name) [Some-State]:C
Locality Name (eg, city) []:C
Organization Name (eg, company) [Internet Widgits Pty Ltd]:U of C
Organizational Unit Name (eg, section) []:CL
Common Name (e.g. server FQDN or YOUR name) []:localhost.localdomain
Email Address []:unis
: 나는 필드를 완료하고 어떻게 LOCALDOMAIN 포스트
Python SSL example from docs gives "Connection reset by peer" error
openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem
다음3210
Errors: after going to https://localhost:8080/move?a=77 on a browser (Firefox and Chrome)
Connection from: ('127.0.0.1', 39107)
Traceback (most recent call last):
File "ser.py", line 29, in <module>
dataBuf = connstream.recv(44096) # read what is there to read
File "/usr/lib/python2.7/ssl.py", line 241, in recv
return self.read(buflen)
File "/usr/lib/python2.7/ssl.py", line 160, in read
return self._sslobj.read(len)
ssl.SSLError: [Errno 1] _ssl.c:1359: error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca
감사합니다. 감사!
추신 :
내가 파이어 폭스에 가서 인증서를 수동으로 추가 : 나는 후속
/// TLSv1의 및 PROTOCOL_SSLv23, 동일한 오류 ...
을 시도했다. 지금 내가 얻을 :Connection from: ('127.0.0.1', 39220)
Traceback (most recent call last):
File "ser.py", line 29, in <module>
dataBuf = connstream.recv(44096) # read what is there to read
File "/usr/lib/python2.7/ssl.py", line 241, in recv
return self.read(buflen)
File "/usr/lib/python2.7/ssl.py", line 160, in read
return self._sslobj.read(len)
ssl.SSLError: [Errno 1] _ssl.c:1359: error:14094419:SSL routines:SSL3_READ_BYTES:tlsv1 alert access denied
어떤 아이디어?
// 또 다른 시도 :
내가 인증서를 신뢰하는 파이어 폭스에게 지금은이 줄 아무것도Connection from: ('127.0.0.1', 39248)
Traceback (most recent call last):
File "ser.py", line 29, in <module>
dataBuf = connstream.recv(44096) # read what is there to read
File "/usr/lib/python2.7/ssl.py", line 241, in recv
return self.read(buflen)
File "/usr/lib/python2.7/ssl.py", line 160, in read
return self._sslobj.read(len)
ssl.SSLError: [Errno 1] _ssl.c:1359: error:14094412:SSL routines:SSL3_READ_BYTES:sslv3 alert bad certificate
검색을 얻을!
// 후속 : 또한 일반 이름 localhost
로두고
재생성 키와 http://devsec.org/info/ssl-cert.html를 사용하여 인증서. 연결이되지만 서버가 멈추고 응답하지 않습니다 ... 읽은 부분에 문제가있을 수 있습니까? 후속 질문에 대해서는
자체 서명 인증서를 생성하는 경우 "일반 이름"(CN)은 HTTP'Host :'헤더의 호스트 이름과 정확하게 일치해야합니다. 즉, URL에서 사용중인 호스트 이름과 일치해야합니다. if 'https : // localhost : 8080/move? a = 77' URL을 사용하고 있다면 CN은'localhost.localdomain'이 아닌'localhost'이어야합니다. – Aya
@Aya 좋아, 내가 바꿨어. 파이어 폭스가 확인 후 인증서를 삭제하지 않았 음을 확인했다. 연결은되지만 GET 요청은 끝나지 않습니다. 왜 그런가? 그것은 단지 거기에 앉아서 끝내지 않습니다 ... – unixsnob