13 return {std::make_shared<MemberCOSESign1AuthnPolicy>(gov_msg_type)};
17 const std::string& gov_msg_type)
19 return {std::make_shared<ActiveMemberCOSESign1AuthnPolicy>(gov_msg_type)};
24 static void set_gov_error(
25 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
27 const std::string& code,
31 "{} {} returning error {}: {}",
32 rpc_ctx->get_request_verb().c_str(),
33 rpc_ctx->get_request_path(),
37 rpc_ctx->set_error(status, code, std::move(msg));
40 template <
typename EntityType>
52 if (std::any_of(s.begin(), s.end(), [](
char c) {
53 return (c <
'0') || (c >
'9' && c <
'A') || (c >
'F' && c <
'a') ||
65 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
ccf::MemberId& member_id)
68 std::string member_id_str;
71 rpc_ctx->get_request_path_params(),
"memberId", member_id_str,
error))
73 detail::set_gov_error(
75 HTTP_STATUS_BAD_REQUEST,
76 ccf::errors::InvalidResourceName,
82 const auto member_id_opt = parse_hex_id<ccf::MemberId>(member_id_str);
83 if (!member_id_opt.has_value())
85 detail::set_gov_error(
87 HTTP_STATUS_BAD_REQUEST,
88 ccf::errors::InvalidResourceName,
90 "'{}' is not a valid hex-encoded member ID", member_id_str));
94 member_id = member_id_opt.
value();
102 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
112 detail::set_gov_error(
114 HTTP_STATUS_BAD_REQUEST,
115 ccf::errors::InvalidResourceName,
116 "Authenticated member id does not match URL");
125 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
ccf::UserId& user_id)
128 std::string user_id_str;
131 rpc_ctx->get_request_path_params(),
"userId", user_id_str,
error))
133 detail::set_gov_error(
135 HTTP_STATUS_BAD_REQUEST,
136 ccf::errors::InvalidResourceName,
142 const auto user_id_opt = parse_hex_id<ccf::UserId>(user_id_str);
143 if (!user_id_opt.has_value())
145 detail::set_gov_error(
147 HTTP_STATUS_BAD_REQUEST,
148 ccf::errors::InvalidResourceName,
149 fmt::format(
"'{}' is not a valid hex-encoded user ID", user_id_str));
153 user_id = user_id_opt.
value();
159 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
163 std::string proposal_id_str;
166 rpc_ctx->get_request_path_params(),
171 detail::set_gov_error(
173 HTTP_STATUS_BAD_REQUEST,
174 ccf::errors::InvalidResourceName,
180 const auto proposal_id_opt = parse_hex_id<ccf::ProposalId>(proposal_id_str);
181 if (!proposal_id_opt.has_value())
183 detail::set_gov_error(
185 HTTP_STATUS_BAD_REQUEST,
186 ccf::errors::InvalidResourceName,
188 "'{}' is not a valid hex-encoded proposal ID", proposal_id_str));
192 proposal_id = proposal_id_opt.value();
200 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
208 const auto& signed_proposal_id =
211 !signed_proposal_id.has_value() ||
212 signed_proposal_id.value() != proposal_id)
214 detail::set_gov_error(
216 HTTP_STATUS_BAD_REQUEST,
217 ccf::errors::InvalidResourceName,
218 "Authenticated proposal id does not match URL");
227 const std::shared_ptr<ccf::RpcContext>& rpc_ctx,
ccf::NodeId& node_id)
230 std::string node_id_str;
233 rpc_ctx->get_request_path_params(),
"nodeId", node_id_str,
error))
235 detail::set_gov_error(
237 HTTP_STATUS_BAD_REQUEST,
238 ccf::errors::InvalidResourceName,
244 const auto node_id_opt = parse_hex_id<ccf::NodeId>(node_id_str);
245 if (!node_id_opt.has_value())
247 detail::set_gov_error(
249 HTTP_STATUS_BAD_REQUEST,
250 ccf::errors::InvalidResourceName,
251 fmt::format(
"'{}' is not a valid hex-encoded node ID", node_id_str));
255 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:124
bool try_parse_member_id(const std::shared_ptr< ccf::RpcContext > &rpc_ctx, ccf::MemberId &member_id)
Definition helpers.h:64
bool try_parse_proposal_id(const std::shared_ptr< ccf::RpcContext > &rpc_ctx, ccf::ProposalId &proposal_id)
Definition helpers.h:158
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:100
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:198
std::optional< EntityType > parse_hex_id(const std::string &s)
Definition helpers.h:41
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:226
AuthnPolicies active_member_sig_only_policies(const std::string &gov_msg_type)
Definition helpers.h:16
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
@ error
Definition tls_session.h:23
Value & value()
Definition entity_id.h:67
Definition cose_auth.h:59
GovernanceProtectedHeader protected_header
Definition cose_auth.h:67
MemberId member_id
Definition cose_auth.h:61