CCF
Loading...
Searching...
No Matches
cose_auth.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ccf/crypto/pem.h"
7#include "ccf/entity_id.h"
9
10namespace ccf
11{
13 {
14 int64_t alg = 0;
15 std::string kid;
16 };
17
19 {
20 std::optional<std::string> gov_msg_type;
21 std::optional<std::string> gov_msg_proposal_id;
22 uint64_t gov_msg_created_at = 0;
23 };
24
26 {
27 std::optional<std::string> msg_type;
28 std::optional<uint64_t> msg_created_at;
29 };
30
32 {
34 std::span<const uint8_t> content;
35
41 std::span<const uint8_t> envelope;
42
44 std::span<const uint8_t> signature;
45
47 const std::span<const uint8_t>& content_,
48 const std::span<const uint8_t>& envelope_,
49 const std::span<const uint8_t>& signature_) :
50 content(content_),
51 envelope(envelope_),
52 signature(signature_)
53 {}
54
56 };
57
59 {
62
65
68
70 const std::span<const uint8_t>& content_,
71 const std::span<const uint8_t>& envelope_,
72 const std::span<const uint8_t>& signature_,
73 MemberId member_id_,
74 ccf::crypto::Pem member_cert_,
75 GovernanceProtectedHeader protected_header_) :
76 COSESign1AuthnIdentity(content_, envelope_, signature_),
77 member_id(std::move(member_id_)),
78 member_cert(std::move(member_cert_)),
79 protected_header(std::move(protected_header_))
80 {}
81 };
82
84 {
87
90
93
95 const std::span<const uint8_t>& content_,
96 const std::span<const uint8_t>& envelope_,
97 const std::span<const uint8_t>& signature_,
98 UserId user_id_,
99 ccf::crypto::Pem user_cert_,
100 TimestampedProtectedHeader protected_header_) :
101 COSESign1AuthnIdentity(content_, envelope_, signature_),
102 user_id(std::move(user_id_)),
103 user_cert(std::move(user_cert_)),
104 protected_header(std::move(protected_header_))
105 {}
106 };
107
115 {
116 protected:
118 std::optional<std::string> gov_msg_type = std::nullopt;
119
120 public:
121 static constexpr auto SECURITY_SCHEME_NAME = "member_cose_sign1";
122
124 std::optional<std::string> gov_msg_type_ = std::nullopt);
126
127 std::unique_ptr<AuthnIdentity> authenticate(
129 const std::shared_ptr<ccf::RpcContext>& ctx,
130 std::string& error_reason) override;
131
133 std::shared_ptr<ccf::RpcContext> ctx,
134 std::string&& error_reason) override;
135
136 [[nodiscard]] std::optional<OpenAPISecuritySchema>
138 {
139 return security_schema;
140 }
141
142 std::string get_security_scheme_name() override
143 {
145 }
146 };
147
154 {
155 public:
156 static constexpr auto SECURITY_SCHEME_NAME = "active_member_cose_sign1";
157
159
160 std::unique_ptr<AuthnIdentity> authenticate(
162 const std::shared_ptr<ccf::RpcContext>& ctx,
163 std::string& error_reason) override;
164
165 std::string get_security_scheme_name() override
166 {
168 }
169 };
170
177 {
178 std::string msg_type_name;
179 std::string msg_created_at_name;
180
181 protected:
183
184 virtual std::unique_ptr<UserCOSESign1AuthnIdentity> _authenticate(
186 const std::shared_ptr<ccf::RpcContext>& ctx,
187 std::string& error_reason);
188
189 public:
190 static constexpr auto SECURITY_SCHEME_NAME = "user_cose_sign1";
191
193 std::string msg_type_name_ = "ccf.msg.type",
194 std::string msg_created_at_name_ = "ccf.msg.created_at") :
195 msg_type_name(std::move(msg_type_name_)),
196 msg_created_at_name(std::move(msg_created_at_name_))
197 {}
199
200 std::unique_ptr<AuthnIdentity> authenticate(
202 const std::shared_ptr<ccf::RpcContext>& ctx,
203 std::string& error_reason) override;
204
206 std::shared_ptr<ccf::RpcContext> ctx,
207 std::string&& error_reason) override;
208
209 [[nodiscard]] std::optional<OpenAPISecuritySchema>
211 {
212 return security_schema;
213 }
214
215 std::string get_security_scheme_name() override
216 {
218 }
219 };
220
227 {
228 private:
229 std::string expected_msg_type;
230
231 public:
232 static constexpr auto SECURITY_SCHEME_NAME = "typed_user_cose_sign1";
233
235 std::string expected_msg_type_,
236 std::string msg_type_name_ = "ccf.msg.type",
237 std::string msg_created_at_name_ = "ccf.msg.created_at") :
239 std::move(msg_type_name_), std::move(msg_created_at_name_)),
240 expected_msg_type(std::move(expected_msg_type_))
241 {}
242
243 std::unique_ptr<AuthnIdentity> authenticate(
245 const std::shared_ptr<ccf::RpcContext>& ctx,
246 std::string& error_reason) override;
247
248 std::string get_security_scheme_name() override
249 {
251 }
252 };
253}
Definition cose_auth.h:154
std::string get_security_scheme_name() override
Definition cose_auth.h:165
std::unique_ptr< AuthnIdentity > authenticate(ccf::kv::ReadOnlyTx &tx, const std::shared_ptr< ccf::RpcContext > &ctx, std::string &error_reason) override
Definition cose_auth.cpp:404
static constexpr auto SECURITY_SCHEME_NAME
Definition cose_auth.h:156
Definition authentication_types.h:28
Definition cose_auth.h:115
std::optional< OpenAPISecuritySchema > get_openapi_security_schema() const override
Definition cose_auth.h:137
static const OpenAPISecuritySchema security_schema
Definition cose_auth.h:117
void set_unauthenticated_error(std::shared_ptr< ccf::RpcContext > ctx, std::string &&error_reason) override
Definition cose_auth.cpp:381
static constexpr auto SECURITY_SCHEME_NAME
Definition cose_auth.h:121
std::optional< std::string > gov_msg_type
Definition cose_auth.h:118
std::unique_ptr< AuthnIdentity > authenticate(ccf::kv::ReadOnlyTx &tx, const std::shared_ptr< ccf::RpcContext > &ctx, std::string &error_reason) override
Definition cose_auth.cpp:301
MemberCOSESign1AuthnPolicy(std::optional< std::string > gov_msg_type_=std::nullopt)
Definition cose_auth.cpp:296
std::string get_security_scheme_name() override
Definition cose_auth.h:142
Definition cose_auth.h:227
TypedUserCOSESign1AuthnPolicy(std::string expected_msg_type_, std::string msg_type_name_="ccf.msg.type", std::string msg_created_at_name_="ccf.msg.created_at")
Definition cose_auth.h:234
std::string get_security_scheme_name() override
Definition cose_auth.h:248
std::unique_ptr< AuthnIdentity > authenticate(ccf::kv::ReadOnlyTx &tx, const std::shared_ptr< ccf::RpcContext > &ctx, std::string &error_reason) override
Definition cose_auth.cpp:528
static constexpr auto SECURITY_SCHEME_NAME
Definition cose_auth.h:232
Definition cose_auth.h:177
std::optional< OpenAPISecuritySchema > get_openapi_security_schema() const override
Definition cose_auth.h:210
static const OpenAPISecuritySchema security_schema
Definition cose_auth.h:182
static constexpr auto SECURITY_SCHEME_NAME
Definition cose_auth.h:190
void set_unauthenticated_error(std::shared_ptr< ccf::RpcContext > ctx, std::string &&error_reason) override
Definition cose_auth.cpp:505
UserCOSESign1AuthnPolicy(std::string msg_type_name_="ccf.msg.type", std::string msg_created_at_name_="ccf.msg.created_at")
Definition cose_auth.h:192
std::string get_security_scheme_name() override
Definition cose_auth.h:215
std::unique_ptr< AuthnIdentity > authenticate(ccf::kv::ReadOnlyTx &tx, const std::shared_ptr< ccf::RpcContext > &ctx, std::string &error_reason) override
Definition cose_auth.cpp:497
virtual std::unique_ptr< UserCOSESign1AuthnIdentity > _authenticate(ccf::kv::ReadOnlyTx &tx, const std::shared_ptr< ccf::RpcContext > &ctx, std::string &error_reason)
Definition cose_auth.cpp:439
Definition pem.h:18
Definition tx.h:159
Definition app_interface.h:14
std::pair< std::string, nlohmann::json > OpenAPISecuritySchema
Definition authentication_types.h:23
STL namespace.
Definition authentication_types.h:19
Definition cose_auth.h:32
std::span< const uint8_t > content
Definition cose_auth.h:34
std::span< const uint8_t > envelope
Definition cose_auth.h:41
std::span< const uint8_t > signature
Definition cose_auth.h:44
COSESign1AuthnIdentity(const std::span< const uint8_t > &content_, const std::span< const uint8_t > &envelope_, const std::span< const uint8_t > &signature_)
Definition cose_auth.h:46
Definition cose_auth.h:19
std::optional< std::string > gov_msg_type
Definition cose_auth.h:20
uint64_t gov_msg_created_at
Definition cose_auth.h:22
std::optional< std::string > gov_msg_proposal_id
Definition cose_auth.h:21
Definition cose_auth.h:59
GovernanceProtectedHeader protected_header
Definition cose_auth.h:67
MemberId member_id
Definition cose_auth.h:61
ccf::crypto::Pem member_cert
Definition cose_auth.h:64
MemberCOSESign1AuthnIdentity(const std::span< const uint8_t > &content_, const std::span< const uint8_t > &envelope_, const std::span< const uint8_t > &signature_, MemberId member_id_, ccf::crypto::Pem member_cert_, GovernanceProtectedHeader protected_header_)
Definition cose_auth.h:69
Definition cose_auth.h:13
std::string kid
Definition cose_auth.h:15
int64_t alg
Definition cose_auth.h:14
Definition cose_auth.h:26
std::optional< uint64_t > msg_created_at
Definition cose_auth.h:28
std::optional< std::string > msg_type
Definition cose_auth.h:27
Definition cose_auth.h:84
UserCOSESign1AuthnIdentity(const std::span< const uint8_t > &content_, const std::span< const uint8_t > &envelope_, const std::span< const uint8_t > &signature_, UserId user_id_, ccf::crypto::Pem user_cert_, TimestampedProtectedHeader protected_header_)
Definition cose_auth.h:94
ccf::crypto::Pem user_cert
Definition cose_auth.h:89
UserId user_id
Definition cose_auth.h:86
TimestampedProtectedHeader protected_header
Definition cose_auth.h:92