bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
retired/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
45namespace AWSV4 {
46
47const std::string ENDL{"\n"};
48const std::string POST{"POST"};
49const std::string GET{"GET"};
50const std::string STRING_TO_SIGN_ALGO{"AWS4-HMAC-SHA256"};
51const std::string AWS4{"AWS4"};
52const std::string AWS4_REQUEST{"aws4_request"};
53
54std::string join(const std::vector<std::string> &ss, const std::string &delim);
55
56std::string sha256_base16(const std::string &str);
57
58std::map<std::string, std::string> canonicalize_headers(const std::vector<std::string> &headers);
59
60std::string map_headers_string(const std::map<std::string, std::string> &header_key2val);
61
62std::string map_signed_headers(const std::map<std::string, std::string> &header_key2val);
63
64std::string canonicalize_request(const std::string &http_request_method,
65 const std::string &canonical_uri,
66 const std::string &canonical_query_string,
67 const std::string &canonical_headers,
68 const std::string &signed_headers,
69 const std::string &payload);
70
71std::string string_to_sign(const std::string &algorithm,
72 const std::time_t &request_date,
73 const std::string &credential_scope,
74 const std::string &hashed_canonical_request);
75
76std::string ISO8601_date(const std::time_t &t);
77
78std::string utc_yyyymmdd(const std::time_t &t);
79
80std::string credential_scope(const std::time_t &t,
81 const std::string &region,
82 const std::string &service);
83
84std::string calculate_signature(const std::time_t &request_date,
85 const std::string &secret,
86 const std::string &region,
87 const std::string &service,
88 const std::string &string_to_sign);
89
90// The whole enchilada. Added jhrg 11/25/19
91std::string compute_awsv4_signature(const std::shared_ptr<http::url> &uri_str, const std::time_t &request_date,
92 const std::string &public_key, const std::string &secret_key,
93 const std::string &region, const std::string &service = "s3");
94
95// Added these two as part of removing the use of std::shared_ptr<http::url>. jhrg 2/20/25
96std::string compute_awsv4_signature(const http::url &uri, const std::time_t &request_date,
97 const std::string &public_key, const std::string &secret_key,
98 const std::string &region, const std::string &service = "s3");
99
100std::string compute_awsv4_signature(const std::string &canonical_uri, const std::string &canonical_query,
101 const std::string &host, const std::time_t &request_date,
102 const std::string &public_key, const std::string &secret_key,
103 const std::string &region, const std::string &service);
104}
105
106#endif