Can I use TLS version 1.1 or 1.2 in python 2?

后端 未结 3 619
梦如初夏
梦如初夏 2021-01-12 06:08

I read a document that says that Python 2 only has ssl.PROTOCOL_TLSv1 constant, and that ssl.PROTOCOL_TLSv1_1 and ssl.PROTOCOL_TLSv1_2

相关标签:
3条回答
  • 2021-01-12 06:34

    No there is no support planned for TLS 1.1 or 1.2 in Python 2, see:

    http://bugs.python.org/issue16692

    It states clearly that TLS > 1.0 won't be backported to Python 2.7, and Python maintainers stated several times that Python 2.8 is not going to happen.

    Please note that few servers support TLS 1.2 for now. Hopefully it will change in the future.

    0 讨论(0)
  • 2021-01-12 06:38

    I recently had to terminate a TLSv1.2 connection with mutually authenticated SSL and this was no go on vanilla 2.7.8. I was about to begin painfully porting my network i/o intensive application to Python 3, changing every string to bytes and back for recv/send. It was going to suck.

    Then I found PEP466. You can apply the patch from PEP466 (Google it) to 2.7.7 or 2.7.8 pretty easily to get TLS 1.1 and TLS 1.2 working.

    The patch for PEP 466 is @ http://bugs.python.org/file36423/ssl-backport.diff

    Also, you will need the following patch to fix a Unicode related bug that causes a segfault when constructing errors in the SSL code:

    this patch is @ http://bugs.python.org/file36017/unicode_fromformat.patch

    Also, once you apply the patch, you should technically do the following before configuring and compiling:

    ~/Python-2.7.8$ python3 ./Tools/ssl/make_ssl_data.py /usr/include/openssl/ _ssl_data.h
    ~/Python-2.7.8$ mv _ssl_data.h Modules/_ssl_data.h
    

    You can then configure && make && make install and should be good to go w/TLSv1.1 and TLSv1.2.

    ~/Python-2.7.8$ ./configure --enable-unicode=ucs2 --prefix=/opt/Python-2.7.8/ --with-pth && make -j && sudo make install
    

    TLS 1.2 is now working fine for me, so I don't have to port a gigantic app to Python 3.

    Anyway, the wording on the PEP page is confusing, it makes it sound like 2.7.9 in December is supposed to have this support included (?) but I'm not sure if that is acccurate or if this is just a manual workaround until you port your code to Python 3. I suppose it doesn't really matter.

    0 讨论(0)
  • 2021-01-12 06:42

    With my apologies for resurrecting an old question, it appears that support for TLS1.1 and TLS1.2 will be brought in for Python 2.7.9, scheduled for release around December 2014.

    0 讨论(0)
提交回复
热议问题