lua中的https请求

发布于 2024-12-18 09:17:05 字数 688 浏览 0 评论 0原文

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

local https = require("socket.http")
local resp = {}
local r, c, h, s = https.request{
    url = "https://my-server:443/example.php",
    sink = ltn12.sink.table(resp),
    protocol = "tlsv1"
}

服务器返回:

错误的请求 您的浏览器发送了该服务器无法理解的请求。 原因:您正在向启用 SSL 的服务器端口发送纯 HTTP。 请改用 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。使用浏览器中的相同 URL 或使用 wget 可以正常工作。

I am trying to retrieve a page on my SSL enabled server with a lua script. Important to note that the server has a self-signed certificate. No problem with certificate issued by a trusted CA.

local https = require("socket.http")
local resp = {}
local r, c, h, s = https.request{
    url = "https://my-server:443/example.php",
    sink = ltn12.sink.table(resp),
    protocol = "tlsv1"
}

The server returns:

Bad Request
Your browser sent a request that this server could not understand.
Reason: You're speaking plain HTTP to an SSL-enabled server port.
Instead use the HTTPS scheme to access this URL, please.

And on the server side, that request produce this entry in the Apache ssl_access.log

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

Furthermore, tcpdump shows that after the SYN-ACK handshake, no SSL 257 Client Hello is sent. Using the same URL from my browser or with wget works ok.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

回眸一笑 2024-12-25 09:17:05

正如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"
}

As Doug Currie said, you should use luasec. In order to enable https.request, you have to require the ssl.https module:

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"
}
与之呼应 2024-12-25 09:17:05

请参阅 此 lua-l 线程 描述如何添加支持对于使用 luasec 的 luasocket https 客户端。

See this lua-l thread describing how to add support for luasocket https client using luasec.

不即不离 2024-12-25 09:17:05

像这样

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"
}

like this

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"
}
终难遇 2024-12-25 09:17:05

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

它带有一个 luasocket/luasec 兼容接口。

A more modern solution is to use lua-http: https://github.com/daurnimator/lua-http

It comes with a luasocket/luasec compatible interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文