16
16
*
17
17
*/
18
18
19
+ // Package credentials contains experimental TLS credentials.
19
20
package credentials
20
21
21
22
import (
@@ -24,58 +25,13 @@ import (
24
25
"crypto/x509"
25
26
"fmt"
26
27
"net"
27
- "net/url"
28
28
"os"
29
29
30
30
"golang.org/x/net/http2"
31
31
"google.golang.org/grpc/credentials"
32
32
"google.golang.org/grpc/experimental/credentials/internal"
33
- "google.golang.org/grpc/grpclog"
34
33
)
35
34
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
-
79
35
// tlsCreds is the credentials required for authenticating a connection using TLS.
80
36
type tlsCreds struct {
81
37
// TLS configuration
@@ -118,7 +74,7 @@ func (c *tlsCreds) ClientHandshake(ctx context.Context, authority string, rawCon
118
74
return nil , nil , ctx .Err ()
119
75
}
120
76
121
- tlsInfo := TLSInfo {
77
+ tlsInfo := credentials. TLSInfo {
122
78
State : conn .ConnectionState (),
123
79
CommonAuthInfo : credentials.CommonAuthInfo {
124
80
SecurityLevel : credentials .PrivacyAndIntegrity ,
@@ -138,7 +94,7 @@ func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, credentials.Auth
138
94
return nil , nil , err
139
95
}
140
96
cs := conn .ConnectionState ()
141
- tlsInfo := TLSInfo {
97
+ tlsInfo := credentials. TLSInfo {
142
98
State : cs ,
143
99
CommonAuthInfo : credentials.CommonAuthInfo {
144
100
SecurityLevel : credentials .PrivacyAndIntegrity ,
@@ -245,20 +201,6 @@ func NewServerTLSFromFileWithALPNDisabled(certFile, keyFile string) (credentials
245
201
return NewTLSWithALPNDisabled (& tls.Config {Certificates : []tls.Certificate {cert }}), nil
246
202
}
247
203
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
-
262
204
// cloneTLSConfig returns a shallow clone of the exported
263
205
// fields of cfg, ignoring the unexported sync.Once, which
264
206
// contains a mutex and must not be copied.
0 commit comments