From 38d9cb496de556f9adb2c0f463960f30cdfc6ee9 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 20 Apr 2020 15:06:29 +0200 Subject: [PATCH 1/6] feat: upgrade cose-c --- .gitmodules | 2 +- third_party/COSE-C/repo | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 353ca2f92..e126c676f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,7 +16,7 @@ branch = master [submodule "third_party/COSE-C/repo"] path = third_party/COSE-C/repo - url = https://github.com/wgtdkp/COSE-C.git + url = https://github.com/cose-wg/COSE-C.git branch = master [submodule "third_party/cn-cbor/repo"] path = third_party/cn-cbor/repo diff --git a/third_party/COSE-C/repo b/third_party/COSE-C/repo index 059e8f4db..f207f3f10 160000 --- a/third_party/COSE-C/repo +++ b/third_party/COSE-C/repo @@ -1 +1 @@ -Subproject commit 059e8f4dbe9827ed89f6731e95052a5a1b79ed94 +Subproject commit f207f3f10e237be740eb41de156a297ced503a8a From 083eb9b908a7b4ad9617d8fb99cec509046ff038 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 20 Apr 2020 16:19:09 +0200 Subject: [PATCH 2/6] chore: use find package for cose-c --- src/library/CMakeLists.txt | 4 +- tests/unit/CMakeLists.txt | 2 +- third_party/CMakeLists.txt | 11 ++++- third_party/COSE-C/CMakeLists.txt | 72 ------------------------------- 4 files changed, 12 insertions(+), 77 deletions(-) delete mode 100644 third_party/COSE-C/CMakeLists.txt diff --git a/src/library/CMakeLists.txt b/src/library/CMakeLists.txt index 6a468cd97..69f469c32 100644 --- a/src/library/CMakeLists.txt +++ b/src/library/CMakeLists.txt @@ -80,7 +80,7 @@ target_sources(commissioner target_link_libraries(commissioner PRIVATE cn-cbor::cn-cbor - cose + cose-c::cose-c mdns mbedtls mbedx509 @@ -112,7 +112,7 @@ install(TARGETS commissioner if (BUILD_SHARED_LIBS) install(FILES $ - $ + $ $ $ $ diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index dbe82a788..44b39198c 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -47,7 +47,7 @@ target_sources(commissioner-tests target_link_libraries(commissioner-tests PRIVATE cn-cbor::cn-cbor - cose + cose-c::cose-c mdns mbedtls mbedx509 diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 445cbe56d..6caf75a08 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -28,9 +28,16 @@ add_subdirectory(Catch2/repo) -set(coveralls OFF CACHE BOOL "Disbale generating coveralls data") +set(coveralls + OFF + CACHE BOOL "Disbale generating coveralls data") add_subdirectory(cn-cbor/repo) -add_subdirectory(COSE-C) + +set(COSE_C_USE_FIND_PACKAGE + ON + CACHE BOOL "do not download packages" FORCE) + +add_subdirectory(COSE-C/repo) add_subdirectory(fmtlib/repo) add_subdirectory(json/repo) diff --git a/third_party/COSE-C/CMakeLists.txt b/third_party/COSE-C/CMakeLists.txt deleted file mode 100644 index ba200f76f..000000000 --- a/third_party/COSE-C/CMakeLists.txt +++ /dev/null @@ -1,72 +0,0 @@ -# -# Copyright (c) 2019, The OpenThread Authors. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -add_library(cose) - -target_sources(cose - PRIVATE - repo/src/bcrypt.c - repo/src/cbor.c - repo/src/cose_int.h - repo/src/Cose.c - repo/src/crypto.h - repo/src/Encrypt.c - repo/src/Encrypt0.c - repo/src/key.c - repo/src/MacMessage.c - repo/src/MacMessage0.c - repo/src/mbedtls.c - repo/src/openssl.c - repo/src/Recipient.c - repo/src/Sign.c - repo/src/Sign0.c - repo/src/SignerInfo.c -) - -target_compile_definitions(cose - PUBLIC USE_MBED_TLS -) - -target_compile_options(cose - PRIVATE - -std=gnu99 - -Wall - -Wextra - -Wfatal-errors - -pedantic -) - -target_link_libraries(cose - PUBLIC - cn-cbor - mbedtls -) - -target_include_directories(cose - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/repo/include -) From 4b68fed397076d38d4b873762bf19066040fc785 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 20 Apr 2020 18:27:46 +0200 Subject: [PATCH 3/6] chore: make it compile with latest version --- third_party/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 6caf75a08..1e3ec1a94 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -28,15 +28,23 @@ add_subdirectory(Catch2/repo) +set(BUILD_SHARED_LIBS + OFF + CACHE BOOL "Disbale generating coveralls data") set(coveralls OFF CACHE BOOL "Disbale generating coveralls data") add_subdirectory(cn-cbor/repo) +set(COSE_C_COVERALLS + OFF + CACHE BOOL "do not link gcov" FORCE) set(COSE_C_USE_FIND_PACKAGE ON CACHE BOOL "do not download packages" FORCE) - +set(COSE_C_USE_MBEDTLS + ON + CACHE BOOL "use mbedtls" FORCE) add_subdirectory(COSE-C/repo) add_subdirectory(fmtlib/repo) add_subdirectory(json/repo) From 99e421c4614eaf27056a7809c2b6b522abe300b4 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 20 Apr 2020 18:27:58 +0200 Subject: [PATCH 4/6] chore: make it compile with latest version --- build.sh | 4 ++++ src/library/cose.cpp | 10 +++++----- src/library/cose.hpp | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 000000000..bf9d419a8 --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +#!/bin/sh +rm -rf build +mkdir build +cd build && cmake .. && make $* diff --git a/src/library/cose.cpp b/src/library/cose.cpp index 61383e4da..dde08ed60 100644 --- a/src/library/cose.cpp +++ b/src/library/cose.cpp @@ -81,11 +81,11 @@ Error Sign1Message::Deserialize(Sign1Message &aCose, const ByteArray &aBuf) { Error error = Error::kNone; int type; - HCOSE_SIGN0 sign; + HCOSE_SIGN1 sign; VerifyOrExit(!aBuf.empty(), error = Error::kInvalidArgs); - sign = reinterpret_cast(COSE_Decode(&aBuf[0], aBuf.size(), &type, COSE_sign0_object, nullptr)); - VerifyOrExit(sign != nullptr && type == COSE_sign0_object, error = Error::kBadFormat); + sign = reinterpret_cast(COSE_Decode(&aBuf[0], aBuf.size(), &type, COSE_sign1_object, nullptr)); + VerifyOrExit(sign != nullptr && type == COSE_sign1_object, error = Error::kBadFormat); aCose.mSign = sign; @@ -114,7 +114,7 @@ Error Sign1Message::Validate(const mbedtls_pk_context &aPubKey) VerifyOrExit(mbedtls_pk_can_do(&aPubKey, MBEDTLS_PK_ECDSA), error = Error::kInvalidArgs); VerifyOrExit((eckey = mbedtls_pk_ec(aPubKey)) != nullptr, error = Error::kInvalidArgs); - VerifyOrExit(COSE_Sign0_validate_eckey(mSign, eckey, nullptr), error = Error::kSecurity); + // VerifyOrExit(COSE_Sign1_validate_eckey(mSign, eckey, nullptr), error = Error::kSecurity); exit: return error; @@ -128,7 +128,7 @@ Error Sign1Message::Sign(const mbedtls_pk_context &aPrivateKey) VerifyOrExit(mbedtls_pk_can_do(&aPrivateKey, MBEDTLS_PK_ECDSA), error = Error::kInvalidArgs); VerifyOrExit((eckey = mbedtls_pk_ec(aPrivateKey)) != nullptr, error = Error::kInvalidArgs); - VerifyOrExit(COSE_Sign0_Sign_eckey(mSign, eckey, nullptr), error = Error::kSecurity); + // VerifyOrExit(COSE_Sign1_Sign_eckey(mSign, eckey, nullptr), error = Error::kSecurity); exit: return error; diff --git a/src/library/cose.hpp b/src/library/cose.hpp index 47b2be1af..9a142f564 100644 --- a/src/library/cose.hpp +++ b/src/library/cose.hpp @@ -41,7 +41,7 @@ #include #include "cbor.hpp" -#include +#include #include #include @@ -108,7 +108,7 @@ class Sign1Message : public Object private: Error AddAttribute(int key, cn_cbor *value, int flags); - HCOSE_SIGN0 mSign; + HCOSE_SIGN1 mSign; }; Error MakeCoseKey(ByteArray &aEncodedCoseKey, const mbedtls_pk_context &aKey, const ByteArray &aKeyId); From fbb8c42511fed1bfc06dbc458b7c9bab65441980 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 22 Apr 2020 10:33:05 +0200 Subject: [PATCH 5/6] chore: make it compile --- src/library/cose.cpp | 8 ++++---- third_party/CMakeLists.txt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/library/cose.cpp b/src/library/cose.cpp index dde08ed60..accfe585a 100644 --- a/src/library/cose.cpp +++ b/src/library/cose.cpp @@ -107,14 +107,14 @@ Error Sign1Message::Validate(const CborMap &aCborPublicKey) Error Sign1Message::Validate(const mbedtls_pk_context &aPubKey) { - Error error = Error::kNone; - const struct mbedtls_ecp_keypair *eckey; + Error error = Error::kNone; + const mbedtls_ecp_keypair *eckey; // Accepts only EC keys VerifyOrExit(mbedtls_pk_can_do(&aPubKey, MBEDTLS_PK_ECDSA), error = Error::kInvalidArgs); VerifyOrExit((eckey = mbedtls_pk_ec(aPubKey)) != nullptr, error = Error::kInvalidArgs); - // VerifyOrExit(COSE_Sign1_validate_eckey(mSign, eckey, nullptr), error = Error::kSecurity); + VerifyOrExit(COSE_Sign1_validate_eckey(mSign, eckey, nullptr), error = Error::kSecurity); exit: return error; @@ -128,7 +128,7 @@ Error Sign1Message::Sign(const mbedtls_pk_context &aPrivateKey) VerifyOrExit(mbedtls_pk_can_do(&aPrivateKey, MBEDTLS_PK_ECDSA), error = Error::kInvalidArgs); VerifyOrExit((eckey = mbedtls_pk_ec(aPrivateKey)) != nullptr, error = Error::kInvalidArgs); - // VerifyOrExit(COSE_Sign1_Sign_eckey(mSign, eckey, nullptr), error = Error::kSecurity); + VerifyOrExit(COSE_Sign1_Sign_eckey(mSign, eckey, nullptr), error = Error::kSecurity); exit: return error; diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 1e3ec1a94..113559f04 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -27,6 +27,7 @@ # add_subdirectory(Catch2/repo) +add_subdirectory(mbedtls) set(BUILD_SHARED_LIBS OFF @@ -51,5 +52,4 @@ add_subdirectory(json/repo) add_subdirectory(libevent) -add_subdirectory(mbedtls) add_subdirectory(mdns/repo) From 4c4a479ffba98a22fa3b84be76cb9227d3f4b0d7 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Fri, 24 Apr 2020 15:35:05 +0200 Subject: [PATCH 6/6] chore: use carlos fork to test compilation --- .gitmodules | 3 +-- third_party/COSE-C/repo | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index e126c676f..7538561b3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,8 +16,7 @@ branch = master [submodule "third_party/COSE-C/repo"] path = third_party/COSE-C/repo - url = https://github.com/cose-wg/COSE-C.git - branch = master + url = https://github.com/gocarlos/COSE-C.git [submodule "third_party/cn-cbor/repo"] path = third_party/cn-cbor/repo url = https://github.com/jimsch/cn-cbor.git diff --git a/third_party/COSE-C/repo b/third_party/COSE-C/repo index f207f3f10..a590f555b 160000 --- a/third_party/COSE-C/repo +++ b/third_party/COSE-C/repo @@ -1 +1 @@ -Subproject commit f207f3f10e237be740eb41de156a297ced503a8a +Subproject commit a590f555b6c6bcd1882788162f0bd925ef0b0aea