Skip to content

Commit

Permalink
fixup! Serialize selected certificates to PEM string
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Jan 9, 2024
1 parent 8140ce5 commit 42740e7
Show file tree
Hide file tree
Showing 12 changed files with 475 additions and 369 deletions.
24 changes: 3 additions & 21 deletions port/esp32/adapter/include/debug_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
extern "C" {
#endif

#define APP_PRINT(...) printf(__VA_ARGS__)

/**
* @brief print current all macro information
*
Expand All @@ -40,22 +38,6 @@ void print_macro_info();
*/
void print_message_info(const oc_message_t *message);

/**
* @brief print the data detail information
*
* print input data, print from data[0] to data[len-1], addtionally add notes
* string
*
* @param[in] data: input data pointer to print
* @param[in] len: data length
* @param[in] note: notes for read easily
* @param[in] mode: 0x00, 0x01, 0x10, 0x11 to decide the BINARY_SHOW &&
* BYTES_SHOW
*
*/
void print_debug(const char *data, const unsigned int len, const char *note,
int mode);

/**
* @brief print the fatal error information and cycle it
*
Expand All @@ -73,9 +55,9 @@ void print_debug(const char *data, const unsigned int len, const char *note,

#define APP_LOG(level, ...) \
do { \
APP_PRINT("%s: %s <%s:%d>: ", level, __FILE__, __FUNCTION__, __LINE__); \
APP_PRINT(__VA_ARGS__); \
APP_PRINT("\n"); \
printf("%s: %s <%s:%d>: ", level, __FILE__, __FUNCTION__, __LINE__); \
printf(__VA_ARGS__); \
printf("\n"); \
} while (0)
#define APP_DBG(...) APP_LOG("DEBUG", __VA_ARGS__)
#define APP_WRN(...) APP_LOG("WARNING", __VA_ARGS__)
Expand Down
107 changes: 0 additions & 107 deletions port/esp32/adapter/include/oc_certificates.h

This file was deleted.

45 changes: 0 additions & 45 deletions port/esp32/adapter/src/debug_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,48 +127,3 @@ print_message_info(const oc_message_t *message)
printf("\n****************************************\n");
#endif
}

/**
* @brief print the data detail information
*
* print input data, print from data[0] to data[len-1], addtionally add notes
* string
*
* @param[in] data: input data pointer to print
* @param[in] len: data length
* @param[in] note: notes for read easily
* @param[in] mode: 0x00, 0x01, 0x10, 0x11 to decide the BINARY_SHOW &&
* BYTES_SHOW
*
* @return noreturn
*
*/
void
print_debug(const char *data, const unsigned int len, const char *note,
int mode)
{
#define BINARY_SHOW 0x10
#define BYTES_SHOW 0x01
printf("\n********** %s [len:%u] start addr:%p **********\n", note, len,
data);
int i = 0;
for (i = 0; i < len; ++i) {
if (BINARY_SHOW & mode) {
printf("%02x ", data[i]);
} else {
if (data[i] < 32 || data[i] > 126) { // control || invisible charset
if (i > 0 && (data[i - 1] >= 33 && data[i - 1] <= 126))
printf(" ");
printf("%02x ", data[i]);
} else {
printf("%c", data[i]);
}
}

if ((BYTES_SHOW & mode) && ((i + 1) % 32 == 0)) {
printf(" | %d Bytes\n", i + 1);
}
} // end for

printf("\n---------- %s End ----------\n", note);
}
2 changes: 0 additions & 2 deletions port/esp32/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

#ifdef OC_HAS_FEATURE_PLGD_HAWKBIT
#include "hawkbit.h"
#else /* !OC_HAS_FEATURE_PLGD_HAWKBIT */
#include "oc_certificates.h"
#endif /* OC_HAS_FEATURE_PLGD_HAWKBIT */

#include "driver/gpio.h"
Expand Down
6 changes: 6 additions & 0 deletions security/oc_certs.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ oc_certs_parse_serial_number(const unsigned char *cert, size_t cert_size,
int ret = mbedtls_x509_crt_parse(&crt, cert, cert_size);
if (ret != 0) {
OC_ERR("could not parse the provided cert %d", ret);
mbedtls_x509_crt_free(&crt);
return ret;
}

Expand Down Expand Up @@ -197,6 +198,7 @@ oc_certs_parse_private_key(size_t device, const unsigned char *cert,
int ret = mbedtls_x509_crt_parse(&crt, cert, cert_size);
if (ret != 0) {
OC_ERR("could not parse the provided cert %d", ret);
mbedtls_x509_crt_free(&crt);
return ret;
}

Expand Down Expand Up @@ -255,6 +257,7 @@ oc_certs_parse_public_key(const unsigned char *cert, size_t cert_size,
int ret = mbedtls_x509_crt_parse(&crt, cert, cert_size);
if (ret != 0) {
OC_ERR("could not parse the provided cert %d", ret);
mbedtls_x509_crt_free(&crt);
return -1;
}

Expand All @@ -273,6 +276,7 @@ oc_certs_parse_public_key_to_oc_string(const unsigned char *cert,
int ret = mbedtls_x509_crt_parse(&crt, cert, cert_size);
if (ret != 0) {
OC_ERR("could not parse the provided cert %d", ret);
mbedtls_x509_crt_free(&crt);
return -1;
}

Expand Down Expand Up @@ -372,6 +376,7 @@ oc_certs_parse_CN_for_UUID(const unsigned char *cert, size_t cert_size,
int ret = mbedtls_x509_crt_parse(&crt, cert, cert_size);
if (ret != 0) {
OC_ERR("could not parse the provided cert %d", ret);
mbedtls_x509_crt_free(&crt);
return false;
}

Expand Down Expand Up @@ -544,6 +549,7 @@ oc_certs_parse_first_role(const unsigned char *cert, size_t cert_size,
int ret = mbedtls_x509_crt_parse(&crt, cert, cert_size);
if (ret != 0) {
OC_ERR("could not parse the provided cert %d", ret);
mbedtls_x509_crt_free(&crt);
return false;
}

Expand Down
1 change: 1 addition & 0 deletions security/oc_cred.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@ oc_cred_parse_certificate(const oc_sec_cred_t *cred, mbedtls_x509_crt *crt)
int ret = mbedtls_x509_crt_parse(crt, cert, cert_size);
if (ret < 0) {
OC_ERR("failed to parse certificate: %d", ret);
mbedtls_x509_crt_free(crt);
return false;
}
return true;
Expand Down
Loading

0 comments on commit 42740e7

Please sign in to comment.