OpenSSL PKI Tutorial v1.1

本教程通过实例介绍如何使用 OpenSSL 工具包创建和管理公钥基础设施 (PKI)。涵盖 PKI 的基本概念、配置文件的重要性及示例演练,从简单的 PKI 到复杂的多层次 CA 架构。

OpenSSL PKI Tutorial v1.1
Create and operate Public Key Infrastructures with OpenSSL.

Overview
This tutorial shows how to implement real-world PKIs with the OpenSSL toolkit.

In the first part of the tutorial we introduce the necessary terms and concepts. The second part consists of examples, where we build increasingly more sophisticated PKIs using nothing but the openssl utility. The tutorial puts a special focus on configuration files, which are key to taming the openssl command line. It also serves to promote what we have found to be the most effective way of partinioning the configuration space:

One configuration file per CA, and
One configuration file per CSR type.
Please study the configuration files included in the examples, it’s where most of the treasure is buried.

PKI Concepts
At its heart, an X.509 PKI is a security architecture that uses well-established cryptographic mechanisms to support use-cases like email protection and web server authentication. In this regard it is similar to other systems based on public-key cryptography, for example OpenPGP [RFC 4880]. In the realm of X.509 however, and thanks to its roots in a globe-spanning scheme devised by the telecom industry, these mechanisms come with a fair amount of administrative overhead.

One thing to keep in mind is that X.509 is not an application, but a specification upon which applications like Secure Multipurpose Internet Mail Extensions (S/MIME) and Transport Layer Security (TLS) are based. The building blocks are very generic and derive most of their meaning from the relations that exist/are established between them. It’s called an infrastructure for a reason.

Process

_images/PKIProcess.png
A requestor generates a CSR and submits it to the CA.
The CA issues a certificate based on the CSR and returns it to the requestor.
Should the certificate at some point be revoked, the CA adds it to its CRL.
Components

Public Key Infrastructure (PKI)
Security architecture where trust is conveyed through the signature of a trusted CA.
Certificate Authority (CA)
Entity issuing certificates and CRLs.
Registration Authority (RA)
Entity handling PKI enrollment. May be identical with the CA.
Certificate
Public key and ID bound by a CA signature.
Certificate Signing Request (CSR)
Request for certification. Contains public key and ID to be certified.
Certificate Revocation List (CRL)
List of revoked certificates. Issued by a CA at regular intervals.
Certification Practice Statement (CPS)
Document describing structure and processes of a CA.
CA Types

Root CA
CA at the root of a PKI hierarchy. Issues only CA certificates.
Intermediate CA
CA below the root CA but not a signing CA. Issues only CA certificates.
Signing CA
CA at the bottom of a PKI hierarchy. Issues only user certificates.
Certificate Types

CA Certificate
Certificate of a CA. Used to sign certificates and CRLs.
Root Certificate
Self-signed CA certificate at the root of a PKI hierarchy. Serves as the PKI’s trust anchor.
Cross Certificate
CA certificate issued by a CA external to the primary PKI hierarchy. Used to connect two PKIs and thus usually comes in pairs. [1]
User Certificate
End-user certificate issued for one or more purposes: email-protection, server-auth, client-auth, code-signing, etc. A user certificate cannot sign other certificates.
Footnotes

[1] The RFC classifies any CA-signs-CA scenario as cross-certification, to distinguish it from self-issuing. Outside of specs however, the term normally only refers to inter-PKI cross-certification.
File Formats

Privacy Enhanced Mail (PEM)
Text format. Base-64 encoded data with header and footer lines. Preferred format in OpenSSL and most software based on it (e.g. Apache mod_ssl, stunnel).
Distinguished Encoding Rules (DER)
Binary format. Preferred format in Windows environments. Also the official format for Internet download of certificates and CRLs.
Examples
The examples are meant to be done in order, each providing the basis for the ones that follow. They are deliberately low on prose, we prefer to let the configuration files and command lines speak for themselves.

You will find a reference section at the bottom of each page, with links to relevant parts of the OpenSSL documentation. Please use the links for details on command line options and configuration file settings.

Note: You need at least OpenSSL 1.0.1. Check with:

openssl version
Simple PKI

In this example we create the simplest possible PKI: One root CA and one signing CA. We use the CA to issue two types of user certificates.

Simple PKI
Advanced PKI

In this example we create a larger setup, consisting of a root CA and three signing CAs. We use the CAs to issue 4 different types of user certificates. We also encounter two new certificate extensions: authorityInfoAccess and crlDistributionPoints.

Advanced PKI
Expert PKI

In this example we create a 3-tier CA hierarchy: One root CA, one intermediate CA, and two signing CAs. We use the CAs to issue 6 types of user certificates. We introduce certificate policies and the certificatePolicies extension. We also show how to configure an OCSP responder.

Expert PKI
Appendices
MIME Types

This section takes a closer look at the MIME types and file extensions used.

Appendix A: MIME Types
CA Database

This section examines the format of the CA database.

Appendix B: CA Database
References
RFC 5280
Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile
RFC 2585
Internet X.509 Public Key Infrastructure Operational Protocols: FTP and HTTP
RFC 5750
Secure/Multipurpose Internet Mail Extensions (S/MIME) Version 3.2 Certificate Handling
RFC 6125
Representation and Verification of Domain-Based Application Service Identity within Internet Public Key Infrastructure Using X.509 (PKIX) Certificates in the Context of Transport Layer Security (TLS)
Baseline Requirements [pdf, opens in browser]
CA/Browser Forum Baseline Requirements for the Issuance and Management of Publicly-Trusted Certificates
X.509 Recommendation [pdf, direct download]
ITU-T X.509 Public-Key and Attribute Certificate Frameworks Recommendation
OpenSSL TEST CA [pdf, direct download]
Carillon Information Security: How to Set Up an OpenSSL TEST CA for Interoperability Testing with CertiPath

### 卸载 OpenSSL 1.0 并安装 OpenSSL 1.1 的解决方案 在 CentOS 6 上卸载 OpenSSL 1.0 并正确安装 OpenSSL 1.1 版本的过程涉及多个步骤,主要包括备份现有配置、卸载旧版本、编译安装新版本以及设置必要的软链接。 #### 备份当前的 OpenSSL 配置 为了防止意外破坏系统的网络功能,在操作之前建议先备份现有的 OpenSSL 文件和配置文件。可以运行以下命令来完成备份: ```bash cp -r /etc/pki/tls /etc/pki/tls.backup tar czvf openssl_backup.tar.gz /etc/pki/tls.backup ``` #### 卸载原有的 OpenSSL 1.0 由于直接卸载系统自带的 OpenSSL 可能会影响其他依赖它的服务(如 `yum`),因此不推荐完全移除它。可以通过重新指定路径的方式绕过默认使用的 OpenSSL 库。如果确实需要卸载,则需谨慎执行以下命令: ```bash rpm -qa | grep openssl rpm -e --nodeps <openssl-package-name> ``` 注意:此方法可能影响到某些核心组件的功能,请务必确认是否有替代方案[^1]。 #### 编译并安装 OpenSSL 1.1 获取最新的 OpenSSL 源码包后解压至工作目录 `/opt/openssl-1.1.x` 下,并按照如下方式构建: 进入源代码所在位置: ```bash cd /opt/openssl-1.1.x/ ./config --prefix=/usr/local/ssl shared zlib-dynamic make && make test && make install ``` 上述命令中的参数解释如下: - `--prefix=/usr/local/ssl`: 将新的 OpenSSL 安装到自定义路径下; - `shared`: 构建动态共享库而非静态库; - `zlib-dynamic`: 启用压缩支持[^2]。 #### 创建必要软连接 为了让系统能够识别刚安装的新版 OpenSSL,还需要建立一些符号链接指向实际二进制程序及其头文件的位置: ```bash ln -sf /usr/local/ssl/bin/openssl /usr/bin/openssl ln -sf /usr/local/ssl/lib/* /usr/lib64/ ldconfig ``` 另外还需调整环境变量以便于后续开发工具链找到正确的 include 和 lib 路径: ```bash export PATH=$PATH:/usr/local/ssl/bin echo "/usr/local/ssl/lib" >> /etc/ld.so.conf.d/openssl-1.1.conf ldconfig ``` #### 测试已安装的 OpenSSL 是否正常运作 最后一步是验证刚刚替换上去的服务是否可用无误。打开终端输入下面这条指令查看其基本信息: ```bash openssl version -a ``` 应该返回类似于这样的输出表明成功切换到了目标版本号:“OpenSSL 1.1.X XXXXXXXX”。 --- ### 注意事项 尽管以上流程适用于大多数场景下的升级需求,但在生产环境中实施前仍应充分测试兼容性和稳定性。特别是当存在大量第三方应用程序或者框架绑定特定版本时更需小心处理迁移过程带来的潜在风险[^3]。 相关问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值