使用luasec记录SSL会话密钥

时间:2019-01-17 02:52:28

标签: lua luasec

我正在尝试使用lua和luasec调用Web服务。 SSL部分似乎可以正常工作,但是我从服务器返回了一条失败消息。我想使用Wireshark捕获SSL交换,我认为这需要获取SSL会话密钥。我知道OpenSSL支持会话密钥记录,但是如何通过lua / luasec代码实现它呢?

我的代码:

false

这是脚本输出:

require('ltn12')
local https = require('ssl.https')

-- 5 Second timeout
https.TIMEOUT = 5

  local response_body = {}
  local request_body = '{"lockId": "3","eventType": "LOCKED","eventDateTime": "'..os.date("%Y-%m-%d %X")..'","eventUser": "KG - Test"}'
  local request_headers = {
      ["Content-Length"] = string.len(request_body),
      ["Content-Type"] = "application/json"
    }
  print ('Request Body: '..request_body)
  print ('Request Headers:')
  local k,v
  for k,v in pairs(request_headers) do
    print(k,v)
  end

  local curlStatus, httpStatus, responseHeaders, responseStatus = https.request{
    url = 'https://somedomain.com/rest/MyService/logevent',
    method = 'POST',
    headers = request_header,
    protocol = 'tlsv1_2',
    verify = 'none',
    key = 'server.pem',
    certificate = 'server.crt',
    source = ltn12.source.string(request_body),
    sink = ltn12.sink.table(response_body)
  }
  print('command status: '..curlStatus)
  print('http status: '..httpStatus)
  print('response status: '..responseStatus)
  print('response headers: ')
  for k,v in pairs(responseHeaders) do
    print('  '..k,v)
  end
  print('response body: ')
  for k,v in pairs(response_body) do
    print('  '..k,v)
  end

作为旁注,我编写了一个powershell脚本来调用此服务并传递相同的请求正文,然后获得成功响应。我想比较Wireshark中的两个调用,以便找出两者之间的区别。

0 个答案:

没有答案