Hazelcast C++ Client
Hazelcast C++ Client Library
ec2_request_signer.h
1 /*
2  * Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
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  */
16 #pragma once
17 
18 #include <string>
19 #include <unordered_map>
20 #include <vector>
21 
22 #include "hazelcast/util/export.h"
23 
24 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
25 #pragma warning(push)
26 #pragma warning(disable : 4251) // for dll export
27 #endif
28 
29 namespace hazelcast {
30 namespace client {
31 namespace config {
32 class client_aws_config;
33 }
34 namespace aws {
35 namespace security {
36 class HAZELCAST_API ec2_request_signer
37 {
38 public:
40  const std::string& timestamp,
41  const std::string& endpoint);
42 
43  virtual ~ec2_request_signer();
44 
45  std::string sign(
46  const std::unordered_map<std::string, std::string>& attributes);
47 
48  std::string create_formatted_credential() const;
49 
50  std::string get_canonicalized_query_string(
51  const std::unordered_map<std::string, std::string>& attributes) const;
52 
53 private:
54  /* Task 1 */
55  std::string get_canonicalized_request(
56  const std::unordered_map<std::string, std::string>& attributes) const;
57 
58  std::string get_canonical_headers() const;
59 
60  std::string get_canonicalized_query_string(
61  const std::vector<std::string>& list) const;
62 
63  std::vector<std::string> get_list_of_entries(
64  const std::unordered_map<std::string, std::string>& entries) const;
65 
66  static std::string format_attribute(const std::string& key,
67  const std::string& value);
68 
69  /* Task 2 */
70  std::string create_string_to_sign(
71  const std::string& canonical_request) const;
72 
73  std::string get_credential_scope() const;
74 
75  /* Task 3 */
76  std::vector<unsigned char> derive_signing_key() const;
77 
78  std::string create_signature(
79  const std::string& string_to_sign,
80  const std::vector<unsigned char>& signing_key) const;
81 
82  std::string hmac_sh_a256_hex(const std::vector<unsigned char>& key,
83  const std::string& msg) const;
84 
85  std::string convert_to_hex_string(const unsigned char* buffer,
86  unsigned int len) const;
87 
88  unsigned int hmac_sh_a256_bytes(const void* key,
89  int key_len,
90  const std::string& msg,
91  unsigned char* hash) const;
92 
93  unsigned int hmac_sh_a256_bytes(const std::string& key,
94  const std::string& msg,
95  unsigned char* hash) const;
96 
97  unsigned int hmac_sh_a256_bytes(const std::vector<unsigned char>& key,
98  const std::string& msg,
99  unsigned char* hash) const;
100 
101  unsigned int hmac_sh_a256_bytes(const void* key_buffer,
102  int key_len,
103  const unsigned char* data,
104  size_t data_len,
105  unsigned char* hash) const;
106 
107  std::string sha256_hashhex(const std::string& in) const;
108 
109  static std::string NEW_LINE;
110  static size_t DATE_LENGTH;
111 
112  const config::client_aws_config& aws_config_;
113  std::string timestamp_;
114  const std::string& endpoint_;
115 };
116 } // namespace security
117 } // namespace aws
118 } // namespace client
119 } // namespace hazelcast
120 
121 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
122 #pragma warning(pop)
123 #endif
The client_aws_config contains the configuration for client to connect to nodes in aws environment.
Endpoint represents a peer in the cluster.
Definition: endpoint.h:35