1 回答

TA贡献2012条经验 获得超12个赞
即我需要在加载客户端证书结构后对其进行修改。这需要解码 PEM 并解析出证书。对于 API Gateway 客户端证书,我必须将BasicConstraintsValidand设置IsCA为 true 和KeyUsageto KeyUsageCertSign; 对于我本地生成的证书,我只需要后两个。enableClientAuth()在我的问题中修改func:
func enableClientAuth(server *http.Server, clientCertFile string) error {
pemBytes, err := ioutil.ReadFile(clientCertFile)
if err != nil {
return err
}
pemBlock, _ := pem.Decode(pemBytes)
clientCert, err := x509.ParseCertificate(pemBlock.Bytes)
if err != nil {
return err
}
clientCert.BasicConstraintsValid = true
clientCert.IsCA = true
clientCert.KeyUsage = x509.KeyUsageCertSign
caCertPool := x509.NewCertPool()
caCertPool.AddCert(clientCert)
tlsConfig := &tls.Config{
ClientAuth: tls.RequireAndVerifyClientCert,
ClientCAs: caCertPool,
}
tlsConfig.BuildNameToCertificate()
server.TLSConfig = tlsConfig
return nil
}
- 1 回答
- 0 关注
- 293 浏览
添加回答
举报