簡體   English   中英

卡在luasec Lua安全插座上

[英]Stuck with luasec Lua secure socket

此示例代碼失敗:

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

LuaSec是OpenSSL的綁定,因此,您遇到的錯誤( 加載CA位置錯誤 )意味着OpenSSL庫無法讀取您的CA文件。 您確定它們在當前目錄中並且具有適當的權限嗎?

編輯:根據LuaSec消息來源,它目前僅將PEM格式用於私鑰。 確保私鑰存儲為PEM,而不是DER。

CAFile包含服務器或客戶端信任的一組證書(.crt)。 您將密鑰(.key)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM