被困在luasec Lua安全套接字中

这段示例代码失败了:

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

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

点赞
stackoverflow用户221509
stackoverflow用户221509

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

编辑:根据LuaSec的源代码,它目前仅使用PEM格式的私钥。请确保私钥以PEM格式存储,而不是DER格式。

2010-05-14 12:34:35
stackoverflow用户363556
stackoverflow用户363556

CAFile 包含你的服务端或客户端所信任的证书集合(.crt)。而密钥文件则需放在同一目录下并以 .key 结尾。

2010-06-10 14:38:50