模拟CA自签证书

第一部分,配置CA的工作环境

1、 配置CA工作配置文件

vim /etc/pki/tls/openssl.cnf 

[ CA_default ] # CA的配置信息

dir             = /etc/pki/CA           # Where everything is kept ,CA的工作目录
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 ,CA自己的证书
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 ,CA自己的私钥
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

default_days    = 365                   # how long to certify for
default_crl_days= 30                    # how long before next CRL
default_md      = sha256                # use SHA-256 by default
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

[ req_distinguished_name ]  #请求者的默认信息,主机名和邮件不会默认
countryName                     = Country Name (2 letter code)
countryName_default             = CN
countryName_min                 = 2
countryName_max                 = 2

stateOrProvinceName             = State or Province Name (full name)
stateOrProvinceName_default    = GD

localityName                    = Locality Name (eg, city)
localityName_default            = SHENZHEN

0.organizationName              = Organization Name (eg, company)
0.organizationName_default      = SZXX

# 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 =  TECH

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

2、生成CA的私钥

cd /etc/pki/CA
(umask 077;openssl genrsa -out private/cakey.pem 2048)  # 生成一个私钥 

# ls private/
cakey.pem

openssl rsa -in cakey.pem  -pubout # 从私钥中提取公钥

3、根据私钥生成CA自己的证书

 openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365  # 加上-x509 参数用来生成一个自签证书
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) [CN]:
State or Province Name (full name) [GD]:
Locality Name (eg, city) [shengzhen]:
Organization Name (eg, company) [SZXX]:
Organizational Unit Name (eg, section) [IT]:
Common Name (eg, your name or your server‘s hostname) []:ca.fish.com  -- 这个名字非常重要,跟主机名或者DNS保持一致
Email Address []:[email protected]

# openssl x509 -text -in private/cakey.pem    -- 查看证书中的信息

4、创建颁发证书时工作的目录和文件

mkdir certs  crl newcerts
touch index.txt
echo 01 > serial

# tree .
.
├── cacert.pem
├── certs
├── crl
├── index.txt
├── newcerts
├── private
│?? └── cakey.pem
├── serial

第二部分,准备客户端签发的证书请求

1、客户端生成私钥

mkdir /etc/httpd/ssl
cd /etc/httpd/ssl

(umask 077; openssl genrsa -out httpd.key 1024)

2、客户端生成证书请求

# openssl req -new -key httpd.key -out httpd.csr
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) [CN]:
State or Province Name (full name) [GD]:
Locality Name (eg, city) [shengzhen]:
Organization Name (eg, company) [SZXX]:
Organizational Unit Name (eg, section) [IT]:
Common Name (eg, your name or your server‘s hostname) []:www.fish.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 []:

3、CA 根据证书申请请求办法证书,此时客户端的证书请求一般是拷贝到CA服务器上的

openssl ca -in httpd.csr -out http.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: May 29 14:33:26 2019 GMT
            Not After : May 28 14:33:26 2020 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = GD
            organizationName          = SZXX
            organizationalUnitName    = IT
            commonName                = www.fish.com
            emailAddress              = [email protected]
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier:
                F6:61:F0:99:90:29:F7:66:5E:55:F9:D1:D0:7F:58:14:CA:53:0A:72
            X509v3 Authority Key Identifier:
                keyid:88:A4:07:29:65:16:7D:A0:87:26:B0:0D:AC:22:DB:3A:5A:12:FF:20

Certificate is to be certified until May 28 14:33:26 2020 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

# ll
total 12
-rw-r--r-- 1 root root 3840 May 29 22:34 http.crt
-rw-r--r-- 1 root root  696 May 29 22:32 httpd.csr
-rw------- 1 root root  887 May 29 22:29 httpd.key

3、此时CA的情况

# cat /etc/pki/CA/index.txt
V   200528143326Z       01  unknown /C=CN/ST=GD/O=SZXX/OU=IT/CN=www.fish.com/[email protected]

# cat /etc/pki/CA/serial
02

原文地址:https://blog.51cto.com/395469372/2402377

时间: 2024-10-21 15:30:51

模拟CA自签证书的相关文章

架设CA服务器实现https通信,web服务器使用CA自签证书与https通信

. 教程目标:web服务器使用CA自签证书与https通信 日    期:2015年08月19日 联系邮箱:[email protected] Q Q  群:1851 15701 51CTO博客首页:http://990487026.blog.51cto.com 做一个对读者负责的博主. ====================================================准备: 系统环境:CentOS 6.6 X64 Desktop安装,附加开发工具包的安装 本机作为签证机构

创建CA自签证书

创建CA自签证书 1,创建CA服务器的私钥: (umask 0077;openssl genrsa -out cakey.pem 2048) 注意:将私钥放在目录下 /etc/pki/CA/private 2,创建CA服务器自签证书: [[email protected] CA]# openssl req -new -x509 -key cakey.pem -out /etc/pki/CA/cacert.pem You are about to be asked to enter informa

Openssl应用实例:创建私有CA并申请证书

一:实验环境 CA:centos6   172.17.252.226 客户端:centos7 172.17.252.188 二:阅读CA相关配置文件 CA配置文件路径:/etc/pki/tls/openssl.cnf 图一 图二 图三 三:证书申请及签署步骤 1.生成申请请求 2.RA核验 3.CA签署 4.获取证书 具体实验步骤 一:创建私有CA(certificate autrority  签证机构)    ##操作环境:centos6 1.创建所需要的文件  (如图一所示) ①生成证书索引

创建私有CA及颁发证书

证书申请及签署步骤: 1.生成申请请求 2.RA核验 3.CA签署 4.获取证书 三种策略:匹配.支持和可选 ①匹配:指要求申请填写的信息跟CA设置信息必须一致,默认国家.省.公司信息必须一致 ②支持:指必须填写这项申请信息,但是可以和CA信息不一致 ③可选:指可有可无 创建私有CA及颁发证书步骤: 1.创建所需要的文件 ①openssl的配置文件:/etc/pki/tls/openssl.cnf 如果没有这个文件,那么需要安装一个包 rpm -ivh openssl-libs-1.0.1e-6

如何使用"OpenSSL"自签证书(Self-Sign Certificate)

当您访问自己组织或个人的服务时是否经常遇到如下的证书问题: 当然,您可以容忍此错误,Continue to this website. 或者从CA(证书颁发机构)购买SSL证书,除此之外我们是否还有更多的选择呢? 是的,我们可以使用OpenSSL创建个人的免费证书. OpenSSL OpenSSL是大多数MacOS X,Linux,和Unix安装的免费工具. 您还可以在 http://slproweb.com/products/Win32OpenSSL.html 下载Windows版本进行使用.

使用OpenSSL创建CA和申请证书

OpenSSL简介 OpenSSL是一种加密工具套件,可实现安全套接字层(SSL v2 / v3)和传输层安全性(TLS v1)网络协议以及它们所需的相关加密标准. openssl命令行工具用于从shell程序使用OpenSSL加密库的各种加密功能. 它可以用于: 创建和管理私钥,公钥和参数 公钥加密操作 创建X.509证书,CSR和CRL 消息摘要的计算 使用密码进行加密和解密 SSL / TLS客户端和服务器测试 处理S / MIME签名或加密的邮件 时间戳记请求,生成和验证 openssl

使用OpenSSL创建私有CA、签署证书

OpenSSL工具包是Linux上SSL v2/v3和TLS v1协议的实现方式之一,并建提供了常用的加密解密功能. OpenSSL主要由三部分组成: 1:libcrypto:加密库,主要用来实现加密.解密的功能库 2:libssl:实现SSL服务器端功能会话库 3:openssl命令行工具:/usr/bin/openssl 本文仅是介绍如何通过openssl命令创建私有CA,以及如何申请证书.签署证书等过程. 证书主要包含的就是拥有者自身的属性信息.公钥以及CA的签名,核心就是用户的公钥.服务

Openssl 创建CA和申请证书

Openssl 创建CA和申请证书 =============================================================================== 概述: 本章是上篇加密解密技术的续,主要介绍Openssl创建CA.申请证书.办法证书的整个操作,具体内容如下: 创建私有CA: 给节点颁发证书: 吊销证书  详情查看上篇加密解密技术:http://1992tao.blog.51cto.com/11606804/1856438 ============

OpenSSL:实现创建私有CA、签署证书请求详解

一.OpenSSL:CA默认配置信息 1.证书签发机构CA:公共信任CA.私有CA 建立私有CA方式如下: 小范围测试使用openssl. 大范围维护大量证书企业使用OpenCA(对openssl进行了二次封装,更加方便使用) 2.openssl 配置文件:/etc/pki/tls/openssl.cnf [[email protected] tmp]# cat  /etc/pki/tls/openssl.cnf 该配置文件中以 "[配置段]",的形式配置相关信息 ==========