OpenSSL - 利用OpenSSL自签证书和CA颁发证书
秘钥操作
这个命令会生成一个1024/2048位的密钥,包含私钥和公钥。
openssl genrsa -out private.key 1024/2038 (with out password protected)
openssl genrsa -des3 -out private.key 1024/2048 (password protected)
这个命令可以利用private.key文件生成公钥。
openssl rsa -in private.key -pubout -out public.key
查看私钥命令
openssl rsa -noout -text -in public.key
证书请求
openssl req -new -key private.key -out cert.csr (-config openssl.cnf)
openssl req -new -nodes -key private.key -out cert.csr (-config openssl.cnf)
这个命令将会生成一个证书请求,当然,用到了前面生成的密钥private.key文件
这里将生成一个新的文件cert.csr,即一个证书请求文件,你可以拿着这个文件去数字证书颁发机构(即CA)申请一个数字证书。CA会给你一个新的文件cacert.pem,那才是包含公钥给对方用的数字证书。
查看证书请求
openssl req -noout -text -in cert.csr
生成证书
自签名证书,用于自己测试,不需要CA签发
openssl req -new -x509 -key private.key -out cacert.pem -days 1095 (-config openssl.cnf)
CA签发证书:
CA是专门签发证书的权威机构,处于证书的最顶端。自签是用自己的私钥给证书签名,CA签发则是用CA的私钥给自己的证书签名来保证证书的可靠性,
利用OpenSSL可以自己作为CA进行证书签发,当然这并不权威。
CA签发证书生成的cacert.pem 见“建立CA颁发证书”
有了private.key和cacert.pem文件后就可以在自己的程序中使用了,比如做一个加密通讯的服务器
从证书中提取公钥
openssl x509 -in cacert.pem -pubkey >> public.key
查看证书信息
openssl x509 -noout -text -in cacert.pem
建立CA颁发证书
(1) 环境准备
首先,需要准备一个目录放置CA文件,包括颁发的证书和CRL(Certificate Revoke List)。
mkdir ./CA
(2) 创建配置文件
之前生成秘钥和证书可以进行命令行配置,但是在创建CA的时候必须使用配置文件,因为做证书颁发的时候只能使用配置文件。
创建配置文件如下:vi openssl.cnf
################################################################
# openssl example configuration file.
# This is mostly used for generation of certificate requests.
#################################################################
[ ca ]
default_ca= CA_default # The default ca section
################################################################# [ CA_default ] dir=/opt/iona/OrbixSSL1.0c/certs # Where everything is kept
certs=$dir # Where the issued certs are kept
crl_dir= $dir/crl # Where the issued crl are kept
database= $dir/index.txt # database index file
new_certs_dir= $dir/new_certs # default place for new certs
certificate=$dir/CA/OrbixCA # The CA certificate
serial= $dir/serial # The current serial number
crl= $dir/crl.pem # The current CRL
private_key= $dir/CA/OrbixCA.pk # The private key
RANDFILE= $dir/.rand # private random number file
default_days= # how long to certify for
default_crl_days= # how long before next CRL
default_md= md5 # which message digest to use
preserve= no # keep passed DN ordering # A few different ways of specifying how closely the request should
# conform to the details of the CA 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 =
default_keyfile= privkey.pem
distinguished_name = req_distinguished_name
attributes = req_attributes [ req_distinguished_name ]
countryName= Country Name ( letter code)
countryName_min=
countryName_max =
stateOrProvinceName= State or Province Name (full name)
localityName = Locality Name (eg, city)
organizationName = Organization Name (eg, company)
organizationalUnitName = Organizational Unit Name (eg, section)
commonName = Common Name (eg. YOUR name)
commonName_max =
emailAddress = Email Address
emailAddress_max = [ req_attributes ]
challengePassword = A challenge password
challengePassword_min =
challengePassword_max =
unstructuredName= An optional company name
根据配置文件。创建以下三个文件:
touch index.txt
touch index.txt.attr
touch serial 内容为01
(3) 生成CA私钥和证书
openssl genrsa -out ca.key 1024
openssl req -new -x509 -key ca.key -out ca.pem -days 365 -config openssl.cnf (CA只能自签名证书,注意信息与要颁发的证书信息一致)
(4) 颁发证书
颁发证书就是用CA的秘钥给其他人签名证书,输入需要证书请求,CA的私钥及CA的证书,输出的是签名好的还给用户的证书
这里用户的证书请求信息填写的国家省份等需要与CA配置一致,否则颁发的证书将会无效。
openssl ca -in ../cert.csr -out cacert.pem -cert ca.pem -keyfile ca.key -config openssl.cnf
对比CA颁发的证书提取公钥和私钥导出的公钥是否一致:

同时产生01.pem,这个是CA的备份保留,与生成发送给请求证书的内容一致,serial内序号自动+1。
OpenSSL - 利用OpenSSL自签证书和CA颁发证书的更多相关文章
- CA证书、自颁发证书、自签名证书联系
一.理论基础 ssl:secure socket layer(安全套接层协议)的缩写,通过此协议可以保证两个应用通信的可靠性和保密性.openssl:是ssl协议的实现.提供了对称加密算法.非对称加密 ...
- 自己搭建CA颁发证书做https加密网站
192.168.10.187 CA服务器 192.168.10.190 web服务器 (1)搭建CA cd /etc/pki/CA 在这个目录下创建serial和index.txt两个文件 echo ...
- 自建 ca 及使用 ca 颁发证书
创建CA: 一.安装openssl [root@localhost ~]# yum install -y openssl 二.创建CA的相关文件及目录 mkdir /opt/root_ca & ...
- 搭建CA颁发证书做https加密网站
92.168.10.187 CA服务器 192.168.10.190 web服务器 (1)搭建CA cd /etc/pki/CA 在这个目录下创建serial和index.txt两个文件 echo 0 ...
- [加密]证书、CA、证书信任链
转自:https://www.jianshu.com/p/6bf2f9a37feb TLS 传输层安全性协定 TLS(Transport Layer Security),及其前身安全套接层 SSL(S ...
- 部署自建CA颁发证书实现https加密
理论忽略:百度上很多 需求:自建证书并实现域名的https加密 部署: 在linux机器上执行以下命令生成私钥 mkdir -p /opt/ssl-cert cd /opt/ssl-cert 1.# ...
- 【openssl】利用openssl完成X509证书和PFX证书之间的互转
利用openssl完成X509证书和PFX证书之间的互转 # OpenSSL的下载与安装: 1.下载地址: 官方网址—— https://www.openssl.org/source/ OpenSSL ...
- 数字证书的理解以及自建CA机构颁发证书
一.理解什么是数字证书 http://www.cnblogs.com/JeffreySun/archive/2010/06/24/1627247.html 理解数字证书等概念,无数次想好好看 ...
- 利用openssl管理证书及SSL编程第1部分: openssl证书管理
利用openssl管理证书及SSL编程第1部分 参考:1) 利用openssl创建一个简单的CAhttp://www.cppblog.com/flyonok/archive/2010/10/30/13 ...
随机推荐
- 【20160924】GOCVHelper 图像处理部分(3)
//根据轮廓的圆的特性进行选择 vector<VP> selectShapeCircularity(Mat src,Mat& draw,vector<VP> c ...
- sql 、linq、lambda 查询语句的区别
LINQ的书写格式如下: from 临时变量 in 集合对象或数据库对象 where 条件表达式 [order by条件] select 临时变量中被查询的值 [group by 条件] Lambda ...
- consul模板配置参数值示例
参看https://github.com/hashicorp/consul-template#examples // This is the address of the Consul agent. ...
- ubuntu14.04纯命令行下连接有线网和无线网
在ubuntu下网络管理器Network Manager莫名奇妙出现无法连接无线网的情况,于是昨天就开始着手解决这一问题: 一 :卸载 1.第一步卸载Network-Manager (具体字母的大小写 ...
- Cron表达式简单学习
CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTrigger,你可以指定触 ...
- 学的一点点ps
从C语言的代码中解脱开始学ps,看到色彩鲜明的东西,心里只有那么爽.哈哈.只学习3天,虽然只是一些皮毛,可还是学到了一些以前不知道的东西.让我对ps多了很多兴趣,决定以后要自学更多的ps技能.要给图片 ...
- openstack 流量控制
G版的流量控制,可以在horizon通过对flavor进行配置来实现 1.有admin权限,点击admin进入管理界面:点击Flavors,选取要控制的flavor:点击more,找到View Ext ...
- [Oracle] SQL*Loader 详细使用教程(2)- 命令行参数
sqlldr工具 SQL*Loader的客户端工具是sqlldr,在操作系统的命令行下输入sqlldr,后面不接任何参数,将显示帮助信息如下所示(所有命令行参数的简单描述及其默认值),所以你并不需 ...
- windows+linux开发环境 解决laravel blade模板缓存问题
编码环境windows10 编码IDE:phpstorm 2016.2 PHP框架:laravel5.3 + 代码运行环境:centos7 + nginx 在开发过程中,上传blade模板文件到lin ...
- Deep Learning 5_深度学习UFLDL教程:PCA and Whitening_Exercise(斯坦福大学深度学习教程)
前言 本文是基于Exercise:PCA and Whitening的练习. 理论知识见:UFLDL教程. 实验内容:从10张512*512自然图像中随机选取10000个12*12的图像块(patch ...