You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

88 line
2.8 KiB

  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. // Package authinfo provide authentication information returned by handshakers.
  19. package authinfo
  20. import (
  21. "google.golang.org/grpc/credentials"
  22. altspb "google.golang.org/grpc/credentials/alts/internal/proto/grpc_gcp"
  23. )
  24. var _ credentials.AuthInfo = (*altsAuthInfo)(nil)
  25. // altsAuthInfo exposes security information from the ALTS handshake to the
  26. // application. altsAuthInfo is immutable and implements credentials.AuthInfo.
  27. type altsAuthInfo struct {
  28. p *altspb.AltsContext
  29. }
  30. // New returns a new altsAuthInfo object given handshaker results.
  31. func New(result *altspb.HandshakerResult) credentials.AuthInfo {
  32. return newAuthInfo(result)
  33. }
  34. func newAuthInfo(result *altspb.HandshakerResult) *altsAuthInfo {
  35. return &altsAuthInfo{
  36. p: &altspb.AltsContext{
  37. ApplicationProtocol: result.GetApplicationProtocol(),
  38. RecordProtocol: result.GetRecordProtocol(),
  39. // TODO: assign security level from result.
  40. SecurityLevel: altspb.SecurityLevel_INTEGRITY_AND_PRIVACY,
  41. PeerServiceAccount: result.GetPeerIdentity().GetServiceAccount(),
  42. LocalServiceAccount: result.GetLocalIdentity().GetServiceAccount(),
  43. PeerRpcVersions: result.GetPeerRpcVersions(),
  44. },
  45. }
  46. }
  47. // AuthType identifies the context as providing ALTS authentication information.
  48. func (s *altsAuthInfo) AuthType() string {
  49. return "alts"
  50. }
  51. // ApplicationProtocol returns the context's application protocol.
  52. func (s *altsAuthInfo) ApplicationProtocol() string {
  53. return s.p.GetApplicationProtocol()
  54. }
  55. // RecordProtocol returns the context's record protocol.
  56. func (s *altsAuthInfo) RecordProtocol() string {
  57. return s.p.GetRecordProtocol()
  58. }
  59. // SecurityLevel returns the context's security level.
  60. func (s *altsAuthInfo) SecurityLevel() altspb.SecurityLevel {
  61. return s.p.GetSecurityLevel()
  62. }
  63. // PeerServiceAccount returns the context's peer service account.
  64. func (s *altsAuthInfo) PeerServiceAccount() string {
  65. return s.p.GetPeerServiceAccount()
  66. }
  67. // LocalServiceAccount returns the context's local service account.
  68. func (s *altsAuthInfo) LocalServiceAccount() string {
  69. return s.p.GetLocalServiceAccount()
  70. }
  71. // PeerRPCVersions returns the context's peer RPC versions.
  72. func (s *altsAuthInfo) PeerRPCVersions() *altspb.RpcProtocolVersions {
  73. return s.p.GetPeerRpcVersions()
  74. }