Asylo
enclave_client.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_PLATFORM_CORE_ENCLAVE_CLIENT_H_
20 #define ASYLO_PLATFORM_CORE_ENCLAVE_CLIENT_H_
21 
22 #include "absl/container/flat_hash_map.h"
23 #include "absl/memory/memory.h"
24 #include "asylo/enclave.pb.h" // IWYU pragma: export
25 #include "asylo/platform/core/shared_name.h"
26 #include "asylo/util/status.h" // IWYU pragma: export
27 
28 namespace asylo {
29 
30 /// An abstract enclave client.
31 ///
32 /// A handle to an enclave object which provides methods for invoking its entry
33 /// points and managing its lifecycle.
35  public:
36  EnclaveClient(const EnclaveClient &) = delete;
37 
38  EnclaveClient &operator=(const EnclaveClient &) = delete;
39 
40  virtual ~EnclaveClient() = default;
41 
42  /// Enters the enclave and invokes its execution entry point.
43  ///
44  /// \param input A protobuf message that may be extended with a user-defined
45  /// message.
46  /// \param[out] output A nullable pointer to a protobuf message that can store
47  /// a response message.
48  /// \anchor enter-and-run
49  virtual Status EnterAndRun(const EnclaveInput &input,
50  EnclaveOutput *output) = 0;
51 
52  /// Returns the name of the enclave.
53  ///
54  /// \return The name of the enclave.
55  virtual absl::string_view get_name() const { return name_; }
56 
57  protected:
58  /// Called by the EnclaveManager to create a client instance.
59  ///
60  /// \param name The enclave name as registered with the EnclaveManager.
61  explicit EnclaveClient(absl::string_view name) : name_(name) {}
62 
63  private:
64  friend class EnclaveManager;
65  friend class EnclaveSignalDispatcher;
66 
67  // Enters the enclave and invokes its initialization entry point.
68  virtual Status EnterAndInitialize(const EnclaveConfig &config) = 0;
69 
70  // Enters the enclave and invokes its finalization entry point.
71  virtual Status EnterAndFinalize(const EnclaveFinal &final_input) = 0;
72 
73  // Invoked by the EnclaveManager immediately before the enclave is
74  // destroyed. This hook is provided to enable execution of custom logic by the
75  // client at the time the enclave is destroyed.
76  virtual Status DestroyEnclave() = 0;
77 
78  /// Frees enclave resources registered to the client. Called after
79  /// EnclaveClient::DestroyEnclave from within
80  /// EnclaveManager::DestroyEnclave.
81  virtual void ReleaseMemory() {}
82 
83  std::string name_;
84 };
85 
86 } // namespace asylo
87 
88 #endif // ASYLO_PLATFORM_CORE_ENCLAVE_CLIENT_H_
virtual ~EnclaveClient()=default
An abstract enclave client.
Definition: enclave_client.h:34
ABSL_CONST_INIT const char kStatusMoveAssignmentMsg[]
EnclaveClient & operator=(const EnclaveClient &)=delete
EnclaveClient(absl::string_view name)
Called by the EnclaveManager to create a client instance.
Definition: enclave_client.h:61
virtual absl::string_view get_name() const
Returns the name of the enclave.
Definition: enclave_client.h:55
virtual Status EnterAndRun(const EnclaveInput &input, EnclaveOutput *output)=0
Enters the enclave and invokes its execution entry point.
EnclaveClient(const EnclaveClient &)=delete