自建CA并签名server证书实现https

因为目前环境在本地进行测试,所以我们采用自建CA并签名server证书的方式实现https。(如果使用AWS服务则是AWS作为CA,并根据我们提供的资料生成server证书)

数字签名相关知识课参阅:https://blog.csdn.net/m0_37263637/article/details/80285143
server环境:nginx(ubuntu)
工具:openssl
名词说明:CA 证书授权中心(Certificate Authority )
参考链接:http://www.cnblogs.com/kyrios/p/tls-and-certificates.html

1 自建CA

1.1 生成CA私匙

openssl genrsa -out icatchtek.key 2048

1.2 生成CA证书请求

openssl req -new -key icatchtek.key -out icatchtek.csr

过程中需要你输入该根证书相关信息
PS:证书请求是对签名的请求,需要使用私钥进行签名

1.3 生成CA根证书

openssl x509 -req -in icatchtek.csr -extensions v3_ca -signkey icatchtek.key -out icatchtek.crt

这里就得到的CA的根证书
PS:证书是自签名或CA签名过的凭据,用来进行身份认证

2 自建server端证书

2.1 生成server私匙

openssl genrsa -out smarthome_server.key 2048

2.2 生成server证书请求

openssl req -new -key smarthome_server.key -out smarthome_server.csr

2.3 生成server证书

生成server证书,需要一份配置文件,可参阅:vi openssl.cnf

[req]  
    distinguished_name = req_distinguished_name  
    req_extensions = v3_req  

    [req_distinguished_name]  
    countryName = Country Name (2 letter code)  
    countryName_default = CN  
    stateOrProvinceName = State or Province Name (full name)  
    stateOrProvinceName_default = SiChuan  
    localityName = ChengDu (eg, city)  
    localityName_default = xx.xx
    organizationalUnitName  = xxxxxx
    organizationalUnitName_default  = Domain Control Validated  
    commonName = Internet Widgits Ltd  
    commonName_max  = 64  

    [ v3_req ]  
    # Extensions to add to a certificate request  
    basicConstraints = CA:FALSE  
    keyUsage = nonRepudiation, digitalSignature, keyEncipherment  
    subjectAltName = @alt_names  

    [alt_names]  
   #注意这个IP.1的设置,IP地址需要和你的服务器的监听地址一样 DNS为server网址
    IP.1 = 172.28.28.4
    DNS.1 = www.helloworld.com

需要将server监听的地址写入证书中,如果方式时地址与证书中地址不一致将不能通过证书认证。
执行命令生成server证书

openssl x509 -days 365 -req -in smarthome_server.csr -extensions  v3_req -CAkey icatchtek.key -CA icatchtek.crt -CAcreateserial -out smarthome_server.crt  -extfile openssl.cnf

-days 为证书有效期

3 在server部署server证书

Nginx 部署可参考:https://blog.csdn.net/m0_37263637/article/details/80077925
在2中我们得到了经过CA认证后的并生成的server证书,现在我们将证书部署到nginx目录下进行测试.
在nginx.conf中 server 块内 listen 端口后添加下面的语句

      ssl on;
      ssl_certificate      /home/ubuntu/webvideo/nginx/conf/smarthome_server.crt;
      ssl_certificate_key  /home/ubuntu/webvideo/nginx/conf/smarthome_server.key;

我们直接访问nginx 开放的端口,会得到浏览器的警告:
这里写图片描述
PS:2中openssl.cnf中的地址一定要与nginx架设地址一致。

4 将自建CA根证书加入到浏览器

因为我们不是官方的CA机构并没有内置在浏览器或系统中,所以浏览器会认为该CA非法,此时我们需要将我们自建CA的根证书加入到浏览器中。(1操作流程中得到的证书)

  • Chrome :设置-设置-设置-高级-隐私设置和安全性-管理证书-导入
  • 火狐:设置-选项-高级-证书-查看证书-证书机构-导入

以上设置均可百度相关浏览器导入证书。
IE 和 safari 使用的windows 默认证书导入方式但不能被识别
现在访问就没有这个警告了。
这里写图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值