设为首页 收藏本站
查看: 525|回复: 0

[经验分享] openssl建立私有CA的过程

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-2-2 08:51:14 | 显示全部楼层 |阅读模式
openssl建立私有CA:

        1.生成密钥;

        2.自签署证书;


      通信节点:

         1.生成密钥对儿;

         2.生成证书签署请求;

         3.把请求发送给CA;


       CA:

          1.验证请求者信息;

          2.签署证书

          3.把签好的证书发送给请求者;


                简单通信结构图

wKiom1TK52jx1oHRAAEhVd5nom4230.jpg

     在系统上的/etc/pki/CA目录下有存放CA的相关信息文件

     [iyunv@kvm ~]# ls /etc/pki/CA/
     certs/    crl/      newcerts/ private/

     openssl默认是安装了的,查看openssl安装后生成的配置文件:

     [iyunv@kvm ~]# rpm -qc openssl
     /etc/pki/tls/openssl.cnf

     查看配置文件的手册

     [iyunv@kvm ~]# man openssl.cnf

     下面是部分openssl配置文件内容

####################################################################
[ ca ]
default_ca    = CA_default        # The default ca section

####################################################################
[ CA_default ]

dir        = /etc/pki/CA        # Where everything is kept
certs        = $dir/certs        # Where the issued certs are kept
crl_dir        = $dir/crl        # Where the issued crl are kept
database    = $dir/index.txt    # database index file.
#unique_subject    = no            # Set to 'no' to allow creation of
                    # several ctificates with same subject.
new_certs_dir    = $dir/newcerts        # default place for new certs.

certificate    = $dir/cacert.pem     # The CA certificate
serial        = $dir/serial         # The current serial number
crlnumber    = $dir/crlnumber    # the current crl number
                    # must be commented out to leave a V1 CRL
crl        = $dir/crl.pem         # The current CRL
private_key    = $dir/private/cakey.pem # The private key
RANDFILE    = $dir/private/.rand    # private random number file

x509_extensions    = usr_cert        # The extentions to add to the cert

# Comment out the following two lines for the "traditional"
# (and highly broken) format.
name_opt     = ca_default        # Subject Name options
cert_opt     = ca_default        # Certificate field options

# Extension copying option: use with caution.
# copy_extensions = copy

# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
# so this is commented out by default to leave a V1 CRL.
# crlnumber must also be commented out to leave a V1 CRL.
# crl_extensions    = crl_ext

default_days    = 365            # how long to certify for
default_crl_days= 30            # how long before next CRL
default_md    = default        # use public key default MD
preserve    = no            # keep passed DN ordering

# A few difference way of specifying how similar the request should look
# For type CA, the listed attributes must be the same, and the optional
# and supplied fields are just that :-)
policy        = policy_match

# For the CA policy
[ policy_match ]
countryName        = match
stateOrProvinceName    = match
organizationName    = match
organizationalUnitName    = optional
commonName        = supplied
emailAddress        = optional

# For the 'anything' policy
# At this point in time, you must list all acceptable 'object'
# types.
[ policy_anything ]
countryName        = optional
stateOrProvinceName    = optional
localityName        = optional
organizationName    = optional
organizationalUnitName    = optional
commonName        = supplied
emailAddress        = optional

####################################################################
[ req ]
default_bits        = 2048
default_md        = sha1
default_keyfile     = privkey.pem
distinguished_name    = req_distinguished_name
attributes        = req_attributes
x509_extensions    = v3_ca    # The extentions to add to the self signed cert

# Passwords for private keys if not present they will be prompted for
# input_password = secret
# output_password = secret

# This sets a mask for permitted string types. There are several options.
# default: PrintableString, T61String, BMPString.
# pkix     : PrintableString, BMPString (PKIX recommendation before 2004)
# utf8only: only UTF8Strings (PKIX recommendation after 2004).
# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
# MASK:XXXX a literal mask value.
# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings.
string_mask = utf8only

# req_extensions = v3_req # The extensions to add to a certificate request

[ req_distinguished_name ]
countryName            = Country Name (2 letter code)
countryName_default        = XX
countryName_min            = 2
countryName_max            = 2

stateOrProvinceName        = State or Province Name (full name)
#stateOrProvinceName_default    = Default Province

localityName            = Locality Name (eg, city)
localityName_default    = Default City

0.organizationName        = Organization Name (eg, company)
0.organizationName_default    = Default Company Ltd

# we can do this but it is not needed normally :-)
#1.organizationName        = Second Organization Name (eg, company)
#1.organizationName_default    = World Wide Web Pty Ltd

organizationalUnitName        = Organizational Unit Name (eg, section)
#organizationalUnitName_default    =

commonName            = Common Name (eg, your name or your server\'s hostname)
commonName_max            = 64

emailAddress            = Email Address
emailAddress_max        = 64

# SET-ex3            = SET extension number 3

[ req_attributes ]
challengePassword        = A challenge password
challengePassword_min        = 4
challengePassword_max        = 20

unstructuredName        = An optional company name      


    一、建立CA服务器:

       1.生成密钥

       # (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)

wKiom1TK7_3C6njKAAleQ00lU9s854.jpg

       2.自签署证书

        # openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3655
                req: 生成证书签署请求
                    -news: 生成新请求
                    -key /path/to/keyfile: 指定私钥文件
                    -out /path/to/somefile: 指定证书文件
                    -x509: 生成自签署证书
                    -days n: 有效天数

wKioL1TK8v-i8GbCAAo1RvsOaPI422.jpg

       3.初始化工作环境

            # touch /etc/pki/CA/{index.txt,serial}   index.txt 是数据库索引文件   serial 序列号文件,指定序列号从哪里开始,配置文件中有说明
            # echo 01 > /etc/pki/CA/serial


wKioL1TK9DfSZ_W1AACOTRqT5Kk118.jpg

    二、通信节点申请证书:

      (一)节点生成请求

        1、生成密钥对

            #(umask 077;openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)


         2、生成证书签署请求

            #openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr


         3、把签署请求文件发送给CA服务器

            #scp /etc/httpd/ssl/httpd.csr root@ipaddr:/path/to/file


wKiom1TK_83RdVC2AAi15Vsswo8749.jpg

         (二)CA签署证书

            1、验证证书中的信息;

            2、签署证书;

            #openssl ca -in /path/to/somefile.csr -out /path/to/somefile.crt -days N

            3、发送签署证书给请求者

                scp /path/to/file  root@ipaddr:/path/to/file


            [iyunv@kvm ~]# cat /etc/pki/CA/serial 文件内数据没有成功定向到,刚修改过了,用echo 01 > /etc/pki/CA/serial
            01

wKiom1TLA4yQ7XTWAART8gIyT8U429.jpg
wKiom1TLBJjxcx_SAAJAvLeEfwU600.jpg

wKioL1TLH2GSwLfoAAWt52-UBrU698.jpg
wKiom1TLHv2z5_QzAAXV7203CIM912.jpg

    再用同样的方法添加192.168.20.120实现认证


    三、吊销证书

        当主机的私钥丢失时,预防别人拿着证书做破坏,就需要把其证书置为无效。

        (一)节点

            1、获取证书serial

               #openssl x509 -in /path/to/certificate_file.crt -noout -serial -subject

                 x509 - Certificate display and signing utility

                  证书和签名工具显示

                 -noout
                   this option prevents output of the encoded version of the request.

                    这个选项可以防止输出编码版本的请求

                -serial
                  outputs the certificate serial number.

                     输出证书序列号

                -subject
                   outputs the subject name.

                      输出主题名称


wKioL1TLJQHTAjBEAADI0QoyN3M209.jpg
wKiom1TLJGvA55ySAAE1jte3fhE799.jpg

             (二)CA

                2、根据节点提交的serial和subject信息来验证与index.txt文件中的信息是否一致;

                    一致,则回收证书

wKioL1TLJzSQgJowAAG4EXYD7k4334.jpg

                3、吊销证书

                    #openssl ca -revoke /etc/pki/CA/newcerts/SERIAL.pem

                        -revoke filename
                           a filename containing a certificate to revoke.

                            证书文件内容吊销

wKioL1TLJ-3DOefoAAE-w5raAbA089.jpg
wKiom1TLKEez4wBMAAJ2jOz8RgM104.jpg

              4.生成吊销证书的编号(如果是第一次吊销)

                #echo 00 > /etc/pki/CA/crlnumber

                [iyunv@kvm ~]# echo 00 > /etc/pki/CA/crlnumber

               5.更新证书吊销列表

                #openssl ca -gencrl -out thisca.crl(可以自己取名)

                    -gencrl
                         this option generates a CRL based on information in the index file.

                           该选项生成CRL基于索引文件中的信息。

                  如果需要查看crl文件的内容(真正使用时,crl是pem的格式,火狐浏览器(支持der格式)是不支持这种格 式的):CA端把证书吊销列表文件生成以后,用一种服务把其共享出来,使用者就可以经常更新这个文件到本地,导入到浏览器中浏览器验证时会自动识别证书是否被吊销。

                    #openssl crl -in /path/to/crlfile.crl -noout -text

                        -text
                           print out the CRL in text form.
                           以文本格式输出CRL。

wKioL1TLLPrizsQiAAZAg61R2zA906.jpg
                    


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-41819-1-1.html 上篇帖子: linux 批量重命名文件 下篇帖子: Centos6.6系统fstab故障及root用户密码恢复案例
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表