sse.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // MinIO C++ Library for Amazon S3 Compatible Cloud Storage
  2. // Copyright 2022 MinIO, Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #ifndef _MINIO_S3_SSE_H
  16. #define _MINIO_S3_SSE_H
  17. #include "utils.h"
  18. namespace minio {
  19. namespace s3 {
  20. class Sse {
  21. protected:
  22. utils::Multimap headers_;
  23. utils::Multimap copy_headers_;
  24. public:
  25. Sse() {}
  26. virtual ~Sse() {}
  27. utils::Multimap Headers() { return headers_; }
  28. utils::Multimap CopyHeaders() { return copy_headers_; }
  29. virtual bool TlsRequired() = 0;
  30. }; // class Sse
  31. class SseCustomerKey : public Sse {
  32. public:
  33. SseCustomerKey(std::string_view key) {
  34. std::string b64key = utils::Base64Encode(key);
  35. std::string md5key = utils::Md5sumHash(key);
  36. this->headers_.Add("X-Amz-Server-Side-Encryption-Customer-Algorithm",
  37. "AES256");
  38. this->headers_.Add("X-Amz-Server-Side-Encryption-Customer-Key", b64key);
  39. this->headers_.Add("X-Amz-Server-Side-Encryption-Customer-Key-MD5", md5key);
  40. this->copy_headers_.Add(
  41. "X-Amz-Copy-Source-Server-Side-Encryption-Customer-Algorithm",
  42. "AES256");
  43. this->copy_headers_.Add(
  44. "X-Amz-Copy-Source-Server-Side-Encryption-Customer-Key", b64key);
  45. this->copy_headers_.Add(
  46. "X-Amz-Copy-Source-Server-Side-Encryption-Customer-Key-MD5", md5key);
  47. }
  48. bool TlsRequired() { return true; }
  49. }; // class SseCustomerKey
  50. class SseKms : public Sse {
  51. public:
  52. SseKms(std::string_view key, std::string_view context) {
  53. this->headers_.Add("X-Amz-Server-Side-Encryption-Aws-Kms-Key-Id",
  54. std::string(key));
  55. this->headers_.Add("X-Amz-Server-Side-Encryption", "aws:kms");
  56. if (!context.empty()) {
  57. this->headers_.Add("X-Amz-Server-Side-Encryption-Context",
  58. utils::Base64Encode(context));
  59. }
  60. }
  61. bool TlsRequired() { return true; }
  62. }; // class SseKms
  63. class SseS3 : public Sse {
  64. public:
  65. SseS3() { this->headers_.Add("X-Amz-Server-Side-Encryption", "AES256"); }
  66. bool TlsRequired() { return false; }
  67. }; // class SseS3
  68. } // namespace s3
  69. } // namespace minio
  70. #endif // #ifndef __MINIO_S3_SSE_H