请叫我峰子:
感受VPS建站的乐趣。

升级WORDPRESS错误”ASN1_VERIFY:UNKNOWN…”的解决方法

原标题:【Git笔记】"error:0D0890A1:asn1encodingroutines:ASN1_verify:unknownmessagedigestalgorithm"的解决方法

备注:本笔记所描述的问题的前提是机器上已安装成功git且通过配置ca证书支持以https方式获取远程仓库,如果使用git时碰到这篇文章描述的问题,那么按那篇文章给出的办法解决即可。

最近从github clone repo时,git clone命令报错如下(以vim代码补全插件youcompleteme为例):

1
2
3
$ git clone https://github.com/Valloric/YouCompleteMe.git
Cloning into 'YouCompleteMe'...
fatal: unable to access 'https://github.com/Valloric/YouCompleteMe.git/': error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm

由于git底层是用本机安装的curl去fetch远程repo的,所以我们可以打开curl调试选项查看具体的错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ export GIT_CURL_VERBOSE=1
$ git clone https://github.com/Valloric/YouCompleteMe.git
Cloning into 'YouCompleteMe'...
* Couldn't find host github.com in the .netrc file, using defaults
* About to connect() to github.com port 443
*   Trying 192.30.252.129... * connected
* Connected to github.com (192.30.252.129) port 443
* successfully set certificate verify locations:
*   CAfile: /home/slvher/tools/https-ca/github-ca/ca-bundle.crt
  CApath: none
* error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm
* Closing connection #0
fatal: unable to access 'https://github.com/Valloric/YouCompleteMe.git/': error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm

从verbose输出可知,git已经借助curl成功连接上github.com,但以https方式clone remote repo时,由于本地配置的CAfile无法识别github提供的ssl认证算法,所以本次session失败退出。
从stackoverflow的这个帖子(Can not use “git pull” beacause of some error)得知,github在https的ssl认证中,采用的是sha256算法,而这个sha256算法是openssl从version 0.9.8o才引入的。
用下面的命令验证我机器(公司统一的开发环境)上openssl的版本,发现居然是0.9.7a,这个版本不支持github采用的sha256算法,真心蛋疼。。。

1
2
$ python -c 'import ssl; print ssl.OPENSSL_VERSION'
OpenSSL 0.9.7a Feb 19 2003

既然git clone报错的原因已清楚,解决思路就明确了,可以执行下面的步骤进行修复。

1. 更新机器上的openssl库至v0.9.8o或更高版本
a. 从openssl官网下载合适的版本,例如我下载的是openssl-1.0.1j.tar.gz
b. 解压上步下载的压缩包,cd至解压目录
c. 在当前shell终端执行以下命令

1
2
3
4
5
$ export CFLAGS="-fPIC"
$ ./config shared --openssldir=/home/slvher/tools/openssl-1.0.1j/  ## 无root权限,故由openssldir指定自定义安装路径
$ make depend
$ make all
$ make install

openssl源码编译/安装成功后,可在openssldir指定的目录下看到下面的目录结构

1
2
$ ls
bin  certs  include  lib  man  misc  openssl.cnf  private

我们需要的共享库libssl.so文件在lib目录下。
备注1:更新版本时需注意曾在2014年4月爆发的针对openssl version 1.0.1的heartbleed漏洞,所以需要下载openssl ver 1.0.1g或更高版本。
备注2:这步安装openssl至非系统默认目录是由于我没有root权限,不能覆盖系统默认的openssl版本,而且冒然升级也可能影响到机器上其他用户。这也直接导致本文的解决方法还需要完成下面3个步骤。

2. 重新编译curl或替换curl依赖的openssl共享库
显然,相比于重新源码编译curl,直接替换curl依赖的libssl.so更方便,借助LD_PRELOAD即可实现目的:

1
2
$ export LD_PRELOAD=/home/slvher/tools/openssl-1.0.1j/lib/libssl.so:/home/slvher/tools/openssl-1.0.1j/lib/libcrypto.so
$ python -c 'import ssl; print ssl.OPENSSL_VERSION' ## 验证是否替换成功,我机器的输出为OpenSSL 1.0.1j 15 Oct2014,可见成功替换

 

3. 验证git clone是否能成功执行

1
2
3
4
5
6
7
8
$ git clone https://github.com/Valloric/YouCompleteMe.git
Cloning into 'YouCompleteMe'...
remote: Counting objects: 29685, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 29685 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (29685/29685), 28.81 MiB | 5.77 MiB/s, done.
Resolving deltas: 100% (9501/9501), done.
Checking connectivity... done.

至此,目的达成。世界真美妙 ^_^

4. 将替换openssl库的过程自动化
第2步通过设置环境变量LD_PRELOAD实现了更新curl依赖的libssl.so共享库版本的目的。但这个替换动作只对当前终端的session有效,当该session窗口关闭或切换到其它窗口时,执行git clone还是会出错。
将这种替换操作自动化的一个方法是在~/.bash_profile中将LD_PRELOAD设置为新版libssl.so的路径并export该变量。但这种方式可能会影响当前用户下的所有模块。
这里我借助bash的alias命令对git clone的动作做改写:
1) 打开~/.bashrc文件
2) 给git命令设置alias

1
alias git='export LD_PRELOAD=/home/slvher/tools/openssl-1.0.1j/lib/libssl.so:/home/slvher/tools/openssl-1.0.1j/lib/libcrypto.so; git'

3) 保存退出
4) 在其他终端窗口执行source ~/.bashrc
5) 在该窗口验证git clone是否正常,可以验证,alias设置是成功的

 

至此,终于大功告成。

赞(0) 打赏
转载请注明:峰网博客 » 升级WORDPRESS错误”ASN1_VERIFY:UNKNOWN…”的解决方法

评论 抢沙发

评论前必须登录!

 

网站建设

企业专线联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏