openssl 代码分析--- SSL_connect .

SSL_connect函数会负责完成ssl handshake过程,那么我们来看看他是怎么实现的。

SSL_connect函数本身的code非常简单,只有短短几行,但是最后通过函数指针调用来实现它的功能。这个函数指针是s->method->ssl_connect,此处method即为之前介绍的初始化到SSL_Ctx中的method。我们就看看常用的SSLv3的method, SSLv3_client_method。在SSLv3_client_method里面,首先会将method初始化为一个base的ssl v3 method,里面定义了一组ssl v3会用到的函数指针,然后将ssl_connect定义为ssl3_connect。 所以之前SSL_connect最终要调用的函数指针即为ssl3_connect。

然后我们进入ssl3_connect中看看到底是如何实现。

这个函数很长,但是基本结构也很清晰,首先是一些基本的初始化操作,然后就是一个for循环,且没有循环变量,也就是这个循环自己不会结束,需要通过循环体内达到某种状态自己结束,我想肯定是ssl handshake成功或是失败之后就会跳出这个循环的。

在这个for循环中,核心的又是一个大大的switch语句,根据当前ssl的state进入不同的处理逻辑,那么这显然就是ssl client的handshake 状态处理机了。

下面就是ssl client的状态机,可以对照之前的ssl handshake图。

SSL Client

你遇到的错误: ``` ./configure: error: invalid option "--without-http_ssl_module" ``` 说明你在 Nginx 源码中使用了 **不被支持或已被废弃的 `--without-http_ssl_module` 选项**。 --- ## 🔍 根本原因 Nginx 的模块系统从 **1.11.x 版本开始进行了重构**,许多原本可以通过 `--without-http_xxx_module` 禁用的模块(尤其是核心模块)变成了 **内置不可关闭**,或者需要通过其他方式控制。 特别是: > ❌ `--without-http_ssl_module` 是一个 **无效且不存在的标准选项** 因为: - HTTPS/SSL 功能是由多个组件组成的(如 `ngx_http_ssl_module`),但它不是一个独立可开关的 HTTP 模块。 - 实际上,SSL 支持依赖于外部库(OpenSSL、BoringSSL 等),而不是简单的模块开关。 - 要禁用 SSL,正确的方法是 **不要链接 OpenSSL 库**,而不是传入 `--without-http_ssl_module`。 --- ## ✅ 正确禁用 SSL 支持的方法 要让 Nginx **不支持 HTTPS 和 SSL/TLS**,你应该: ### ✔️ 方法一:不引入 OpenSSL(推荐) 只要你不指定 `--with-http_ssl_module`,并且确保没有安装 PCRE/OpenSSL 开发包,Nginx 就不会启用 SSL。 但如果你想 **明确禁止** 它被启用,可以这样做: ```bash ./configure \ --prefix=/opt/nginx \ --with-cc=aarch64-linux-gnu-gcc \ --without-pcre \ --without-http_rewrite_module \ --without-http_gzip_module \ ... ``` ✅ 不要加任何与 SSL 相关的 `--with-http_ssl_module`,这样默认就不会包含 SSL 支持。 如果你之前手动添加了 `--with-http_ssl_module`,请删除它。 --- ### 🛠️ 验证是否真的没启用 SSL 编译完成后检查: ```bash grep -r "NGX_HTTP_SSL" objs/autoconf.h ``` 如果输出为空,说明没有启用 SSL 支持。 也可以查看生成的二进制是否有 SSL 符号: ```bash aarch64-linux-gnu-readelf -s objs/nginx | grep SSL ``` 如果没有或只有少量无关符号,说明成功去除了 SSL--- ## ⚠️ 常见误解:哪些 `--without-http_xxx_module` 是无效的? | 错误写法 | 是否有效 | 正确做法 | |--------|--------|--------| | `--without-http_ssl_module` | ❌ 不存在 | 不使用 `--with-http_ssl_module` 即可 | | `--without-http_rewrite_module` | ✅ 存在(但依赖 PCRE) | 同时禁用 PCRE 更彻底 | | `--without-http_gzip_module` | ✅ 存在(依赖 zlib) | 不链接 zlib 并关闭模块 | | `--without-http_proxy_module` | ✅ 存在 | 可安全关闭 | | `--without-mail_smtp_module` | ✅ 存在 | 需配合 `--without-mail` | 📌 所以你不能“禁用”一个从未“开启”的功能。SSL 模块默认是关闭的,除非你主动开启它。 --- ## ✅ 推荐配置(完全无 SSL / 无 PCRE / 极简版) ```bash CC=aarch64-linux-gnu-gcc \ CXX=aarch64-linux-gnu-g++ \ AR=aarch64-linux-gnu-ar \ RANLIB=aarch64-linux-gnu-ranlib \ ./configure \ --prefix=/opt/nginx \ --with-cc=aarch64-linux-gnu-gcc \ --with-cpp=aarch64-linux-gnu-cpp \ --with-ld-opt="-static" \ --without-pcre \ --without-http_rewrite_module \ --without-http_gzip_module \ --without-http_proxy_module \ --without-http_fastcgi_module \ --without-http_uwsgi_module \ --without-http_scgi_module \ --without-http_memcached_module \ --without-http_empty_gif_module \ --without-http_browser_module \ --without-http_geo_module \ --without-http_map_module \ --without-http_split_clients_module \ --without-http_referer_module \ --without-http_limit_conn_module \ --without-http_limit_req_module \ --without-http_auth_basic_module \ --without-http_access_module \ --without-http_realip_module \ --without-http_addition_module \ --without-http_degradation_module \ --without-http_flv_module \ --without-http_mp4_module \ --without-http_sub_module \ --without-http_slice_module \ --without-mail \ --without-http_upstream_ip_hash_module \ --without-http_upstream_least_conn_module \ --without-http_upstream_keepalive_module \ --without-http_upstream_zone_module \ --without-threads \ --without-select_module \ --without-poll_module \ --without-kqueue_module \ --without-eventport_module \ --without-file_aio \ --without-http_dav_module \ --without-http_ssi_module \ --crossbuild=Linux::x86_64::unknown ``` > ✅ 这个配置天然就不包含 SSL 支持,无需额外 `--without-http_ssl_module` --- ## 💡 如何确认你的 Nginx 是否真的不含 SSL? 运行以下命令: ```bash strings objs/nginx | grep -i ssl ``` 如果输出很少或只有类似 `"SSL"` 字符串(可能是日志提示文字),而没有函数名如 `SSL_accept`、`SSL_connect`,说明未链接 OpenSSL。 进一步验证: ```bash aarch64-linux-gnu-readelf -d objs/nginx | grep ssl ``` 不应出现对 `libssl.so` 或 `libcrypto.so` 的依赖。 --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值