25.3. 使用 OpenSSL 创建自定义 IMA 密钥
使用 OpenSSL 生成 CSR,为代码安全性创建数字证书。内核使用 .ima 密钥环中的代码签名密钥验证 IMA 签名。在添加密钥前,请确保其由可信密钥环中存在的 IMA CA 密钥签名。
先决条件
自定义 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可选:要检查
ima_ca.conf文件的内容,请运行:# cat ima_ca.conf [ req ] default_bits = 2048 distinguished_name = req_distinguished_name prompt = no string_mask = utf8only x509_extensions = ca [ req_distinguished_name ] O = YOUR_ORG CN = YOUR_COMMON_NAME IMA CA emailAddress = YOUR_EMAIL [ ca ] basicConstraints=critical,CA:TRUE subjectKeyIdentifier=hash authorityKeyIdentifier=keyid:always,issuer keyUsage=critical,keyCertSign,cRLSign要为 IMA 代码签名密钥生成一个私钥和一个签名请求的证书(CSR),请运行:
# openssl req -new -utf8 -sha256 -days 365 -batch -config ima.conf -out custom_ima.csr -keyout custom_ima.priv可选:要检查
ima.conf文件的内容,请运行:# cat ima.conf [ req ] default_bits = 2048 distinguished_name = req_distinguished_name prompt = no string_mask = utf8only x509_extensions = code_signing [ req_distinguished_name ] O = YOUR_ORG CN = YOUR_COMMON_NAME IMA signing key emailAddress = YOUR_EMAIL [ code_signing ] basicConstraints=critical,CA:FALSE keyUsage=digitalSignature subjectKeyIdentifier=hash authorityKeyIdentifier=keyid:always,issuer使用 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