13 return {std::make_shared<MemberCOSESign1AuthnPolicy>(gov_msg_type)};
18 return {std::make_shared<ActiveMemberCOSESign1AuthnPolicy>(gov_msg_type)};
23 static void set_gov_error(
24 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
26 const std::string& code,
30 "{} {} returning error {}: {}",
31 rpc_ctx->get_request_verb().c_str(),
32 rpc_ctx->get_request_path(),
36 rpc_ctx->set_error(status, code, std::move(msg));
39 template <
typename EntityType>
51 if (std::any_of(s.begin(), s.end(), [](
char c) {
52 return (c <
'0') || (c >
'9' && c <
'A') || (c >
'F' && c <
'a') ||
64 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
ccf::MemberId& member_id)
67 std::string member_id_str;
70 rpc_ctx->get_request_path_params(),
"memberId", member_id_str,
error))
72 detail::set_gov_error(
74 HTTP_STATUS_BAD_REQUEST,
75 ccf::errors::InvalidResourceName,
81 const auto member_id_opt = parse_hex_id<ccf::MemberId>(member_id_str);
82 if (!member_id_opt.has_value())
84 detail::set_gov_error(
86 HTTP_STATUS_BAD_REQUEST,
87 ccf::errors::InvalidResourceName,
89 "'{}' is not a valid hex-encoded member ID", member_id_str));
93 member_id = member_id_opt.
value();
101 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
111 detail::set_gov_error(
113 HTTP_STATUS_BAD_REQUEST,
114 ccf::errors::InvalidResourceName,
115 "Authenticated member id does not match URL");
124 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
ccf::UserId& user_id)
127 std::string user_id_str;
130 rpc_ctx->get_request_path_params(),
"userId", user_id_str,
error))
132 detail::set_gov_error(
134 HTTP_STATUS_BAD_REQUEST,
135 ccf::errors::InvalidResourceName,
141 const auto user_id_opt = parse_hex_id<ccf::UserId>(user_id_str);
142 if (!user_id_opt.has_value())
144 detail::set_gov_error(
146 HTTP_STATUS_BAD_REQUEST,
147 ccf::errors::InvalidResourceName,
148 fmt::format(
"'{}' is not a valid hex-encoded user ID", user_id_str));
152 user_id = user_id_opt.
value();
158 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
162 std::string proposal_id_str;
165 rpc_ctx->get_request_path_params(),
170 detail::set_gov_error(
172 HTTP_STATUS_BAD_REQUEST,
173 ccf::errors::InvalidResourceName,
179 const auto proposal_id_opt = parse_hex_id<ccf::ProposalId>(proposal_id_str);
180 if (!proposal_id_opt.has_value())
182 detail::set_gov_error(
184 HTTP_STATUS_BAD_REQUEST,
185 ccf::errors::InvalidResourceName,
187 "'{}' is not a valid hex-encoded proposal ID", proposal_id_str));
191 proposal_id = proposal_id_opt.value();
199 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
207 const auto& signed_proposal_id =
210 !signed_proposal_id.has_value() ||
211 signed_proposal_id.value() != proposal_id)
213 detail::set_gov_error(
215 HTTP_STATUS_BAD_REQUEST,
216 ccf::errors::InvalidResourceName,
217 "Authenticated proposal id does not match URL");
226 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
ccf::NodeId& node_id)
229 std::string node_id_str;
232 rpc_ctx->get_request_path_params(),
"nodeId", node_id_str,
error))
234 detail::set_gov_error(
236 HTTP_STATUS_BAD_REQUEST,
237 ccf::errors::InvalidResourceName,
243 const auto node_id_opt = parse_hex_id<ccf::NodeId>(node_id_str);
244 if (!node_id_opt.has_value())
246 detail::set_gov_error(
248 HTTP_STATUS_BAD_REQUEST,
249 ccf::errors::InvalidResourceName,
250 fmt::format(
"'{}' is not a valid hex-encoded node ID", node_id_str));
254 node_id = node_id_opt.
value();
#define GOV_INFO_FMT
Definition gov_logging.h:10
bool get_path_param(const ccf::PathParams ¶ms, const std::string ¶m_name, T &value, std::string &error)
Definition endpoint_registry.h:64
bool try_parse_user_id(const std::shared_ptr< ccf::RpcContext > &rpc_ctx, ccf::UserId &user_id)
Definition helpers.h:123
bool try_parse_member_id(const std::shared_ptr< ccf::RpcContext > &rpc_ctx, ccf::MemberId &member_id)
Definition helpers.h:63
bool try_parse_proposal_id(const std::shared_ptr< ccf::RpcContext > &rpc_ctx, ccf::ProposalId &proposal_id)
Definition helpers.h:157
bool try_parse_signed_member_id(const ccf::MemberCOSESign1AuthnIdentity &cose_ident, const std::shared_ptr< ccf::RpcContext > &rpc_ctx, ccf::MemberId &member_id)
Definition helpers.h:99
bool try_parse_signed_proposal_id(const ccf::MemberCOSESign1AuthnIdentity &cose_ident, const std::shared_ptr< ccf::RpcContext > &rpc_ctx, ccf::ProposalId &proposal_id)
Definition helpers.h:197
std::optional< EntityType > parse_hex_id(const std::string &s)
Definition helpers.h:40
AuthnPolicies member_sig_only_policies(const std::string &gov_msg_type)
Definition helpers.h:11
bool try_parse_node_id(const std::shared_ptr< ccf::RpcContext > &rpc_ctx, ccf::NodeId &node_id)
Definition helpers.h:225
AuthnPolicies active_member_sig_only_policies(const std::string &gov_msg_type)
Definition helpers.h:16
@ error
Definition tls_session.h:24
std::vector< std::shared_ptr< AuthnPolicy > > AuthnPolicies
Definition authentication_types.h:47
llhttp_status http_status
Definition http_status.h:9
std::string ProposalId
Definition proposals.h:40
Value & value()
Definition entity_id.h:60
Definition cose_auth.h:59
GovernanceProtectedHeader protected_header
Definition cose_auth.h:67
MemberId member_id
Definition cose_auth.h:61