Add build dependency on the Embed TLS crypto package
We want to build a version that is based on the Embed TLS crypto
package. This is the first step.
diff --git a/.gitignore b/.gitignore
index 89b9e01..94ef967 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,9 +55,12 @@
*.vcxproj
*.vcxproj.filters
*.opensdf
+*.VC.db
+*.VC.opendb
# CMake and CTest directories
project_cn-cbor-prefix
+project_embedtls-prefix
Testing
dist
test/test.cbor
diff --git a/.travis.yml b/.travis.yml
index dc9ecf0..d509d95 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,10 +9,13 @@
env:
- USE_CONTEXT=ON
- USE_CONTEXT=OFF
+ - USE_CONTEXT=OFF USE_EMBED_TLS=ON
matrix:
exclude:
- compiler: gcc
env: USE_CONTEXT=OFF
+ - compiler: gcc
+ env: USE_CONTEXT=OFF USE_EMBED_TLS=ON
addons:
apt:
sources:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 863bc27..96fabba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,6 +25,7 @@
option ( coveralls_send "Send data to coveralls site" OFF )
option (build_docs "Create docs using Doxygen" ${DOXYGEN_FOUND} )
option (build_shared_libs "Build Shared Libraries" ON)
+option (use_embedtls "Use MBedTLS for the Crypto Package" OFF)
set ( dist_dir ${CMAKE_BINARY_DIR}/dist )
set ( prefix ${CMAKE_INSTALL_PREFIX} )
@@ -117,6 +118,23 @@
set_property (TARGET cn-cbor PROPERTY IMPORTED_LOCATION "${install_dir}/lib/${CMAKE_SHARED_MODULE_PREFIX}cn-cbor${CMAKE_SHARED_LIBRARY_SUFFIX}")
add_dependencies(cn-cbor project_cn-cbor)
+if (use_embedtls)
+ add_definitions( -DUSE_MBED_TLS )
+ ExternalProject_Add(
+ project_embedtls
+ GIT_REPOSITORY https://github.com/ARMmbed/mbedtls
+ CMAKE_ARGS -DENABLED_PROGRAMS=OFF -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -Dcoveralls=OFF -Dbuild_shared_libs=${build_shared_libs} -Dfatal_warnings=OFF -DENABLE_TESTING=OFF
+ INTALL_DIR "${dist_dir}"
+ UPDATE_DISCONNECTED 1
+ )
+
+ ExternalProject_Get_Property(project_embedtls install_dir)
+ include_directories( "${install_dir}/include" )
+ add_library( embedtls STATIC IMPORTED)
+ set_property (TARGET embedtls PROPERTY IMPORTED_LOCATION "${install_dir}/lib/${CMAKE_SHARED_MODULE_PREFIX}embedtls${CMAKE_SHARED_LIBRARY_SUFFIX}")
+ add_dependencies(embedtls project_embedtls)
+endif ()
+
## include the parts
add_subdirectory(src)
diff --git a/src/Cose.c b/src/Cose.c
index 2de060e..dd2bb1a 100644
--- a/src/Cose.c
+++ b/src/Cose.c
@@ -406,14 +406,14 @@
HCOSE_COUNTERSIGN _COSE_CounterSign_get(COSE * pMessage, int iSigner, cose_errback * perr)
{
- COSE_SignerInfo * pSigner = pMessage->m_counterSigners;
+ COSE_CounterSign * pSigner = pMessage->m_counterSigners;
int i;
- for (i = 0; i < iSigner; i++, pSigner = pSigner->m_signerNext) {
+ for (i = 0; i < iSigner; i++, pSigner = pSigner->m_next) {
CHECK_CONDITION(pSigner != NULL, COSE_ERR_INVALID_PARAMETER);
}
- return pSigner;
+ return (HCOSE_COUNTERSIGN) pSigner;
errorReturn:
return false;
@@ -425,8 +425,8 @@
cn_cbor_errback cbor_err;
COSE_CounterSign * pSigner = NULL;
cn_cbor * pcnProtected = NULL;
- cn_cbor * pcn;
- cn_cbor * pcn2;
+ cn_cbor * pcn = NULL;
+ cn_cbor * pcn2 = NULL;
if (pMessage->m_counterSigners == NULL) return true;
@@ -439,14 +439,16 @@
pcnProtected = _COSE_arrayget_int(pMessage, INDEX_PROTECTED);
CHECK_CONDITION(pcnProtected != NULL, COSE_ERR_INTERNAL);
- for (pSigner = pMessage->m_counterSigners; pSigner != NULL; pSigner = pSigner->m_signer.m_signerNext) {
+ for (pSigner = pMessage->m_counterSigners; pSigner != NULL; pSigner = pSigner->m_next) {
+ CHECK_CONDITION(pSigner->m_signer.m_signerNext == NULL, COSE_ERR_INTERNAL);
+
pcn = cn_cbor_data_create(pcnProtected->v.bytes, pcnProtected->v.count, CBOR_CONTEXT_PARAM_COMMA &cbor_err);
CHECK_CONDITION_CBOR(pcnProtected != NULL, cbor_err);
pcn2 = cn_cbor_clone(pcnBody, CBOR_CONTEXT_PARAM_COMMA &cbor_err);
CHECK_CONDITION_CBOR(pcnBody != NULL, cbor_err);
- if (!_COSE_Signer_sign(pSigner, pcnBody, pcn2, perr)) goto errorReturn;
+ if (!_COSE_Signer_sign(&pSigner->m_signer, pcnBody, pcn2, perr)) goto errorReturn;
pcn = NULL;
pcn2 = NULL;
diff --git a/src/configure.h b/src/configure.h
index 183ca31..2ca1024 100644
--- a/src/configure.h
+++ b/src/configure.h
@@ -89,7 +89,16 @@
#define USE_ECDSA_SHA_512
-#define USE_OPEN_SSL 1
-#define USE_BCRYPT 0
+#if defined(USE_MBED_TLS)
+#if defined(USE_OPEN_SSL) || defined(USE_BCRYPT)
+#error Only Define One Crypto Package
+#endif
+#elif defined(USE_BCRYPT)
+#if defined(USE_OPENSSL)
+#error Only Define One Crypto Package
+#endif
+#elif !defined(USE_OPEN_SSL)
+#define USE_OPEN_SSL
+#endif
-//#define USE_COUNTER_SIGNATURES
+#define USE_COUNTER_SIGNATURES
diff --git a/src/cose_int.h b/src/cose_int.h
index 72a2bd5..b4033a5 100644
--- a/src/cose_int.h
+++ b/src/cose_int.h
@@ -5,7 +5,7 @@
#ifdef USE_COUNTER_SIGNATURES
struct _COSE_COUNTER_SIGN;
-typedef struct _COSE_COUNTER_SIGN COSE_Counter_Sign;
+typedef struct _COSE_COUNTER_SIGN COSE_CounterSign;
#endif
typedef struct _COSE {
@@ -26,7 +26,7 @@
#endif
struct _COSE * m_handleList;
#ifdef USE_COUNTER_SIGNATURES
- COSE_Counter_Sign * m_counterSigners;
+ COSE_CounterSign * m_counterSigners;
#endif
} COSE;
@@ -90,6 +90,7 @@
#ifdef USE_COUNTER_SIGNATURES
typedef struct _COSE_COUNTER_SIGN {
COSE_SignerInfo m_signer;
+ COSE_CounterSign * m_next;
} COSE_CounterSign;
#endif
diff --git a/test/encrypt.c b/test/encrypt.c
index 541fdec..24141d5 100644
--- a/test/encrypt.c
+++ b/test/encrypt.c
@@ -213,6 +213,15 @@
if (!SetSendingAttributes((HCOSE)hEncObj, pEnveloped, Attributes_Enveloped_protected)) goto returnError;
+#if 0
+ const cn_cbor * pCounterSign = cn_cbor_mapget_string(pEnveloped, "countersign");
+ if (pCounterSign != NULL) {
+ HCOSE_COUNTERSIGN hCSign = BuildCounterSign(pCounterSign);
+ if (hCSign == NULL) goto returnError;
+ if (!COSE_Enveloped_AddCounterSigner(hEncObj, hCSign, NULL)) goto returnError;
+ }
+#endif
+
const cn_cbor * pAlg = COSE_Enveloped_map_get_int(hEncObj, 1, COSE_BOTH, NULL);
if (pAlg == NULL) goto returnError;
diff --git a/test/mac_test.c b/test/mac_test.c
index 455a395..eb288af 100644
--- a/test/mac_test.c
+++ b/test/mac_test.c
@@ -130,8 +130,6 @@
if (!SetSendingAttributes((HCOSE)hMacObj, pMac, Attributes_MAC_protected)) goto returnError;
- const cn_cbor * pAlg = COSE_Mac_map_get_int(hMacObj, 1, COSE_BOTH, NULL);
-
const cn_cbor * pRecipients = cn_cbor_mapget_string(pMac, "recipients");
if ((pRecipients == NULL) || (pRecipients->type != CN_CBOR_ARRAY)) goto returnError;
@@ -347,8 +345,6 @@
if (!SetSendingAttributes((HCOSE)hMacObj, pMac, Attributes_MAC0_protected)) goto returnError;
- const cn_cbor * pAlg = COSE_Mac0_map_get_int(hMacObj, 1, COSE_BOTH, NULL);
-
const cn_cbor * pRecipients = cn_cbor_mapget_string(pMac, "recipients");
if ((pRecipients == NULL) || (pRecipients->type != CN_CBOR_ARRAY)) goto returnError;
diff --git a/test/sign.c b/test/sign.c
index 6bb1e6b..1ed188d 100644
--- a/test/sign.c
+++ b/test/sign.c
@@ -124,8 +124,6 @@
if (!SetSendingAttributes((HCOSE)hSignObj, pSign, Attributes_Sign_protected)) goto returnError;
- const cn_cbor * pAlg = COSE_Sign_map_get_int(hSignObj, 1, COSE_BOTH, NULL);
-
const cn_cbor * pSigners = cn_cbor_mapget_string(pSign, "signers");
if ((pSigners == NULL) || (pSigners->type != CN_CBOR_ARRAY)) goto returnError;
@@ -326,8 +324,6 @@
if (!SetSendingAttributes((HCOSE)hSignObj, pSign, Attributes_Sign0_protected)) goto returnError;
- const cn_cbor * pAlg = COSE_Sign0_map_get_int(hSignObj, 1, COSE_BOTH, NULL);
-
cn_cbor * pkey = BuildKey(cn_cbor_mapget_string(pSign, "key"), false);
if (pkey == NULL) goto returnError;