Skip to content

Commit b82861f

Browse files
committed
调整readme.md的样式
1 parent ce9a4ec commit b82861f

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

readme.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#GOLANG搭建单、双向自认证HTTPS服务器
2-
###前言
1+
# GOLANG搭建单、双向自认证HTTPS服务器
2+
### 前言
33
>2015年双11期间淘宝、天猫实现了全站式https安全传输,web安全问题已经成了人们关注的话题,那什么是https呢?如何实现单、双向自认证https服务器呢?接下来我们将一一介绍。
44
5-
##一、HTTPS相关概念已经认证流程
6-
######基本概念:
5+
## 一、HTTPS相关概念已经认证流程
6+
###### 基本概念:
77
[**HTTPS**](http://baike.baidu.com/link?url=XuEFqp8HTAIWBO12QMzj54K1iIBGPL6VJGPEn85nyCirdG8LE104hMYvOeDgfucyMf3gu1zPLap3i0BKb-SKHa)(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。 它是一个URI scheme(抽象标识符体系),句法类同http:体系。用于安全的HTTP数据传输。https:URL表明它使用了HTTP,但HTTPS存在不同于HTTP的默认端口及一个加密/身份验证层(在HTTP与TCP之间)。这个系统的最初研发由网景公司(Netscape)进行,并内置于其浏览器Netscape Navigator中,提供了身份验证与加密通讯方法。现在它被广泛用于万维网上安全敏感的通讯,例如交易支付方面。关于https详细介绍请见:[大型网站的HTTPS实践](http://studygolang.com/articles/2984)
88

99
**SSL**(Secure Socket Layer):是Netscape公司设计的主要用于WEB的安全传输协议。从名字就可以看出它在https协议栈中负责实现上面提到的加密层。
@@ -31,15 +31,15 @@
3131
##二、自认证根证书
3232
1. 创建根证书密钥文件(自己做CA)root.key:
3333

34-
```shell
34+
``` shell
3535
$openssl genrsa -des3 -out root.key 2048
3636
```
3737

3838
需要输入两次私钥密码
3939
![](/res/1.png)
4040
2. 创建根证书的申请文件root.csr:
4141

42-
```shell
42+
``` shell
4343
$openssl req -new -key root.key -out root.csr
4444
```
4545

@@ -48,7 +48,7 @@
4848

4949
3. 创建根证书root.crt:
5050

51-
```shell
51+
``` shell
5252
$openssl x509 -req -days 3650 -sha256 -extensions v3_ca -signkey root.key -in root.csr -out root.crt
5353
```
5454

@@ -58,31 +58,31 @@
5858
##三、SSL单向认证
5959
1. 创建服务器证书秘钥
6060

61-
```shell
61+
``` shell
6262
$openssl genrsa –des3 -out server.key 2048
6363
```
6464

6565
需要输入两次私钥密码
6666
![](/res/4.png)
6767
2. 去除key口令
6868

69-
```shell
69+
``` shell
7070
$openssl rsa -in server.key -out server.key
7171
```
7272

7373
需要输入私钥密码
7474
![](/res/5.png)
7575
3. 创建服务器证书申请文件server.csr
7676

77-
```shell
77+
``` shell
7878
$openssl req -new -key server.key -out server.csr
7979
```
8080

8181
"Common Name"最好跟网站的域名一致
8282
![](/res/6.png)
8383
4. 创建服务器证书server.crt
8484

85-
```shell
85+
``` shell
8686
$openssl x509 -req -days 365 -sha256 -extensions v3_req -CA root.crt -CAkey root.key -CAcreateserial -in server.csr -out server.crt
8787
```
8888

@@ -100,7 +100,7 @@
100100
![](/res/15.png)
101101
6. golang实现简单的https服务器
102102

103-
```Go
103+
``` Go
104104
package main
105105

106106
import (
@@ -130,38 +130,38 @@
130130

131131
1. 创建客户端证书私钥
132132

133-
```shell
133+
``` shell
134134
$openssl genrsa -des3 -out client.key 2048
135135
```
136136

137137
需要输入两次私钥密码
138138
![](/res/17.png)
139139
2. 去除key口令
140140

141-
```shell
141+
``` shell
142142
$openssl rsa -in client.key -out client.key
143143
```
144144

145145
需要输入私钥密码
146146
![](/res/18.png)
147147
3. 创建客户端证书申请文件client.csr
148148

149-
```shell
149+
``` shell
150150
$openssl req -new -key client.key -out client.csr
151151
```
152152

153153
![](/res/19.png)
154154

155155
3. 创建客户端证书文件client.crt
156156

157-
```shell
157+
``` shell
158158
$openssl x509 -req -days 365 -sha256 -extensions v3_req -CA root.crt -CAkey root.key -CAcreateserial -in client.csr -out client.crt
159159
```
160160

161161
![](/res/20.png)
162162
4. 将客户端证书文件client.crt和客户端证书密钥文件client.key合并成客户端证书安装包client.pfx
163163

164-
```shell
164+
``` shell
165165
$openssl pkcs12 -export -in client.crt -inkey client.key -out client.pfx
166166
```
167167

@@ -173,7 +173,7 @@
173173
![](/res/21.png)
174174
3. 修改服务器代码
175175

176-
```Go
176+
``` Go
177177
package main
178178

179179
import (
@@ -222,7 +222,7 @@
222222
![](/res/22.png)
223223
5. 使用golang访问https服务器
224224

225-
```Go
225+
``` Go
226226
package main
227227

228228
import (
@@ -269,5 +269,5 @@
269269

270270
```
271271

272-
###结语
272+
### 结语
273273
希望通过这次实例能让大家更好的理解、应用https,谢谢观看。

0 commit comments

Comments
 (0)