Python Forum
SSL not working with Python 3.7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SSL not working with Python 3.7
#1
I started to learn python and sockets those days and I made a simple client-server app just to make some tests and it works fine with Python 3.6, but gives me error in the newest version. I make the code while studying the Python's docs. I'm using Python 3.7.2 in Windows 10 64 bits.

Server.py

import socket, ssl

context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.verify_mode = ssl.CERT_REQUIRED
context.load_cert_chain(certfile="SSL/server.crt", keyfile="SSL/server.key")
context.load_verify_locations("SSL/client.crt")

bindsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
bindsocket.bind(("127.0.0.1", 65405))
bindsocket.listen(5)

while True:
    newsocket, fromaddr = bindsocket.accept()
    print(newsocket) #it prints successfully
    connstream = context.wrap_socket(newsocket, server_side=True) #this line gives me the error
    try:
        print(connstream.getpeercert())
    finally:
        connstream.shutdown(socket.SHUT_RDWR)
        connstream.close()
Client.py

import ssl, socket

context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.load_cert_chain(certfile="SSL/clientKaori.crt", keyfile="SSL/clientKaori.key")
context.verify_mode = ssl.CERT_REQUIRED
context.check_hostname = True
context.load_verify_locations("SSL/serverKaori.crt")

conn = context.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM), server_hostname="127.0.0.1")

try:
    conn.connect(("127.0.0.1", 65405))
    conn.sendall(b"aff")
    print(conn.getpeercert())
except:
    print("não")
finally:
    conn.shutdown(socket.SHUT_RDWR)
    conn.close()
The error is:

Error:
Traceback (most recent call last): File "C:/Users/nicol/Desktop/Kyuu/Bot/Kaori/Python/server.py", line 15, in <module> connstream = context.wrap_socket(newsocket, server_side=True) File "C:\Users\nicol\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 412, in wrap_socket session=session File "C:\Users\nicol\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 853, in _create self.do_handshake() File "C:\Users\nicol\AppData\Local\Programs\Python\Python37-32\lib\ssl.py", line 1117, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: SSLV3_ALERT_BAD_CERTIFICATE] sslv3 alert bad certificate (_ssl.c:1056)
Thanks for all!
Reply
#2
When I use the command "s_client -connect 127.0.0.1:65405 -cert client.pem -key client.pem -CAfile server.crt" in the OpenSSL it works fine
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020