Skip to content

Commit 8ed71eb

Browse files
committed
WIP
1 parent e0872fe commit 8ed71eb

File tree

10 files changed

+470
-78
lines changed

10 files changed

+470
-78
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ set(HTTP_PARSER_SOURCES
173173
${CCF_3RD_PARTY_EXPORTED_DIR}/llhttp/llhttp.c
174174
)
175175

176+
include(${CCF_DIR}/cmake/cose_openssl.cmake)
176177
include(${CCF_DIR}/cmake/crypto.cmake)
177178
include(${CCF_DIR}/cmake/quickjs.cmake)
178179
include(${CCF_DIR}/cmake/qcbor.cmake)

cmake/cose_openssl.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the Apache 2.0 License.
3+
4+
include(FetchContent)
5+
6+
FetchContent_Declare(
7+
Corrosion
8+
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
9+
GIT_TAG a1a1aaa057a5da656c06c3d8505b767a4e941709 # v0.5.2
10+
)
11+
FetchContent_MakeAvailable(Corrosion)
12+
13+
corrosion_import_crate(
14+
MANIFEST_PATH
15+
"${CCF_DIR}/src/cose/ccf_cose/Cargo.toml"
16+
PROFILE
17+
"release"
18+
CRATES
19+
"ccf-cose"
20+
CRATE_TYPES
21+
"staticlib"
22+
)

cmake/crypto.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ target_compile_options(ccfcrypto PUBLIC ${COMPILE_LIBCXX})
4040
target_link_options(ccfcrypto PUBLIC ${LINK_LIBCXX})
4141

4242
target_link_libraries(ccfcrypto PUBLIC crypto ssl evercbor)
43-
target_link_libraries(ccfcrypto PRIVATE t_cose)
43+
target_link_libraries(
44+
ccfcrypto PRIVATE t_cose ${CMAKE_BINARY_DIR}/libccf_cose.a
45+
)
46+
add_dependencies(ccfcrypto cargo-build_ccf_cose)
47+
target_include_directories(
48+
ccfcrypto PUBLIC $<BUILD_INTERFACE:${CCF_DIR}/src/cose>
49+
)
4450
set_property(TARGET ccfcrypto PROPERTY POSITION_INDEPENDENT_CODE ON)
4551

4652
install(

scripts/setup-ci.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ tdnf --snapshottime=$SOURCE_DATE_EPOCH -y install procps
4848
tdnf --snapshottime=$SOURCE_DATE_EPOCH install -y bind-utils
4949
curl -L --output h2spec_linux_amd64.tar.gz https://github.com/summerwind/h2spec/releases/download/$H2SPEC_VERSION/h2spec_linux_amd64.tar.gz
5050
tar -xvf h2spec_linux_amd64.tar.gz
51-
mkdir /opt/h2spec
51+
mkdir -p /opt/h2spec
5252
mv h2spec /opt/h2spec/h2spec
5353
rm h2spec_linux_amd64.tar.gz
5454

@@ -58,3 +58,6 @@ tdnf --snapshottime=$SOURCE_DATE_EPOCH -y install strace
5858

5959
# For packaging
6060
tdnf --snapshottime=$SOURCE_DATE_EPOCH -y install rpm-build
61+
62+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --component rustfmt
63+
export PATH="$HOME/.cargo/bin:$PATH"

src/cose/ccf_cose.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the Apache 2.0 License.
3+
4+
#pragma once
5+
6+
#include <cstddef>
7+
#include <cstdint>
8+
9+
#ifdef __cplusplus
10+
extern "C"
11+
{
12+
#endif
13+
14+
/// Sign a CCF ledger signature (COSE_Sign1, detached payload).
15+
/// Returns 0 on success, non-zero on failure.
16+
int ccf_cose_sign_ledger(
17+
const uint8_t* key_der_ptr,
18+
size_t key_der_len,
19+
const uint8_t* kid_ptr,
20+
size_t kid_len,
21+
int64_t iat,
22+
const uint8_t* issuer_ptr,
23+
size_t issuer_len,
24+
const uint8_t* subject_ptr,
25+
size_t subject_len,
26+
const uint8_t* txid_ptr,
27+
size_t txid_len,
28+
const uint8_t* payload_ptr,
29+
size_t payload_len,
30+
uint8_t** out_ptr,
31+
size_t* out_len);
32+
33+
/// Sign a CCF identity endorsement (COSE_Sign1, embedded payload).
34+
/// epoch_end and prev_root may be NULL/0 if not applicable.
35+
/// Returns 0 on success, non-zero on failure.
36+
int ccf_cose_sign_endorsement(
37+
const uint8_t* key_der_ptr,
38+
size_t key_der_len,
39+
int64_t iat,
40+
const uint8_t* epoch_begin_ptr,
41+
size_t epoch_begin_len,
42+
const uint8_t* epoch_end_ptr,
43+
size_t epoch_end_len,
44+
const uint8_t* prev_root_ptr,
45+
size_t prev_root_len,
46+
const uint8_t* payload_ptr,
47+
size_t payload_len,
48+
uint8_t** out_ptr,
49+
size_t* out_len);
50+
51+
/// Free a buffer returned by ccf_cose_sign_*.
52+
void ccf_cose_free(uint8_t* ptr, size_t len);
53+
54+
#ifdef __cplusplus
55+
}
56+
#endif

src/cose/ccf_cose/Cargo.lock

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cose/ccf_cose/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "ccf-cose"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["staticlib"]
8+
9+
[dependencies]
10+
cose-openssl = { git = "https://github.com/maxtropets/cose-openssl.git", branch = "f/cose-wrapped" }
11+
12+
[profile.release]
13+
lto = true

0 commit comments

Comments
 (0)