由于最近项目用到了skywalking,在开启了tls后发现grpc报错:
authentication handshake failed: x509: certificate relies on legacy Common Name field, use SANs instead....
查找资料后发现是因为 go 1.15 版本开始废弃 CommonName,因此推荐使用 SAN 证书。 如果想兼容之前的方式,需要设置环境变量 GODEBUG 为 x509ignoreCN=0。
我不想修改GO的环境变量,因此我打算重新做下证书,下面把步骤记录下
# Changes these CN's to match your hosts in your environment if needed.
SERVER_CN=localhost # Server common name
#---------------------CA
# 生成ca .key 私钥文件
echo Generate CA key:
openssl genrsa -out ca.key 2048
# 自签名生成ca .crt 证书文件
echo Generate CA certificate:
# 如果在 Windows 使用 Git Bash 出现错误
# name is expected to be in the format /type0=value0/type1=value1/type2=... where characters may be escaped by \. This name is not in that format: ...
# 则需要在命令前加上
# MSYS_NO_PATHCONV=1
# 例如 MSYS_NO_PATHCONV=1 openssl ...
MSYS_NO_PATHCONV=1 openssl req -new -x509 -da