Skip to content

Commit f54c0f8

Browse files
authored
Add cose signature subsystem (#6707)
1 parent 5bd5e23 commit f54c0f8

File tree

7 files changed

+130
-2
lines changed

7 files changed

+130
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
### Added
1313

1414
- Expose `ccf:http::parse_accept_header()` and `ccf::http::AcceptHeaderField` (#6706).
15+
- Added `ccf::cose::AbstractCOSESignaturesConfig` subsystem to expose COSE signature configuration to application handlers (#6707).
1516

1617
## [6.0.0-dev9]
1718

doc/schemas/app_openapi.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
"info": {
258258
"description": "This CCF sample app implements a simple logging application, securely recording messages at client-specified IDs. It demonstrates most of the features available to CCF apps.",
259259
"title": "CCF Sample Logging App",
260-
"version": "2.7.0"
260+
"version": "2.8.0"
261261
},
262262
"openapi": "3.0.0",
263263
"paths": {
@@ -328,6 +328,30 @@
328328
}
329329
}
330330
},
331+
"/app/cose_signatures_config": {
332+
"get": {
333+
"operationId": "GetAppCoseSignaturesConfig",
334+
"responses": {
335+
"204": {
336+
"description": "Default response description"
337+
},
338+
"default": {
339+
"$ref": "#/components/responses/default"
340+
}
341+
},
342+
"security": [
343+
{
344+
"jwt": []
345+
},
346+
{
347+
"user_cose_sign1": []
348+
}
349+
],
350+
"x-ccf-forwarding": {
351+
"$ref": "#/components/x-ccf-forwarding/never"
352+
}
353+
}
354+
},
331355
"/app/custom_auth": {
332356
"get": {
333357
"operationId": "GetAppCustomAuth",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the Apache 2.0 License.
3+
#pragma once
4+
5+
#include "ccf/node/cose_signatures_config.h"
6+
#include "ccf/node_subsystem_interface.h"
7+
8+
#include <chrono>
9+
#include <memory>
10+
11+
namespace ccf::cose
12+
{
13+
/** Exposes the COSE signatures configuration to the application.
14+
*/
15+
class AbstractCOSESignaturesConfig : public ccf::AbstractNodeSubSystem
16+
{
17+
public:
18+
virtual ~AbstractCOSESignaturesConfig() = default;
19+
20+
static char const* get_subsystem_name()
21+
{
22+
return "COSESignaturesConfig";
23+
}
24+
25+
virtual const ccf::COSESignaturesConfig& get_cose_signatures_config()
26+
const = 0;
27+
};
28+
}

samples/apps/logging/logging.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// CCF
88
#include "ccf/app_interface.h"
99
#include "ccf/common_auth_policies.h"
10+
#include "ccf/cose_signatures_config_interface.h"
1011
#include "ccf/crypto/cose.h"
1112
#include "ccf/crypto/verifier.h"
1213
#include "ccf/ds/hash.h"
@@ -470,7 +471,7 @@ namespace loggingapp
470471
"recording messages at client-specified IDs. It demonstrates most of "
471472
"the features available to CCF apps.";
472473

473-
openapi_info.document_version = "2.7.0";
474+
openapi_info.document_version = "2.8.0";
474475

475476
index_per_public_key = std::make_shared<RecordsIndexingStrategy>(
476477
PUBLIC_RECORDS, context, 10000, 20);
@@ -2100,6 +2101,33 @@ namespace loggingapp
21002101
.set_auto_schema<void, void>()
21012102
.set_forwarding_required(ccf::endpoints::ForwardingRequired::Never)
21022103
.install();
2104+
2105+
auto get_cose_signatures_config =
2106+
[&](ccf::endpoints::ReadOnlyEndpointContext& ctx) {
2107+
auto subsystem =
2108+
context.get_subsystem<ccf::cose::AbstractCOSESignaturesConfig>();
2109+
if (!subsystem)
2110+
{
2111+
ctx.rpc_ctx->set_error(
2112+
HTTP_STATUS_INTERNAL_SERVER_ERROR,
2113+
ccf::errors::InternalError,
2114+
"COSE signatures subsystem not available");
2115+
return;
2116+
}
2117+
auto config = subsystem->get_cose_signatures_config();
2118+
2119+
ctx.rpc_ctx->set_response_status(HTTP_STATUS_OK);
2120+
ctx.rpc_ctx->set_response_body(nlohmann::json(config).dump());
2121+
};
2122+
2123+
make_read_only_endpoint(
2124+
"/cose_signatures_config",
2125+
HTTP_GET,
2126+
get_cose_signatures_config,
2127+
auth_policies)
2128+
.set_auto_schema<void, void>()
2129+
.set_forwarding_required(ccf::endpoints::ForwardingRequired::Never)
2130+
.install();
21032131
}
21042132
};
21052133
}

src/enclave/enclave.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "node/node_state.h"
2323
#include "node/node_types.h"
2424
#include "node/rpc/acme_subsystem.h"
25+
#include "node/rpc/cosesigconfig_subsystem.h"
2526
#include "node/rpc/custom_protocol_subsystem.h"
2627
#include "node/rpc/forwarder.h"
2728
#include "node/rpc/gov_effects.h"
@@ -172,6 +173,9 @@ namespace ccf
172173
std::make_shared<ccf::js::InterpreterCache>(max_interpreter_cache_size);
173174
context->install_subsystem(interpreter_cache);
174175

176+
context->install_subsystem(
177+
std::make_shared<ccf::AbstractCOSESignaturesConfigSubsystem>(*node));
178+
175179
LOG_TRACE_FMT("Creating RPC actors / ffi");
176180
rpc_map->register_frontend<ccf::ActorsType::members>(
177181
std::make_unique<ccf::MemberRpcFrontend>(network, *context));
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the Apache 2.0 License.
3+
#pragma once
4+
5+
#include "ccf/cose_signatures_config_interface.h"
6+
7+
namespace ccf
8+
{
9+
class AbstractCOSESignaturesConfigSubsystem
10+
: public cose::AbstractCOSESignaturesConfig
11+
{
12+
protected:
13+
AbstractNodeState& node_state;
14+
15+
public:
16+
AbstractCOSESignaturesConfigSubsystem(AbstractNodeState& node_state_) :
17+
node_state(node_state_)
18+
{}
19+
20+
virtual const ccf::COSESignaturesConfig& get_cose_signatures_config() const
21+
{
22+
return node_state.get_cose_signatures_config();
23+
}
24+
};
25+
}

tests/e2e_logging.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,23 @@ def run_app_space_js(args):
22512251
run_main_tests(network, args)
22522252

22532253

2254+
def test_cose_config(network, args):
2255+
2256+
configs = set()
2257+
2258+
for node in network.get_joined_nodes():
2259+
with node.client("user0") as c:
2260+
r = c.get("/cose_signatures_config")
2261+
assert r.status_code == http.HTTPStatus.OK.value, r.status_code
2262+
configs.add(r.body.text())
2263+
2264+
assert len(configs) == 1, configs
2265+
assert (
2266+
configs.pop() == '{"issuer":"service.example.com","subject":"ledger.signature"}'
2267+
), configs
2268+
return network
2269+
2270+
22542271
def run_main_tests(network, args):
22552272
test_basic_constraints(network, args)
22562273
test(network, args)
@@ -2295,6 +2312,7 @@ def run_main_tests(network, args):
22952312
test_genesis_receipt(network, args)
22962313
if args.package == "samples/apps/logging/liblogging":
22972314
test_etags(network, args)
2315+
test_cose_config(network, args)
22982316

22992317

23002318
def run_parsing_errors(args):

0 commit comments

Comments
 (0)