2010-05-14 80 views
1

此示例代碼失敗卡住:與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]: ? 

不是非常多的信息。任何想法如何追溯到這個問題?

更新

現在得到這樣的:憑證檔案錯誤參數是沒有必要的服務器模式:

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

請不要大寫Lua。它不是縮寫:http://lua.org/about.html#name – 2010-05-14 16:59:07

回答

3

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

編輯:根據LuaSec來源,它目前只使用PEM格式的私鑰。確保私鑰存儲爲PEM,而不是DER。

0

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