【原创】与 SSL 功能相关的问题

  1. 云栖社区>
  2. 博客>
  3. 正文

【原创】与 SSL 功能相关的问题

摩云飞 2016-05-11 13:42:56 浏览1664 评论0

摘要: SSL certificate problem 打算从 git 上下载 rabbitmq_in_action 的源码来做试验,出现如下问题:  ? 1 2 3 4 5 6 [root@Betty GIT_DIR]# git clone https://github.


SSL certificate problem 

打算从 git 上下载 rabbitmq_in_action 的源码来做试验,出现如下问题: 
1
2
3
4
5
6
[root@Betty GIT_DIR]# git clone https://github.com/rabbitinaction/sourcecode.git
Cloning into 'sourcecode'...
error: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed while accessing https://github.com/rabbitinaction/sourcecode.git/info/refs?service=git-upload-pack
fatal: HTTP request failed
[root@Betty GIT_DIR]#

网友推荐解决办法:

1.设置 shell 环境变量 
1
# export GIT_SSL_NO_VERIFY=true
2.设置 git 的环境变量 
1
# git config --global http.sslVerify false

采用第二种方法执行结果: 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@Betty GIT_DIR]# git config --global http.sslVerify false
[root@Betty GIT_DIR]#
[root@Betty GIT_DIR]# git clone https://github.com/rabbitinaction/sourcecode.git
Cloning into 'sourcecode'...
remote: Counting objects: 643, done.
remote: Compressing objects: 100% (318/318), done.
remote: Total 643 (delta 289), reused 640 (delta 289)
Receiving objects: 100% (643/643), 324.81 KiB | 113 KiB/s, done.
Resolving deltas: 100% (289/289), done.
[root@Betty GIT_DIR]#
[root@Betty GIT_DIR]# ll
total 4
drwxr-xr-x 10 root root 4096 Jul 15 12:33 sourcecode
[root@Betty GIT_DIR]#

注:在通过 yum 安装 openssl-devel 后使用 git 就不会报上述错误了。
1
2
3
4
5
6
7
8
[root@Betty GIT_DIR]# git clone https://github.com/rabbitinaction/sourcecode.git
Cloning into 'sourcecode'...
remote: Counting objects: 643, done.
remote: Compressing objects: 100% (318/318), done.
remote: Total 643 (delta 289), reused 640 (delta 289)
Receiving objects: 100% (643/643), 324.81 KiB | 26 KiB/s, done.
Resolving deltas: 100% (289/289), done.
[root@Betty GIT_DIR]#

certificate common name `xxx' doesn't match requested host name 'yyy' 

1
2
3
4
5
6
7
8
[root@Betty WGET_DIR]# wget https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz
--2013-07-15 12:53:14--  https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz
Resolving pypi.python.org... 103.245.222.184
Connecting to pypi.python.org|103.245.222.184|:443... connected.
ERROR: certificate common name `*.a.ssl.fastly.net' doesn't match requested host name `pypi.python.org'.
To connect to pypi.python.org insecurely, use `--no-check-certificate'.
Unable to establish SSL connection.
[root@Betty WGET_DIR]#

忽略证书检查

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@Betty WGET_DIR]# wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz
--2013-07-15 12:53:47--  https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz
Resolving pypi.python.org... 103.245.222.184
Connecting to pypi.python.org|103.245.222.184|:443... connected.
WARNING: certificate common name `*.a.ssl.fastly.net' doesn't match requested host name `pypi.python.org'.
HTTP request sent, awaiting response... 200 OK
Length: 247594 (242K) [application/x-gzip]
Saving to: `pip-1.3.1.tar.gz'
 
100%[==========================================================================================>] 247,594     60.9K/s   in 4.0s   
 
2013-07-15 12:53:52 (60.9 KB/s) - `pip-1.3.1.tar.gz' saved [247594/247594]
 
[root@Betty WGET_DIR]#

RuntimeError: Compression requires the (missing) zlib module 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@Betty WGET_DIR]# tar zxvf setuptools-0.9.1.tar.gz
[root@Betty WGET_DIR]# cd  setuptools-0.9.1
[root@Betty setuptools-0.9.1]# python setup.py install
...
creating 'dist/setuptools-0.9.1-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
Traceback (most recent call last):
  File "setup.py", line 198, in <module>
    dist = setuptools.setup(**setup_params)
  File "/usr/local/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/root/workstation/WGET_DIR/setuptools-0.9.1/setuptools/command/install.py", line 73, in run
    self.do_egg_install()
  File "/root/workstation/WGET_DIR/setuptools-0.9.1/setuptools/command/install.py", line 93, in do_egg_install
    self.run_command('bdist_egg')
  File "/usr/local/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/root/workstation/WGET_DIR/setuptools-0.9.1/setuptools/command/bdist_egg.py", line 246, in run
    dry_run=self.dry_run, mode=self.gen_header())
  File "/root/workstation/WGET_DIR/setuptools-0.9.1/setuptools/command/bdist_egg.py", line 545, in make_zipfile
    z = zipfile.ZipFile(zip_filename, mode, compression=compression)
  File "/usr/local/lib/python2.7/zipfile.py", line 732, in __init__
    "Compression requires the (missing) zlib module"
RuntimeError: Compression requires the (missing) zlib module
[root@Betty setuptools-0.9.1]#

      安装 setuptools-0.9.1 过程中报缺少 zlib 库。原因应该是,我在安装 Python2.7 的时候尚未安装 zlib 和 zlib-devel 。后续安装了这两个库,但此时 Python 中没有将其编译进去。所以需要重新编译 Python 。

若未安装可以使用如下命令安装:

1
# yum install zlib zlib-devel

重新安装 setuptools-0.9.1 成功。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[root@Betty setuptools-0.9.1]# python setup.py install
running install
running bdist_egg
running egg_info
writing requirements to setuptools.egg-info/requires.txt
writing setuptools.egg-info/PKG-INFO
writing top-level names to setuptools.egg-info/top_level.txt
writing dependency_links to setuptools.egg-info/dependency_links.txt
writing entry points to setuptools.egg-info/entry_points.txt
reading manifest file 'setuptools.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'setuptools.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
copying setuptools.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating 'dist/setuptools-0.9.1-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing setuptools-0.9.1-py2.7.egg
Copying setuptools-0.9.1-py2.7.egg to /usr/local/lib/python2.7/site-packages
Adding setuptools 0.9.1 to easy-install.pth file
Installing easy_install script to /usr/local/bin
Installing easy_install-2.7 script to /usr/local/bin
 
Installed /usr/local/lib/python2.7/site-packages/setuptools-0.9.1-py2.7.egg
Processing dependencies for setuptools==0.9.1
Finished processing dependencies for setuptools==0.9.1
[root@Betty setuptools-0.9.1]#

AttributeError: 'module' object has no attribute 'HTTPSConnection' 

在成功安装了 setuptools 和 pip 之后进行 pika 的安装: 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@Betty ~]# pip install pika==0.9.13
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 9, in <module>
    load_entry_point('pip==1.3.1', 'console_scripts', 'pip')()
  File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 378, in load_entry_point
  File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2566, in load_entry_point
  File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2260, in load
  File "/usr/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/__init__.py", line 11, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/usr/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/vcs/mercurial.py", line 9, in <module>
    from pip.download import path_to_url2
  File "/usr/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/download.py", line 72, in <module>
    class VerifiedHTTPSConnection(httplib.HTTPSConnection):
AttributeError: 'module' object has no attribute 'HTTPSConnection'
[root@Betty ~]#
网友说:因为 Python 编译安装时缺少 SSL 相关的库导致,所以需要安装 openssl-devel 后重新编译安装 Python 。 
1
[root@Betty ~]# yum -y install openssl-devel
安装成功后,重新编译安装 Python ,在执行 pip 命令安装 pika 成功。 
1
2
3
4
5
6
7
8
9
10
11
[root@Betty ~]# pip install pika==0.9.13
Downloading/unpacking pika==0.9.13
  Downloading pika-0.9.13.tar.gz (63kB): 63kB downloaded
  Running setup.py egg_info for package pika
     
Installing collected packages: pika
  Running setup.py install for pika
     
Successfully installed pika
Cleaning up...
[root@Betty ~]#

【云栖快讯】一站式开发者服务,海量学习资源免费学  详情请点击

网友评论