Skip to content

Commit 78c4cbf

Browse files
committed
Fix vet
1 parent e1ebfe8 commit 78c4cbf

File tree

3 files changed

+8
-82
lines changed

3 files changed

+8
-82
lines changed

experimental/credentials/credentials_test.go

+4-20
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,6 @@ func Test(t *testing.T) {
4141
grpctest.RunSubTests(t, s{})
4242
}
4343

44-
// A struct that implements AuthInfo interface but does not implement GetCommonAuthInfo() method.
45-
type testAuthInfoNoGetCommonAuthInfoMethod struct{}
46-
47-
func (ta testAuthInfoNoGetCommonAuthInfoMethod) AuthType() string {
48-
return "testAuthInfoNoGetCommonAuthInfoMethod"
49-
}
50-
51-
// A struct that implements AuthInfo interface and implements CommonAuthInfo() method.
52-
type testAuthInfo struct {
53-
credentials.CommonAuthInfo
54-
}
55-
56-
func (ta testAuthInfo) AuthType() string {
57-
return "testAuthInfo"
58-
}
59-
6044
func (s) TestTLSOverrideServerName(t *testing.T) {
6145
expectedServerName := "server.name"
6246
c := NewTLSWithALPNDisabled(nil)
@@ -157,8 +141,8 @@ func compare(a1, a2 credentials.AuthInfo) bool {
157141
}
158142
switch a1.AuthType() {
159143
case "tls":
160-
state1 := a1.(TLSInfo).State
161-
state2 := a2.(TLSInfo).State
144+
state1 := a1.(credentials.TLSInfo).State
145+
state2 := a2.(credentials.TLSInfo).State
162146
if state1.Version == state2.Version &&
163147
state1.HandshakeComplete == state2.HandshakeComplete &&
164148
state1.CipherSuite == state2.CipherSuite &&
@@ -255,7 +239,7 @@ func tlsServerHandshake(conn net.Conn) (credentials.AuthInfo, error) {
255239
if err != nil {
256240
return nil, err
257241
}
258-
return TLSInfo{State: serverConn.ConnectionState(), CommonAuthInfo: credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}}, nil
242+
return credentials.TLSInfo{State: serverConn.ConnectionState(), CommonAuthInfo: credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}}, nil
259243
}
260244

261245
func tlsClientHandshake(conn net.Conn, _ string) (credentials.AuthInfo, error) {
@@ -264,5 +248,5 @@ func tlsClientHandshake(conn net.Conn, _ string) (credentials.AuthInfo, error) {
264248
if err := clientConn.Handshake(); err != nil {
265249
return nil, err
266250
}
267-
return TLSInfo{State: clientConn.ConnectionState(), CommonAuthInfo: credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}}, nil
251+
return credentials.TLSInfo{State: clientConn.ConnectionState(), CommonAuthInfo: credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}}, nil
268252
}

experimental/credentials/internal/spiffe.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*/
1818

19-
// Package credentials defines APIs for parsing SPIFFE ID.
19+
// Package internal defines APIs for parsing SPIFFE ID.
2020
//
2121
// All APIs in this package are experimental.
2222
package internal

experimental/credentials/tls.go

+3-61
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
*/
1818

19+
// Package credentials contains experimental TLS credentials.
1920
package credentials
2021

2122
import (
@@ -24,58 +25,13 @@ import (
2425
"crypto/x509"
2526
"fmt"
2627
"net"
27-
"net/url"
2828
"os"
2929

3030
"golang.org/x/net/http2"
3131
"google.golang.org/grpc/credentials"
3232
"google.golang.org/grpc/experimental/credentials/internal"
33-
"google.golang.org/grpc/grpclog"
3433
)
3534

36-
var logger = grpclog.Component("credentials")
37-
38-
// TLSInfo contains the auth information for a TLS authenticated connection.
39-
// It implements the AuthInfo interface.
40-
type TLSInfo struct {
41-
State tls.ConnectionState
42-
credentials.CommonAuthInfo
43-
// This API is experimental.
44-
SPIFFEID *url.URL
45-
}
46-
47-
// AuthType returns the type of TLSInfo as a string.
48-
func (t TLSInfo) AuthType() string {
49-
return "tls"
50-
}
51-
52-
// cipherSuiteLookup returns the string version of a TLS cipher suite ID.
53-
func cipherSuiteLookup(cipherSuiteID uint16) string {
54-
for _, s := range tls.CipherSuites() {
55-
if s.ID == cipherSuiteID {
56-
return s.Name
57-
}
58-
}
59-
for _, s := range tls.InsecureCipherSuites() {
60-
if s.ID == cipherSuiteID {
61-
return s.Name
62-
}
63-
}
64-
return fmt.Sprintf("unknown ID: %v", cipherSuiteID)
65-
}
66-
67-
// GetSecurityValue returns security info requested by channelz.
68-
func (t TLSInfo) GetSecurityValue() credentials.ChannelzSecurityValue {
69-
v := &TLSChannelzSecurityValue{
70-
StandardName: cipherSuiteLookup(t.State.CipherSuite),
71-
}
72-
// Currently there's no way to get LocalCertificate info from tls package.
73-
if len(t.State.PeerCertificates) > 0 {
74-
v.RemoteCertificate = t.State.PeerCertificates[0].Raw
75-
}
76-
return v
77-
}
78-
7935
// tlsCreds is the credentials required for authenticating a connection using TLS.
8036
type tlsCreds struct {
8137
// TLS configuration
@@ -118,7 +74,7 @@ func (c *tlsCreds) ClientHandshake(ctx context.Context, authority string, rawCon
11874
return nil, nil, ctx.Err()
11975
}
12076

121-
tlsInfo := TLSInfo{
77+
tlsInfo := credentials.TLSInfo{
12278
State: conn.ConnectionState(),
12379
CommonAuthInfo: credentials.CommonAuthInfo{
12480
SecurityLevel: credentials.PrivacyAndIntegrity,
@@ -138,7 +94,7 @@ func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, credentials.Auth
13894
return nil, nil, err
13995
}
14096
cs := conn.ConnectionState()
141-
tlsInfo := TLSInfo{
97+
tlsInfo := credentials.TLSInfo{
14298
State: cs,
14399
CommonAuthInfo: credentials.CommonAuthInfo{
144100
SecurityLevel: credentials.PrivacyAndIntegrity,
@@ -245,20 +201,6 @@ func NewServerTLSFromFileWithALPNDisabled(certFile, keyFile string) (credentials
245201
return NewTLSWithALPNDisabled(&tls.Config{Certificates: []tls.Certificate{cert}}), nil
246202
}
247203

248-
// TLSChannelzSecurityValue defines the struct that TLS protocol should return
249-
// from GetSecurityValue(), containing security info like cipher and certificate used.
250-
//
251-
// # Experimental
252-
//
253-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
254-
// later release.
255-
type TLSChannelzSecurityValue struct {
256-
credentials.ChannelzSecurityValue
257-
StandardName string
258-
LocalCertificate []byte
259-
RemoteCertificate []byte
260-
}
261-
262204
// cloneTLSConfig returns a shallow clone of the exported
263205
// fields of cfg, ignoring the unexported sync.Once, which
264206
// contains a mutex and must not be copied.

0 commit comments

Comments
 (0)