首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >golang使用自定义openssl?

golang使用自定义openssl?

提问于 2022-07-06 16:59:06
回答 0关注 0查看 197

我项目中grpc需要对证书进行验证,使用x509,但是线上服务器openssl的版本太低0.9.7,并且线上服务器使用了集群,会不定时的进行迁移项目,所以升级线上服务器的openssl版本无法实现,现在我想的是在项目中自定义一个高版本的openssl,然后x509解析证书时使用自定义的高版本,但是我查看对应的package,没有找到添加自定义openssl的地方,问一下大家有什么方法可以让我的x509使用高版本openssl?

var certFile, _ = filepath.Abs("conf/pem/ser.pem")
	var keyFile, _ = filepath.Abs("conf/pem/ser.auto_key")
	var client_ca, _ = filepath.Abs("conf/pem/ca.pem")

	var opts []grpc.ServerOption
	certificate, err := tls.LoadX509KeyPair(
		certFile,
		keyFile,
	)

	certPool := x509.NewCertPool()
	bs, err := ioutil.ReadFile(client_ca)
	if err != nil {
		log.Fatalf("failed to read client ca cert: %s", err)
	}

	ok := certPool.AppendCertsFromPEM(bs)
	if !ok {
		log.Fatal("failed to append client certs")
	}

	tlsConfig := &tls.Config{
		ClientAuth:   tls.RequireAndVerifyClientCert,
		Certificates: []tls.Certificate{certificate},
		ClientCAs:    certPool,
	}

	serverOption := grpc.Creds(credentials.NewTLS(tlsConfig))
	opts = []grpc.ServerOption{serverOption}
	s := grpc.NewServer(opts...)

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档