一、背景

在一次学习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的过程的更多相关文章

  1. CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境

    CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境 什么是LNMP? LNMP(别名LEMP)是指由Linux, Nginx, MySQL/MariaDB, PHP/ ...

  2. ubuntu上源码编译安装mysql5.7.27

    一.查看操作系统环境和目录结构,并创建mysql用户和组,以及规划安装mysql所需要的目录. #cat /etc/issue 查看发行版本信息: #cat  /proc/version 查看正在运行 ...

  3. debian 7上源码编译MongoDB 3.4版本

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 要想精通一个数据库,除了知道该数据库的功能特性.使用方法等,还需要能够看懂数据库源码,能够使用gdb工具对其 ...

  4. linux上源码编译安装mysql-5.6.28

    在 linux 上编译安装 mysql-.tar.gz http://www.mysql.com/ mysql下载地址: http://www.mysql.com/downloads/mysql/#d ...

  5. ubuntu 14.04上源码编译安装php7

    wget https://downloads.php.net/~ab/php-7.0.0alpha2.tar.bz2 //用winscp把下载好的文件上传到网站中 tar jxf php-7.0.0a ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. windows 10上源码编译dlib教程 | compile dlib on windows 10

    本文首发于个人博客https://kezunlin.me/post/654a6d04/,欢迎阅读! compile dlib on windows 10 Series Part 1: compile ...

随机推荐

  1. 51nod1584加权约数和

    题目大意: 求: \[ \sum_{i-1}^n\sum_{j=1}^nmax(i,j)\sigma(i*j) \] 题解 对于这个\(\max\),套路的把它转化成: \[ 2*\sum_{i=1} ...

  2. 封装类和非封装类比较相同不int和Integer

    A.所有和int(非封装类比较的,只要数值相同就行) B.io3由valueof弄出来的,所以和io1相同 C.io4是new出来的,所以地址不一样,就不相同 D.和A相同

  3. [CSP-S模拟测试]:e(树上主席树)

    题目传送门(内部题66) 输入格式 第一行,一个正整数$n$,一个自然数$q$,一个整数$type$.第二行,$n$个正整数,代表$a_i$.接下来$n-1$行,每行两个正整数$u$.$v$,代表树中 ...

  4. React 进阶设计与控制权问题

    控制权--这个概念在编程中至关重要.比如,"轮子"封装层与业务消费层对于控制权的"争夺",就是一个很有意思的话题.这在 React 世界里也不例外.表面上看,我 ...

  5. 模拟赛DAY1 T2腐草为萤

    2.腐草为萤(dzy.cpp/c) [题目背景] 纤弱的淤泥中妖冶颓废在季夏第三月最幼嫩的新叶连凋零都不屑何必生离死别——银临<腐草为萤> [问题描述] 扶苏给了你一棵树,这棵树上长满了幼 ...

  6. VMware 接入 Openstack — 使用 Openstack 创建 vCenter 虚拟机

    目录 目录 软件环境 前言 Openstack 接口驱动 使用 KVM 在 Compute Node 上创建虚拟机的流程 使用 VCDirver 在 vCenter 上创建虚拟机的流程 配置 vCen ...

  7. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_04 IO字节流_5_文件存储的原理和记事本打开文本显示原理

    原理 流对象指向这个文件a.txt 往文件中写数据,写的时候比较特殊 97转换成二进制是多少呢? 输入97然后选择二进制.转换后为 1100001 硬盘上实际存的是97的二进制 97查询阿斯克码表就是 ...

  8. abstract 和 interface 抽象类和接口的区别

    初版:以后再整理. 接口是公开的,里面不能有私有的方法或变量,是用于让别人使用的,而抽象类是可以有私有方法或私有变量的, 另外,实现接口的一定要实现接口里定义的所有方法,而实现抽象类可以有选择地重写需 ...

  9. Krustal重构树

    zz:https://blog.csdn.net/ouqingliang/article/details/81206050 Kruskal重构树基于Kruskal算法.在执行算法过程中,Kruskal ...

  10. 内网渗透 - 权限维持 - Linux

    1.预加载型动态链接库后门2.strace后门3.ssh后门4.OpnenSSH后门5.sshd软链接后门6.wrapper后门7.SUID后门8.inetd服务后门9.协议后门10.vim后门11. ...