| 1 | |
| 2 | |
| 3 | |
| 4 | package client |
| 5 | |
| 6 | import ( |
| 7 | "context" |
| 8 | "net" |
| 9 | |
| 10 | "google.golang.org/grpc/credentials" |
| 11 | ) |
| 12 | |
| 13 | |
| 14 | func NewCredentials() credentials.TransportCredentials { |
| 15 | return &secureTC{ |
| 16 | info: credentials.ProtocolInfo{ |
| 17 | SecurityProtocol: "local", |
| 18 | }, |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | |
| 23 | type secureTC struct { |
| 24 | info credentials.ProtocolInfo |
| 25 | } |
| 26 | |
| 27 | func (c *secureTC) Info() credentials.ProtocolInfo { |
| 28 | return c.info |
| 29 | } |
| 30 | |
| 31 | func (*secureTC) ClientHandshake(_ context.Context, _ string, conn net.Conn) (net.Conn, credentials.AuthInfo, error) { |
| 32 | return conn, info{credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}}, nil |
| 33 | } |
| 34 | |
| 35 | func (*secureTC) ServerHandshake(conn net.Conn) (net.Conn, credentials.AuthInfo, error) { |
| 36 | return conn, info{credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}}, nil |
| 37 | } |
| 38 | |
| 39 | func (c *secureTC) Clone() credentials.TransportCredentials { |
| 40 | return &secureTC{info: c.info} |
| 41 | } |
| 42 | |
| 43 | func (c *secureTC) OverrideServerName(serverNameOverride string) error { |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | c.info.ServerName = serverNameOverride |
| 49 | return nil |
| 50 | } |
| 51 | |
| 52 | type info struct { |
| 53 | credentials.CommonAuthInfo |
| 54 | } |
| 55 | |
| 56 | func (info) AuthType() string { |
| 57 | return "local" |
| 58 | } |