https证书自签

https

http over ssl = https 443/tcp

ssl: v3

tls: v1

https://

SSL会话的简化过程

(1) 客户端发送可供选择的加密方式,并向服务器请求证书;

(2) 服务器端发送证书以及选定的加密方式给客户端;

(3) 客户端取得证书并进行证书验正:

如果信任给其发证书的CA:

(a) 验正证书来源的合法性;用CA的公钥解密证书上数字签名;

(b) 验正证书的内容的合法性:完整性验正

(c) 检查证书的有效期限;

(d) 检查证书是否被吊销;

(e) 证书中拥有者的名字,与访问的目标主机要一致;

(4) 客户端生成临时会话密钥(对称密钥),并使用服务器端的公钥加密此数据发送给服务器,完成密钥交换;

(5) 服务用此密钥加密用户请求的资源,响应给客户端;

注意:SSL会话是基于IP地址创建;所以单IP的主机上,仅可以使用一个https虚拟主机;

回顾几个术语:PKI,CA,CRL,X.509 (v1, v2, v3)

配置httpd支持https:

(1) 为服务器申请数字证书;

测试:通过私建CA发证书

(a) 创建私有CA

(b) 在服务器创建证书签署请求

(c) CA签证

(2) 配置httpd支持使用ssl,及使用的证书;

# yum -y install mod_ssl

配置文件:/etc/httpd/conf.d/ssl.conf

DocumentRoot

ServerName

SSLCertificateFile

SSLCertificateKeyFile

(3) 测试基于https访问相应的主机;

# openssl s_client [-connect host:port] [-cert filename] [-CApath directory] [-CAfile filename]

测试实例过程:

用centos7:192.168.244.101 作为CA服务器

[[email protected] ~]# cd /etc/pki/CA/

[[email protected] CA]# ls

certs  crl  newcerts  private

[[email protected] CA]# (umask 077;openssl genrsa -out private//cakey.pem 2048)   #生成私钥

Generating RSA private key, 2048 bit long modulus

...............................................................................................................................................+++

........................+++

e is 65537 (0x10001)

[[email protected] CA]# ll

total 0

drwxr-xr-x. 2 root root  6 Jun 29  2015 certs

drwxr-xr-x. 2 root root  6 Jun 29  2015 crl

drwxr-xr-x. 2 root root  6 Jun 29  2015 newcerts

drwx------. 2 root root 22 May  9 22:00 private

[[email protected] CA]# ll private/

total 4

-rw-------. 1 root root 1675 May  9 22:00 cakey.pem

[[email protected] CA]# ls

certs  crl  newcerts  private

[[email protected] CA]# touch index.txt

[[email protected] CA]# echo 01 > serial

[[email protected] CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 7300  #给自己创建一个自签证书

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) []:FuJian

Locality Name (eg, city) [Default City]:XiaMen

Organization Name (eg, company) [Default Company Ltd]:wangsu

Organizational Unit Name (eg, section) []:Tech

Common Name (eg, your name or your server‘s hostname) []:www.fush.com

Email Address []:[email protected]

[[email protected] CA]# ll

total 8

-rw-r--r--. 1 root root 1407 May  9 22:05 cacert.pem

drwxr-xr-x. 2 root root    6 Jun 29  2015 certs

drwxr-xr-x. 2 root root    6 Jun 29  2015 crl

-rw-r--r--. 1 root root    0 May  9 22:01 index.txt

drwxr-xr-x. 2 root root    6 Jun 29  2015 newcerts

drwx------. 2 root root   22 May  9 22:00 private

-rw-r--r--. 1 root root    3 May  9 22:01 serial

到web(httpd)服务器上192.168.244.100:

[[email protected] conf]# cd /etc/httpd/

[[email protected] httpd]# mkdir ssl

[[email protected] httpd]# cd ssl/

[[email protected] ssl]# (umask 077;openssl genrsa -out httpd.key 1024)   ###生成key

Generating RSA private key, 1024 bit long modulus

.++++++

.............++++++

e is 65537 (0x10001)

[[email protected] ssl]# ll

total 4

-rw------- 1 root root 891 Jun 13 07:35 httpd.key

[[email protected] ssl]# 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) [XX]:CN

State or Province Name (full name) []:FuJian

Locality Name (eg, city) [Default City]:XiaMen

Organization Name (eg, company) [Default Company Ltd]:wangsu

Organizational Unit Name (eg, section) []:Tech

Common Name (eg, your name or your server‘s hostname) []:www.web1.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] ssl]# ll

total 8

-rw-r--r-- 1 root root 696 Jun 13 07:38 httpd.csr

-rw------- 1 root root 891 Jun 13 07:35 httpd.key

接下来把httpd.csr 传给ca服务器

[[email protected] ssl]# scp httpd.csr [email protected]:/tmp/

在ca服务器签署证书

[[email protected] CA]# openssl ca -in /tmp/httpd.csr -out certs/www.web1.com.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 10 02:30:52 2017 GMT

Not After : May 10 02:30:52 2018 GMT

Subject:

countryName               = CN

stateOrProvinceName       = FuJian

organizationName          = wangsu

organizationalUnitName    = Tech

commonName                = www.web1.com

emailAddress              = [email protected]

X509v3 extensions:

X509v3 Basic Constraints:

CA:FALSE

Netscape Comment:

OpenSSL Generated Certificate

X509v3 Subject Key Identifier:

84:0F:DF:DE:6B:A2:CE:38:5E:E3:A4:8D:64:00:9B:0D:9B:AA:7B:16

X509v3 Authority Key Identifier:

keyid:AE:F2:75:4B:53:5B:9E:2E:30:1F:AE:09:48:EE:0C:87:D2:87:E8:D0

Certificate is to be certified until May 10 02:30:52 2018 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] CA]# ls

cacert.pem  certs  crl  index.txt  index.txt.attr  index.txt.old  newcerts  private  serial  serial.old

[[email protected] CA]# ls newcerts/

01.pem

[[email protected] CA]# ls certs/

www.web1.com.crt

再将签署好的证书返回给httpd服务器

[[email protected] CA]# scp certs/www.web1.com.crt 192.168.244.100:/etc/httpd/ssl

接下来配置httpd,让其支持使用ssl

[[email protected] ssl]# yum install -y mod_ssl

[[email protected] ssl]# httpd -M |grep ssl

ssl_module (shared)

[[email protected] ssl]# rpm -ql mod_ssl

/etc/httpd/conf.d/ssl.conf

/usr/lib64/httpd/modules/mod_ssl.so

/var/cache/mod_ssl

/var/cache/mod_ssl/scache.dir

/var/cache/mod_ssl/scache.pag

/var/cache/mod_ssl/scache.sem

编辑前先复制一份

[[email protected] conf.d]# cp ssl.conf{,.bak}

[[email protected] conf.d]# ll

total 32

-rw-r--r-- 1 root root  392 Jan 13  2017 README

-rw-r--r-- 1 root root 9465 Dec 13  2016 ssl.conf

-rw-r--r-- 1 root root 9465 Jun 13 08:11 ssl.conf.bak

-rw-r--r-- 1 root root  299 Dec 13  2016 welcome.conf

[[email protected] conf.d]# vim /etc/httpd/conf.d/ssl.conf

主要修改如下几项:

<VirtualHost *:443>

DocumentRoot "/vhost/web1/htdocs"

ServerName www.web1.com:443

SSLCertificateFile /etc/httpd/ssl/www.web1.com.crt

SSLCertificateKeyFile /etc/httpd/ssl/httpd.key

[[email protected] conf.d]# ss  -tnl|grep 443

LISTEN     0      128                      :::443                     :::*

测试证书(用openssl s_client命令):

# openssl s_client [-connect host:port] [-cert filename] [-CApath directory] [-CAfile filename]

[[email protected] CA]# openssl s_client -connect 192.168.244.100:443 -CAfile /etc/pki/CA/cacert.pem

GET / HTTP/1.1

Host: www.web1.com   输入红色部分内容得到,连续回车可以得到内容

HTTP/1.1 200 OK

Date: Mon, 13 Jun 2016 00:47:59 GMT

Server: Apache/2.2.15 (CentOS)

Last-Modified: Sun, 12 Jun 2016 18:58:27 GMT

ETag: "216dd-13-535195b6de019"

Accept-Ranges: bytes

Content-Length: 19

Vary: Accept-Encoding

Connection: close

Content-Type: text/html; charset=UTF-8

192.168.244.100:80

closed

[[email protected] CA]# openssl s_client -connect 192.168.244.100:443 -servername www.web1.com

浏览器要先导入ca

通过浏览器测试:

18、httpd自带的工具程序

htpasswd: basic认证基于文件实现时,用到的账号密码文件生成工具;

apachectl:httpd自带的服务控制脚本,支持start, stop;

apxs:由httpd-devel包提供的,扩展httpd使用第三方模块的工具;

rotatelogs:日志滚动工具;

access.log -->

access.log, access.1.log

access.log, access.1.log, access.2.log

suexec:

访问某些有特殊权限配置的资源时,临时切换至指定用户运行;

ab: apache benchmark

19、http压力测试工具

ab

webbench

http_load

jmeter

loadrunner

tcpcopy

ab [OPTIONS] URL

-n: 总的请求数

-c:模拟的并发数 (类似于多少个人同时请求)

-k: 以持久连接模式测试

ulimit -n #: 调整当前用户所同时打开的文件数;

测试例子:

[[email protected] CA]# ab -c 100 -n 10000 http://192.168.244.100/deflate.html

This is ApacheBench, Version 2.3 <$Revision: 1430300 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.244.100 (be patient)

Completed 1000 requests

Completed 2000 requests

Completed 3000 requests

Completed 4000 requests

Completed 5000 requests

Completed 6000 requests

Completed 7000 requests

Completed 8000 requests

Completed 9000 requests

Completed 10000 requests

Finished 10000 requests

Server Software:        Apache/2.2.15

Server Hostname:        192.168.244.100

Server Port:            80

Document Path:          /deflate.html

Document Length:        20097 bytes

Concurrency Level:      100

Time taken for tests:   9.905 seconds

Complete requests:      10000

Failed requests:        0

Write errors:           0

Total transferred:      203920000 bytes

HTML transferred:       200970000 bytes

Requests per second:    1009.59 [#/sec] (mean)

Time per request:       99.050 [ms] (mean)

Time per request:       0.991 [ms] (mean, across all concurrent requests)

Transfer rate:          20105.06 [Kbytes/sec] received

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        0    2   7.6      0     122

Processing:    15   96  56.9     76     443

Waiting:        2   91  53.8     70     423

Total:         47   98  57.8     77     443

Percentage of the requests served within a certain time (ms)

50%     77

66%     89

75%    108

80%    122

90%    163

95%    218

98%    297

99%    332

100%    443 (longest request)

时间: 2024-10-14 17:59:41

https证书自签的相关文章

【HTTPS】自签CA证书 &amp;&amp; nginx配置https服务

首先,搭建https服务肯定需要一个https证书.这个证书可以看做是一个应用层面的证书.之所以这么说是因为https证书是基于CA证书生成的.对于正式的网站,CA证书需要到有资质的第三方证书颁发机构去申请获取.对于我们自建的一些小项目,可以使用自己的服务器自签CA证书.这类证书构建出来的HTTPS服务在访问的时候浏览器会发出不可信任的警告,对于自身项目无视即可. 参考文:[https://blog.csdn.net/xizaihui/article/details/53178897] ■ 自签

在okhttp3,WebView中忽略HTTPS证书校验

在APP开发过程中,后台使用的可能是自签的Https证书,如果不忽略证书校验,会出现Trust anchor for certification path not found的错误 Okhttp3忽略HTTPS证书校验 import java.security.SecureRandom; import java.security.cert.X509Certificate; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SS

申请https证书需要注意的4大问题

HTTPS证书是什么 https证书是数字证书中的一种,由受信任的数字证书颁发机构CA如[沃通CA]在验证服务器身份后颁发,具有服务器身份验证和数据传输加密 功能,因其要配置在服务器上,所以也称SSL服务器证书或者SSL证书.由合法CA机构颁发的ssl证书遵循ssl协议,通过在客户端浏览器和Web服务 器之间建立一条SSL安全通道,对传送的数据进行加密和隐藏;确保数据在传送中不被篡改和窃取,保障数据的完整性和安全性,ssl安全协议是由网景 (Netscape Communication)公司设计

自制Https证书并在Spring Boot和Nginx中使用(转)

白话Https一文中, 介绍了Https存在的目的和工作原理,但多是偏向于原理性的介绍,本文介绍如何一步一步自制一个能够通过浏览器认证的Https证书,并讲解在Spring Boot环境和Nginx环境中服务器端的配置. 如果你还没有读过白话Https,我强烈建议你先去读一下.按照白话Https中的介绍,Https协议涉及到的主体主要有三个:客户端.服务端.以及CA机构.如下图所示: 在白话Https一文中,曾介绍一个服务要申请使用Https的流程.本文所介绍的流程,针对自制Https证书,更多

项目迁移腾讯云后,用户反馈,https证书不匹配。

腾讯云大禹高防大禹BGP同一IP绑定多个证书,用户反馈无法匹配我们域名对应证书.但是浏览器是支持的.定位为客户端不支持sni在运维检查lb及高防证书关联无误,定位发现是用户端httpclient没有设置ssl.最终解决方案:不明确用户jdk版本,设置httpclient忽略证书验证. 引用: http://ju.outofmemory.cn/entry/115735 HTTPS和SNI HTTPS证书签名 ============================= 的前端代理服务器时候,通常会遇

Let&#39;s Encrypt,免费好用的 HTTPS 证书

#参考https://imququ.com/post/letsencrypt-certificate.html#####argparse安装#http://www.cnblogs.com/emanlee/p/4577249.html 很早之前我就在关注 Let's Encrypt 这个免费.自动化.开放的证书签发服务.它由 ISRG(Internet Security Research Group,互联网安全研究小组)提供服务,而 ISRG 是来自于美国加利福尼亚州的一个公益组织.Let's E

我的Android进阶之旅------&gt;Android关于HttpsURLConnection一个忽略Https证书是否正确的Https请求工具类

下面是一个Android HttpsURLConnection忽略Https证书是否正确的Https请求工具类,不需要验证服务器端证书是否正确 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.UnsupportedEn

MSXML2.ServerXMLHTTP &amp; HTTPS &amp; 证书过期 — msxml3.dll &#39;80072f05&#39;

昨天测试一个几天前写的一个应用,时不时的报错: msxml3.dll  '80072f05' The date in the certificate is invalid or has expired 经过上午3个小时的努力,终于找到原因和解决办法. 原因: 证书过期 解决办法: Dim xmlhttp Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")        xmlhttp.setOption(2) = 1305

免费好用的阿里云云盾证书服务(https证书)申请步骤

推荐一个免费的阿里云产品:云盾证书(https证书) 为了能让非专业人士看懂,同样尽量用直白的话,一般来说:当你个人需要建立网站,或者公司要建立官网.商城,通常需要先购买服务器或云主机,虚拟空间,然后将网页和程序.数据库部署上去,用户就可以用浏览器访问了,比如说浏览页面的内容.登录.发表评论.购物等.这时候浏览器默认是通过http协议与网站所在的服务器进行数据交互的,由于历史的原因,http被证实并不是那么安全,容易被别有用心的人窃取信息,于是就出现了https,也就是把http加密传输,区别就