一、背景

在一次学习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. es之关于consistency(数据一致性问题)

    Es集群内部是有一个约定是用来约束我们的写操作的,就是“一致性”: 也就是说:新建.索引.删除这些操作都是写操作,他们都有一个大前提: 当前的分片副本处于活跃状态的数量 >= int( (pri ...

  2. 纯css实现Material Design中的水滴动画按钮

    前言 大家平时应该经常见到这种特效,很炫酷不是吗 这是谷歌Material Design中最常见的特效了,市面上也有很多现成的js库,用来模拟这一特效.但是往往要引入一大堆js和css,其实在已有的项 ...

  3. Mysql中主键与索引

    摘自: https://www.cnblogs.com/wicub/p/5898286.html 一.什么是索引?索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没 ...

  4. oracle 表连接 - nested loop 嵌套循环连接

    一. nested loop 原理 nested loop 连接(循环嵌套连接)指的是两个表连接时, 通过两层嵌套循环来进行依次的匹配, 最后得到返回结果集的表连接方法. 假如下面的 sql 语句中表 ...

  5. Phaser 源码分析

    Phaser 一个可重用的同步屏障,功能上与 CyclicBarrier 和 CountDownLatch 类似,但是支持更灵活的使用. 把多个线程协作执行的任务划分为多个阶段,编程时需要明确各个阶段 ...

  6. 《JavaScript 高级程序设计》

    第 3 章 基本概念 3.5.2 位操作符 ECMAScript 中所有数值都是以 IEEE-754 64 位格式存储,但位操作符并不直接操作 64 位的值.而是先将 64 位的值转换成 32 位的整 ...

  7. import * as 用法

  8. Java Bean 使用包装类型 还是基本类型

    参考:实体类中用基本类型好,还是用包装类型好_ - 牵牛花 - 博客园 int优缺点 优点: 1.用于Bean的时候,有默认值.比如自己拼接sql增加一个User时,会方便很多,不过现在都用ORM框架 ...

  9. Flink流式引擎技术分析--大纲

    Flink简介 Flink组件栈 Flink特性 流处理特性 API支持 Libraries支持 整合支持 Flink概念 Stream.Transformation.Operator Paralle ...

  10. c# Thread5——线程同步之基本原子操作。Mutex互斥量的使用

    之前的博文也说到了如果多线程对于访问的公共资源操作都是原子操作,那么可以避免竞争条件.关于多线程的竞争可以百度. 1.执行最基本的原子操作 c#提供了一系列供我们使用的原子操作的方法和类型,比如我们的 ...