当前位置:网站首页>Cryptography series: certificate format representation of PKI X.509
Cryptography series: certificate format representation of PKI X.509
2022-06-23 06:05:00 【flydean】
brief introduction
stay PKI(public key infrastructure) Public key infrastructure , All operations are around certificates and keys , It provides the creation of 、 management 、 distribution 、 Use 、 A set of roles required to store and revoke digital certificates and manage public key encryption 、 Strategy 、 Hardware 、 Software and programs .
With the key , You can create a certificate based on the key . If you want certificates to be widely used , A common standard must be indispensable , stay PKI In the system , It's called this standard X.509.
X.509 The standard defines the most commonly used format for public key certificates .
An example of a certificate
The most important part of the certificate is the public key information , Extract the public key from the certificate , The public key can be used to decrypt the data encrypted by the sender with the private key . Public key information is the core of certificate .
In addition to the public key , The certificate contains a lot of other information , For example, it contains identity information ( Host name 、 Organizations or individuals, etc ).
Creating a certificate is very simple , Let's take a look at the use openssl Command to create a certificate .
Before creating a certificate , First, you need to create the public and private keys that the certificate depends on ,x.509 Certificates can support a variety of public and private key algorithms , such as RSA, DSA, ECDSA, ed25519 etc. .
Here we choose to use RSA Algorithm , The generated key pair is as follows :
openssl genrsa -des3 -out ca.key 1024Generating RSA private key, 1024 bit long modulus...............++++++.............................................++++++e is 65537 (0x10001)Enter pass phrase for ca.key:Verifying - Enter pass phrase for ca.key:Input pass, We can get ca.key, This is a RSA PRIVATE KEY.
And then you can use this ca.key To create a certificate .
openssl req -new -x509 -days 20 -key ca.key -out ca.crtEnter pass phrase for ca.key:You are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) []:SHState or Province Name (full name) []:SHLocality Name (eg, city) []:SHOrganization Name (eg, company) []:HWOrganizational Unit Name (eg, section) []:HWCommon Name (eg, fully qualified host name) []:caserverEmail Address []:[email protected]You can see , Based on the key , Certificates also need to be provided, such as Country Name,Province Name,Organization Name Extra information .
Last , We can get one CA certificate ca.crt.
If you want to view the status of the certificate , You can use the following command :
openssl x509 -noout -text -in ca.crtCertificate: Data: Version: 1 (0x0) Serial Number: 9511149647544559472 (0x83fe64365379a770) Signature Algorithm: sha256WithRSAEncryption Issuer: C=SH, ST=SH, L=SH, O=HW, OU=HW, CN=caserver/[email protected] Validity Not Before: Apr 27 06:33:16 2022 GMT Not After : May 17 06:33:16 2022 GMT Subject: C=SH, ST=SH, L=SH, O=HW, OU=HW, CN=caserver/[email protected] Subject Public Key Info: Public Key Algorithm: rsaEncryption Public-Key: (1024 bit) Modulus: 00:9f:b4:ff:16:15:51:2a:de:2f:23:cd:7d:27:41: 3c:30:1f:f3:cb:bf:3f:7c:96:ba:c3:81:a8:eb:88: be:11:31:03:6f:c3:1d:f1:dc:4c:ea:3d:da:15:24: 59:32:8b:7e:87:a0:0b:57:b9:79:e4:72:2f:4b:50: 9d:00:eb:ee:52:24:f3:e8:e9:92:1c:ec:47:d9:98: 8c:f9:0f:71:a6:91:b2:5b:c1:59:bf:1f:27:47:6b: 9c:ce:22:e7:9d:2c:4a:3a:83:72:43:47:5d:ee:9e: 64:78:cb:3c:48:af:27:08:c1:08:41:c0:e0:92:e9: 13:81:1c:c7:72:3c:2f:5f:f3 Exponent: 65537 (0x10001) Signature Algorithm: sha256WithRSAEncryption 68:09:be:cb:89:c0:0d:27:d2:bb:b2:f0:fb:6e:e2:0a:19:86: 92:cf:e5:90:48:b7:99:02:f1:75:6a:6d:79:1e:18:c7:95:7c: 89:92:ed:a1:bf:ad:91:76:c6:63:59:bb:6d:31:1e:11:5a:5e: 32:86:12:89:00:69:d0:77:c6:d6:69:11:0a:f7:7b:61:6e:95: f8:d6:6b:89:c0:6c:49:eb:38:d9:f5:82:43:32:6e:14:fb:a0: fb:be:12:a5:dc:69:66:b8:1b:22:cb:0f:9f:56:52:40:6d:48: b6:78:29:dc:67:aa:79:c5:00:e3:68:9a:65:9a:94:99:be:ce: b0:d2You can see CA The certificate contains the date , Serial number , Signature algorithm , publisher , Additional information such as effectiveness .
The certificate generated above is actually a root certificate , This root certificate can sign other certificate requests , So as to generate sub certificates , Thus, a cascade structure of certificates is generated .
If a client wants to send a message to CA server What should I do to request a new certificate ?
First, the client also needs to generate its own key pair . If the client is CA server own , So this request CA The process of signing a certificate is called self signing .
To request a certificate , First you have to generate a request csr, It can also be used openssl Order to proceed :
openssl req -new -key ca.key -out server.csrEnter pass phrase for ca.key:You are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) []:CNState or Province Name (full name) []:SHLocality Name (eg, city) []:SHOrganization Name (eg, company) []:citiOrganizational Unit Name (eg, section) []:orgCommon Name (eg, fully qualified host name) []:clientEmail Address []:[email protected] enter the following 'extra' attributesto be sent with your certificate requestA challenge password []:csr Because the request also needs to generate a CA certificate , So you need to enter similar information .
Finally, we generate a server.csr file .
Next use this csr File to request a certificate :
openssl x509 -req -days 20 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crtSignature oksubject=/C=CN/ST=SH/L=SH/O=citi/OU=org/CN=client/[email protected] CA Private KeyEnter pass phrase for ca.key:The meaning of the above command is CA server Upper private key, Root certificate and just generated certificate request server.csr, Build use CA server Signed self signed certificate .
Finally, we get a self signature server.csr Certificate file .
Also use openssl Command to view the status of the certificate :
openssl x509 -noout -text -in server.crtCertificate: Data: Version: 1 (0x0) Serial Number: 14663444799761243679 (0xcb7f055ae9515e1f) Signature Algorithm: sha1WithRSAEncryption Issuer: C=SH, ST=SH, L=SH, O=HW, OU=HW, CN=caserver/[email protected] Validity Not Before: Apr 27 07:28:08 2022 GMT Not After : May 17 07:28:08 2022 GMT Subject: C=CN, ST=SH, L=SH, O=citi, OU=org, CN=client/[email protected] Subject Public Key Info: Public Key Algorithm: rsaEncryption Public-Key: (1024 bit) Modulus: 00:9f:b4:ff:16:15:51:2a:de:2f:23:cd:7d:27:41: 3c:30:1f:f3:cb:bf:3f:7c:96:ba:c3:81:a8:eb:88: be:11:31:03:6f:c3:1d:f1:dc:4c:ea:3d:da:15:24: 59:32:8b:7e:87:a0:0b:57:b9:79:e4:72:2f:4b:50: 9d:00:eb:ee:52:24:f3:e8:e9:92:1c:ec:47:d9:98: 8c:f9:0f:71:a6:91:b2:5b:c1:59:bf:1f:27:47:6b: 9c:ce:22:e7:9d:2c:4a:3a:83:72:43:47:5d:ee:9e: 64:78:cb:3c:48:af:27:08:c1:08:41:c0:e0:92:e9: 13:81:1c:c7:72:3c:2f:5f:f3 Exponent: 65537 (0x10001) Signature Algorithm: sha1WithRSAEncryption 31:2e:b6:d7:3e:2d:ae:f1:2e:44:b5:5e:73:42:91:39:80:9f: a8:ed:9c:60:78:35:21:df:4a:45:b0:b1:d1:80:c1:ee:cb:30: 75:34:66:61:43:6c:0a:85:4f:a3:e5:09:9f:2b:07:62:6a:3a: 60:22:78:f0:7d:32:ef:2f:46:95:34:60:22:03:47:78:6f:0c: 7e:f1:85:ea:d6:4b:1e:45:b5:56:a1:d7:52:9c:19:ae:24:26: 3d:a7:0b:f2:94:c1:d3:e3:04:25:f8:ce:b8:cb:84:6a:d1:b4: 63:7c:df:87:f8:44:86:49:b5:96:dc:43:c7:7a:17:d3:82:c6: 6a:afYou can see the structure and structure root ca The certificate is the same , there Subject Is to create server.csr Information entered in .
X.509 The suffix of the certificate
The certificate suffix we used above is crt, That is to say certificate Abbreviation .
in fact X.509 Certificates also support several other types of suffixes .
.pem
pem The full name is Privacy-enhanced Electronic Mail, You can tell by the name ,pem Originally prepared for encrypted mail .
It is a kind of DER+Base64 Certificate to encode .PEM Certificates are usually in text format , With ”—–BEGIN CERTIFICATE—–“ start , And ”—–END CERTIFICATE—–“ end .
.cer, .crt, .der
All three are based on DER Binary certificate for encoding , But sometimes you use Base64 Encoding , such as .pem.
.p7b, .p7c
Yes, it is PKCS#7 Signed data .
PKCS The full name is Public-Key Cryptography Standards , By RSA A series of standards developed by laboratories and other security system developers to promote the development of public key cryptography .
PKCS#7 The full name of is called Cryptographic Message Syntax Standard.
.p12
Yes, it is PKCS#12 Signed data , Can contain both certificate and private key .
.pfx
PKCS#12 The forerunner of , Usually contains PKCS#12 Formatted data .
Certificate hierarchy and cross certification
The hierarchy of certificates should be well understood , The hierarchy of certificates is also called certificate chain .
From the final certificate we received , It can be followed by one or more CA certificate , The last certificate is the root certificate .
For example, the chain structure of certificates is A->B->C.
To verify A Validity of certificate , Then we need to use B To verify , that B The effectiveness of the , Also needed C To verify , In this way, the level of verification is up to the root certificate .
What is cross certification ?
If there is now A->B and D->E These two certificate chains . But now the two chains are independent , If A Certificates also want to use E How should we handle the authentication ?
Let's think about it first A->B The meaning of ,A->B intend A Certificate use B Certificate to sign . More precisely, it is A Certificate is used B The public key in the certificate is used to sign .
If we use E Yes B Sign the public key in to get a certificate C, that B and C Have the same public key , So for A Come on ,A->B and A->C->E Are valid certificate chains .
If you use B Yes E The public key of , Get a certificate F, So for D->E and D->F->B There are also two valid certificate chains .
Such a structure is called cross authentication .
Cross certification is used in different root systems CA The scenario of chain mutual authentication , Very useful .
x.509 Scope of use of certificate
x.509 Certificates are widely used , such as web The most common way to visit TLS/SSL and HTTPS It's all about x.509 certificate .
in addition SMTP, POP, IMAP, LDAP, XMPP Provide for the right to x.509 Certificate support .
summary
That's all x.509 Introduction to the use of certificates and related principles .
Please refer to http://www.flydean.com/42-pki-x509/
The most popular interpretation , The deepest dry goods , The most concise tutorial , There are so many tricks you don't know about waiting for you to discover !
Welcome to my official account. :「 Program those things 」, Know technology , Know you better !
边栏推荐
- Visual Studio调试技巧
- PAT 乙等 1020.月饼
- PAT 乙等 1012 C语言
- Data migration from dolphin scheduler 1.2.1 to dolphin scheduler 2.0.5 and data test records after migration
- Ant Usage Summary (III): batch packaging apk
- Dolphin scheduler dolphin scheduling upgrade code transformation -upgradedolphin scheduler
- Adnroid activity截屏 保存显示到相册 View显示图片 动画消失
- PAT 乙等 1022 D进制的A+B
- Pat class B 1016 C language
- 三项最高级认证,两项创新技术、两大优秀案例,阿里云亮相云原生产业大会
猜你喜欢

jvm-06. Garbage collector

The digital collection market has just begun

runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)

ant使用总结(二):相关命令说明

金融科技之高效办公(一):自动生成信托计划说明书

Summary of ant usage (I): using ant to automatically package apk

编址和编址单位

Kotlin Android simple activity jump, simple combination of handler and thread

Data migration from dolphin scheduler 1.2.1 to dolphin scheduler 2.0.5 and data test records after migration

新课上线 | 每次 5 分钟,轻松玩转阿里云容器服务!
随机推荐
工作积累-判断GPS是否打开
最优传输理论下对抗攻击可解释性
新课上线 | 每次 5 分钟,轻松玩转阿里云容器服务!
Behind the hot digital collections, a strong technical team is needed to support the northern technical team
HierarchyViewer工具找不到 HierarchyViewer位置
TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.3 全双工, 节能, 自动协商机制, 802.1X 流控制 / 3.3.3 链路层流量控制
Pat class B 1023 minimum decimals
jvm-05.垃圾回收
[open source project] excel export Lua configuration table tool
Work accumulation - judge whether GPS is on
About the error of installing PIP3 install chatterbot
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code
PAT 乙等 1011 C语言
PAT 乙等 1013 C语言
Android handler memory leak kotlin memory leak handling
The digital collection market has just begun
Layer 2技术方案进展情况
[cocos2d-x] screenshot sharing function
runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
The author believes that the so-called industrial Internet is a process of deep integration of industry and the Internet