MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / formatJWSRequestData

Method formatJWSRequestData

src/Server/ACME/API.cpp:129–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127}
128
129std::string API::formatJWSRequestData(const Poco::URI & url, const std::string & payload, const std::string & nonce) const
130{
131 chassert(configuration.private_key);
132
133 std::string protected_data;
134 if (!key_id.empty())
135 protected_data = fmt::format(R"({{"alg":"RS256","kid":"{}","nonce":"{}","url":"{}"}})", key_id, nonce, url.toString());
136 else
137 {
138 auto jwk = JSONWebKey::fromRSAKey(*configuration.private_key).toString();
139 protected_data = fmt::format(R"({{"alg":"RS256","jwk":{},"nonce":"{}","url":"{}"}})", jwk, nonce, url.toString());
140 }
141
142 std::string protected_enc = base64Encode(protected_data, /*url_encoding*/ true, /*no_padding*/ true);
143
144 auto payload_enc = base64Encode(payload, /*url_encoding*/ true, /*no_padding*/ true);
145
146 EVP_PKEY * pkey = static_cast<EVP_PKEY*>(*configuration.private_key);
147 std::string to_sign = fmt::format("{}.{}", protected_enc, payload_enc);
148 std::string signature = rsaSHA256Sign(pkey, to_sign);
149 std::string encoded_signature = base64Encode(signature, /*url_encoding*/ true, /*no_padding*/ true);
150
151 return
152 R"({"protected":")" + protected_enc
153 + R"(","payload":")" + payload_enc
154 + R"(","signature":")" + encoded_signature
155 + R"("})";
156}
157
158std::string API::doJWSRequest(
159 const Poco::URI & url,

Callers

nothing calls this directly

Calls 5

base64EncodeFunction · 0.85
rsaSHA256SignFunction · 0.85
formatFunction · 0.50
emptyMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected