在 Lua 中进行 HTTPS 请求

我正在尝试使用 lua 脚本从我的 SSL 启用的服务器检索页面。需要注意的是,该服务器具有自签名证书。使用受信任的 CA 发行的证书没有问题。

服务器返回:

错误请求 您的浏览器发送了一个服务器无法理解的请求。 原因:您正在使用纯 HTTP 与启用 SSL 的服务器端口通信。 请改用 HTTPS 访问此 URL。

而且,在服务器端,该请求在 Apache ssl_access.log 中产生以下条目:

192.168.0.150 - - [27/Nov/2011:16:32:07 +0100] "GET /" 400 529 "-" "-"

此外,tcpdump 显示,在 SYN-ACK 握手之后,未发送 SSL 257 Client Hello。使用浏览器或使用 wget 从同一 URL 进行操作均正常。

原文链接 https://stackoverflow.com/questions/8286677

点赞
stackoverflow用户33252
stackoverflow用户33252

参考 lua-l thread 中的说明,可以利用 luasec 添加支持 luasocket 的 https 客户端。

2011-11-27 16:46:04
stackoverflow用户221509
stackoverflow用户221509

正如Doug Currie所说的,你应该使用luasec。为了启用https.request,你必须要求ssl.https模块:

local https = require 'ssl.https'
local r, c, h, s = https.request{
    url = "https://my-server:443/example.php",
    sink = ltn12.sink.table(resp),
    protocol = "tlsv1"
} 
2011-11-27 21:18:02
stackoverflow用户5052781
stackoverflow用户5052781
```lua
local https = require("ssl.https")
local one, code, headers, status = https.request{
       url = "https://www.test.com",
       key = "/root/client.key",
       certificate="/root/client.crt",
       cafile="/root/ca.crt"
}

```lua
local https = require("ssl.https")
local one, code, headers, status = https.request{
       url = "https://www.test.com",
       key = "/root/client.key",
       certificate="/root/client.crt",
       cafile="/root/ca.crt"
}
2015-07-17 07:14:47
stackoverflow用户282536
stackoverflow用户282536

一个更现代的解决方案是使用 lua-http:https://github.com/daurnimator/lua-http

它带有 luasocket/luasec 兼容的接口。

2016-07-23 00:14:54