记一次在mac上源码编译curl,使其支持NSS的过程
一、背景
在一次学习https原理的过程中,希望客户端指定特定的cipher suites来抓包分析SSL/TLS的握手过程,就想到了使用curl工具,而不是使用浏览器。
接下来使用man curl找到—ciphers选项,同时man文档中同时提到了需要到https://curl.haxx.se/docs/ssl-ciphers.html这个地方去寻找具体的ciphers suites列表,从中我们可以看到这样一句话:The names of the known ciphers differ depending on which TLS backend that libcurl was built to use. This is an attempt to list known cipher names.大概意思就是不同的TLS实现(包括openssl、NSS、LibreSSL等),即使是同一个ciphers,curl工具能识别的名称也是不同的。
在不同的操作系统中,系统自带的curl工具,使用的SSL库是不同的,可以使用curl -V来查看:
1.1、mac自带的curl

1.2、redhat系列系统自带的curl

由于在上面提到的文档中,没有与LlibreSSL的ciphers有关的介绍,因此决定在mac上源码编译curl,使其支持NSS。
二、环境介绍
| 环境 | 版本 |
|---|---|
| 操作系统 | macOS Mojave(10.14) |
| curl | 7.65.1 |
| NSS | 3.44 |
三、过程
3.1、下载curl和nss源码包
在https://curl.haxx.se/download/中选择对应的curl源码包进行下载
在https://ftp.mozilla.org/pub/security/nss/releases/中选择对应的nss源码包进行下载
Because NSS depends on the base library NSPR, you should download the archive that combines both NSS and NSPR:因为nss依赖NSPR,所以应该选择NSS和NSPR的组合包,例如:https://ftp.mozilla.org/pub/security/nss/releases/NSS_3_45_RTM/src/nss-3.44-with-nspr-4.21.tar.gz
3.2、安装NSS
3.2.1、源码编译
tar -zxf nss-3.44-with-nspr-4.21.tar.gz
cd nss-3.44
make -C nss nss_build_all USE_64=1
编译过程参照https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Building ,编译时会遇到下面的报错,暂时还没有解决掉,之所以还要进行这个明知会失败的操作,是因为下面还需要从这个编译生成的dist目录中复制一些.h文件
Undefined symbols for architecture x86_64:
"_PK11_FindRawCertsWithSubject", referenced from:
nss_test::PK11FindRawCertsBySubjectTest_TestNoCertsImportedNoCertsFound_Test::TestBody() in pk11_find_certs_unittest.o
nss_test::PK11FindRawCertsBySubjectTest_TestOneCertImportedNoCertsFound_Test::TestBody() in pk11_find_certs_unittest.o
nss_test::PK11FindRawCertsBySubjectTest_TestMultipleMatchingCertsFound_Test::TestBody() in pk11_find_certs_unittest.o
nss_test::PK11FindRawCertsBySubjectTest_TestNoCertsOnInternalSlots_Test::TestBody() in pk11_find_certs_unittest.o
nss_test::PK11FindRawCertsBySubjectTest_TestFindEmptySubject_Test::TestBody() in pk11_find_certs_unittest.o
nss_test::PK11FindRawCertsBySubjectTest_TestSearchForNullSubject_Test::TestBody() in pk11_find_certs_unittest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Darwin18.0.0_cc_64_DBG.OBJ/pk11_gtest] Error 1
make[1]: *** [libs] Error 2
make: *** [libs] Error 2
3.2.2、brew安装
$ brew install nss
#设置环境变量
export LDFLAGS="-L/usr/local/opt/nss/lib"
export CPPFLAGS="-I/usr/local/opt/nss/include/nss"
3.2.3、复制.h文件
#还是进入到上面由nss-3.44-with-nspr-4.21.tar.gz解压出来的那个nss-3.44目录中
cd nss-3.44
cp -r dist/Darwin18.0.0_cc_64_OPT.OBJ/include/* /usr/local/opt/nss/include/nss/
上面的Darwin18.0.0_cc_64_OPT.OBJ这一级目录名与自己的操作系统版本有关,之所以要进行复制这个操作,是因为brew安装的nss会缺少很多
.h文件,导致编译curl过程中引用NSS会失败,原因暂时未知。
3.3、安装curl
tar -zxf curl-7.65.1.tar.gz
cd curl-7.65.1
./configure --prefix=/usr/local/opt/curl --without-ssl --with-nss=/usr/local/opt/nss/
make && make install
3.4、验证

四、关于根证书库的问题
上面基于NSS源码编译生成的curl没有附带ca证书库,在使用curl访问https的url时,会卡在证书验证的环节上,如下图所示:

有人可能会说,可以给curl配置CA证书库,但是由于一些原因,好像在mac平台上暂时无法实现,可以见下面的说明:
If libcurl was built with NSS support, then depending on the OS distribution, it is probably required to take some additional steps to use the system-wide CA cert db. RedHat ships with an additional module, libnsspem.so, which enables NSS to read the OpenSSL PEM CA bundle. On openSUSE you can install p11-kit-nss-trust which makes NSS use the system wide CA certificate store. NSS also has a new database format
Starting with version 7.19.7, libcurl automatically adds the 'sql:' prefix to the certdb directory (either the hardcoded default /etc/pki/nssdb or the directory configured with SSL_DIR environment variable). To check which certdb format your distribution provides, examine the default certdb location: /etc/pki/nssdb; the new certdb format can be identified by the filenames cert9.db, key4.db, pkcs11.txt; filenames of older versions are cert8.db, key3.db, secmod.db.
摘自:https://curl.haxx.se/docs/sslcerts.html ,大致意思就是redhat系列的操作系统会有一个额外的模块libnsspem.so(/usr/lib64/libnsspem.so),可以使NSS能够使用系统级的CA证书库,openSUSE操作系统也可以通过安装p11-kit-nss-trust来实现,mac系统中好像没有相应的支持,上面的截图中有一个错误警告"WARNING: failed to load NSS PEM library libnsspem.so. Using OpenSSL PEM certificates will not work",curl好像默认是去尝试加载libnsspem.so这个库文件。
因此在使用这个curl时,需要加上-k参数来跳过证书验证的环节,也因此,我也仅仅只是用这个curl工具做一些特定的测试。
记一次在mac上源码编译curl,使其支持NSS的过程的更多相关文章
- CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境
CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境 什么是LNMP? LNMP(别名LEMP)是指由Linux, Nginx, MySQL/MariaDB, PHP/ ...
- ubuntu上源码编译安装mysql5.7.27
一.查看操作系统环境和目录结构,并创建mysql用户和组,以及规划安装mysql所需要的目录. #cat /etc/issue 查看发行版本信息: #cat /proc/version 查看正在运行 ...
- debian 7上源码编译MongoDB 3.4版本
此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 要想精通一个数据库,除了知道该数据库的功能特性.使用方法等,还需要能够看懂数据库源码,能够使用gdb工具对其 ...
- linux上源码编译安装mysql-5.6.28
在 linux 上编译安装 mysql-.tar.gz http://www.mysql.com/ mysql下载地址: http://www.mysql.com/downloads/mysql/#d ...
- ubuntu 14.04上源码编译安装php7
wget https://downloads.php.net/~ab/php-7.0.0alpha2.tar.bz2 //用winscp把下载好的文件上传到网站中 tar jxf php-7.0.0a ...
- windows 10 上源码编译OpenCV并支持CUDA | compile opencv with CUDA support on windows 10
本文首发于个人博客https://kezunlin.me/post/6580691f/,欢迎阅读! compile opencv with CUDA support on windows 10 Ser ...
- Ubuntu 16.04上源码编译和安装pytorch教程,并编写C++ Demo CMakeLists.txt | tutorial to compile and use pytorch on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/54e7a3d8/,欢迎阅读最新内容! tutorial to compile and use pytorch on ubuntu ...
- ubuntu 16.04上源码编译dlib教程 | compile dlib on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/c6ead512/,欢迎阅读! compile dlib on ubuntu 16.04 Series Part 1: compil ...
- windows 10上源码编译dlib教程 | compile dlib on windows 10
本文首发于个人博客https://kezunlin.me/post/654a6d04/,欢迎阅读! compile dlib on windows 10 Series Part 1: compile ...
随机推荐
- js中获取当前系统时间
使用var myDate = new Date();//获取系统当前时间 获取特定格式的时间: 1 myDate.getYear(); //获取当前年份(2位) 2 myDate.getFullYea ...
- Charles抓取手机https请求
1.下载Charles工具,3.92破解版:http://pan.baidu.com/s/1cko2L4 密码:chmy 2.安装SSL证书,默认安装就可以 3.证书安装成功后,点击详细信息--> ...
- CharacterEncodingFilter详解
字符编码过滤器 (Spring框架对字符编码的处理) 基于函数回调,对所有请求起作用,只在容器初始化时调用一次,依赖于servlet容器. web.xml配置文件 <filter> &l ...
- angular项目开发
第 1 步:安装 Angular CLI 你可以使用 Angular CLI 来创建项目.生成应用和库代码,以及执行各种持续开发任务,比如测试.打包和部署. 全局安装 Angular CLI. 要使用 ...
- Solr单机环境搭建及部署
一.定义 官网的定义: Solr是基于Lucene构建的流行,快速,开放源代码的企业搜索平台.它具有高度的可靠性,可伸缩性和容错能力,可提供分布式索引,复制和负载平衡查询,自动故障转移和恢复,集中式配 ...
- 《HTML5 高级程序设计》
第一章 HTML5 概述 开发 HTML5 的组织 Web Hypertext Application Technology Working Group (WHATWG):开发 HTML 和 Web ...
- 控制 input 输入框不能输入中文,即不能在输入框中使用输入法
设置输入框的样式,代码如下 <span style="font-size:18px;"><input type = "text" id = & ...
- QCOW2/RAW/qemu-img 概念浅析
目录 目录 扩展阅读 RAW QCOW2 QEMU-COW 2 QCOW2 Header QCOW2 的 COW 特性 QCOW2 的快照 qemu-img 的基本使用 RAW 与 QCOW2 的区别 ...
- vue-methods方法与computed计算属性的差别
好吧,我就是单纯的举个例子:实现显示变量 message 的翻转字符串 第一种:methods:我们可以通过在表达式中调用方法来达到同样的效果: 第二种:computed:计算属性 上面的2中方法都实 ...
- python基础-7模块,第三方模块安装方法,使用方法。sys.path os sys time datetime hashlib pickle json requests xml
模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要多个函数才 ...