加载OpenSSL引擎后如何使用OpenSSL命令行进行操作例如签名?

问题描述

我在ubuntu 20.4中编写了一个自定义的OpenSSL引擎和引擎测试器。 OpenSSL 版本为 1.1.1。

目标是在TLS会话中使用引擎,第一步是使用命令行对摘要进行签名。参考网站是: https://wiki.openssl.org/index.php/Creating_an_OpenSSL_Engine_to_use_indigenous_ECDH_ECDSA_and_HASH_Algorithms

但是测试人员通过调用函数来使用引擎,如代码中的ECDSA_sign和ECDSA_verify,无法按预期运行。我希望达到这样的效果:

$ openssl dgst -engine -sha256 -sign -out

那我该怎么办?这可行吗? 非常感谢!

解决方法

那个 OpenSSL wiki 页面对于初学者了解 OpenSSL 引擎的工作原理很有用,但是页面中的许多 API 已被弃用,特别是 ECC 功能,这太旧了。

是的,这是可行的。

将您的 YOUR_ENGINE_NAME.so 复制到 /usr/lib/x86_64-linux-gnu/engines-1.1/,然后编辑 /etc/openssl.cnf 以告诉 OpenSSL 命令行实用程序开始加载您的引擎:

# Insert near top of file openssl.cnf:
openssl_conf = openssl_init

# OpenSSL example configuration file.
# This is mostly being used for generation of certificate requests.
#

......
......

# Insert at bottom of file openssl.cnf:
[ openssl_init ]
engines = engine_section
[ engine_section ]
YOUR_ENGINE_NAME = YOUR_ENGINE_NAME_section
[ YOUR_ENGINE_NAME_section ]
engine_id = YOUR_ENGINE_NAME
dynamic_path = /usr/lib/x86_64-linux-gnu/engines-1.1/YOUR_ENGINE_NAME.so
default_algorithms = ALL
init = 1

您可以在引擎的 init 函数中放入一些 printf 信息。如果引擎正确加载,它将在 OpenSSL 命令行实用程序启动后显示:

$ openssl
engine bind start
YOUR_ENGINE init success
OpenSSL> 

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...