linux下简单自建证书颁发机构-CA

CA机构的搭建

1、CA简介:

ca:Certificate Authority,证书颁发机构,也叫证书授权中心。CA主要职责是颁发和管理数字证书。其中心任务是颁发数字证书,并履行用户身份认证的责任。现阶段主要作为电子商务交易中受信任的第三方,承担公钥体系中公钥的合法性检验的责任。

2、公司自建CA实现架构:

1、使用openssl程序完成搭建;

2、需要构建角色:

1、CA服务器;

2、客户端pc;

3、电商web服务器;

3、构建CA的过程:

CA服务器上操作:

[[email protected] ~]# yum -y install openssl            :安装openssl,这是搭建的核心命令;

[[email protected] ~]# vim /etc/pki/tls/openssl.cnf

[CA_default]

dir  :ca的工作目录变量。被下方参数引用(注意:centos5上,此参数要改成绝对路径,不能用相对路径);

certs    :证书存放位置;

crl_dir     :吊销证书的存放位置;

database    :索引文件数据库。签署的所有证书索引文件。自动生成;

new_certs_dir    :刚签署的证书存放位置;

certificate       :ca自己的证书位置;

serial        :下一个证书的编号;

crlnumber         :已吊销证书的证书编号;

crl        :当前正在使用的证书吊销列表文件;

private_key        :ca自己的私钥,安全性很高(可以加密私钥位置文件,让别人拿到也看不了。但是每次使用都得解密);

RANDFILE                     :随机种子数据文件;

x509_extensions    :用户证书;

name_opt        :

cert_opt        :

.........

自签证书默认使用期限

吊销期限

自签证书需要的交互式信息,如国家代码..

..........

:查看CA主配置文件,了解部分参数内容;

[[email protected] ~]# cd /etc/pki/CA/        :进入CA的工作目录;

[[email protected] CA]# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048)
    Generating RSA private key, 2048 bit long modulus
    ................................................+++
    ....................................+++
    e is 65537 (0x10001)        : 生成CA自己的私钥文件,cakey.pem。默认权限为600;

[[email protected] CA]# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki    /CA/cacert.pem -days 365
    You are about to be asked to enter information that will be incorporated
    into 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 blank
    For some fields there will be a default value,
    If you enter ‘.‘, the field will be left blank.
    -----
    Country Name (2 letter code) [XX]:cn                                      :国家代码;
    State or Province Name (full name) []:beijing                             :所在省份;
    Locality Name (eg, city) [Default City]:beijing                           :所在城市;
    Organization Name (eg, company) [Default Company Ltd]:CA                  :机构名称;
    Organizational Unit Name (eg, section) []:manager                         :部门名称;
    Common Name (eg, your name or your server‘s hostname) []:ca.manager.com   :主机名称(重要);
    Email Address []:[email protected]                                             :邮箱地址;
    [[email protected] CA]#

:根据私钥文件生成CA自签证书。CA给自己签发一个证书;

[[email protected] CA]# pwd
    /etc/pki/CA
    [[email protected] CA]# touch index.txt            :创建索引文件;
    [[email protected] CA]# touch serial               :证书编号位置;
    [[email protected] CA]# echo 01 > serial           :自定义开始证书编号;
    [[email protected] CA]# touch crlnumber            :已吊销证书编号文件;
    [[email protected] CA]# ll

:以上的三个文件,是CA配置文件中定义的文件名,必须手动创建出来;

ok,以上简单自建CA机构配置完毕;

4、为httpd服务签发证书:

有了自己的CA证书机构,现在测试给httpd服务器颁发一次证书;

操作位置:

CA服务器---192.168.57.172;

httpd服务器---192.168.57.175;

httpd服务器上操作:

[[email protected] ~]# cd /etc/httpd/
    [[email protected] httpd]# mkdir ssl

[[email protected] httpd]# (umask 077; openssl genrsa -out httpd.key 1024)
    Generating RSA private key, 1024 bit long modulus
    ......................++++++
    ..++++++

e is 65537 (0x10001)          :生成httpd私钥;

[[email protected] httpd]# mv httpd.key ssl/
    [[email protected] httpd]# openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr     -days 365
    You are about to be asked to enter information that will be incorporated
    into 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 blank
    For some fields there will be a default value,
    If you enter ‘.‘, the field will be left blank.
    -----
    Country Name (2 letter code) [XX]:cn
    State or Province Name (full name) []:beijing
    Locality Name (eg, city) [Default City]:beijing
    Organization Name (eg, company) [Default Company Ltd]:test
    Organizational Unit Name (eg, section) []:test
    Common Name (eg, your name or your server‘s hostname) []:www.test.com
    Email Address []:[email protected]

Please enter the following ‘extra‘ attributes
    to be sent with your certificate request
    A challenge password []:  空
    An optional company name []: 空
    [[email protected] httpd]#          :根据私钥,创建证书申请文件httpd.csr;

[[email protected] httpd]# scp /etc/httpd/ssl/httpd.csr 192.168.57.172:/tmp/
    The authenticity of host ‘192.168.57.172 (192.168.57.172)‘ can‘t be established.
    RSA key fingerprint is f3:c6:fd:6b:c8:66:56:15:c7:2e:88:07:b3:ff:4b:48.
    Are you sure you want to continue connecting (yes/no)? y
    Please type ‘yes‘ or ‘no‘: yes
    Warning: Permanently added ‘192.168.57.172‘ (RSA) to the list of known hosts.
    [email protected]‘s password:
    httpd.csr                                                            100%  688     0.7KB/s   00:00  
    [[email protected] httpd]#     :利用scp命令,将httpd证书申请文件复制到CA服务器上,有CA进行数字签名;

CA服务器上操作:

[[email protected] tmp]# openssl ca -in /tmp/httpd.csr -out /tmp/httpd.crt -days 365
    Using configuration from /etc/pki/tls/openssl.cnf
    Check that the request matches the signature
    Signature ok
    The organizationName field needed to be the same in the
    CA certificate (CA) and the request (test)
    [[email protected] tmp]#    :报错了,这里说httpd申请里的机构名字跟CA证书里的机构名字不一样。原因就是CA配置文件中有策略定义必须要一样,编辑配置文件,关闭这些策略即可;

[[email protected] tmp]# vim /etc/pki/tls/openssl.cnf

[ policy_match ]
    countryName             = match                 
    stateOrProvinceName     = match
    organizationName        = match
    organizationalUnitName  = optional
    commonName              = supplied
    emailAddress            = optional

:将match改成optional即可,如下:

[ policy_match ]
        countryName             = optional
        stateOrProvinceName     = optional
        organizationName        = optional
        organizationalUnitName  = optional
        commonName              = supplied
        emailAddress            = optional

[[email protected] tmp]# openssl ca -in /tmp/httpd.csr -out /tmp/httpd.crt -days 365
    Using configuration from /etc/pki/tls/openssl.cnf
    Check that the request matches the signature
    Signature ok
    Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Mar 31 12:11:08 2015 GMT
            Not After : Mar 30 12:11:08 2016 GMT
        Subject:
            countryName               = cn
            stateOrProvinceName       = beijing
            organizationName          = test
            organizationalUnitName    = test
            commonName                = www.test.com
            emailAddress              = [email protected]
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                7E:01:A5:A2:66:F4:5A:8C:D5:A1:2F:6A:B1:86:B2:89:28:D4:24:4D
            X509v3 Authority Key Identifier:
                keyid:25:CE:A2:A1:00:A7:19:69:94:96:7C:4F:32:1C:C8:7E:2D:E1:85:0B

Certificate is to be certified until Mar 30 12:11:08 2016 GMT (365 days)
    Sign the certificate? [y/n]:y
    1 out of 1 certificate requests certified, commit? [y/n]y
    Write out database with 1 new entries
    Data Base Updated
    [[email protected] tmp]#    :再次执行证书签发,生成httpd.crt证书文件。ok,没问题了;

[[email protected] tmp]# cat /etc/pki/CA/serial
    02

[[email protected] tmp]# ll /etc/pki/CA/newcerts/
    总用量 4
    -rw-r--r--. 1 root root 3830 3月  31 20:11 01.pem
    [[email protected] tmp]#                   :查看CA证书编号和已颁发的证书;

[[email protected] tmp]# pwd
    /tmp
    [[email protected] tmp]# scp httpd.crt 192.168.57.175:/etc/httpd/ssl/
    The authenticity of host ‘192.168.57.175 (192.168.57.175)‘ can‘t be established.
    RSA key fingerprint is f3:c6:fd:6b:c8:66:56:15:c7:2e:88:07:b3:ff:4b:48.
    Are you sure you want to continue connecting (yes/no)? y
    Please type ‘yes‘ or ‘no‘: yes
    Warning: Permanently added ‘192.168.57.175‘ (RSA) to the list of known hosts.
    [email protected]‘s password:
    httpd.crt                                                            100% 3830     3.7KB/s   00:00  
    [[email protected] tmp]#      :将证书文件复制到httpd服务器的指定目录下面;

[[email protected] ssl]# pwd
    /etc/httpd/ssl
    [[email protected] ssl]#
    [[email protected] ssl]#
    [[email protected] ssl]# ll
    总用量 12
    -rw-r--r--. 1 root root 3830 3月  31 20:15 httpd.crt
    -rw-r--r--. 1 root root  688 3月  31 19:23 httpd.csr
    -rw-------. 1 root root  887 3月  31 19:20 httpd.key
    [[email protected] ssl]#       :来到httpd服务器上,查看自己成功申请的证书;

ok,至此,简单的CA搭建和签证过程完成了。

时间: 2024-08-08 01:28:06

linux下简单自建证书颁发机构-CA的相关文章

Active Direcyory之证书颁发机构(CA服务器)

今天给大家带来的是CA服务器,全称是证书颁发机构,那么,哪里需要用到AC服务器呢?这里就要说一下https了,https(全称:Hyper Text Transfer Protocol over Secure Socket Layer)简单讲是HTTP的安全版. 今天的示例有两个: 示例一: 部署企业内部CA服务器 示例二: 实现安全的WEB站点 先给大家说一下今天的实验环境,两台服务器server01,server02,server01为域控制器,CA服务器,DNS服务器,server02为W

Active Direcyory之证书颁发机构(CA服务器)升级

前几次给大家介绍过CA服务器的部署于使用,今天给大家介绍一下,CA服务器的升级 首先说一下,今天的实验环境,本次实验室CA的升级,从Windows server 2003升级到Windows server 2012,本次实验,需要三台服务器,一台是2003,安装CA,一台做域控制器,一台做升级后的CA服务器. 实验准备: server01:域控制器(windows server 2012) server02:升级后的CA服务器(windows server 2012) server06:升级前的

CA机构介绍(Certificate Authority 域名SSL证书颁发机构)

SSL证书机构即CA机构的全称为Certificate Authority证书认证中心,只有通过WebTrust国际安全审计认证,根证书才能预装到主流浏览器,成为全球可信的ssl证书颁发机构. HTTPS (全称:Hyper Text Transfer Protocol over SecureSocket Layer),是以安全为目标的 HTTP 通道,在HTTP的基础上通过传输加密和身份认证保证了传输过程的安全性 .HTTPS 在HTTP 的基础下加入SSL 层,HTTPS 的安全基础是 SS

如何在Windows中查询证书颁发机构已颁发的证书

有时候需要看一下证书颁发机构已经颁发出去的证书,看看某个用户或者某个计算机获取过的证书有哪些.通常可以在证书颁发机构的MMC中查看.对于测试环境或者刚开始用的CA来说,这样查看挺简单的.但是对于用了一段时间,颁发了上千张证书的CA来说,就无法直接查看了,需要用到view菜单里的filter.可以根据证书的各个字段来做筛选,图片中我筛选了contoso\dc-232$申请的证书. 这里再介绍另一个基于Powershell的命令,Get-CertificationAuthority来筛选我们需要的信

Linux下简单的socket通信实例

Linux下简单的socket通信实例 If you spend too much time thinking about a thing, you’ll never get it done. —Bruce Lee       学习网络编程也一段时间了,刚开始看<UNIX网络编程>的时候,觉得这本厚厚的书好难啊!看到后来,发现并没有想象中的那么难.如果你是新手,建议你看到第二部分结束后,开始着手写代码.不写代码肯定是不行的.看100遍也没有敲一遍实现一遍来的清楚.敲完以后,带着问题去看书,你会

linux下简单抓包分析

有时候会遇到一些问题需要我们来抓包分析,当手头又没有专业的抓包工具的时候,可以用tcpdump来替代一下(一般的发行版都自带这个工具) 比如我们要分析一下eth0接口下跟192.168.7.188 这个目的IP地址22端口的发包情况 tcpdump -i eth0 dst 192.168.7.188 and port 22 tcpdump -i eth0 dst 192.168.7.188 and port 22 tcpdump: verbose output suppressed, use -

2.域控制器及证书颁发机构

安装域控制器部分: 1.修改计算机名称IP地址 2.安装AD DNS 角色 运行服务器向导 3.配置AD域 (选定域名,推荐公网内网一致) 安装配置证书颁发机构部分: 1.运行服务器向导,安装以下证书角色 证书颁发机构 证书颁发机构Web注册 2.配置证书颁发机构,企业根CA 3.配置证书颁发机构WEB注册 4.修改证书颁发机构属性,添加CRL部分访问方式(http 建议使用非80端口,如果要使用80端口,请和运营商确认是否需要备案开通 ) 5.修改证书颁发机构属性,添加证书AIA部分访问方式(

Linux下简单基本操作【备查】

Linux下简单基本操作[备查]①解压文件指令 tar zxvf filename (filename文件名)②查看修改文件内容 vi filename i 进入修改模式 修改后保存步骤 esc——shift+: ——wq(保存退出 q直接退出)③文件删除命令rm 命令格式:rm [fir] 文件或目录 参数说明: -f:强制删除 -i:交互模式,在删除前询问用户是否操作 -r:递归删除,常用在目录的删除 如删除/test目录下的file1文件,可以输入以下命令: rm -i /test/fil

Linux下简单的取点阵字模程序

源:Linux下简单的取点阵字模程序 Linux操作系统下进行简单的图形开发,经常会用到取字模的软件,但是Linux并没有像Windows下的小工具可用,我们也并不希望为了取字模而频繁地切换操作系统.(由于是完全由C语言编写,所以不需要任何修改,这个字库同样可以用在嵌入式环境的Windows操作系统下面) 本人结合网上的资料,对这个问题进行了总结,整理了代码,供有需要的朋友使用我参考.转载请注明出处:http://blog.csdn.net/weiwang876253631/article/de