Source File
tls.go
Belonging Package
google.golang.org/grpc/credentials
package credentials
import (
credinternal
)
type TLSInfo struct {
State tls.ConnectionState
func ( TLSInfo) () ChannelzSecurityValue {
:= &TLSChannelzSecurityValue{
StandardName: cipherSuiteLookup[.State.CipherSuite],
if len(.State.PeerCertificates) > 0 {
.RemoteCertificate = .State.PeerCertificates[0].Raw
}
return
}
config *tls.Config
}
func ( tlsCreds) () ProtocolInfo {
return ProtocolInfo{
SecurityProtocol: "tls",
SecurityVersion: "1.2",
ServerName: .config.ServerName,
}
}
:= credinternal.CloneTLSConfig(.config)
if .ServerName == "" {
, , := net.SplitHostPort()
=
}
.ServerName =
}
:= tls.Client(, )
:= make(chan error, 1)
go func() {
<- .Handshake()
close()
}()
select {
case := <-:
if != nil {
.Close()
return nil, nil,
}
case <-.Done():
.Close()
return nil, nil, .Err()
}
:= TLSInfo{
State: .ConnectionState(),
CommonAuthInfo: CommonAuthInfo{
SecurityLevel: PrivacyAndIntegrity,
},
}
:= credinternal.SPIFFEIDFromState(.ConnectionState())
if != nil {
.SPIFFEID =
}
return credinternal.WrapSyscallConn(, ), , nil
}
func ( *tlsCreds) ( net.Conn) (net.Conn, AuthInfo, error) {
:= tls.Server(, .config)
if := .Handshake(); != nil {
.Close()
return nil, nil,
}
:= TLSInfo{
State: .ConnectionState(),
CommonAuthInfo: CommonAuthInfo{
SecurityLevel: PrivacyAndIntegrity,
},
}
:= credinternal.SPIFFEIDFromState(.ConnectionState())
if != nil {
.SPIFFEID =
}
return credinternal.WrapSyscallConn(, ), , nil
}
func ( *tlsCreds) () TransportCredentials {
return NewTLS(.config)
}
func ( *tlsCreds) ( string) error {
.config.ServerName =
return nil
}
func ( *tls.Config) TransportCredentials {
:= &tlsCreds{credinternal.CloneTLSConfig()}
.config.NextProtos = credinternal.AppendH2ToNextProtos(.config.NextProtos)
return
}
func ( *x509.CertPool, string) TransportCredentials {
return NewTLS(&tls.Config{ServerName: , RootCAs: })
}
func (, string) (TransportCredentials, error) {
, := ioutil.ReadFile()
if != nil {
return nil,
}
:= x509.NewCertPool()
if !.AppendCertsFromPEM() {
return nil, fmt.Errorf("credentials: failed to append certificates")
}
return NewTLS(&tls.Config{ServerName: , RootCAs: }), nil
}
func ( *tls.Certificate) TransportCredentials {
return NewTLS(&tls.Config{Certificates: []tls.Certificate{*}})
}
func (, string) (TransportCredentials, error) {
, := tls.LoadX509KeyPair(, )
if != nil {
return nil,
}
return NewTLS(&tls.Config{Certificates: []tls.Certificate{}}), nil
}
type TLSChannelzSecurityValue struct {
ChannelzSecurityValue
StandardName string
LocalCertificate []byte
RemoteCertificate []byte
}
var cipherSuiteLookup = map[uint16]string{
tls.TLS_RSA_WITH_RC4_128_SHA: "TLS_RSA_WITH_RC4_128_SHA",
tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_RSA_WITH_3DES_EDE_CBC_SHA",
tls.TLS_RSA_WITH_AES_128_CBC_SHA: "TLS_RSA_WITH_AES_128_CBC_SHA",
tls.TLS_RSA_WITH_AES_256_CBC_SHA: "TLS_RSA_WITH_AES_256_CBC_SHA",
tls.TLS_RSA_WITH_AES_128_GCM_SHA256: "TLS_RSA_WITH_AES_128_GCM_SHA256",
tls.TLS_RSA_WITH_AES_256_GCM_SHA384: "TLS_RSA_WITH_AES_256_GCM_SHA384",
tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA: "TLS_ECDHE_RSA_WITH_RC4_128_SHA",
tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384: "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
tls.TLS_FALLBACK_SCSV: "TLS_FALLBACK_SCSV",
tls.TLS_RSA_WITH_AES_128_CBC_SHA256: "TLS_RSA_WITH_AES_128_CBC_SHA256",
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305",
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |