Asylo
enclave_assertion_generator.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_IDENTITY_ENCLAVE_ASSERTION_GENERATOR_H_
20 #define ASYLO_IDENTITY_ENCLAVE_ASSERTION_GENERATOR_H_
21 
22 #include <string>
23 
24 #include "asylo/identity/enclave_assertion_authority.h"
25 #include "asylo/identity/identity.pb.h"
26 #include "asylo/platform/common/static_map.h"
27 #include "asylo/util/status.h"
28 #include "asylo/util/statusor.h"
29 
30 namespace asylo {
31 
32 /// Defines an interface for assertion authorities that create assertion offers
33 /// and generate assertions.
34 ///
35 /// EnclaveAssertionGenerator cannot be instantiated; it is intended to be
36 /// derived from by classes that implement the EnclaveAssertionGenerator
37 /// interface for a particular identity type and authority type.
38 ///
39 /// Derived classes of EnclaveAssertionGenerator must:
40 /// * Be marked final
41 /// * Be trivially default-constructible
42 ///
43 /// Derived classes of EnclaveAssertionGenerator must also implement virtual
44 /// methods presented by EnclaveAssertionAuthority.
46  public:
47  /// Creates an assertion offer compatible with this generator's identity type
48  /// and authority type and places the result in `offer`.
49  ///
50  /// \param[out] offer The generated offer.
51  /// \return A Status indicating whether the offer was created. Returns a
52  /// non-OK Status if this generator is not initialized or if an
53  /// internal error occurs while attempting the operation.
54  virtual Status CreateAssertionOffer(AssertionOffer *offer) const = 0;
55 
56  /// Indicates whether the assertion requested in `request` can be generated by
57  /// this generator.
58  ///
59  /// \param request A request to be fulfilled.
60  /// \return True if the assertion specified in `request` can be generated,
61  /// and false if no errors occur during the operation but `request`
62  /// cannot be fulfilled. Returns a non-OK Status if this generator is
63  /// not yet initialized or if an internal error occurs while
64  /// attempting the operation.
65  virtual StatusOr<bool> CanGenerate(const AssertionRequest &request) const = 0;
66 
67  /// Generates an assertion that satisfies the given `request`, if `request` is
68  /// compatible with this generator's identity type and authority type.
69  ///
70  /// The caller cannot make any assumptions about the contents of `assertion`
71  /// if generation fails.
72  ///
73  /// \param user_data User-provided binding data.
74  /// \param request A request to fulfill.
75  /// \param[out] assertion The generated assertion.
76  /// \return A Status indicating whether an assertion was generated
77  /// successfully. Returns a non-OK Status if the generator is not
78  /// initialized or if an internal error occurs while attempting the
79  /// operation.
80  virtual Status Generate(const std::string &user_data,
82  Assertion *assertion) const = 0;
83 };
84 
85 // \cond Internal
86 template <>
87 struct Namer<EnclaveAssertionGenerator> {
88  std::string operator()(const EnclaveAssertionGenerator &generator) {
89  return EnclaveAssertionAuthority::GenerateAuthorityId(
90  generator.IdentityType(), generator.AuthorityType())
91  .ValueOrDie();
92  }
93 };
94 
95 DEFINE_STATIC_MAP_OF_BASE_TYPE(AssertionGeneratorMap,
96  EnclaveAssertionGenerator);
97 // \endcond
98 
99 } // namespace asylo
100 
101 #endif // ASYLO_IDENTITY_ENCLAVE_ASSERTION_GENERATOR_H_
virtual StatusOr< bool > CanGenerate(const AssertionRequest &request) const =0
Indicates whether the assertion requested in request can be generated by this generator.
Definition: aes_gcm_siv.h:37
virtual Status Generate(const std::string &user_data, const AssertionRequest &request, Assertion *assertion) const =0
Generates an assertion that satisfies the given request, if request is compatible with this generator...
Defines an interface for assertion authorities that create assertion offers and generate assertions...
Definition: enclave_assertion_generator.h:45
virtual Status CreateAssertionOffer(AssertionOffer *offer) const =0
Creates an assertion offer compatible with this generator&#39;s identity type and authority type and plac...