# SSLSocket-Go **Repository Path**: fmldd/sslsocket-go ## Basic Information - **Project Name**: SSLSocket-Go - **Description**: Go实现SSL双向认证并通过套接字通讯; - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 1 - **Created**: 2021-01-19 - **Last Updated**: 2023-08-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SSLSocket-Go SSL/TLS理论基础参考: https://gitee.com/fmldd/ssl-tls #### Description Go实现SSL双向认证并通过套接字通讯; 注:x509: certificate relies on legacy Common Name field, use SANs or temporarily enable Common Name matching with GODEBUG=x509ignoreCN=0; go1.15版本开始废弃CommonName,因此推荐使用SAN证书;如果想兼容之前的方式,需要设置环境变量set GODEBUG=x509ignoreCN=0; #### 证书生成 1.生成自签名根证书 ``` :: 生成根证书私钥(pem文件) openssl genrsa -out root.key 2048 :: 生成根证书签发申请文件(csr文件) openssl req -new -key root.key -out root.csr -subj "/CN=localhost/C=CN/ST=rootprovince/L=rootcity/O=rootorganization/OU=rootgroup" :: 自签发根证书(cer文件) openssl x509 -req -days 365 -extensions v3_ca -signkey root.key -in root.csr -out root.crt ``` 2.通过CA证书签发服务端证书 ``` :: 生成服务端私钥 openssl genrsa -out server.key 2048 :: 生成证书请求文件 openssl req -new -key server.key -out server.csr -subj "/CN=localhost/C=CN/ST=serverprovince/L=servercity/O=serverorganization/OU=servergroup" :: 使用根证书签发服务端证书 openssl x509 -req -days 365 -extensions v3_req -CA root.crt -CAkey root.key -CAserial root.srl -CAcreateserial -in server.csr -out server.crt :: 使用CA证书验证服务端证书 openssl verify -CAfile root.crt server.crt ``` 3.通过CA证书签发客户端证书 ``` :: 生成客户端私钥 openssl genrsa -out client.key 2048 :: 生成证书请求文件 openssl req -new -key client.key -out client.csr -subj "/CN=localhost/C=CN/ST=clientprovince/L=clientcity/O=clientorganization/OU=clientgroup" :: 使用根证书签发客户端证书 openssl x509 -req -days 365 -extensions v3_req -CA root.crt -CAkey root.key -CAserial root.srl -CAcreateserial -in client.csr -out client.crt :: 使用CA证书验证客户端证书 openssl verify -CAfile root.crt client.crt ``` #### 文档