49 return !
error.empty();
64 ret +=
" error='" +
error +
'\'';
71 const int debug_level_arg)
72 :
cs(std::move(cs_arg)),
79 const std::string &role_for_credentials_arg,
80 const std::string &certs_dir_arg)
81 :
cs(std::move(cs_arg)),
93 http_config->frame =
frame;
94 http_config->connect_timeout = 15;
95 http_config->general_timeout = 30;
99 ts->host.host =
"169.254.169.254";
100 ts->host.port =
"80";
101 ts->http_config = http_config;
112 throw awspc_query_error(
"request pending");
127 t->req.method =
"PUT";
128 t->req.uri =
"/latest/api/token";
129 t->ci.extra_headers.emplace_back(
"X-aws-ec2-metadata-token-ttl-seconds: 60");
130 ts->transactions.push_back(std::move(t));
136 self->token_query_complete(ts);
142 catch (
const std::exception &e)
171 done(
"could not fetch AWS identity document: " + ident_trans.
format_status(lts));
178 done(
"could not fetch AWS identity document signature: " + sig_trans.
format_status(lts));
184 const std::string sig =
"-----BEGIN PKCS7-----\n"
186 +
"\n-----END PKCS7-----\n";
198 std::list<OpenSSLPKI::X509> certs;
200 certs.emplace_back(
awscert(),
"AWS Cert");
211 const std::string title =
"identity-document";
212 const Json::Value root =
json::parse(ident, title);
237 catch (
const std::exception &e)
261 t->req.method =
"GET";
262 t->req.uri =
"/latest/dynamic/instance-identity/document";
263 t->ci.extra_headers.emplace_back(
"X-aws-ec2-metadata-token: " + token);
264 ts->transactions.push_back(std::move(t));
270 t->req.method =
"GET";
271 t->req.uri =
"/latest/dynamic/instance-identity/pkcs7";
272 t->ci.extra_headers.emplace_back(
"X-aws-ec2-metadata-token: " + token);
273 ts->transactions.push_back(std::move(t));
280 t->req.method =
"GET";
282 t->ci.extra_headers.emplace_back(
"X-aws-ec2-metadata-token: " + token);
283 ts->transactions.push_back(std::move(t));
289 self->local_query_complete(ts);
295 catch (
const std::exception &e)
305 "-----BEGIN CERTIFICATE-----\n"
306 "MIIC7TCCAq0CCQCWukjZ5V4aZzAJBgcqhkjOOAQDMFwxCzAJBgNVBAYTAlVTMRkw\n"
307 "FwYDVQQIExBXYXNoaW5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ptr cs_arg, const std::string &role_for_credentials_arg, const std::string &certs_dir_arg)
OPENVPN_EXCEPTION(awspc_query_error)
void token_query_complete(WS::ClientSet::TransactionSet <s)
static std::string awscert()
void done(std::string error)
void local_query_complete(WS::ClientSet::TransactionSet <s)
std::function< void(Info info)> completion
PCQuery(WS::ClientSet::Ptr cs_arg, const int debug_level_arg)
void start(std::function< void(Info info)> completion_arg)
std::string role_for_credentials
WS::ClientSet::TransactionSet::Ptr prepare_transaction_set()
Reference count base class for objects tracked by RCPtr. Disallows copying and assignment.
#define OPENVPN_LOG(args)
void verify_pkcs7(const std::list< OpenSSLPKI::X509 > &certs, const std::string &sig, const std::string &data)
Json::Value parse(const std::string &str, const TITLE &title)
std::string get_string(const Json::Value &root, const NAME &name, const TITLE &title)
Frame::Ptr frame_init_simple(const size_t payload)
std::string read_text(const std::string &filename, const std::uint64_t max_size=0)
bool enum_dir(const std::string &dirname, F func)
std::string to_string() const
bool instance_data_defined() const
std::string to_string() const
bool request_status_success() const
std::string format_status(const TransactionSet &ts) const