25.3. 使用 OpenSSL 创建自定义 IMA 密钥


使用 OpenSSL 生成 CSR,为代码安全性创建数字证书。内核使用 .ima 密钥环中的代码签名密钥验证 IMA 签名。在添加密钥前,请确保其由可信密钥环中存在的 IMA CA 密钥签名。

先决条件

  • 自定义 IMA CA 密钥有以下扩展:

    • 具有 CA 布尔值断言的基本约束扩展。
    • 带有 keyCertSign 位断言,但 没有 digitalSignature 断言的 KeyUsage 扩展。
  • 自定义 IMA 代码签名密钥符合以下条件:

    • IMA CA 密钥签名了这个自定义 IMA 代码签名密钥。
    • 自定义密钥包括 subjectKeyIdentifier 扩展。
  • x86_64aarch64 系统或 ppc64le 系统上的 PowerVM 安全引导启用了 UEFI 安全引导。

流程

  1. 要生成一个自定义 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
  2. 可选:要检查 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
  3. 要为 IMA 代码签名密钥生成一个私钥和一个签名请求的证书(CSR),请运行:

    # openssl req -new -utf8 -sha256 -days 365 -batch -config ima.conf -out custom_ima.csr -keyout custom_ima.priv
  4. 可选:要检查 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
  5. 使用 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
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部