Asylo
enclave_auth_context.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 Asylo 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 #ifndef ASYLO_GRPC_AUTH_ENCLAVE_AUTH_CONTEXT_H_
20 #define ASYLO_GRPC_AUTH_ENCLAVE_AUTH_CONTEXT_H_
21 
22 #include <string>
23 #include <vector>
24 
25 #include "asylo/grpc/auth/core/handshake.pb.h"
26 #include "asylo/identity/delegating_identity_expectation_matcher.h"
27 #include "asylo/identity/identity.pb.h"
28 #include "asylo/identity/identity_acl.pb.h"
29 #include "asylo/util/statusor.h"
30 #include "include/grpcpp/server_context.h"
31 
32 namespace asylo {
33 
34 /// Encapsulates the authentication properties of an EKEP-based gRPC connection.
35 ///
36 /// The authentication properties in an EnclaveAuthContext object include the
37 /// secure transport protocol and the peer's enclave identities.
38 ///
39 /// Virtual functions are only for mocking.
41  public:
42  /// Constructs an EnclaveAuthContext using the authentication properties from
43  /// `server_context`.
44  ///
45  /// The resulting EnclaveAuthContext contains the authentication properties on
46  /// the server-side of the connection.
47  ///
48  /// \param server_context The server's authentication context.
51 
52  /// Creates an EnclaveAuthContext from the authentication properties in
53  /// `auth_context`.
54  ///
55  /// \param auth_context An authentication context.
57  const ::grpc::AuthContext &auth_context);
58 
59  EnclaveAuthContext() = default;
60  virtual ~EnclaveAuthContext() = default;
61 
62  /// Gets the secure transport record-protocol used for securing frames over
63  /// the connection.
64  ///
65  /// \return The secure transport record-protocol.
66  virtual RecordProtocol GetRecordProtocol() const;
67 
68  /// Indicates whether the authenticated peer has an identity matching
69  /// `description`.
70  ///
71  /// \param description A description of the identity.
72  /// \return True if the peer has the specified identity.
73  virtual bool HasEnclaveIdentity(
74  const EnclaveIdentityDescription &description) const;
75 
76  /// Finds and returns a peer identity matching `description`, if one exists.
77  ///
78  /// \param description A description of an identity to find.
79  /// \return A pointer to the identity on success, and a StatusOr with a
80  /// `GoogleError::NOT_FOUND` Status on failure.
83 
84  /// Evaluates the peer's identities against `acl`.
85  ///
86  /// \param acl The ACL against which to evaluate the peer's identities.
87  /// \return A bool indicating whether the peer's identities match `acl`, or a
88  /// non-OK Status if an error occurred while evaluating the ACL.
89  virtual StatusOr<bool> EvaluateAcl(const IdentityAclPredicate &acl) const;
90 
91  /// Evaluates the peer's identities against `acl`.
92  ///
93  /// \param acl The ACL against which to evaluate the peer's identities.
94  /// \param[out] explanation An explanation of why the peer's identities did
95  /// not match `acl`, if the result is false.
96  /// \return A bool indicating whether the peer's identities match `acl`, or a
97  /// non-OK Status if an error occurred while evaluating the ACL.
98  virtual StatusOr<bool> EvaluateAcl(const IdentityAclPredicate &acl,
99  std::string *explanation) const;
100 
101  /// Evaluates whether any of the peer's identities match `expectation`.
102  ///
103  /// \param expectation The expectation against which to evaluate the peer's
104  /// identities.
105  /// \return A bool indicating whether any of the peer's identities match
106  /// `expectation`, or a non-OK Status if an error occurred while
107  /// evaluating `expectation`.
108  virtual StatusOr<bool> EvaluateAcl(
110 
111  /// Evaluates whether any of the peer's identities match `expectation`.
112  ///
113  /// \param expectation The expectation against which to evaluate the peer's
114  /// identities.
115  /// \param[out] explanation An explanation of why the peer's identities did
116  /// not match `expectation`, if the result is false.
117  /// \return A bool indicating whether any of the peer's identities match
118  /// `expectation`, or a non-OK Status if an error occurred while
119  /// evaluating `expectation`.
120  virtual StatusOr<bool> EvaluateAcl(
122  std::string *explanation) const;
123 
124  private:
125  // Creates an EnclaveAuthContext for the given peer's |identities| and the
126  // session |record_protocol|.
127  EnclaveAuthContext(EnclaveIdentities identities,
128  RecordProtocol record_protocol);
129 
130  // Enclave identities held by the authenticated peer.
131  std::vector<EnclaveIdentity> identities_;
132 
133  // Secure transport record protocol.
134  RecordProtocol record_protocol_;
135 
136  // Matcher used to evaluate ACLs against the authenticated peer's identities.
137  DelegatingIdentityExpectationMatcher matcher_;
138 };
139 
140 } // namespace asylo
141 
142 #endif // ASYLO_GRPC_AUTH_ENCLAVE_AUTH_CONTEXT_H_
virtual StatusOr< const EnclaveIdentity * > FindEnclaveIdentity(const EnclaveIdentityDescription &description) const
Finds and returns a peer identity matching description, if one exists.
virtual ~EnclaveAuthContext()=default
ABSL_CONST_INIT const char kStatusMoveAssignmentMsg[]
virtual RecordProtocol GetRecordProtocol() const
Gets the secure transport record-protocol used for securing frames over the connection.
Encapsulates the authentication properties of an EKEP-based gRPC connection.
Definition: enclave_auth_context.h:40
static StatusOr< EnclaveAuthContext > CreateFromAuthContext(const ::grpc::AuthContext &auth_context)
Creates an EnclaveAuthContext from the authentication properties in auth_context. ...
virtual StatusOr< bool > EvaluateAcl(const EnclaveIdentityExpectation &expectation, std::string *explanation) const
Evaluates whether any of the peer&#39;s identities match expectation.
virtual bool HasEnclaveIdentity(const EnclaveIdentityDescription &description) const
Indicates whether the authenticated peer has an identity matching description.
static StatusOr< EnclaveAuthContext > CreateFromServerContext(const ::grpc::ServerContext &server_context)
Constructs an EnclaveAuthContext using the authentication properties from server_context.
virtual StatusOr< bool > EvaluateAcl(const EnclaveIdentityExpectation &expectation) const
Evaluates whether any of the peer&#39;s identities match expectation.