您可以将此问题视为How do I install the OpenSSL C++ library on Ubuntu?
的后续问题我正在尝试在需要OpenSSL 1.0.0的Ubuntu 10.04 LTS上构建一些代码。
Ubuntu 10.04 LTS附带OpenSSL 0.9.8k:
$ openssl version
OpenSSL 0.9.8k 25 Mar 2009
所以在运行sudo apt-get install libssl-dev
并构建之后,运行ldd确认我已经在0.9.8中链接了:
$ ldd foo
...
libssl.so.0.9.8 => /lib/i686/cmov/libssl.so.0.9.8 (0x00110000)
...
libcrypto.so.0.9.8 => /lib/i686/cmov/libcrypto.so.0.9.8 (0x002b0000)
...
如何安装OpenSSL 1.0.0和1.0.0开发包?
更新:我在阅读SB的答案后(但在尝试之前)写了这个更新,因为很明显我需要解释下载和安装的明显解决方案OpenSSL 1.0.0不起作用:
成功执行以下操作(在INSTALL文件中推荐):
$ ./config
$ make
$ make test
$ make install
......我仍然得到:
OpenSSL 0.9.8k 25 Mar 2009
...和
$ sudo apt-get install libssl-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libssl-dev is already the newest version.
The following packages were automatically installed and are no longer required:
linux-headers-2.6.32-21 linux-headers-2.6.32-21-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
...和(只是为了确保)在重建我的代码之后,ldd仍然返回相同的东西。
更新#2 :我添加了“-I / usr / local / ssl / include”和“-L / usr / local / ssl / lib”选项(由{{3}建议) })我的makefile,但我现在得到一堆未定义的引用编译错误,例如:
/home/dspitzer/foo/foo.cpp:86: undefined reference to `BIO_f_base64'
/home/dspitzer/foo/foo.cpp:86: undefined reference to `BIO_new'
/ usr / local / ssl / include /只包含一个openssl目录(包含大量的.h文件),所以我也试过“-I / usr / local / ssl / include / openssl”,但是出现了同样的错误。
更新#3 :我尝试更改OpenSSL包含(例如):
#include <openssl/bio.h>
...为:
#include "openssl/bio.h"
...在.cpp源文件中,但仍然得到相同的未定义引用错误。
更新#4 :我现在意识到那些未定义的引用错误是链接器错误。如果我从我的Makefile中删除“-L / usr / local / ssl / lib”,我没有得到错误(但它链接到OpenSSL 0.9.8)。 / usr / local / ssl / lib /的内容是:
$ ls /usr/local/ssl/lib/
engines libcrypto.a libssl.a pkgconfig
我添加了-lcrypto,错误消失了。
答案 0 :(得分:18)
从here获取1.0.0a来源。
# tar -xf openssl-1.0.0a.tar.gz
# cd openssl-1.0.0a
# ./config
# sudo make install
默认情况下将其放在/ usr / local / ssl中
构建时,需要告诉gcc在/ usr / local / ssl / include中查找头文件,并与/ usr / local / ssl / lib中的libs链接。您可以通过执行以下操作来指定:
gcc test.c -o test -I/usr/local/ssl/include -L/usr/local/ssl/lib -lssl -lcrypto
编辑请勿覆盖任何系统库。最好将新库保留在/ usr / local中。覆盖Ubuntu默认值可能会危害您的健康并破坏您的系统。
另外,我在Ubuntu 10.04 VM中试过这个路径时错了。固定的。
注意,没有必要更改LD_LIBRARY_PATH,因为默认链接的openssl lib是静态库(至少在默认情况下 - 可能有一种方法可以在./config步骤中将它们配置为动态库)
您可能需要链接libcrypto,因为您正在使用libcrypto包中构建和定义的一些调用。 Openssl 1.0.0实际上构建了两个库,libcrypto和libssl。
编辑2 将-lcrypto
添加到gcc行。
答案 1 :(得分:4)
而不是:
$ ./config
$ make
$ make test
$ make install
执行:
$ sudo ./config --prefix=/usr
$ sudo make
$ sudo make test
$ sudo make install
这将帮助您更新到openssl 1.0.1g以修补CVE-2014-0160(Heartbleed)。
处理TLS心跳扩展的缺失边界检查可以是 用于向连接的客户端或服务器显示高达64k的内存。
只有1.0.1和1.0.2-beta版本的OpenSSL受到影响,包括 1.0.1f和1.0.2-beta1。
感谢Google Security的Neel Mehta发现了这个错误 Adam Langley和Bodo Moeller 准备修复。
受影响的用户应升级到OpenSSL 1.0.1g。用户无法立即 升级也可以使用-DOPENSSL_NO_HEARTBEATS重新编译OpenSSL。
1.0.2将在1.0.2-beta2中修复。
答案 2 :(得分:0)
以下是为我解决的问题: Upgrade latest version OpenSSL on Ubuntu
转录主要信息:
Download the OpenSSL v1.0.0g source:
$ wget http://www.openssl.org/source/openssl-1.0.0g.tar.gz
Unpack the archive and install:
$ tar xzvf openssl-1.0.0g.tar.gz
$ cd openssl-1.0.0g
$ ./config
$ make
$ make test
$ sudo make install
All files, including binaries and man pages are install under the directory /usr/local/ssl. To ensure users use this version of OpenSSL instead of the previous version you must update the paths for man pages and binaries.
Edit the file /etc/manpath.config adding the following line before the first MANPATH_MAP:
MANPATH_MAP /usr/local/ssl/bin /usr/local/ssl/man
Update the man database (I honestly can't remember and don't know for sure if this command was necessary - maybe try without it and at the end when testing if the man pages are still the old versions come back and run mandb):
sudo mandb
Edit the file /etc/environment and insert the path for OpenSSL binaries (/usr/local/ssl/bin) before the path for Ubuntu's version of OpenSSL (/usr/bin). My environment file looks like this:
PATH="/usr/local/sbin:/usr/local/bin:/usr/local/ssl/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
Logout and login and test:
$ openssl version
OpenSSL 1.0.0g 18 Jan 2012
Also test the man pages by running man openssl and at the very bottom in the left hand corner it should report 1.0.0g.
Note that although the users will now automatically use the new version of OpenSSL, existing programs (e.g. Apache) may not as they are linked against the libraries from the Ubuntu version.