




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
openssl生成证书及吊销列表一,先来讲讲基本概念。证书分类:按类型可以分为CA证书和用户用户证书,我们我说的root也是特殊的CA证书。用户证书又可以根据用途分类,放在服务器端的称为服务器证书,放在客户端一般称为客户端证书(这种说法不是很准确,只是一种理解。实际应该是在对客户端认证时才会用到客户端证书且root、ca证书都可以放在客户端),记住,这两种证书都应为用户证书。一般可以理解为证书由key和证书(没有key的文件也称为证书)组成,谁拥有这两个东西才真正拥有这个证书。好比锁是有钥匙和锁头组成的,你得两都有。你只有锁头锁住东西,却没有钥匙打开,也没什么用。如果你对证书不了解,那一定要知道证书这三点作用(纯个人认为比较重要三点):1,签名:通过签名技术可以保证证书拥有者的唯一性,而且所有信息没有被篡改。想了解数字签名的自己百度一下。2,提供公钥:通过签名技术知道证书拥有者是A,且所有信息都是A,就可以拿到A的公钥算法及公钥。所以有些人理解为证书就是一个公钥(个人认为这种理解与实际偏差较大)。3,颁发者:找到颁发者很重要,每个证书都有一个颁发者。这个在证书认证时用得到。对于用户(人)来说还是通过证书名称来区分证书,下面讲解几种常见的证书。a).cert或.crt文件:这种证书倒是可以理解为公钥证书,因为它最主要的作用就是来提供公钥的,只是一种理解,签名认证这些作用一样不会少。这种文件不含有key,就好像一个打开的锁头,可以发给任何人。所以拥有.cer或.crt文件的不是真正的拥有者,因为你可以用证书里的公钥加密,但并没有私钥解密。b).pfx文件:这种证书文件可以理解为.cer文件与key结合体,即拥有.pfx证书相当同时拥有公钥与私钥。即可以加密也可以解密。c).key文件:就是钥匙啦。锁头可以给任何人,但是钥匙只能自己保留,所以这玩意一定要保存好。d).p7b文件:为证书链文件,也不含私钥。证书链即证书的拥有者、颁发者、颁发者的颁发者、依次类推的证书合成一个文件。 以上对证书概念基础的了解,有基础的可以不用看。实际证书分类根据编码方式来区分的,只是为了方便理解才这么分的。当我们需要向对方发送加密数据时,我们只需要对方的cer或crt文件就可以了。而需要对方向自己发送加密数据时,自己得拥有key,并且对方要有自己公钥(从cer文件获得)。二、环境搭建安装openssl这个就不讲了,现在很多linux版本都默认安装了。先来看下配置文件中一段。默认配置文件/usr/local/openssl/ssl/f或者/etc/pki/tls/f。dir = ./demoCA # Where everything is keptcerts = $dir/certs # Where the issued certs are keptcrl_dir = $dir/crl # Where the issued crl are keptdatabase = $dir/index.txt # database index file.#unique_subject = no # Set to no to allowcreation of #several ctificates with same subject.new_certs_dir = $dir/newcerts # default place for new certs. certificate = $dir/cacert.pem # The CA certificateserial = $dir/serial # The current serial numbercrlnumber = $dir/crlnumber # the current crl number # mustbe commented out to leave a V1 CRLcrl = $dir/crl.pem # The current CRLprivate_key = $dir/private/cakey.pem# The private keyRANDFILE = $dir/private/.rand # private random number file根据上面配置文件就知道,我们得搭建相同的目录结构环境。先创建一个目录test,并且将1, 配置文件cp到test目录下。iyunvlocalhost # mkdir testiyunvlocalhost # cd testiyunvlocalhost test# cp/usr/local/openssl/ssl/f ./iyunvlocalhost test# f2, 根据配置文件中目录结构可知有个demoCA目录,目录下有各种文件。iyunvlocalhost test# mkdir ./demoCA./demoCA/newcerts ./demoCA/privateiyunvlocalhost test# chmod 777./demoCA/privateiyunvlocalhost test# echo01./demoCA/serialiyunvlocalhost test# touch./demoCA/index.txt生成证书暂时用到这么多,其他可以先不创建,用到时再作修改。环境目录结构如下:iyunvlocalhost test# tree. demoCA certs index.txt private newcerts f3, 环境搭建很重要的东西就修改配置文件了。这里只是实现生成证书,不讲解配置文件。所以只需要修改如下一句就可以了。dir = ./demoCA # Where everything is kept将路径改为实际绝对路径。我这里就是/root/test/demoCA,所以修改后就是:dir = /root/test/demoCA # Whereeverything is kept三、整体步骤openssl genrsa -des3 out server.key 1024/生成keyopenssl req -new key server.key -outserver.csr -config f/生成csr文件openssl req -new -x509 -keyoutca.key -outca.crt -config f/自生成CA(root)openssl ca -in server.csr out server.crt-cert ca.crt -keyfile ca.key -config f/签名penssl pkcs12 -export -inkeyserver.key -inserver.crt -out server.pfx/合成pfx格式四、具体生成证书步骤将以生成服务器端证书为例讲解1,生成私钥文件,保存为server.key。使用的3des算法,密钥长度为2048。iyunvlocalhost test# openssl genrsa -des3-out server.key 2048Generating RSA private key, 2048 bit longmodulus.+.+e is 65537 (0x10001)Enter pass phrase for server.key: #输入秘密Verifying - Enter pass phrase forserver.key: #输入秘密iyunvlocalhost test# lsdemoCA f server.key2,生成证书签名申请文件(csr)。保存为server.csriyunvlocalhost test# openssl req -new-key server.key -out server.csr -config fEnter pass phrase for server.key: #输入第1步输入的密码You are about to be asked to enterinformation that will be incorporatedinto your certificate request.What you are about to enter is what iscalled a Distinguished Name or a DN.There are quite a few fields but you canleave some blankFor some fields there will be a defaultvalue,If you enter ., the field will be leftblank.-Country Name (2 letter code) AU:cnState or Province Name (full name)Some-State:bjLocality Name (eg, city) :hdOrganization Name (eg, company) InternetWidgits Pty Ltd:Organizational Unit Name (eg, section):testCommon Name (e.g. server FQDN or YOUR name):Email Address : Please enter the following extraattributesto be sent with your certificate requestA challenge password : #这里可以不输入An optional company name : #这里可以不输入iyunvlocalhost test# lsdemoCA f server.csr server.key3,有申请文件,要有个机构来签名,实际是将server.csr文件提供给第三方可信任机构签名就可以。这里为了演示,将自生成CA(root)。证书保存为root.crt,key保存为root.key。iyunvlocalhost test# openssl req -new-x509 -keyout root.key -out root.crt -config fGenerating a 1024 bit RSA private key.+.+writing new private key to root.keyEnter PEM pass phrase: #输入密码 Verifying - Enter PEM pass phrase: #确认输入-You are about to be asked to enterinformation that will be incorporatedinto your certificate request.What you are about to enter is what iscalled a Distinguished Name or a DN.There are quite a few fields but you canleave some blankFor some fields there will be a defaultvalue,If you enter ., the field will be leftblank.-Country Name (2 letter code) AU:cn #保持与csr文件信息一致,与配置文件有关。State or Province Name (full name)Some-State:bj #保持与csr文件信息一致Locality Name (eg, city) :hd #保持与csr文件信息一致Organization Name (eg, company) InternetWidgits Pty Ltd: #保持与csr文件信息一致Organizational Unit Name (eg, section):test # 保持与csr文件信息一致Common Name (e.g. server FQDN or YOUR name):Email Address :iyunvlocalhost test# lsdemoCA f root.crt root.key server.csr server.key4,有了CA(root)我们就可以用它来为第2步生的csr文件进行签名了。iyunvlocalhost test# openssl ca -inserver.csr -out server.crt -cert root.crt -keyfile root.key -config fUsing configuration from fEnter pass phrase for root.key:Check that the request matches thesignatureSignature okCertificate Details: Serial Number: 1 (0x1) Validity Not Before: Oct 8 23:26:13 2015GMT Not After : Oct 7 23:26:13 2016GMT Subject: countryName = cn stateOrProvinceName = bj organizationName = organizationalUnitName = test commonName = emailAddress = X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 35:2B:69:AE:42:6F:D7:93:CC:AC:C5:88:89:DE:F0:CC:4E:D9:EF:FD X509v3 Authority Key Identifier: keyid:0C:DA:95:AC:B9:BC:8E:F1:66:EC:DE:28:E3:01:66:D0:A4:82:1F:17 Certificate is to be certified untilOct 7 23:26:13 2016 GMT (365 days)Sign the certificate? y/n:y 1 out of 1 certificate requests certified,commit? y/nyWrite out database with 1 new entriesData Base Updated5,至此所有文件都生成好了,查看下整个过程中需要的文件及生成的文件。iyunvlocalhost test# tree. demoCA index.txt index.txt.attr index.txt.old newcerts 01.pem private serial serial.old f root.crt root.key server.crt #我们要生成的服务器端证书 server.csr server.key #我们要生成的服务器端证书的key五、经常也会碰到证书吊销列表CRL,现在来生成server.crl文件,即将刚才的证书吊销。同样先根据配置文件配置环境,如下:iyunvlocalhost test# cp root.key ./demoCA/private/cakey.pemiyunvlocalhost test# cp root.crt./demoCA/cacert.pemiyunvlocalhost test# echo 00 ./demoCA/crlnumber吊销证书iyunvlocalhost test# openssl ca -revokeserver.crt -config fUsing configuration from fEnter pass phrase for/root/test/demoCA/private/cakey.pem:Revoking Certificate 01.Data Base Updated生成吊销列表iyunvlocalhost test# openssl ca-gencrl -out server.crl -config fUsing configuration from fEnter pass phrase for/root/test/demoCA/pri
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 汽车美容店跨界合作与联名活动协议范本
- 个人创业投资连带责任担保合同
- 2025至2030中国流变改性剂市场运营规划及前景趋势洞察报告
- 上学的出血病人护理要点
- 口服靶向药物皮疹的护理
- 2025至2030中国鼓式融化机行业产业运行态势及投资规划深度研究报告
- 认识东西南北教学课件
- 颅内积气护理查房
- 夫妻离异后子女抚养权人寿保险保障服务协议
- 二手房买卖合同签订中的合同签订与房屋质量保证
- 2022年新高考I卷读后续写David's run公开课课件-高三英语一轮复习
- 蓄水模块专项监理实施细则
- 创业小白实操手册 第2版 课件 6 做原型小验证-课件标准版
- 《全面质量管理》习题集(含答案)
- 数学游戏(单元复习课件)人教版一年级数学上册
- 北师大版小学数学四年级上册第3单元 乘法《卫星运行时间》教学课件
- 新学期幼儿园小班新生家长会课件
- DL∕T 2559-2022 灯泡贯流式水轮机状态检修评估技术导则
- 热固复合聚苯乙烯防火保温板应用技术规程(征求意见稿)
- 法院书记员考试试题
- 计算机系统原理13015习题答案
评论
0/150
提交评论