Skip to content

Commit 61aff74

Browse files
maxtropetsCopilot
andauthored
Verify pre-DR self-issued receipts (#7546)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4eec7bc commit 61aff74

File tree

16 files changed

+248
-32
lines changed

16 files changed

+248
-32
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313

1414
- Experimental self-healing-open protocol for automatically transitioning-to-open during a disaster recovery without operator intervention. (#7189)
1515

16+
### Changed
17+
18+
- Improved `ccf::historical::verify_self_issued_receipt` - now can verify receipts signed by the past service identities if they were back-endorsed (#7546).
19+
1620
## [7.0.0-dev6]
1721

1822
[7.0.0-dev6]: https://github.com/microsoft/CCF/releases/tag/ccf-7.0.0-dev6

doc/schemas/app_openapi.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,14 +1269,6 @@
12691269
"$ref": "#/components/responses/default"
12701270
}
12711271
},
1272-
"security": [
1273-
{
1274-
"jwt": []
1275-
},
1276-
{
1277-
"user_cose_sign1": []
1278-
}
1279-
],
12801272
"x-ccf-forwarding": {
12811273
"$ref": "#/components/x-ccf-forwarding/never"
12821274
}

include/ccf/crypto/base64.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include <cstdint>
6+
#include <span>
67
#include <string>
78
#include <vector>
89

@@ -14,7 +15,7 @@ namespace ccf::crypto
1415

1516
std::string b64_from_raw(const uint8_t* data, size_t size);
1617

17-
std::string b64_from_raw(const std::vector<uint8_t>& data);
18+
std::string b64_from_raw(std::span<const uint8_t> data);
1819

1920
std::string b64url_from_raw(
2021
const uint8_t* data, size_t size, bool with_padding = true);

include/ccf/crypto/cose_verifier.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace ccf::crypto
2525
COSEVerifierUniquePtr make_cose_verifier_from_cert(
2626
const std::vector<uint8_t>& cert);
2727
COSEVerifierUniquePtr make_cose_verifier_from_key(const Pem& public_key);
28+
COSEVerifierUniquePtr make_cose_verifier_from_key(
29+
std::span<const uint8_t> public_key);
2830

2931
struct COSEEndorsementValidity
3032
{

include/ccf/crypto/ec_public_key.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ namespace ccf::crypto
173173
*/
174174
ECPublicKeyPtr make_ec_public_key(const std::vector<uint8_t>& der);
175175

176+
/**
177+
* Construct ECPublicKey from a raw public key in DER format
178+
*
179+
* @param der Sequence of bytes containing the key in DER format
180+
* @return Public key
181+
*/
182+
ECPublicKeyPtr make_ec_public_key(std::span<const uint8_t> der);
183+
176184
/**
177185
* Construct ECPublicKey from a JsonWebKeyECPublic object
178186
*

include/ccf/historical_queries_utils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ namespace ccf::historical
4242
std::shared_ptr<NetworkIdentitySubsystemInterface>
4343
network_identity_subsystem);
4444

45-
// Verifies CCF COSE receipt using the *current network* identity's
46-
// certificate.
45+
// Verifies CCF COSE receipt issued by either current service identity or the
46+
// one from the past that both corresponds to the receipt Tx ID and can be
47+
// trusted via back-endorsement chain.
4748
void verify_self_issued_receipt(
4849
const std::vector<uint8_t>& cose_receipt,
4950
std::shared_ptr<NetworkIdentitySubsystemInterface>

include/ccf/network_identity_interface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache 2.0 License.
33
#pragma once
44

5+
#include "ccf/crypto/ec_public_key.h"
56
#include "ccf/node_subsystem_interface.h"
67

78
#include <optional>
@@ -38,5 +39,8 @@ namespace ccf
3839

3940
[[nodiscard]] virtual std::optional<CoseEndorsementsChain>
4041
get_cose_endorsements_chain(ccf::SeqNo seqno) const = 0;
42+
43+
[[nodiscard]] virtual ccf::crypto::ECPublicKeyPtr get_trusted_identity_for(
44+
ccf::SeqNo seqno) const = 0;
4145
};
4246
}

samples/apps/logging/logging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,7 @@ namespace loggingapp
21242124
HTTP_GET,
21252125
ccf::historical::read_only_adapter_v4(
21262126
get_cose_receipt, context, is_tx_committed),
2127-
auth_policies)
2127+
ccf::no_auth_required)
21282128
.set_auto_schema<void, void>()
21292129
.set_forwarding_required(ccf::endpoints::ForwardingRequired::Never)
21302130
.install();

src/crypto/base64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace ccf::crypto
4343
return Base64Impl::b64_from_raw(data, size);
4444
}
4545

46-
std::string b64_from_raw(const std::vector<uint8_t>& data)
46+
std::string b64_from_raw(std::span<const uint8_t> data)
4747
{
4848
return b64_from_raw(data.data(), data.size());
4949
}

src/crypto/openssl/cose_verifier.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ namespace ccf::crypto
162162
public_key = std::make_shared<PublicKey_OpenSSL>(public_key_);
163163
}
164164

165+
COSEKeyVerifier_OpenSSL::COSEKeyVerifier_OpenSSL(
166+
std::span<const uint8_t> public_key_der_)
167+
{
168+
public_key = std::make_shared<PublicKey_OpenSSL>(public_key_der_);
169+
}
170+
165171
COSEVerifier_OpenSSL::~COSEVerifier_OpenSSL() = default;
166172

167173
bool COSEVerifier_OpenSSL::verify(
@@ -235,6 +241,12 @@ namespace ccf::crypto
235241
return std::make_unique<COSEKeyVerifier_OpenSSL>(public_key);
236242
}
237243

244+
COSEVerifierUniquePtr make_cose_verifier_from_key(
245+
std::span<const uint8_t> public_key)
246+
{
247+
return std::make_unique<COSEKeyVerifier_OpenSSL>(public_key);
248+
}
249+
238250
COSEEndorsementValidity extract_cose_endorsement_validity(
239251
std::span<const uint8_t> cose_msg)
240252
{

0 commit comments

Comments
 (0)