将macOS上的TLS 1.0升级到TLS 1.2

5

我安装一些Python包时遇到问题,我认为是因为我的TLS版本是1.0。如何升级到TLS 1.2?

python -c "import urllib2; import json; print(json.loads(urllib2.urlopen('https://www.howsmyssl.com/a/check').read())['tls_version'])"
TLS 1.0

我的macOS版本:10.13.4 (17E202)
Python版本:Python 2.7.13
OpenSSL版本:LibreSSL 2.2.7

我尝试升级OpenSSL,但它并没有升级LibreSSL。我记得一年前我在使用OpenSSL时遇到了一些问题,可能是手动链接了一些东西。

1个回答

3
尽管brew已下载了新版本的openssl,但旧版本仍与openssl命令一起使用。因此,我禁用了csrutil以消除/usr/bin/openssl中的openssl符号链接:
sudo ln -s /usr/local/Cellar/openssl/1.0.2o_1/bin/openssl /usr/bin/openssl

然后 OpenSSL 版本是最新的:

~ openssl version
OpenSSL 1.0.2o  27 Mar 2018

然而,Python仍然使用旧版本的openssl:
~ python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 0.9.8zh 14 Jan 2016

所以我打算再次禁用csrutil,并继续修复Python版本。

我删除了找到的所有Python 2安装包,基本上是按照以下步骤进行的:

brew uninstall python@2
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
sudo rm -rf "/Applications/Python 2.7"
cd /usr/local/bin/
ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print $9}' | tr -d @ | xargs rm

然后我通过brew安装了Python2,它使用正确的openssl:

~ brew install python@2
~ python -c "import urllib2,json; print(json.loads(urllib2.urlopen('https://www.howsmyssl.com/a/check').read())['tls_version'])"
TLS 1.2

你应该使用某种虚拟环境机制,而不是直接删除Python库,因为它可能被其他东西使用...另外,请记得在满意答案后将其标记为已解决,以关闭问题。 - Patrick Mevzek

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接