1

I am trying to create a kong plugin. It works great when running as part of kong server but when I am trying to write some unit tests with busted, resty.openssl.digest func load fails. More specifically while loading the version.lua

I am not sure what exactly I am missing. Maybe some link which is supposed to link openSSL's C functions to lua.

Here is a minimal snippet to reproduce the problem.

package.cpath = package.cpath .. ';/usr/local/lib/lua/5.1/?.so'

local ffi = require("ffi")

ffi.cdef[[
  // 1.0
  unsigned long SSLeay(void);
  const char *SSLeay_version(int t);
  // >= 1.1
  unsigned long OpenSSL_version_num();
  const char *OpenSSL_version(int t);
  // >= 3.0
  const char *OPENSSL_info(int t);
  // BoringSSL
  int BORINGSSL_self_test(void);
]]

local num = ffi.C.OpenSSL_version_num()
print(num)

Error:

luajit: test.lua:18: Symbol not found: OpenSSL_version_num
stack traceback:
    [C]: in function '__index'
    test.lua:18: in main chunk
    [C]: at 0x55b71c78ffa4
4

1 回答 1

0

You should ffi.load your .so library before using functions from it.

local ffi = require("ffi")
ffi.cdef"long SSLeay(void);"  -- I have ver 1.0
ffi.load("ssl", true)
print(ffi.C.SSLeay())  --> 268439887LL

Note:
package.cpath is used only for require().
It does not affect FFI functions.

于 2021-04-24T23:03:17.480 回答