33 #ifndef _IDENTT_QUERY_PUBKEY_SERVICE_HPP_ 34 #define _IDENTT_QUERY_PUBKEY_SERVICE_HPP_ 42 template <
class HttpServerT>
67 identt::utils::SharedTable::pointer stptr,
68 typename std::shared_ptr<HttpServerT> server,
69 ::identt::query::HelpQuery::pointer helpquery,
71 :
identt::query::
ServiceBase<HttpServerT>(IDENTT_SERVICE_SCOPE_HTTP | IDENTT_SERVICE_SCOPE_HTTPS)
73 if (!(this->myscope & scope))
return;
77 helpquery->add({scope,
"GET _matrix/identity/api/v1/pubkey/{pubkey:string}", {
78 "This is the GET version of pubkey",
79 "Required. The ID of the key. This should take the form algorithm:identifier where algorithm",
80 "identifies the signing algorithm, and the identifier is an opaque string." 84 server->resource[
"/_matrix/identity/api/v1/pubkey/([A-z0-9]*)(%3[Aa]|:)(.*)$"][
"GET"]
85 =[
this,stptr](
typename HttpServerT::RespPtr response,
typename HttpServerT::ReqPtr request) {
86 IDENTT_PARALLEL_ONE([
this,stptr,response,request] {
88 LOG(INFO) << request->path;
91 pubkey.set_algo( request->path_match[1] );
92 pubkey.set_identifier( request->path_match[3] );
103 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
106 int ecode = (e.ecode()>=IDENTT_SYDENT_ERROR_MIN && e.ecode()<=IDENTT_SYDENT_ERROR_MAX) ? e.ecode() : M_UNKNOWN;
107 std::string output =
err2json(SydentErrors.at(ecode),e.what());
108 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
111 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
112 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
113 }
catch (std::exception& e)
115 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
116 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
126 helpquery->add({scope,
"GET _matrix/identity/api/v1/pubkey/isvalid?public_key=...", {
127 "This is the GET version of pubkey/isvalid",
128 "Check whether a long-term public key is valid.",
129 "Required. The unpadded base64-encoded public key to check.",
130 "Returns json with valid whether the public key is recognised and is currently valid" 134 server->resource[
"/_matrix/identity/api/v1/pubkey/isvalid\\\?(.*)$"][
"GET"]
135 =[
this,stptr](
typename HttpServerT::RespPtr response,
typename HttpServerT::ReqPtr request) {
136 IDENTT_PARALLEL_ONE([
this,stptr,response,request] {
138 LOG(INFO) << request->path;
142 auto params =
urldecode(request->path_match[1]);
143 pubkey.set_public_key( params.at(
"public_key") );
154 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
157 int ecode = (e.ecode()>=IDENTT_SYDENT_ERROR_MIN && e.ecode()<=IDENTT_SYDENT_ERROR_MAX) ? e.ecode() : M_UNKNOWN;
158 std::string output =
err2json(SydentErrors.at(ecode),e.what());
159 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
162 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
163 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
164 }
catch (std::exception& e)
166 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
167 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
177 helpquery->add({scope,
"GET _matrix/identity/api/v1/pubkey/ephemeral/isvalid?public_key=...", {
178 "This is the GET version of pubkey/ephemeral/isvalid",
179 "Check whether a short-term public key is valid.",
180 "Required. The unpadded base64-encoded public key to check.",
181 "Returns json with valid whether the public key is recognised and is currently valid" 185 server->resource[
"/_matrix/identity/api/v1/pubkey/ephemeral/isvalid\\\?(.*)$"][
"GET"]
186 =[
this,stptr](
typename HttpServerT::RespPtr response,
typename HttpServerT::ReqPtr request) {
187 IDENTT_PARALLEL_ONE([
this,stptr,response,request] {
189 LOG(INFO) << request->path;
193 auto params =
urldecode(request->path_match[1]);
194 pubkey.set_public_key( params.at(
"public_key") );
205 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
208 int ecode = (e.ecode()>=IDENTT_SYDENT_ERROR_MIN && e.ecode()<=IDENTT_SYDENT_ERROR_MAX) ? e.ecode() : M_UNKNOWN;
209 std::string output =
err2json(SydentErrors.at(ecode),e.what());
210 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
213 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
214 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
215 }
catch (std::exception& e)
217 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
218 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
227 helpquery->add({scope,
"POST _identt/identity/api/v1/sign-{algo:string}", {
228 "The identity service will happily sign invitation details with a request-specified ed25519 private key for you",
229 "params : mxid, token, private_key, sender (optional) ",
230 "This blindly sign for client" 234 server->resource[
"/_matrix/identity/api/v1/sign-([A-z0-9]*)(%3[Aa]|:)(.*)$"][
"POST"]
235 =[
this,stptr](
typename HttpServerT::RespPtr response,
typename HttpServerT::ReqPtr request) {
236 IDENTT_PARALLEL_ONE([
this,stptr,response,request] {
238 LOG(INFO) << request->path;
240 identt::query::PubKeyT pubkey;
241 pubkey.set_algo( request->path_match[1] );
242 pubkey.set_identifier( request->path_match[3] );
245 identt::query::ToSignQueryT query;
248 int stat =
json2pb( request->content.string() , &query , err);
251 form2pb( request->content.string() , &query);
255 if (query.mxid().length()==0)
256 throw ::identt::query::SydentException(
"mxid value required", M_MISSING_PARAMS);
257 if (query.token().length()==0)
258 throw ::identt::query::SydentException(
"token value required", M_MISSING_PARAMS);
259 if (query.private_key().length()==0)
260 throw ::identt::query::SydentException(
"private_key value required", M_MISSING_PARAMS);
263 pubkey.set_private_key( query.private_key() );
264 pubkey.set_no_keyring(
true);
265 if (query.sender().length()==0)
266 pubkey.set_owner(
"unknown");
268 pubkey.set_owner(query.sender());
277 ::identt::query::SignedJson::SignatureListT signatures;
278 pkservice.
AddSign(stptr, &query , &pubkey, output, signatures);
281 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
284 int ecode = (e.ecode()>=IDENTT_SYDENT_ERROR_MIN && e.ecode()<=IDENTT_SYDENT_ERROR_MAX) ? e.ecode() : M_UNKNOWN;
285 std::string output =
err2json(SydentErrors.at(ecode),e.what());
286 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
289 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
290 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
291 }
catch (std::exception& e)
293 std::string output =
err2json(SydentErrors.at(M_UNKNOWN),e.what());
294 this->
HttpOKAction(response,request,200,
"OK",
"application/json",output,
true);
310 #endif // _IDENTT_QUERY_PUBKEY_SERVICE_HPP_ void HttpOKAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, int ec, const char *em, const char *content_type, std::string &payload, bool add_cors)
HttpOKAction : OK Action template.
Definition: ServiceBase.hpp:154
void GetPubKeyValidAction(::identt::utils::SharedTable::pointer stptr, ::identt::query::PubKeyT *pubkey)
GetPubKeyValidAction : Service Endpoint GetPubKeyValid.
Definition: PubKeyService.cc:58
PubKeyService(identt::utils::SharedTable::pointer stptr, typename std::shared_ptr< HttpServerT > server, ::identt::query::HelpQuery::pointer helpquery, unsigned int scope)
PubKeyService : constructor.
Definition: PubKeyService.hpp:66
Sydent Exceptions.
Definition: SydentQuery.hpp:91
void GetPubKeyAction(::identt::utils::SharedTable::pointer stptr, ::identt::query::PubKeyT *pubkey)
GetPubKeyAction : Service Endpoint GetPubKey.
Definition: PubKeyService.cc:43
void HttpErrorAction(typename HttpServerT::RespPtr response, typename HttpServerT::ReqPtr request, int ec, const char *em)
HttpErrorAction : Error Action Template no payload maybe template.
Definition: ServiceBase.hpp:85
Definition: BaseUtils.hpp:52
void pb2json(const google::protobuf::Message *msg, std::string &str)
pb2json : Convert protobuf to json
Definition: ProtoJson.cc:415
Definition: PubKeyService.hpp:42
void GetEphemeralValidAction(::identt::utils::SharedTable::pointer stptr, ::identt::query::PubKeyT *pubkey)
GetEphemeralValidAction : Service Endpoint GetEphemeralValid.
Definition: PubKeyService.cc:77
Definition: ServiceBase.hpp:55
Definition: CryptoBase.hpp:49
Definition: PubKeyService.hpp:43
Definition: BaseUtils.hpp:89
std::string err2json(const std::string errorcode, const std::string error)
err2json : Generate a Json for Error Message
Definition: ProtoJson.cc:511
void AddSign(::identt::utils::SharedTable::pointer stptr, const google::protobuf::Message *result, const ::identt::query::PubKeyT *pubkey, std::string &output, SignatureListT &signatures)
AddSign: Add Signature pb, also adds older signatures.
bool JsonRequest(typename HttpServerT::ReqPtr request)
JsonRequest : Check if request is json from Content-Type and Accept fields.
Definition: ServiceBase.hpp:178
int json2pb(const std::string &json, google::protobuf::Message *msg, std::string &err)
json2pb : Convert json to protobuf
Definition: ProtoJson.cc:446