24.3. 使用 OpenSSL 创建自定义 IMA 密钥
您可以使用 OpenSSL 为您的数字证书生成一个 CSR,以保护您的代码。
内核搜索代码签名密钥的 .ima keyring,以验证 IMA 签名。在向 .ima keyring 中添加代码签名密钥前,您需要确保 IMA CA 密钥在 .builtin_trusted_keys 或 .secondary_trusted_keys keyring 中签名了这个密钥。
先决条件
自定义 IMA CA 密钥有以下扩展:
- 具有 CA 布尔值断言的基本约束扩展。
-
带有
keyCertSign位断言,但 没有digitalSignature断言的KeyUsage扩展。
自定义 IMA 代码签名密钥符合以下条件:
- IMA CA 密钥签名了这个自定义 IMA 代码签名密钥。
-
自定义密钥包括
subjectKeyIdentifier扩展。
-
x86_64或aarch64系统或ppc64le系统上的 PowerVM 安全引导启用了 UEFI 安全引导。
流程
要生成一个自定义 IMA CA 密钥对,请运行:
openssl req -new -x509 -utf8 -sha256 -days 3650 -batch -config ima_ca.conf -outform DER -out custom_ima_ca.der -keyout custom_ima_ca.priv
# openssl req -new -x509 -utf8 -sha256 -days 3650 -batch -config ima_ca.conf -outform DER -out custom_ima_ca.der -keyout custom_ima_ca.privCopy to Clipboard Copied! Toggle word wrap Toggle overflow 可选:要检查
ima_ca.conf文件的内容,请运行:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 要为 IMA 代码签名密钥生成一个私钥和一个签名请求的证书(CSR),请运行:
openssl req -new -utf8 -sha256 -days 365 -batch -config ima.conf -out custom_ima.csr -keyout custom_ima.priv
# openssl req -new -utf8 -sha256 -days 365 -batch -config ima.conf -out custom_ima.csr -keyout custom_ima.privCopy to Clipboard Copied! Toggle word wrap Toggle overflow 可选:要检查
ima.conf文件的内容,请运行:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 使用 IMA CA 私钥签名 CSR ,来创建 IMA 代码签名证书:
openssl x509 -req -in custom_ima.csr -days 365 -extfile ima.conf -extensions code_signing -CA custom_ima_ca.der -CAkey custom_ima_ca.priv -CAcreateserial -outform DER -out ima.der
# openssl x509 -req -in custom_ima.csr -days 365 -extfile ima.conf -extensions code_signing -CA custom_ima_ca.der -CAkey custom_ima_ca.priv -CAcreateserial -outform DER -out ima.derCopy to Clipboard Copied! Toggle word wrap Toggle overflow