bes  Updated for version 3.20.10
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 <memory>
36 #include <map>
37 #include <vector>
38 #include <ctime>
39 #include <iostream>
40 
41 #include <openssl/sha.h>
42 
43 #include "url_impl.h"
44 
45 namespace AWSV4 {
46 const std::string ENDL{"\n"};
47 const std::string POST{"POST"};
48 const std::string GET{"GET"};
49 const std::string STRING_TO_SIGN_ALGO{"AWS4-HMAC-SHA256"};
50 const std::string AWS4{"AWS4"};
51 const std::string AWS4_REQUEST{"aws4_request"};
52 
53 std::string join(const std::vector<std::string> &ss, const std::string &delim);
54 
55 std::string sha256_base16(const std::string &str);
56 
57 std::map<std::string, std::string> canonicalize_headers(const std::vector<std::string> &headers);
58 
59 const std::string map_headers_string(const std::map<std::string, std::string> &header_key2val);
60 
61 const std::string map_signed_headers(const std::map<std::string, std::string> &header_key2val);
62 
63 const std::string canonicalize_request(const std::string &http_request_method,
64  const std::string &canonical_uri,
65  const std::string &canonical_query_string,
66  const std::string &canonical_headers,
67  const std::string &signed_headers,
68  const std::string &payload);
69 
70 const std::string string_to_sign(const std::string &algorithm,
71  const std::time_t &request_date,
72  const std::string &credential_scope,
73  const std::string &hashed_canonical_request);
74 
75 const std::string ISO8601_date(const std::time_t &t);
76 
77 const std::string utc_yyyymmdd(const std::time_t &t);
78 
79 const std::string credential_scope(const std::time_t &t,
80  const std::string region,
81  const std::string service);
82 
83 const std::string calculate_signature(const std::time_t &request_date,
84  const std::string secret,
85  const std::string region,
86  const std::string service,
87  const std::string string_to_sign);
88 
89 // The whole enchilada. Added jhrg 11/25/19
90 const std::string compute_awsv4_signature(std::shared_ptr<http::url> &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 }
94 
95 #endif