(大部分内容网上找到的,但不知道出处)
X.509 v3证书格式
Certificate证书 Version 版本 Serial Number 序列号 Algorithm ID 算法标识 Issuer 颁发者 Validity 有效期 Not Before 有效起始日期 Not After 有效终止日期 Subject 使用者 Subject Public Key Info 使用者公钥信息 Public Key Algorithm 公钥算法 Subject Public Key 公钥 Issuer Unique Identifier (Optional) 颁发者唯一标识 Subject Unique Identifier (Optional) 使用者唯一标识 Extensions (Optional) 扩展 ... Certificate Signature Algorithm 证书签名算法Certificate Signature 证书签名
数字签名
在签发者处,首先求出传递消息Info的HASH值,然后用私钥Private Key对Hash值做加密,然后将传递消息原文Info和经过加密的HASH值一起发给接受者,接受者首先用签发者的公钥解开密码,然后对收到的Info原文计算HASH值,然后比对是否相对,如果相同,则认证成功。
X.509证书示例
以下是一个颁发给login.yahoo的X.509证书解码的案例。这个证书是由GeoTrust签发。所以在签发者栏目中,可以看到“Equifax Secure Certificate Authority” 。在使用者(Subject)中包含多条信息,不过最重要的是通用名(Common Name, CN),因为这个部分是用来和网站的域名相匹配的,同时也包含了RSA的公钥以及Geotrust的签名,目前所有的SSL证书都采用SHA1 HASH算法计算特征值。Certificate:
Data:
Version: 3 (0x2)
Serial Number: 368716 (0x5a04c)
Signature Algorithm: sha1WithRSAEncryption
Issuer:C=US,O=Equifax,
OU=Equifax Secure Certificate Authority
Validity
Not Before: Jan 4 17:09:06 2006 GMT
Not After : Jan 4 17:09:06 2011 GMT
Subject: C=US, ST=California, L=Santa Clara,
O=Yahoo! Inc., OU=Yahoo, CN=login.yahoo
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (1024 bit)
Modulus (1024 bit):
00:b5:6c:4f:ee:ef:1b:04:5d:be:70:4a:d8:55:1d:
8a:77:0d:c1:45:00:f5:3b:1a:10:dd:d7:f7:bb:7a:
65:54:7f:60:d2:16:bb:bd:12:a5:78:78:d6:b3:50:
4e:ba:17:48:27:7a:22:6f:2a:7c:1d:a2:36:22:d8:
59:a2:ae:3a:0b:d4:d2:1b:8a:0e:5a:89:a9:e4:9a:
ff:db:3f:04:e2:9b:75:c1:8d:c5:8c:05:a1:f3:b5:
92:5e:a1:44:49:19:e4:90:b4:e9:ef:e4:5d:b2:20:
6d:f9:23:76:b8:b2:d4:af:a3:06:f5:9e:03:8f:b8:
82:05:21:11:25:44:3a:80:05
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Key Usage: critical
Digital Signature, Non Repudiation,
Key Encipherment,Data Encipherment
X509v3 Subject Key Identifier:
A0:1E:6E:0C:9B:6E:6A:EB:D2:AE:5A:4A:18:FF:0E:93:
46:1A:D6:32
X509v3 CRL Distribution Points:
URI:http://crl.geotrust/crls/secureca.crl
X509v3 Authority Key Identifier:
keyid:48:E6:68:F9:2B:D2:B2:95:D7:47:D8:23:20:10:
4F:33:98:90:9F:D4
X509v3 Extended Key Usage:
TLS Web Server Authentication,
TLS Web Client Authentication
Signature Algorithm: sha1WithRSAEncryption
50:25:65:10:43:e1:74:83:2f:8f:9c:9e:dc:74:64:4e:71:27:
4e:2a:6e:4a:12:7b:4c:41:2e:61:4a:11:0b:41:a6:b1:52:cb:
13:76:b6:45:e4:8d:d4:00:9a:3b:02:c7:82:29:01:a3:ee:7d:
f7:b9:02:88:9d:3e:c3:1c:e6:3d:d3:90:fc:9c:56:db:19:9d:
ab:a8:03:80:7d:c4:e2:c4:09:33:9e:58:5b:77:37:89:59:a3:
86:8e:a1:df:b3:bb:02:ed:21:62:fb:ba:c2:ba:e8:d4:8f:66:
c1:a5:5f:ad:f9:3f:cf:22:9b:17:57:a0:ca:28:c6:76:03:a4:
c4:e7
对证书的解释
版本: 3 (0x2)
序列号:368716 (0x5a04c)
算法标示:sha1WithRSAEncryption
颁发者:C=US,O=Equifax,OU=Equifax Secure Certificate Authority
有效期:2006-1-4-17:09:06到2011-1-4-17:9:6(格林尼治平均时)
使用者: C=US, ST=California, L=Santa Clara,O=Yahoo! Inc., OU=Yahoo, CN=login.yahoo
后面的都是使用者的公钥信息
解码
为了验证这个证书,需要用这个证书签发者的根证书(Geotrust的Equifax Secure Certificate Authority)。由于这个证书是用Geotrust的根证书的私钥来签名的,所以我们可以用Geotrust的公钥来对证书的SHA1哈希值进行解码,然后验证解码后的哈希值是否和证书的哈希值一致。以下是Geotrust根证书的样例:
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 903804111 (0x35def4cf)
Signature Algorithm: sha1WithRSAEncryption
Issuer:C=US,O=Equifax,
OU=Equifax Secure Certificate Authority
Validity
Not Before: Aug 22 16:41:51 1998 GMT
Not After : Aug 22 16:41:51 2018 GMT
Subject:C=US,O=Equifax,
OU=Equifax Secure Certificate Authority
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (1024 bit)
Modulus (1024 bit):
00:c1:5d:b1:58:67:08:62:ee:a0:9a:2d:1f:08:6d:
91:14:68:98:0a:1e:fe:da:04:6f:13:84:62:21:c3:
d1:7c:ce:9f:05:e0:b8:01:f0:4e:34:ec:e2:8a:95:
04:64:ac:f1:6b:53:5f:05:b3:cb:67:80:bf:42:02:
8e:fe:dd:01:09:ec:e1:00:14:4f:fc:fb:f0:0c:dd:
43:ba:5b:2b:e1:1f:80:70:99:15:57:93:16:f1:0f:
97:6a:b7:c2:68:23:1c:cc:4d:59:30:ac:51:1e:3b:
af:2b:d6:ee:63:45:7b:c5:d9:5f:50:d2:e3:50:0f:
3a:88:e7:bf:14:fd:e0:c7:b9
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 CRL Distribution Points:
DirName:/C=US/O=Equifax
/OU=Equifax Secure Certificate Authority/CN=CRL1
X509v3 Private Key Usage Period:
Not After: Aug 22 16:41:51 2018 GMT
X509v3 Key Usage:
Certificate Sign, CRL Sign
X509v3 Authority Key Identifier:
keyid:48:E6:68:F9:2B:D2:B2:95:D7:47:D8:23:20:10:
4F:33:98:90:9F:D4
X509v3 Subject Key Identifier:
48:E6:68:F9:2B:D2:B2:95:D7:47:D8:23:20:10:4F:33:
98:90:9F:D4
X509v3 Basic Constraints:
CA:TRUE
1.2.840.113533.7.65.0:
0...V3.0c....
Signature Algorithm: sha1WithRSAEncryption
58:ce:29:ea:fc:f7:de:b5:ce:02:b9:17:b5:85:d1:b9:e3:e0:
95:cc:25:31:0d:00:a6:92:6e:7f:b6:92:63:9e:50:95:d1:9a:
6f:e4:11:de:63:85:6e:98:ee:a8:ff:5a:c8:d3:55:b2:66:71:
57:de:c0:21:eb:3d:2a:a7:23:49:01:04:86:42:7b:fc:ee:7f:
a2:16:52:b5:67:67:d3:40:db:3b:26:58:b2:28:77:3d:ae:14:
77:61:d6:fa:2a:66:27:a0:0d:fa:a7:73:5c:ea:70:f1:94:21:
65:44:5f:fa:fc:ef:29:68:a9:a2:87:79:ef:79:ef:4f:ac:07:
77:38
如果签发证书的根证书,浏览器的根信任列表中,浏览器就会主动识别该证书是安全的,反之,浏览器就会提出一个警告。GeoTrust的根证书已经被全球所有主要浏览器:Internet Explorer, Netscape ,Mozila ,Opera, Firefox, Safari安装在缺省的信任根证书列表中,GeoTrust签发的证书被广泛的信任和接受。