bes  Updated for version 3.20.6
awsv4.h
1 
2 
3 // -*- mode: c++; c-basic-offset:4 -*-
4 
5 // This file is part of the Hyrax data server.
6 
7 // This code is derived from https://github.com/bradclawsie/awsv4-cpp
8 // Copyright (c) 2013, brad clawsie
9 // All rights reserved.
10 // see the file AWSV4_LICENSE
11 
12 // Copyright (c) 2019 OPeNDAP, Inc.
13 // Modifications Author: James Gallagher <jgallagher@opendap.org>
14 //
15 // This library is free software; you can redistribute it and/or
16 // modify it under the terms of the GNU Lesser General Public
17 // License as published by the Free Software Foundation; either
18 // version 2.1 of the License, or (at your option) any later version.
19 //
20 // This library is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 // Lesser General Public License for more details.
24 //
25 // You should have received a copy of the GNU Lesser General Public
26 // License along with this library; if not, write to the Free Software
27 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 //
29 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
30 
31 #ifndef AWSV4_HPP
32 #define AWSV4_HPP
33 
34 #include <cstdio>
35 #include <map>
36 #include <vector>
37 #include <ctime>
38 #include <iostream>
39 
40 #include <openssl/sha.h>
41 
42 namespace AWSV4 {
43  const std::string ENDL{"\n"};
44  const std::string POST{"POST"};
45  const std::string GET{"GET"};
46  const std::string STRING_TO_SIGN_ALGO{"AWS4-HMAC-SHA256"};
47  const std::string AWS4{"AWS4"};
48  const std::string AWS4_REQUEST{"aws4_request"};
49 
50 #if 0
51  void sha256(const std::string str, unsigned char outputBuffer[SHA256_DIGEST_LENGTH]);
52 #endif
53 
54  std::string sha256_base16(const std::string);
55 
56  std::map<std::string,std::string> canonicalize_headers(const std::vector<std::string>& headers);
57 
58  const std::string map_headers_string(const std::map<std::string,std::string>& header_key2val);
59 
60  const std::string map_signed_headers(const std::map<std::string,std::string>& header_key2val);
61 
62  const std::string canonicalize_request(const std::string& http_request_method,
63  const std::string& canonical_uri,
64  const std::string& canonical_query_string,
65  const std::string& canonical_headers,
66  const std::string& signed_headers,
67  const std::string& payload);
68 
69  const std::string string_to_sign(const std::string& algorithm,
70  const std::time_t& request_date,
71  const std::string& credential_scope,
72  const std::string& hashed_canonical_request);
73 
74  const std::string ISO8601_date(const std::time_t& t);
75 
76  const std::string utc_yyyymmdd(const std::time_t& t);
77 
78  const std::string credential_scope(const std::time_t& t,
79  const std::string region,
80  const std::string service);
81 
82  const std::string calculate_signature(const std::time_t& request_date,
83  const std::string secret,
84  const std::string region,
85  const std::string service,
86  const std::string string_to_sign,
87  const bool verbose = false);
88 
89  // The whole enchilada. Added jhrg 11/25/19
90  const std::string compute_awsv4_signature(const std::string &uri_str, const std::time_t &request_date,
91  const std::string &public_key, const std::string &secret_key,
92  const std::string &region, const std::string &service = "s3",
93  const bool &verbose = false);
94 }
95 
96 #endif