简体   繁体   English

在python 2.7中更新openssl

[英]Updating openssl in python 2.7

wondering if someone may please explain how openssl works in python2.7. 想知道是否有人可以解释openssl如何在python2.7中工作。 I'm not sure if python got its own openssl or picks it up from local machine/env? 我不确定python是否拥有自己的openssl或从本地计算机/环境中获取它?

let me explain: (if I do this in Python) 让我解释一下:(如果我使用Python进行此操作)

>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 0.9.8x 10 May 2012'

(In terminal) (在终端)

$ openssl version
OpenSSL 0.9.8x 10 May 2012
$ which openssl 
/usr/bin/openssl

now I updated openssl (downloaded .) 现在我更新了openssl(下载。)

$ cd openssl-1.0.1c
$ ./Configure darwin64-x86_64-cc --prefix=/usr --openssldir=/opt/local/etc/openssl shared
$ make
$ sudo make install

this created separate director(as specified), so I copied it to the old path 这创建了单独的导演(如指定),所以我将其复制到旧路径

cp -f /usr/local/ssl/bin/openssl /usr/bin/openssl

now in terminal openssl version has been updated but not from python! 现在在终端openssl版本已更新,但不是从python!

$ openssl version
OpenSSL 1.0.1c 10 May 2012

I did noticed that .dylib is still pointing to old version, how can I change this? 我确实注意到.dylib仍指向旧版本,该如何更改?

$ ls -l /usr/lib/*ssl*
-rwxr-xr-x  1 root  wheel  411680 Jul 17  2012 /usr/lib/libssl.0.9.7.dylib
-rwxr-xr-x  1 root  wheel  602800 May 24 03:43 /usr/lib/libssl.0.9.8.dylib
-rwxr-xr-x  1 root  wheel  390908 Sep  9 17:37 /usr/lib/libssl.1.0.0.dylib
lrwxr-xr-x  1 root  wheel      18 Jul 17  2012 /usr/lib/libssl.dylib -> libssl.0.9.8.dylib

Update : I changed the link still got old version at python. 更新 :我更改了链接,但在python上仍旧版本。

$ ls -l /usr/lib/*ssl*
-rwxr-xr-x  1 root  wheel  411680 Jul 17  2012 /usr/lib/libssl.0.9.7.dylib
-rwxr-xr-x  1 root  wheel  602800 May 24 03:43 /usr/lib/libssl.0.9.8.dylib
-rwxr-xr-x  1 root  wheel  390908 Sep  9 17:37 /usr/lib/libssl.1.0.0.dylib
lrwxr-xr-x  1 root  wheel      18 Sep 11 15:47 /usr/lib/libssl.dylib -> libssl.1.0.0.dylib

Please refer to http://rkulla.blogspot.kr/2014/03/the-path-to-homebrew.html 请参考http://rkulla.blogspot.kr/2014/03/the-path-to-homebrew.html

After upgrading openssl to 1.0.1j by homebrew on MAC, but system python still referred to old version 0.9.8. 在MAC上通过自制软件将openssl升级到1.0.1j之后,但是系统python仍然引用旧版本0.9.8。 It turned out the python referred to openssl. 原来,这是称为openssl的python。 So I have installed new python with brewed openssl and finished this issue on Mac, not yet Ubuntu. 因此,我用brews openssl安装了新的python,并在Mac(尚未Ubuntu)上完成了此问题。

On Mac OS X version 10.10 and system python version 2.7.6, my procedure is as follows: 在Mac OS X 10.10版和系统python 2.7.6版上,我的过程如下:

$ brew update

$ brew install openssl

Then you can see openssl version 1.0.1j. 然后您可以看到openssl版本1.0.1j。

$ brew link openssl --force 

$ brew install python --with-brewed-openssl    

You have to install new python with brewed openssl. 您必须使用酿造的openssl安装新的python。 Then, you can see /usr/local/Cellar/python/2.7.8_2/bin/python. 然后,您可以看到/usr/local/Cellar/python/2.7.8_2/bin/python。

$ sudo ln -s /usr/local/Cellar/python/2.7.8_2/bin/python /usr/local/bin/python

Of course, /usr/local/* should be owned by $USER, not root, which is told by Ryan, but I used 'sudo'. 当然,/ usr / local / *应该由$ USER而不是root拥有,Ryan告诉我,但是我使用了'sudo'。 And, before this instruction, I didn't have /usr/local/bin/python. 而且,在执行此指令之前,我没有/ usr / local / bin / python。 After this instruction, you can use python version 2.7.8 not 2.7.6. 完成此说明后,您可以使用python版本2.7.8而不是2.7.6。

Finally, you can see as belows; 最后,您可以看到以下内容;

$ python --version  
Python 2.7.8

$ python -c "import ssl; print ssl.OPENSSL_VERSION"
OpenSSL 1.0.1j 15 Oct 2014

Till now, I'm working on it on Ubuntu 12.04. 到目前为止,我正在Ubuntu 12.04上进行开发。 If I have a solution for Ubuntu 12.04, then I will update my answer. 如果我有Ubuntu 12.04的解决方案,那么我将更新答案。 I hope this procedure help you. 希望此过程对您有所帮助。

Outdated SSL is a common issue on multiple platforms: SSL过时是多个平台上的常见问题:

Here's the general approach... 这是一般的方法...

0. Install OpenSSL 0.安装OpenSSL

  • Option I: Install system packages of side-by-side OpenSSL 1.x libs (-dev or -devel) packages. 选项I:安装并行OpenSSL 1.x库(-dev或-devel)软件包的系统软件包。

     # FreeBSD pkg install openssl OPENSSL_ROOT=/usr/local # Mac (brew) brew install openssl # DO NOT DO ANY WEIRD SYMLINK HACKS, ITS KEG-ONLY FOR A REASON! OPENSSL_ROOT="$(brew --prefix openssl)" 
  • Option II: Install OpenSSL from source to a temporary directory 选项II:将OpenSSL从源安装到临时目录

     OPENSSL_ROOT="$HOME/.build/openssl-1.0.1e" curl http://www.openssl.org/source/openssl-1.0.1e.tar.gz | tar zxvf - cd openssl-1.0.1e mkdir -p "$OPENSSL_ROOT" ./config no-hw --prefix="$OPENSSL_ROOT" --openssldir=... # osx (instead of previous line): ./Configure darwin64-x86_64-cc no-hw --prefix="$OPENSSL_ROOT" --openssldir=... make install cd .. rm -rf openssl-1.0.1e 

1. Building Python from source 1. 从源代码构建Python

  • Option A : Use pyenv : 选项A :使用pyenv

     export CONFIGURE_OPTS="CPPFLAGS=-I"$OPENSSL_ROOT"/include LDFLAGS=-L"$OPENSSL_ROOT"/lib [your other options here]" pyenv install 2.7.6 
  • Option B : Install Python from source 选项B :从源代码安装Python

     ./configure CPPFLAGS="-I$OPENSSL_ROOT/include" LDFLAGS="-L$OPENSSL_ROOT/lib" [your other options here]` make # ... # if compiled openssl was used, it can be safely deleted because python's module ssl links openssl statically. 

Example: FreeBSD 9.2 (skipping make install for demo purposes) 示例:FreeBSD 9.2(跳过演示make install以进行演示)

pkg install openssl curl gmake gdbm sqlite3 readline ncurses
OPENSSL_ROOT=/usr/local
curl http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz | tar jxvf -
cd Python-2.7.6
./configure CPPFLAGS="-I$OPENSSL_ROOT/include" LDFLAGS="-L$OPENSSL_ROOT/lib" [your other options here]
make
./python -c 'import ssl; print(ssl.OPENSSL_VERSION)' # osx: ./python.exe ...
# prints: OpenSSL 1.0.1e 11 Feb 2013

Afterwards, temporary openssl libraries are no longer needed b/c the ssl modele with openssl statically into the python executable (verify using otool or readelf ). 之后,不再需要临时的openssl库,而将带有openssl的ssl模型静态插入到python可执行文件中(使用otoolreadelf验证)。

This could be because of an outdated version of Python. 这可能是由于Python版本过旧。

After running python -c "import ssl; print ssl.OPENSSL_VERSION" on Python 2.7.1, I saw that I had this outdated version: OpenSSL 0.9.7l 28 Sep 2006 . 在Python 2.7.1上运行python -c "import ssl; print ssl.OPENSSL_VERSION" ,我看到我有一个过时的版本: OpenSSL 0.9.7l 28 Sep 2006

It seems as though my version of Python depended on a deprecated version of OpenSSL, as indicated by this forum : 好像我的Python版本依赖于不推荐使用的OpenSSL版本,如本论坛所示

For the upcoming Python 2.7.9 release (planned for early December), I intend to have the Pythons in the python.org OS X installers use their own versions of OpenSSL and thus no longer depend on the now-deprecated system OpenSSL. 对于即将发布的Python 2.7.9版本(计划于12月初发布),我打算让python.org OS X安装程序中的Python使用它们自己的OpenSSL版本,因此不再依赖于现在不推荐使用的系统OpenSSL。

I updated to Python 2.7.9 and the issue was immediately fixed. 我更新至Python 2.7.9,此问题已立即解决。 Now, after running python -c "import ssl; print ssl.OPENSSL_VERSION" , I get OpenSSL 0.9.8za 5 Jun 2014 . 现在,在运行python -c "import ssl; print ssl.OPENSSL_VERSION" ,我得到OpenSSL 0.9.8za 5 Jun 2014

The following worked for me. 以下对我有用。 I was already able to update OpenSSL from 0.9.8zh to a 1.0.2o version, but python never accessed the newer version until found this suggestion to use pyenv to reinstall python (with 2.7.10, the version I wanted). 我已经能够将OpenSSL从0.9.8zh更新到1.0.2o版本,但是python从未访问过较新的版本,直到找到使用pyenv重新安装python的建议(使用我想要的2.7.10版本)。

brew update
brew install pyenv

echo 'eval "$(pyenv init -)"' >> .bashrc
source .bashrc

pyenv install 2.7.10
pyenv global 2.7.10

and then to check... 然后检查...

python --version
Python 2.7.10

python -c 'import ssl; print ssl.OPENSSL_VERSION'
OpenSSL 1.0.2o  27 Mar 2018

I did have to reinstall python packages of course. 我确实必须重新安装python软件包。

Source: https://github.com/ianunruh/hvac/issues/75 资料来源: https : //github.com/ianunruh/hvac/issues/75

I think python has recognized that this is an issue: https://www.python.org/downloads/release/python-2715/ 我认为python已经意识到这是一个问题: https : //www.python.org/downloads/release/python-2715/

Note 注意

Attention macOS users: as of 2.7.15, all python.org macOS installers ship with a builtin copy of OpenSSL. 注意macOS用户:从2.7.15开始,所有python.org macOS安装程序均附带内置的OpenSSL副本。 Additionally, there is a new additional installer variant for macOS 10.9+ that includes a built-in version of Tcl/Tk 8.6. 此外,macOS 10.9+还有一个新的附加安装程序变体,其中包括Tcl / Tk 8.6的内置版本。 See the installer README for more information. 有关更多信息,请参见安装程序自述文件。

Simply installing 2.7.15 fixed my OpenSSL issues. 只需安装2.7.15,即可解决我的OpenSSL问题。

SOLVED NO HACKS, none of the above worked for me. 解决不了任何麻烦,以上都不对我有用。 I ended up taking a simpler and uncomplicated approach.... 我最终采取了一种简单而不复杂的方法。

  1. Install python 2.7.13 from the official site, it actually installs as the default python, automatically upgrading the old python system wide ( yes! ). 从官方站点安装python 2.7.13,它实际上是作为默认python安装的,并自动在整个python系统范围内进行升级(是!)。

https://www.python.org/downloads/mac-osx/ https://www.python.org/downloads/mac-osx/

  1. Upgrade openssl after the python install. python安装后升级openssl。 Updating it for system python ( yes! ). 为系统python更新它(是!)。

sudo pip install --upgrade pyOpenSSL sudo pip install-升级pyOpenSSL

  1. You will have to re-install all your python modules ( because you replaced python ), I strongly recommend using pip. 您将必须重新安装所有python模块(因为您替换了python),我强烈建议您使用pip。 After a few minutes of pip installs my default OSX python was upgraded, I had openssl upgraded, and I had all my modules ( including django running ). 在安装了pip几分钟之后,我的默认OSX python升级了,openssl升级了,我的所有模块都包括了(包括正在运行的django)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM