bes  Updated for version 3.20.8
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 std::string join(const std::vector<std::string> &ss, const std::string &delim);
51 
52 std::string sha256_base16(const std::string &str);
53 
54 std::map<std::string, std::string> canonicalize_headers(const std::vector<std::string> &headers);
55 
56 const std::string map_headers_string(const std::map<std::string, std::string> &header_key2val);
57 
58 const std::string map_signed_headers(const std::map<std::string, std::string> &header_key2val);
59 
60 const std::string canonicalize_request(const std::string &http_request_method,
61  const std::string &canonical_uri,
62  const std::string &canonical_query_string,
63  const std::string &canonical_headers,
64  const std::string &signed_headers,
65  const std::string &payload);
66 
67 const std::string string_to_sign(const std::string &algorithm,
68  const std::time_t &request_date,
69  const std::string &credential_scope,
70  const std::string &hashed_canonical_request);
71 
72 const std::string ISO8601_date(const std::time_t &t);
73 
74 const std::string utc_yyyymmdd(const std::time_t &t);
75 
76 const std::string credential_scope(const std::time_t &t,
77  const std::string region,
78  const std::string service);
79 
80 const std::string calculate_signature(const std::time_t &request_date,
81  const std::string secret,
82  const std::string region,
83  const std::string service,
84  const std::string string_to_sign);
85 
86 // The whole enchilada. Added jhrg 11/25/19
87 const std::string compute_awsv4_signature(const std::string &uri_str, const std::time_t &request_date,
88  const std::string &public_key, const std::string &secret_key,
89  const std::string &region, const std::string &service = "s3");
90 }
91 
92 #endif