Asylo
sgx_local_secret_sealer.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_SEALING_SGX_SGX_LOCAL_SECRET_SEALER_H_
20 #define ASYLO_IDENTITY_SEALING_SGX_SGX_LOCAL_SECRET_SEALER_H_
21 
22 #include <memory>
23 
24 #include "asylo/crypto/util/byte_container_view.h"
25 #include "asylo/identity/identity.pb.h"
26 #include "asylo/identity/platform/sgx/code_identity.pb.h"
27 #include "asylo/identity/platform/sgx/sgx_identity.pb.h"
28 #include "asylo/identity/sealing/sealed_secret.pb.h"
29 #include "asylo/identity/sealing/secret_sealer.h"
30 #include "asylo/util/cleansing_types.h"
31 #include "asylo/util/status.h"
32 
33 namespace asylo {
34 
35 /// An implementation of the SecretSealer abstract interface that binds the
36 /// secrets to the enclave identity on a local machine. The secrets sealed by
37 /// this sealer can only be unsealed on the same machine.
38 ///
39 /// The SgxLocalSecretSealer can be configured to seal secrets either to
40 /// MRENCLAVE or MRSIGNER. The SgxLocalSecretSealer class provides two factory
41 /// methods--one that creates an SgxLocalSecretSealer configured to seal secrets
42 /// to MRENCLAVE and another that creates an SgxLocalSecretSealer configured to
43 /// seal secrets to MRSIGNER. In the MRENCLAVE-sealing mode, the default
44 /// SealedSecretHeader generated by the sealer binds the secrets to the
45 /// MRENCLAVE portion of the enclave's identity. In the MRSIGNER mode, the
46 /// default SealedSecretHeader generated by the sealer binds the secrets to the
47 /// MRSIGNER portion of the enclave's identity. In either mode, the sealed
48 /// secret is bound to all bits of MISCSELECT, and all security-sensitive bits
49 /// of ATTRIBUTES, as defined in secs_attributes.h.
50 ///
51 /// Note that the SealedSecretHeader provided to the Seal() method also controls
52 /// the cipher suite used for sealing the secret. The default setting of this
53 /// field (as populated by SetDefaultHeader() ) is subject to change. As a
54 /// result, users must not make any assumptions about the default cipher suite.
55 /// If they wish to use a specific cipher suite, they must manually verify or
56 /// override the cipher suite set by the SetDefaultHeader() method.
57 ///
58 /// Sample usage for Seal():
59 /// ```
60 /// std::unique_ptr<SgxLocalSecretSealer> sealer = CreateMrsignerSealer();
61 ///
62 /// SealedSecretHeader header;
63 /// // Fill out the portions of the header that must be set by the client.
64 /// header.set_secret_name("my name");
65 /// header.set_secret_version("my version");
66 /// header.set_secret_purpose("my purpose");
67 /// // secret_handling_policy is a client-specific string, which, for example,
68 /// could be a serialized proto.
69 /// string secret_handling_policy = ...
70 /// header.set_secret_handling_policy(secret_handling_policy);
71 /// sealer->SetDefaultHeader(&header);
72 ///
73 /// // Override fields in the default header, if desired.
74 /// ...
75 ///
76 /// // Generate the secret to be sealed.
77 /// std::vector<uint8_t, CleansingAllocator> secret = ...;
78 ///
79 /// // Generate the additional authenticated data to be tied to the secret.
80 /// string additional_authenticated_data;
81 /// addtional_authenticated_data = ...
82 ///
83 /// // Seal the secret and the additional authenticated data.
84 /// SealedSecret sealed_secret;
85 /// Status status = sealer->Seal(header, additional_authenticated_data,
86 /// secret, &sealed_secret);
87 /// ```
88 ///
89 /// Sample usage for Unseal():
90 /// ```
91 /// std::unique_ptr<SgxLocalSecretSealer> sealer = CreateMrsignerSealer();
92 /// SealedSecret sealed_secret;
93 /// ...
94 /// sealed_secret.ParseFromString(...);
95 ///
96 /// std::vector<uint8_t, CleansingAllocator<uint8_t>> secret;
97 /// ASYLO_RETURN_IF_ERROR(sealer->Unseal(sealed_secret, secret));
98 /// // secret now holds the unsealed secret. The policy and
99 /// // additional_authenticated_data in the sealed_secret are now
100 /// // authenticated.
101 /// ```
102 ///
103 /// It should be noted that the SgxLocalSecretSealer's configuration only
104 /// affects the default header generated by the sealer. Users can override the
105 /// generated default header. A sealer in either MRENCLAVE or MRSIGNER
106 /// configuration can unseal secrets that are sealed by a sealer in either
107 /// configuration.
109  public:
110  /// Creates an SgxLocalSecretSealer that seals secrets to the MRENCLAVE part
111  /// of the enclave code identity.
112  ///
113  /// \return A smart pointer that owns the created sealer.
115 
116  /// Creates an SgxLocalSecretSealer that seals secrets to the MRSIGNER part of
117  /// the enclave identity.
118  ///
119  /// \return A smart pointer that owns the created sealer.
121 
122  SgxLocalSecretSealer(const SgxLocalSecretSealer &other) = delete;
123  virtual ~SgxLocalSecretSealer() = default;
124 
125  SgxLocalSecretSealer &operator=(const SgxLocalSecretSealer &other) = delete;
126 
127  // From SecretSealer interface.
128  SealingRootType RootType() const override;
129  std::string RootName() const override;
130  std::vector<EnclaveIdentityExpectation> RootAcl() const override;
133  const SealedSecretHeader &header) const override;
135  const SealedSecretHeader &header) const override;
140  CleansingVector<uint8_t> *secret) override;
141 
142  private:
143  // Instantiates LocalSecretSealer that sets client_acl in the default sealed
144  // secret header per |default_client_acl|.
145  SgxLocalSecretSealer(const SgxIdentityExpectation &default_client_acl);
146 
147  // The default client ACL for this SecretSealer.
148  SgxIdentityExpectation default_client_acl_;
149 };
150 
151 } // namespace asylo
152 
153 #endif // ASYLO_IDENTITY_SEALING_SGX_SGX_LOCAL_SECRET_SEALER_H_
Status SetDefaultHeader(SealedSecretHeader *header) const override
Generates the default sealed-secret header based on the configuration of the SecretSealer and writes ...
std::vector< EnclaveIdentityExpectation > RootAcl() const override
Gets the sealing root ACL of this SecretSealer.
Status Unseal(const SealedSecret &sealed_secret, CleansingVector< uint8_t > *secret) override
Unseals the sealed_secret and writes it to secret.
Status Seal(const SealedSecretHeader &header, ByteContainerView additional_authenticated_data, ByteContainerView secret, SealedSecret *sealed_secret) override
Seals the input per the header specification.
static std::unique_ptr< SgxLocalSecretSealer > CreateMrenclaveSecretSealer()
Creates an SgxLocalSecretSealer that seals secrets to the MRENCLAVE part of the enclave code identity...
virtual ~SgxLocalSecretSealer()=default
ABSL_CONST_INIT const char kStatusMoveAssignmentMsg[]
SgxLocalSecretSealer & operator=(const SgxLocalSecretSealer &other)=delete
StatusOr< size_t > MaxMessageSize(const SealedSecretHeader &header) const override
Gets the maximum message size (in bytes) that can be sealed according to the cipher-suite configurati...
An implementation of the SecretSealer abstract interface that binds the secrets to the enclave identi...
Definition: sgx_local_secret_sealer.h:108
StatusOr< uint64_t > MaxSealedMessages(const SealedSecretHeader &header) const override
Gets the maximum number of messages that can safely be sealed according to the cipher-suite configura...
SgxLocalSecretSealer(const SgxLocalSecretSealer &other)=delete
SealingRootType RootType() const override
Gets the sealing root type of this SecretSealer.
static std::unique_ptr< SgxLocalSecretSealer > CreateMrsignerSecretSealer()
Creates an SgxLocalSecretSealer that seals secrets to the MRSIGNER part of the enclave identity...
std::string RootName() const override
Gets the sealing root name of this SecretSealer.