您的位置:首页 > 其它

Public Key Infrastructure(PKI)的基本概念和Certificate的创建

2013-03-22 15:51 323 查看
一.PKI的作用
公钥加密也叫做非对称加密,它用一对密钥来进行加密和解密,用某用户密钥加密后所得的信息,只能用该用户的解密密钥才能解密。如果知道了其中一个,并不能计算出另外一个。因此如果公开了一对密钥中的一个,并不会危害到另外一个的秘密性质。称公开的密钥为公钥;不公开的密钥为私钥。
在用户使用公钥加密时并不能确定使用的公钥的可信性,Public Key Infrastructure就是通过引入一个可信的第三方certification authority(CA)来确保公钥的完整性和持有人的身份。

二.X.509PKI的结构
X.509 public key infrastructure标准的结构如下
-- X.509 signed certificate
---------------------------------------------------------------------
SignedContent ::= SEQUENCE
{
certificate CertificateToBeSigned,
algorithm Object Identifier,
signature BITSTRING
}

---------------------------------------------------------------------
-- X.509 certificate to be signed
---------------------------------------------------------------------
CertificateToBeSigned ::= SEQUENCE
{
version [0] CertificateVersion DEFAULT v1,
serialNumber CertificateSerialNumber,
signature AlgorithmIdentifier,
issuer Name
validity Validity,
subject Name
subjectPublicKeyInfo SubjectPublicKeyInfo,
issuerUniqueIdentifier [1] IMPLICIT UniqueIdentifier OPTIONAL,
subjectUniqueIdentifier [2] IMPLICIT UniqueIdentifier OPTIONAL,
extensions [3] Extensions OPTIONAL
}

关于数据结构的更多信息见http://msdn.microsoft.com/en-us/library/bb540790(v=vs.85).aspx

三.Store certificate
如果需要用windows service权限访问certificate,则使用local machine store.需要管理员权限存。
如果是用户权限访问,则使用current user store

在MMC snap-in里查看数字证书
1.运行mmc。
2.在File目录下点Add/Remove Snap In
3.点Add加入想要查看的Certificates。
查看和Internet Explorer有关的数字证书
在Internet Options里面选Content tab里面的Certificates

四.创建certificate
可以用Windows SDK下的makecert.exe来创建用于开发的certificate.需要创建两个certificate,先创建一个self-signed root authority certificate,再创建一个用root authority certificate签名的certificate。
在Visual Studio Command Prompt下运行makecert [options] outputCertificateFile来创建
makecert的参数详见
http://msdn.microsoft.com/en-us/library/bfsktky3.aspx
/article/5140063.html
补充说明:
1.-pe 将所生成的私钥标记为可导出。可导出就是在certificate的detail label下面可以点copy to file将私钥导出,默认是不可导出的。
2.-ss store 指定证书的store name,输出证书即存储在那里。
store name对应的是MMC里面Personal,Trusted Root Certification Authorities等子路径。
具体的对应如下:
AuthRoot:third-party certificate authorities
CertificateAuthority:intermediate certificate authorities
Disallowed:Untrusted certificates(revoked certificates)
My:personal
Root:trusted root certificate authorities
TrustedPeople:trusted people
TrustedPublisher:trusted publishers
AddressBook:The X.509 certificate store for other users
3.-$ authority
指定证书的签名权限,必须设置为 commercial(对于商业软件发行者使用的证书)或 individual(对于个人软件发行者使用的证书)。
设置authority会在Certificate的detail label里面增加两个Field:Enhanced Key Usage和Key Usage Restriction.
4.-cy certType
指定证书类型。有效值是 end(对于最终实体)和 authority(对于证书颁发机构)。
-h number
指定此证书下面的树的最大高度。
分别设定Basic Constraints中的Subject Type和Path Length Constraint
其他配置有待更进一步的学习

了解了怎么使用MakeCert.exe工具就可以分别创建证书了。
先创建self signed的证书并认为它是可信的。

makecert -n "CN=RootCA" -r -sv RootCA.pvk RootCA.cer -ss Root

再用root certificate签名创建其他的证书并导入到Personal下。

makecert -iv RootCA.pvk -n "CN=MySignedCA" -ic RootCA.cer MySignedCA.cer -ss My
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: