Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows环境下SM2调用导入导出密钥函数panic #5

Open
frozenpine opened this issue Apr 15, 2024 · 4 comments
Open

Windows环境下SM2调用导入导出密钥函数panic #5

frozenpine opened this issue Apr 15, 2024 · 4 comments

Comments

@frozenpine
Copy link

GO version: 1.21.6
GmSSL version: 1.3.1
GmSSL Library version: 3.1.1

调用 gmssl.ImportSm2EncryptedPrivateKeyInfoPem 载入加密私钥时,panic
Exception 0xc0000005 0x1 0x24 0x7ffe12b03aca
PC=0x7ffe12b03aca
signal arrived during external code execution

runtime.cgocall(0x1b6b92, 0xc00007bdc8)
C:/Program Files/Go/src/runtime/cgocall.go:157 +0x3e fp=0xc00007bda0 sp=0xc00007bd68 pc=0x13467e
github.com/GmSSL/GmSSL-Go._Cfunc_sm2_private_key_info_decrypt_from_pem(0xc000010230, 0x15f3b6816a0, 0x7ffe129c8a90)
_cgo_gotypes.go:553 +0x55 fp=0xc00007bdc8 sp=0xc00007bda0 pc=0x1b54f5
github.com/GmSSL/GmSSL-Go.ImportSm2EncryptedPrivateKeyInfoPem.func4(0xc000010230, 0x15f3b6816e0?, 0x7ffe129c8a90?)
C:/Users/froze/go/pkg/mod/github.com/!gm!s!s!l/!gm!s!s!l-!go@v1.3.1/sm2.go:70 +0x54 fp=0xc00007be08 sp=0xc00007bdc8 pc=0x1b5994
github.com/GmSSL/GmSSL-Go.ImportSm2EncryptedPrivateKeyInfoPem({0x1e3993?, 0x189a05?}, {0x1e37b3, 0x8})

另外,windows下所有涉及密钥导入导出到pem的函数,均会panic,相同代码,linux环境无此问题

@frozenpine
Copy link
Author

使用C demo测试了sm2 pem密钥载入,目前用msvc编译demo,工作正常的,但是用mingw64 gcc编译,就会segment fault

cgo只能使用gcc编译,就导致了上面的异常

gdb调试堆栈信息:
Thread 1 received signal SIGSEGV, Segmentation fault.
0x00007ffe12b03aca in ntdll!TpWorkOnBehalfClearTicket () from C:\WINDOWS\SYSTEM32\ntdll.dll
(gdb) bt
#0 0x00007ffe12b03aca in ntdll!TpWorkOnBehalfClearTicket () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1 0x00007ffe12af18e4 in ntdll!RtlEnterCriticalSection () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2 0x00007ffe12af16d2 in ntdll!RtlEnterCriticalSection () from C:\WINDOWS\SYSTEM32\ntdll.dll
#3 0x00007ffd8d11090d in ucrtbased!_lock_file () from C:\WINDOWS\SYSTEM32\ucrtbased.dll
#4 0x00007ffd8d0c78eb in ucrtbased!fgetpos () from C:\WINDOWS\SYSTEM32\ucrtbased.dll
#5 0x00007ffd8d0c7f62 in ucrtbased!fgets () from C:\WINDOWS\SYSTEM32\ucrtbased.dll
#6 0x00007ffdad17d4ba in sm9_fp2_div () from C:\Users\froze\Documents\Projects\RDRK\desensitize\examples\sm2\bin\gmssl.dll
#7 0x00007ffdad134cf4 in sm9_fp2_div () from C:\Users\froze\Documents\Projects\RDRK\desensitize\examples\sm2\bin\gmssl.dll
#8 0x00007ff7af52173f in main ()

@wellcomez
Copy link

使用C demo测试了sm2 pem密钥载入,目前用msvc编译demo,工作正常的,但是用mingw64 gcc编译,就会segment fault

cgo只能使用gcc编译,就导致了上面的异常

gdb调试堆栈信息: Thread 1 received signal SIGSEGV, Segmentation fault. 0x00007ffe12b03aca in ntdll!TpWorkOnBehalfClearTicket () from C:\WINDOWS\SYSTEM32\ntdll.dll (gdb) bt #0 0x00007ffe12b03aca in ntdll!TpWorkOnBehalfClearTicket () from C:\WINDOWS\SYSTEM32\ntdll.dll #1 0x00007ffe12af18e4 in ntdll!RtlEnterCriticalSection () from C:\WINDOWS\SYSTEM32\ntdll.dll #2 0x00007ffe12af16d2 in ntdll!RtlEnterCriticalSection () from C:\WINDOWS\SYSTEM32\ntdll.dll #3 0x00007ffd8d11090d in ucrtbased!_lock_file () from C:\WINDOWS\SYSTEM32\ucrtbased.dll #4 0x00007ffd8d0c78eb in ucrtbased!fgetpos () from C:\WINDOWS\SYSTEM32\ucrtbased.dll #5 0x00007ffd8d0c7f62 in ucrtbased!fgets () from C:\WINDOWS\SYSTEM32\ucrtbased.dll #6 0x00007ffdad17d4ba in sm9_fp2_div () from C:\Users\froze\Documents\Projects\RDRK\desensitize\examples\sm2\bin\gmssl.dll #7 0x00007ffdad134cf4 in sm9_fp2_div () from C:\Users\froze\Documents\Projects\RDRK\desensitize\examples\sm2\bin\gmssl.dll #8 0x00007ff7af52173f in main ()
解决了吗?

@frozenpine
Copy link
Author

没有解决,暂时放弃了使用SM2非对称加密的功能,仅使用了SM3

@wellcomez
Copy link

wellcomez commented Jun 13, 2024

没有解决,暂时放弃了使用SM2非对称加密的功能,仅使用了SM3
guanzhi/GmSSL#1697
我已经解决看最新的提的issue需要用minggw编译
@frozenpine

由于你题了issue我猜测走win32就会死,绕道mingw就可以。你不提我可能还以为自己倒霉读一份

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants