gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/grpc/credentials/alts/internal/authinfo/authinfo.go (about) 1 /* 2 * 3 * Copyright 2018 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 // Package authinfo provide authentication information returned by handshakers. 20 package authinfo 21 22 import ( 23 "gitee.com/ks-custle/core-gm/grpc/credentials" 24 altspb "gitee.com/ks-custle/core-gm/grpc/credentials/alts/internal/proto/grpc_gcp" 25 ) 26 27 var _ credentials.AuthInfo = (*altsAuthInfo)(nil) 28 29 // altsAuthInfo exposes security information from the ALTS handshake to the 30 // application. altsAuthInfo is immutable and implements credentials.AuthInfo. 31 type altsAuthInfo struct { 32 p *altspb.AltsContext 33 credentials.CommonAuthInfo 34 } 35 36 // New returns a new altsAuthInfo object given handshaker results. 37 func New(result *altspb.HandshakerResult) credentials.AuthInfo { 38 return newAuthInfo(result) 39 } 40 41 func newAuthInfo(result *altspb.HandshakerResult) *altsAuthInfo { 42 return &altsAuthInfo{ 43 p: &altspb.AltsContext{ 44 ApplicationProtocol: result.GetApplicationProtocol(), 45 RecordProtocol: result.GetRecordProtocol(), 46 // TODO: assign security level from result. 47 SecurityLevel: altspb.SecurityLevel_INTEGRITY_AND_PRIVACY, 48 PeerServiceAccount: result.GetPeerIdentity().GetServiceAccount(), 49 LocalServiceAccount: result.GetLocalIdentity().GetServiceAccount(), 50 PeerRpcVersions: result.GetPeerRpcVersions(), 51 PeerAttributes: result.GetPeerIdentity().GetAttributes(), 52 }, 53 CommonAuthInfo: credentials.CommonAuthInfo{SecurityLevel: credentials.PrivacyAndIntegrity}, 54 } 55 } 56 57 // AuthType identifies the context as providing ALTS authentication information. 58 func (s *altsAuthInfo) AuthType() string { 59 return "alts" 60 } 61 62 // ApplicationProtocol returns the context's application protocol. 63 func (s *altsAuthInfo) ApplicationProtocol() string { 64 return s.p.GetApplicationProtocol() 65 } 66 67 // RecordProtocol returns the context's record protocol. 68 func (s *altsAuthInfo) RecordProtocol() string { 69 return s.p.GetRecordProtocol() 70 } 71 72 // SecurityLevel returns the context's security level. 73 func (s *altsAuthInfo) SecurityLevel() altspb.SecurityLevel { 74 return s.p.GetSecurityLevel() 75 } 76 77 // PeerServiceAccount returns the context's peer service account. 78 func (s *altsAuthInfo) PeerServiceAccount() string { 79 return s.p.GetPeerServiceAccount() 80 } 81 82 // LocalServiceAccount returns the context's local service account. 83 func (s *altsAuthInfo) LocalServiceAccount() string { 84 return s.p.GetLocalServiceAccount() 85 } 86 87 // PeerRPCVersions returns the context's peer RPC versions. 88 func (s *altsAuthInfo) PeerRPCVersions() *altspb.RpcProtocolVersions { 89 return s.p.GetPeerRpcVersions() 90 } 91 92 // PeerAttributes returns the context's peer attributes. 93 func (s *altsAuthInfo) PeerAttributes() map[string]string { 94 return s.p.GetPeerAttributes() 95 }