Hazelcast C++ Client
 All Classes Functions Variables Enumerations Enumerator Pages
EC2RequestSigner.h
1 /*
2  * Copyright (c) 2008-2017, 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 #ifndef HAZELCAST_CLIENT_AWS_SECURITY_EC2REQUESTSIGNER_H_
17 #define HAZELCAST_CLIENT_AWS_SECURITY_EC2REQUESTSIGNER_H_
18 
19 #include <string>
20 #include <map>
21 #include <vector>
22 
23 #include "hazelcast/util/HazelcastDll.h"
24 
25 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
26 #pragma warning(push)
27 #pragma warning(disable: 4251) //for dll export
28 #endif
29 
30 namespace hazelcast {
31  namespace client {
32  namespace config {
33  class ClientAwsConfig;
34  }
35  namespace aws {
36  namespace security {
37  class HAZELCAST_API EC2RequestSigner {
38  public:
39  EC2RequestSigner(const config::ClientAwsConfig &awsConfig, const std::string &timestamp,
40  const std::string &endpoint);
41 
42  virtual ~EC2RequestSigner();
43 
44  std::string sign(const std::map<std::string, std::string> &attributes);
45 
46  std::string createFormattedCredential() const;
47 
48  std::string getCanonicalizedQueryString(const std::map<std::string, std::string> &attributes) const;
49  private:
50  /* Task 1 */
51  std::string getCanonicalizedRequest(const std::map<std::string, std::string> &attributes) const;
52 
53  std::string getCanonicalHeaders() const;
54 
55  std::string getCanonicalizedQueryString(const std::vector<std::string> &list) const;
56 
57  std::vector<std::string> getListOfEntries(const std::map<std::string, std::string> &entries) const;
58 
59  void addComponents(std::vector<std::string> &components,
60  const std::map<std::string, std::string> &attributes,
61  const std::string &key) const;
62 
63  /* Task 2 */
64  std::string createStringToSign(const std::string &canonicalRequest) const;
65 
66  std::string getCredentialScope() const;
67 
68  /* Task 3 */
69  std::vector<unsigned char> deriveSigningKey() const;
70 
71  std::string createSignature(const std::string &stringToSign, const std::vector<unsigned char> &signingKey) const;
72 
73  std::string hmacSHA256Hex(const std::vector<unsigned char> &key, const std::string &msg) const;
74 
75  std::string convertToHexString(const unsigned char *buffer, unsigned int len) const;
76 
77  unsigned int hmacSHA256Bytes(const void *key, int keyLen, const std::string &msg,
78  unsigned char *hash) const;
79 
80  unsigned int hmacSHA256Bytes(const std::string &key, const std::string &msg,
81  unsigned char *hash) const;
82 
83  unsigned int hmacSHA256Bytes(const std::vector<unsigned char> &key, const std::string &msg,
84  unsigned char *hash) const;
85 
86  unsigned int hmacSHA256Bytes(const void *keyBuffer, int keyLen, const unsigned char *data,
87  size_t dataLen,
88  unsigned char *hash) const;
89 
90  std::string sha256Hashhex(const std::string &in) const;
91 
92  static std::string NEW_LINE;
93  static size_t DATE_LENGTH;
94 
95  const config::ClientAwsConfig &awsConfig;
96  std::string timestamp;
97  const std::string &endpoint;
98  };
99  }
100  }
101  }
102 }
103 
104 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
105 #pragma warning(pop)
106 #endif
107 
108 #endif /* HAZELCAST_CLIENT_AWS_SECURITY_EC2REQUESTSIGNER_H_ */
The ClientAwsConfig contains the configuration for client to connect to nodes in aws environment...
Definition: ClientAwsConfig.h:53