Error
/root/GmSSL-3.1.1/src/sm2_lib.c:683:sm2_do_decrypt():
/root/GmSSL-3.1.1/src/sm2_lib.c:852:sm2_decrypt():
Descryption
I wrote a lua encapsulation based on the GMSSSL library and uses FFI to load the GMSSSL library to implement GM functionality. This lua code which I wrote in a Windows environment and runs correctly on Windows。
the test.lua run correct when i tried run the lua encapsulation on arm64 machine command line: luajit test.lua.
but sm2_do_decrypt got error when i require the encapsulation in ngx.lua code and use it.
my lua encapsulation
lua-gmssl
Successful scenarios
machine: x86-64
os: windows10
gmssl version: gmssl.3.1.1-win64
luajit version: LuaJIT 2.1.ROLLING (installed via openresty)
openresty version: 1.25.3.2 win64
test with command line
command line: luajit test.lua
result: all test complete
test with openresty
code in openresty:
local sm2 = require "gmssl.sm2"
local sm4 = require "gmssl.sm4"
local base64 = require "gmssl.base64"
local data = "AHoweAIgAmA/Ay6tUJ6wEjLGNmID8NJ5wvSk03OSeiT/0ClOTTQCIAN/uqrs3QCudAwIQKeCja1rUa5XPrBOYLfIIzy1YAP0BCCGkIljCEOB/Rd8fBqMpmI49i5jJvQkK0XlWr0ePkhrEAQQIvgujbKicRBkfBRD5oX/TSvq4Yleo71W10CfjE8iXu7eC2N7bFQp5SFL/hQjjEYD3BHB0f2NSJ7bZns53fAFYZBMIcvVW8yEPG8yzdg7dz6KoLTZWRul2Fl68zzUBUN48dLnipP9EmGggzYvu4+y24IuiyN4NIxiwmfJcknckNdlcWZ3TjKyGfhtMnDU0Ewk7wNvVTLnGbDU5ZTUZuK2ID6nrwYjaXHhSJr6gCJsbBU="
local priv = "MIGTAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBHkwdwIBAQQg7+l7+Do3/WJQVd1XN4RcCF/+PJnYw7EP673OUrjwlPigCgYIKoEcz1UBgi2hRANCAARGagizACYd0uNP56QodeW5C4+Qwy4Au773zEONTz3/BbofyYJ4CXk822k2mslWLaDxqiUgIM4tUh4CY/idDLmZ"
local byteString = base64.decode(data)
if byteString then
local priv_bytes = base64.decode(priv)
local sm2_ctx = sm2:new()
sm2_ctx:load_private_from_der(priv_bytes)
local key_len_bytes = byteString:sub(1, 2)
local high, low = string.byte(key_len_bytes, 1, 2)
local key_len = high * 256 + low
local key_cipher = byteString:sub(3, key_len + 2)
local data_cipher = byteString:sub(key_len + 2 + 1, #byteString)
local sm4_key = sm2_ctx:decrypt(key_cipher)
local sm4_ctx = sm4:new("ctr", sm4_key)
local data = sm4_ctx:decrypt(data_cipher)
print(data)
end -- 非base64报文,判定为未加密流量
result: success print
Failure scenarios
machine: arm64 华为鲲鹏虚拟机
os: kylin 麒麟操作系统
gmssl version: GmSSL-3.1.1-Linux.tar.gz make in machine
luajit version: LuaJIT 2.1.ROLLING (installed via openresty)
openresty version: 1.25.3.2 make in machine
test with command line
command line: luajit test.lua
result: all test complete
test with openresty
code in openresty: same like successful scenarios
result: got the error
Error
Descryption
I wrote a lua encapsulation based on the GMSSSL library and uses FFI to load the GMSSSL library to implement GM functionality. This lua code which I wrote in a Windows environment and runs correctly on Windows。
the test.lua run correct when i tried run the lua encapsulation on arm64 machine command line:
luajit test.lua.but
sm2_do_decryptgot error when i require the encapsulation in ngx.lua code and use it.my lua encapsulation
lua-gmssl
Successful scenarios
machine: x86-64
os: windows10
gmssl version: gmssl.3.1.1-win64
luajit version: LuaJIT 2.1.ROLLING (installed via openresty)
openresty version: 1.25.3.2 win64
test with command line
command line:
luajit test.luaresult: all test complete
test with openresty
code in openresty:
result: success print
Failure scenarios
machine: arm64 华为鲲鹏虚拟机
os: kylin 麒麟操作系统
gmssl version: GmSSL-3.1.1-Linux.tar.gz make in machine
luajit version: LuaJIT 2.1.ROLLING (installed via openresty)
openresty version: 1.25.3.2 make in machine
test with command line
command line:
luajit test.luaresult: all test complete
test with openresty
code in openresty: same like successful scenarios
result: got the error