【问题标题】:Stuck with luasec Lua secure socket卡在 luasec Lua 安全套接字上
【发布时间】:2010-05-14 12:06:57
【问题描述】:

此示例代码失败:

 require("socket")
 require("ssl")

-- TLS/SSL server parameters
 local params = {
 mode = "server",
 protocol = "sslv23",
 key = "./keys/server.key",
 certificate = "./keys/server.crt",
 cafile = "./keys/server.key",
 password = "123456",
 verify = {"peer", "fail_if_no_peer_cert"},
 options = {"all", "no_sslv2"},
 ciphers = "ALL:!ADH:@STRENGTH",
 }

local socket = require("socket")
local server = socket.bind("*", 8888)
local client = server:accept()
client:settimeout(10)

 -- TLS/SSL initialization
local conn,emsg = ssl.wrap(client, params)
print(emsg)
 conn:dohandshake()
 --
 conn:send("one line\n")
 conn:close()

请求

https://localhost:8888/

输出

error loading CA locations ((null))
lua: a.lua:25: attempt to index local 'conn' (a nil value)
stack traceback:
        a.lua:25: in main chunk
        [C]: ?

信息不多。知道如何追溯到问题吗?

更新

现在知道了:服务器模式不需要 cafile 参数:

local params = {
 mode = "server",
 protocol = "sslv23",
 key = "./keys/server.key",
 certificate = "./keys/server.crt",
 password = "123456",
 options = {"all", "no_sslv2"},
 ciphers = "ALL:!ADH:@STRENGTH",
 }

【问题讨论】:

标签: lua openssl


【解决方案1】:

LuaSec 是 OpenSSL 的绑定,因此您收到的错误(加载 CA 位置时出错)意味着 OpenSSL 库无法读取您的 CA 文件。您确定它们在当前目录中并且具有适当的权限吗?

编辑:根据 LuaSec 消息来源,它目前仅使用 PEM 格式作为私钥。确保私钥存储为 PEM,而不是 DER。

【讨论】:

    【解决方案2】:

    CAFile 包含您的服务器或客户端信任的证书集 (.crt)。你把钥匙(.key)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      相关资源
      最近更新 更多