Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69980

Re: imaplib: how to specify SSL/TLS protocol version?

Date 2014-04-09 15:26 -0500
From Tim Chase <python.list@tim.thechases.com>
Subject Re: imaplib: how to specify SSL/TLS protocol version?
References <li49ik$f94$1@reader1.panix.com>
Newsgroups comp.lang.python
Message-ID <mailman.9094.1397075181.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 2014-04-09 20:12, Grant Edwards wrote:
>  File "/usr/lib64/python2.7/imaplib.py", line 1148, in __init__
>    IMAP4.__init__(self, host, port)
>  SSLError: [Errno 1] _ssl.c:1419: error:1408F10B:SSL
> routines:SSL3_GET_RECORD:wrong version number
> 
> Experiments show that when calling ssl.wrap_socket() I have to
> specify ssl_version=PROTOCOL_TLSv1 to avoid the above error.
> 
> How do I tell imaplib to use TLS1 instead of SSL3?

Sounds like you'd need to make a subclass, something like

  class IMAP4_TLS(imaplib.IMAP4_SSL):
    def open(self, host="", port=IMAP4_SSL_PORT):
      self.host = host
      self.port = port
      self.sock = socket.create_connection((host, port))
      self.sslobj = ssl.wrap_socket(
        self.sock,
        self.keyfile,
        self.certfile,
        ssl_version=PROTOCOL_TLSv1,
        )
      self.file = self.sslobj.makefile('rb')

Alternatively, you could genericify it something like


  class IMAP4_TLS(imaplib.IMAP4_SSL):
    def open(self, host="",
        port=IMAP4_SSL_PORT,
        ssl_version=PROTOCOL_SSLv23,
        ):
      self.host = host
      self.port = port
      self.sock = socket.create_connection((host, port))
      self.sslobj = ssl.wrap_socket(
        self.sock,
        self.keyfile,
        self.certfile,
        ssl_version=ssl_version,
        )
      self.file = self.sslobj.makefile('rb')

and then call .open(..., ssl_version=PROTOCOL_TLSv1) or specify any
other protocol that you need.

-tkc



Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

imaplib: how to specify SSL/TLS protocol version? Grant Edwards <invalid@invalid.invalid> - 2014-04-09 20:12 +0000
  Re: imaplib: how to specify SSL/TLS protocol version? Grant Edwards <invalid@invalid.invalid> - 2014-04-09 20:20 +0000
    Re: imaplib: how to specify SSL/TLS protocol version? Tim Chase <python.list@tim.thechases.com> - 2014-04-09 15:33 -0500
      Re: imaplib: how to specify SSL/TLS protocol version? Grant Edwards <invalid@invalid.invalid> - 2014-04-09 20:55 +0000
        Re: imaplib: how to specify SSL/TLS protocol version? Grant Edwards <invalid@invalid.invalid> - 2014-04-09 21:10 +0000
          Re: imaplib: how to specify SSL/TLS protocol version? Chris Angelico <rosuav@gmail.com> - 2014-04-10 11:55 +1000
  Re: imaplib: how to specify SSL/TLS protocol version? Tim Chase <python.list@tim.thechases.com> - 2014-04-09 15:26 -0500
  Re: imaplib: how to specify SSL/TLS protocol version? Antoine Pitrou <solipsis@pitrou.net> - 2014-04-10 19:57 +0000

csiph-web