Home > Software engineering >  Why does the built in python SSL library give "ssl.SSLError: [SSL] internal error (_ssl.c:1129)
Why does the built in python SSL library give "ssl.SSLError: [SSL] internal error (_ssl.c:1129)

Time:02-10

I am attempting to build an IRC bot. To connect to the server, I am using the built in ssl library from python. When I run my code on Mac (MacOS 10.15.6, Python 3.9.10, OpenSSL 1.1.1k 25 Mar 2021), it connects to the server, and works perfectly fine, however, when I run the exact same program on my ubuntu server (Ubuntu 20.04.3 LTS, Python 3.9.5, OpenSSL 1.1.1f 31 Mar 2020) it fails with this error:

Traceback (most recent call last):
  File "/home/kyodie/IRCbot/bot.py", line 42, in <module>
    main()
  File "/home/kyodie/IRCbot/bot.py", line 11, in main
    client = irc.IRCClient("irc.geekshed.net", 6697, botCredentials)
  File "/home/kyodie/IRCbot/irc.py", line 33, in __init__
    self.__login()
  File "/home/kyodie/IRCbot/irc.py", line 166, in __login
    self.socket.connect((self.hostname, self.port))
  File "/usr/lib/python3.9/ssl.py", line 1342, in connect
    self._real_connect(addr, False)
  File "/usr/lib/python3.9/ssl.py", line 1333, in _real_connect
    self.do_handshake()
  File "/usr/lib/python3.9/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL] internal error (_ssl.c:1129)

Here is the relevent code:

# irc.py
def __login(self):
    self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
    self.socket = self.context.wrap_socket(self.socket, server_side=False)

    self.socket.connect((self.hostname, self.port)) # <--- ERROR HERE
    self.__start_listening()
    self.__ident()

CodePudding user response:

Solved: I switched from TLS version 1 to TLS v 1.2

# irc.py
def __login(self):
    self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    self.socket = self.context.wrap_socket(self.socket, server_side=False)

    self.socket.connect((self.hostname, self.port)) # <--- ERROR HERE
    self.__start_listening()
    self.__ident()
  •  Tags:  
  • Related