亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C# 中的 gRPC 客戶端無法與支持 mTLS 的 Go 中的 gRPC 服務器一起使用

C# 中的 gRPC 客戶端無法與支持 mTLS 的 Go 中的 gRPC 服務器一起使用

Go
慕仙森 2023-08-21 14:50:23
我在 Golang 中有一個gRPC 服務器,它使用以下 ServerOptions 啟用了 mTLS:// getServerOptions returns a list of GRPC server options.// Current options are TLS certs and opencensus stats handler.func (h *serviceHandler) getServerOptions() []grpc.ServerOption {? ? tlsCer, err := tls.LoadX509KeyPair(tlsDir+"tls.crt", tlsDir+"tls.key")? ? if err != nil {? ? ? ? logger.WithError(err).Fatal("failed to generate credentials")? ? }? ? cfg := &tls.Config{? ? ? ? Certificates: []tls.Certificate{tlsCer},? ? ? ? ClientAuth:? ?tls.RequireAndVerifyClientCert,? ? ? ? GetConfigForClient: func(*tls.ClientHelloInfo) (*tls.Config, error) {? ? ? ? ? ? h.certMutex.RLock()? ? ? ? ? ? defer h.certMutex.RUnlock()? ? ? ? ? ? return &tls.Config{? ? ? ? ? ? ? ? Certificates: []tls.Certificate{tlsCer},? ? ? ? ? ? ? ? ClientAuth:? ?tls.RequireAndVerifyClientCert,? ? ? ? ? ? ? ? ClientCAs:? ? h.caCertPool,? ? ? ? ? ? }, nil? ? ? ? },? ? }? ? // Add options for creds and OpenCensus stats handler to enable stats and tracing.? ? return []grpc.ServerOption{grpc.Creds(credentials.NewTLS(cfg)), grpc.StatsHandler(&ocgrpc.ServerHandler{})}}服務器對于Golang 中的gRPC 客戶端工作正常,但在證書交換握手后對于以下 gRPC c# 客戶端失敗。? ? ? static async Task Main(string[] args)? ? ? ? {? ? ? ? ? ? string baseAddress = "x.x.x.x";? ? ? ? ? ? var x509Cert = new X509Certificate2("client.pfx", "123");? ? ? ? ? ? var client = CreateClientWithCert("https://" + baseAddress + ":443", x509Cert);? ? ? ? ? ? try {? ? ? ? ? ? ? ? var response = await client.PostAllocateAsync(new AllocationRequest {Namespace = "Default"});? ? ? ? ? ? ? ? Console.Write(response.State.ToString());? ? ? ? ? ? }?? ? ? ? ? ? catch(RpcException e)? ? ? ? ? ? {? ? ? ? ? ? ? ? Console.WriteLine($"gRPC error: {e.Status.Detail}");? ? ? ? ? ? }? ? ? ? ? ? catch?? ? ? ? ? ? {? ? ? ? ? ? ? ? Console.WriteLine($"Unexpected error calling agones-allocator");? ? ? ? ? ? ? ? throw;? ? ? ? ? ? }? ? ? ? }? ? }
查看完整描述

1 回答

?
慕沐林林

TA貢獻2016條經驗 獲得超9個贊

根本原因是當在 golang 服務器中使用 GetConfigForClient 時(在本例中用于刷新客戶端 CA 證書),來自 C# 客戶端的請求失敗。然而,當它被替換為VerifyPeerCertificate時,問題就得到了解決。


查看完整回答
反對 回復 2023-08-21
  • 1 回答
  • 0 關注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號