简体   繁体   English

卡在luasec Lua安全插座上

[英]Stuck with luasec Lua secure socket

This example code fails: 此示例代码失败:

 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()

request 请求

https://localhost:8888/

output 产量

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]: ?

Not very much info. 没有太多的信息。 Any idea how to trace down to the problem ? 知道如何找到问题所在吗?

Update 更新

Got this now: the cafile parameter is not necessary for server mode: 现在知道了:服务器模式下不需要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",
 }

LuaSec is a binding for OpenSSL, so the error you are getting ( error loading CA locations ) means that the OpenSSL library cannot read your CA files. LuaSec是OpenSSL的绑定,因此,您遇到的错误( 加载CA位置错误 )意味着OpenSSL库无法读取您的CA文件。 Are you sure they are in the current directory and with proper permissions? 您确定它们在当前目录中并且具有适当的权限吗?

EDIT: According to LuaSec sources, it currently uses only the PEM format for private key. 编辑:根据LuaSec消息来源,它目前仅将PEM格式用于私钥。 Ensure that the private key is stored as PEM, not DER. 确保私钥存储为PEM,而不是DER。

CAFile contains the set of certificates (.crt) that your server or client trust. CAFile包含服务器或客户端信任的一组证书(.crt)。 You put the key (.key). 您将密钥(.key)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM