AWS SDK for C++

AWS SDK for C++ Version 1.11.808

Loading...
Searching...
No Matches
ContentCryptoMaterial.h
1
5#pragma once
6
7#include <aws/core/Aws.h>
8#include <aws/core/Core_EXPORTS.h>
9#include <aws/core/utils/crypto/CryptoBuf.h>
10#include <aws/core/utils/crypto/ContentCryptoScheme.h>
11#include <aws/core/utils/crypto/KeyWrapAlgorithm.h>
12
13namespace Aws
14{
15 namespace Utils
16 {
17 namespace Crypto
18 {
19 class AWS_CORE_API ContentCryptoMaterial
20 {
21 public:
22 /*
23 Default constructor.
24 */
26 /*
27 Initialize content crypto material with content crypto scheme. Constructor will also generate the cek automatically.
28 Since the creation of the crypto content material will be within the S3 crypto modules, only the crypto scheme is needed for initialization.
29 The rest of the data will be set using the accessors below.
30 */
32
33 /*
34 Initialize with content encryption key (cek) and content crypto scheme.
35 */
37
38 /*
39 Initialize in the error state.
40 */
41 ContentCryptoMaterial(const char * msg);
42
47 {
48 return m_contentEncryptionKey;
49 }
50
55 {
56 return m_encryptedContentEncryptionKey;
57 }
58
62 inline const Aws::Utils::CryptoBuffer& GetIV() const
63 {
64 return m_iv;
65 }
66
71 {
72 return m_encryptionContext;
73 }
74
79 {
80 return m_keyCommitment;
81 }
82
87 {
88 return m_messageId;
89 }
90
94 inline size_t GetCryptoTagLength() const
95 {
96 return m_cryptoTagLength;
97 }
98
103 {
104 return m_materialsDescription;
105 }
106
107 /*
108 * Gets the value of the key in the current materials description map.
109 */
110 inline const Aws::String& GetMaterialsDescription(const Aws::String& key) const
111 {
112 return m_materialsDescription.at(key);
113 }
114
119 {
120 return m_keyWrapAlgorithm;
121 }
122
127 {
128 return m_contentCryptoScheme;
129 }
130
134 inline void SetContentEncryptionKey(const Aws::Utils::CryptoBuffer& contentEncryptionKey)
135 {
136 m_contentEncryptionKey = contentEncryptionKey;
137 }
138
142 inline void SetEncryptedContentEncryptionKey(const Aws::Utils::CryptoBuffer& encryptedContentEncryptionKey)
143 {
144 m_encryptedContentEncryptionKey = encryptedContentEncryptionKey;
145 }
146
150 inline void SetIV(const Aws::Utils::CryptoBuffer& iv)
151 {
152 m_iv = iv;
153 }
154
158 inline void SetV3IV()
159 {
160 //= ../specification/s3-encryption/key-derivation.md#hkdf-operation
161 //# When encrypting or decrypting with ALG_AES_256_GCM_HKDF_SHA512_COMMIT_KEY, the IV used in the AES-GCM content encryption/decryption MUST consist entirely of bytes with the value 0x01.
162 //# The IV's total length MUST match the IV length defined by the algorithm suite.
163 unsigned char iv[12] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
164 CryptoBuffer iv2(&iv[0], 12);
165 SetIV(iv2);
166 }
167
171 inline void SetEncryptionContext(const Aws::Map<Aws::String, Aws::String>& encryptionContext)
172 {
173 m_encryptionContext = encryptionContext;
174 }
175
179 inline void SetKeyCommitment(const Aws::Utils::CryptoBuffer& keyCommitment)
180 {
181 m_keyCommitment = keyCommitment;
182 }
183
187 inline void SetMessageID(const Aws::Utils::CryptoBuffer& messageId)
188 {
189 m_messageId = messageId;
190 }
191
195 inline void SetCryptoTagLength(size_t cryptoTagLength)
196 {
197 m_cryptoTagLength = cryptoTagLength;
198 }
199
203 inline void AddMaterialsDescription(const Aws::String& key, const Aws::String& value)
204 {
205 m_materialsDescription[key] = value;
206 }
207
211 inline void SetMaterialsDescription(const Aws::Map<Aws::String, Aws::String>& materialsDescription)
212 {
213 m_materialsDescription = materialsDescription;
214 }
215
219 inline void SetKeyWrapAlgorithm(KeyWrapAlgorithm keyWrapAlgorithm)
220 {
221 m_keyWrapAlgorithm = keyWrapAlgorithm;
222 }
223
227 inline void SetContentCryptoScheme(ContentCryptoScheme contentCryptoScheme)
228 {
229 m_contentCryptoScheme = contentCryptoScheme;
230 }
231
235 inline void SetGCMAAD(const Aws::Utils::CryptoBuffer& aad)
236 {
237 m_gcmAAD = aad;
238 }
243 {
244 return m_gcmAAD;
245 }
246
251 {
252 m_cekGCMTag = tag;
253 }
258 {
259 return m_cekGCMTag;
260 }
261
265 inline void SetCekIV(const Aws::Utils::CryptoBuffer& iv)
266 {
267 m_cekIV = iv;
268 }
272 inline const Aws::Utils::CryptoBuffer& GetCekIV() const
273 {
274 return m_cekIV;
275 }
276
280 inline void SetFinalCEK(const Aws::Utils::CryptoBuffer& finalCEK)
281 {
282 m_finalCEK = finalCEK;
283 }
288 {
289 return m_finalCEK;
290 }
291
292 //= ../specification/s3-encryption/key-derivation.md#hkdf-operation
293 //= type=implication
294 //# The client MUST set the AAD to the Algorithm Suite ID represented as bytes.
295
296 //= ../specification/s3-encryption/encryption.md#alg-aes-256-gcm-iv12-tag16-no-kdf
297 //= type=implication
298 //# The client MUST NOT provide any AAD when encrypting with ALG_AES_256_GCM_IV12_TAG16_NO_KDF.
299 inline const Aws::Utils::CryptoBuffer GetAAD() const
300 {
301 if (m_contentCryptoScheme == ContentCryptoScheme::GCM_COMMIT) {
302 // Algorithm Suite 0x0073 as bytes
303 static const uint8_t gcmAAD[2] = {0, 0x73};
304 return Aws::Utils::CryptoBuffer(gcmAAD, 2);
305 } else {
307 }
308 }
309
310 inline bool Ok() const {return m_error.empty();}
311 inline bool Fail() const {return !m_error.empty();}
312 inline const Aws::String & Error() const {return m_error;}
313
314 private:
315 Aws::Utils::CryptoBuffer m_contentEncryptionKey;
316 Aws::Utils::CryptoBuffer m_encryptedContentEncryptionKey;
317 /* if using AES_GCM key wrap algorithm, then final CEK is iv + encrypted_key + tag
318 * otherwise it's the same as m_encryptedContentEncryptionKey
319 */
320 Aws::Utils::CryptoBuffer m_finalCEK;
324 Aws::Utils::CryptoBuffer m_cekGCMTag;
325 Aws::Map<Aws::String, Aws::String> m_encryptionContext;
326 Aws::Utils::CryptoBuffer m_keyCommitment;
327 Aws::Utils::CryptoBuffer m_messageId;
328 size_t m_cryptoTagLength;
329 Aws::Map<Aws::String, Aws::String> m_materialsDescription;
330 KeyWrapAlgorithm m_keyWrapAlgorithm;
331 ContentCryptoScheme m_contentCryptoScheme;
332 Aws::String m_error;
333 };
334 }
335 }
336}
void SetKeyCommitment(const Aws::Utils::CryptoBuffer &keyCommitment)
void SetMaterialsDescription(const Aws::Map< Aws::String, Aws::String > &materialsDescription)
void AddMaterialsDescription(const Aws::String &key, const Aws::String &value)
void SetFinalCEK(const Aws::Utils::CryptoBuffer &finalCEK)
void SetGCMAAD(const Aws::Utils::CryptoBuffer &aad)
const Aws::Utils::CryptoBuffer & GetEncryptedContentEncryptionKey() const
const Aws::String & GetMaterialsDescription(const Aws::String &key) const
const Aws::Utils::CryptoBuffer & GetGCMAAD() const
const Aws::Utils::CryptoBuffer & GetIV() const
void SetCekIV(const Aws::Utils::CryptoBuffer &iv)
const Aws::Utils::CryptoBuffer & GetMessageID() const
void SetCEKGCMTag(const Aws::Utils::CryptoBuffer &tag)
const Aws::Utils::CryptoBuffer & GetFinalCEK() const
const Aws::Utils::CryptoBuffer GetAAD() const
const Aws::Utils::CryptoBuffer & GetContentEncryptionKey() const
const Aws::Utils::CryptoBuffer & GetCekIV() const
void SetEncryptedContentEncryptionKey(const Aws::Utils::CryptoBuffer &encryptedContentEncryptionKey)
void SetContentCryptoScheme(ContentCryptoScheme contentCryptoScheme)
void SetContentEncryptionKey(const Aws::Utils::CryptoBuffer &contentEncryptionKey)
ContentCryptoMaterial(const Aws::Utils::CryptoBuffer &cek, ContentCryptoScheme contentCryptoScheme)
const Aws::Map< Aws::String, Aws::String > & GetMaterialsDescription() const
void SetMessageID(const Aws::Utils::CryptoBuffer &messageId)
const Aws::Map< Aws::String, Aws::String > & GetEncryptionContext() const
ContentCryptoMaterial(ContentCryptoScheme contentCryptoScheme)
const Aws::Utils::CryptoBuffer & GetKeyCommitment() const
void SetIV(const Aws::Utils::CryptoBuffer &iv)
void SetKeyWrapAlgorithm(KeyWrapAlgorithm keyWrapAlgorithm)
void SetEncryptionContext(const Aws::Map< Aws::String, Aws::String > &encryptionContext)
const Aws::Utils::CryptoBuffer & GetCEKGCMTag() const
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
Definition AWSMap.h:20
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97