欢迎光临
我们一直在努力

Public Key Infrastructure(一)—CSR 到底是什么?带你拆解证书申请全过程

文章目录

  • 0 前言
  • 1 CSR是什么
  • 2. PKCS #10定义
    • 2.1. overview
    • 2.2 流程
    • 2.3 Certification request syntax
      • 2.3.1 请求文件整体
      • 2.3.2 CertificationRequestInfo
      • 2.3.3 subject Name定义
  • 3.CSR生成及解析
    • 3.1 生成私钥
    • 3.2 生成 CSR
    • 2.3 查看CSR内容
    • 3.4 查看csr结构
  • 4.CSR 与Certificate 对比

0 前言

想象以下场景: A同学:最近在研究以太网通信安全,牵涉到TLS/DTLS B:同学:TLS需要配置数字证书 和私钥 A同学:数字证书与证书签名请求文件CSR有什么关系呢 B同学:我也只里了解过数字证书,证书签名请求文件是个啥?如何产生?包含什么信息呢? 行业老兵:CSR(Certificate Signing Request,证书签名请求)是向 CA(证书颁发机构)申请证书时提交的文件。CSR 并不是证书,它只是申请证书时提交给 CA 的一份"申请材料"。里面包含了申请者的身份信息、公钥以及申请者使用私钥生成的数字签名。CA 根据这些信息验证申请者拥有对应私钥,并据此签发 X.509 证书。 本文将剖析CSR,了解它是如何生成的,结构是怎样的?

1 CSR是什么

一句话理解: 我要申请证书,这是我的公钥,这是我的身份信息,并且我可以证明这个公钥确实属于我。 在这里插入图片描述

CSR(Certificate Signing Request,证书签名请求)是向 CA(证书颁发机构)申请证书时提交的文件,其中包含: 公钥(Public Key) 申请者信息(Subject) 使用对应私钥生成的数字签名(证明你拥有该私钥)

2. PKCS #10定义

2.1. overview

证书签名请求文件,整体结如下 在这里插入图片描述

2.2 流程

敲黑板 Signature Algorithm 没有被签名,签名对象是 CertificationRequestInfo

  • 生成私钥
  • 构造 CertificationRequestInfo
  • 使用私钥签名CertificationRequestInfo
  • 组装,CertificationRequestInfo,算法,签名,

The process by which a certification request is constructed involves the following steps: 1. A CertificationRequestInfo value containing a subject distinguished name, a subject public key, and optionally a set of attributes is constructed by an entity requesting certification. 2. The CertificationRequestInfo value is signed with the subject entity’s private key. 3. The CertificationRequestInfo value, a signature algorithm identifier, and the entity’s signature are collected together into a CertificationRequest value, defined below.

Generate Key Pair


+—————————–+
| CertificationRequestInfo |
|—————————–|
| Subject (DN) |
| Subject Public Key |
| Attributes (Optional) |
+—————————–+

│ Sign with
│ Private Key

+—————————–+
| CertificationRequest (CSR) |
|—————————–|
| CertificationRequestInfo |
| Signature Algorithm |
| Signature |
+—————————–+


Output (PEM / DER)

2.3 Certification request syntax

2.3.1 请求文件整体

CertificationRequest ::= SEQUENCE {
certificationRequestInfo CertificationRequestInfo,
signatureAlgorithm AlgorithmIdentifier{{ SignatureAlgorithms }},
signature BIT STRING
}

2.3.2 CertificationRequestInfo

Certification request information shall have ASN.1 type

CertificationRequestInfo ::= SEQUENCE {
version INTEGER { v1(0) } (v1,…),
subject Name,
subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }},
attributes [0] Attributes{{ CRIAttributes }}
}

SubjectPublicKeyInfo { ALGORITHM : IOSet} ::= SEQUENCE {
algorithm AlgorithmIdentifier {{IOSet}},
subjectPublicKey BIT STRING
}

2.3.3 subject Name定义

PKCS #10中本身没有定义subject Name的具体内容,而是引用了X.500 Distinguished Names 。有兴趣,需要单独去看X.500 。 X.500/X.520 Distinguished Names are used to identify entities, such as those which are named by the subject and issuer (signer) fields of X.509 certificates. keytool supports the following subparts: commonName – common name of a person, e.g., “Susan Jones” organizationUnit – small organization (e.g, department or division) name, e.g., “Purchasing” organizationName – large organization name, e.g., “ABCSystems, Inc.” localityName – locality (city) name, e.g., “Palo Alto” stateName – state or province name, e.g., “California” country – two-letter country code, e.g., “CH”

在这里插入图片描述 在这里插入图片描述

字段全称来源(X.520 属性)
C Country Name X.520
ST State or Province Name 常见实现映射(严格来说对应 stateOrProvinceName 属性)
L Locality Name X.520
O Organization Name X.520
OU Organizational Unit Name X.520
CN Common Name X.520
street Street Address X.520
serialNumber Serial Number X.520
postalCode Postal Code X.520

这些字段都对应 ASN.1 中定义的对象标识符(OID)

属性OID
C 2.5.4.6
O 2.5.4.10
OU 2.5.4.11
CN 2.5.4.3
L 2.5.4.7
ST 2.5.4.8

3.CSR生成及解析

3.1 生成私钥

openssl genpkey \\
-algorithm RSA \\
-pkeyopt rsa_keygen_bits:2048 \\
-out private.key

在这里插入图片描述

3.2 生成 CSR

openssl req \\
-new \\
-key private.key \\
-out request.csr

在这里插入图片描述

2.3 查看CSR内容

openssl req \\
-in request.csr \\
-text \\
-noout
Certificate Request:
Data:
Version: 1 (0x0)
Subject: C = CN, ST = zhejiang, L = hangzhou, O = test_tech, OU = tech, CN = manbushuhai, emailAddress = xxx
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
00:f3:4c:fb:5e:d6:fd:89:ba:c7:14:73:5e:dc:95:
0f:46:97:20:17:ef:b6:cd:23:0a:c9:7a:54:d8:a9:
56:1a:f4:8f:d1:94:fd:7f:69:21:03:8f:bd:b6:2c:
d3:f4:bf:0c:71:66:ef:a4:12:48:f5:0f:62:cd:e2:
ed:65:43:e8:34:a0:44:8a:68:60:b1:3c:30:ad:61:
24:e4:6d:71:2c:b2:d8:42:92:b4:1c:98:c8:ca:e4:
0c:d0:71:c4:20:ed:da:a7:5b:c9:6f:c5:22:ca:f0:
e3:ee:21:ea:07:95:3a:23:f8:32:2b:78:63:67:43:
1f:3b:7c:76:4b:90:cc:d3:02:fa:59:be:9f:75:c3:
e0:5b:0a:76:55:1b:43:d3:68:3b:e3:d8:77:76:f5:
0c:7b:e3:4d:fe:c5:39:d9:98:71:e3:20:e7:a8:3d:
48:e5:05:18:e5:ae:31:a4:e1:db:e2:c7:c5:e7:48:
bf:4c:0d:72:bb:0b:a3:03:ac:f3:39:65:b5:3f:45:
d6:7c:0d:11:3b:80:54:03:7a:fb:ac:b7:71:a3:bf:
c9:d3:4b:fa:e6:92:23:c5:20:e5:56:3e:ca:64:41:
0d:ee:c3:85:8c:a3:41:49:a6:40:43:82:a6:7d:79:
b4:ff:a5:b3:21:72:c3:16:bf:15:b9:7d:eb:ba:cd:
dd:bf
Exponent: 65537 (0x10001)
Attributes:
challengePassword :1234
Requested Extensions:
Signature Algorithm: sha256WithRSAEncryption
Signature Value:
44:59:bf:7a:fc:78:d5:6c:c5:06:5d:32:2f:6c:be:96:f4:64:
9e:19:bc:0f:1d:8e:95:e8:7b:8b:31:b6:c8:5f:83:d3:d1:6c:
f2:37:fc:73:61:cc:b0:96:30:fb:8e:2b:ce:00:88:14:4e:c5:
ba:ce:67:f5:29:70:e1:06:20:bd:9d:b2:ee:70:d0:79:3c:f6:
1d:1f:0e:a7:a0:0e:9f:a3:a6:3a:11:28:f8:ea:3a:b3:8d:f1:
a8:7c:93:a7:b7:28:57:31:f2:00:b8:76:00:e9:e1:ee:cd:59:
df:a1:d0:c1:46:01:55:f7:dc:36:c4:9e:16:71:28:fa:83:b8:
22:b4:3c:71:5d:b9:21:e1:a5:07:0d:1f:6e:0e:c7:86:30:29:
dd:6d:ca:c1:8b:dc:cf:e5:bc:6e:43:3e:f0:88:b1:f5:c8:a3:
b5:66:77:0a:d4:09:ce:15:74:bb:fc:17:cf:40:49:30:99:04:
23:6d:b8:e0:69:10:f4:63:7c:85:f0:9b:c5:8c:a8:86:c7:e9:
b5:59:d2:7f:04:16:cd:b3:de:49:00:03:26:c2:6d:7d:0d:3f:
9e:73:31:59:62:9f:41:2e:bc:a5:be:21:fe:8d:3b:7b:01:1c:
e4:1b:9d:34:49:d8:e4:aa:6d:32:c1:1a:59:9b:b8:5f:ed:89:
8a:af:e4:16

3.4 查看csr结构

  • 转化为der格式

openssl req \\
-in request.csr \\
-outform DER \\
-out request.der

  • 使用ASN.1查看
  • 签名值在尾部 在这里插入图片描述

4.CSR 与Certificate 对比

对比CSRCertificate
标准 PKCS#10 X.509
是否包含公钥
是否包含 Subject
是否包含 Issuer
是否有有效期
谁签名 申请者 CA
是否可信 是(取决于 CA)
是否可以用于 TLS
赞(0)
未经允许不得转载:171主机测评 » Public Key Infrastructure(一)—CSR 到底是什么?带你拆解证书申请全过程
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址