Skip to content

Commit

Permalink
fix: grpc mTLS client dns_name bind logic mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed May 17, 2024
1 parent c0958de commit 02a3f86
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/rpc/app/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ func SetAuthInfoWithContext(ctx context.Context) (context.Context, error) {
return ctx, status.Error(codes.Unauthenticated, "get peer from context failed")
}
tlsAuth, ok := p.AuthInfo.(credentials.TLSInfo)
if !ok {
if !ok || len(tlsAuth.State.PeerCertificates) == 0 || len(tlsAuth.State.PeerCertificates[0].DNSNames) == 0 {
return ctx, status.Error(codes.Unauthenticated, "get tls info from peer failed")
}

return SetAuthInfo(ctx, &AuthInfo{
AppCode: tlsAuth.State.ServerName,
AppCode: tlsAuth.State.PeerCertificates[0].DNSNames[0],
}), nil
}

Expand Down

0 comments on commit 02a3f86

Please sign in to comment.