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  protected:
53  /// Returns the name of the enclave.
54  ///
55  /// \return The name of the enclave.
56  const std::string &get_name() const { return name_; }
57 
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(const std::string &name) : name_(name) {}
62 
63  private:
64  friend class EnclaveManager;
65  friend class EnclaveSignalDispatcher;
66  friend void donate(EnclaveClient *client);
67 
68  // Enters the enclave and invokes its initialization entry point.
69  virtual Status EnterAndInitialize(const EnclaveConfig &config) = 0;
70 
71  // Enters the enclave and invokes its finalization entry point.
72  virtual Status EnterAndFinalize(const EnclaveFinal &final_input) = 0;
73 
74  // Donates the invoking thread to the enclave runtime.
75  virtual Status EnterAndDonateThread() = 0;
76 
77  // Enters the enclave and invokes its signal handling entry point.
78  virtual Status EnterAndHandleSignal(const EnclaveSignal &signal) = 0;
79 
80  // Invoked by the EnclaveManager immediately before the enclave is
81  // destroyed. This hook is provided to enable execution of custom logic by the
82  // client at the time the enclave is destroyed.
83  virtual Status DestroyEnclave() = 0;
84 
85  std::string name_;
86 };
87 
88 } // namespace asylo
89 
90 #endif // ASYLO_PLATFORM_CORE_ENCLAVE_CLIENT_H_
virtual ~EnclaveClient()=default
An abstract enclave client.
Definition: enclave_client.h:34
EnclaveClient(const std::string &name)
Called by the EnclaveManager to create a client instance.
Definition: enclave_client.h:61
friend void donate(EnclaveClient *client)
EnclaveClient & operator=(const EnclaveClient &)=delete
Definition: aes_gcm_siv.h:37
virtual Status EnterAndRun(const EnclaveInput &input, EnclaveOutput *output)=0
Enters the enclave and invokes its execution entry point.
const std::string & get_name() const
Returns the name of the enclave.
Definition: enclave_client.h:56
EnclaveClient(const EnclaveClient &)=delete