From 3f322aa6f52e5d7ba3a6c85b205518eb7d62dabc Mon Sep 17 00:00:00 2001 From: Mateusz Dahlke <39696234+Xavrax@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:44:50 +0100 Subject: [PATCH] Handle unencrypted message while getting messages with crypto (#170) --- .pubnub.yml | 21 +++++++++++++-------- CHANGELOG.md | 6 ++++++ core/pubnub_ccore_pubsub.c | 12 ++++++------ core/pubnub_version_internal.h | 2 +- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index c987cc00..0893684a 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,8 +1,13 @@ name: c-core schema: 1 -version: "4.7.0" +version: "4.7.1" scm: github.com/pubnub/c-core changelog: + - date: 2023-11-23 + version: v4.7.1 + changes: + - type: bug + text: "Handle unencrypted message while getting messages with crypto." - date: 2023-11-20 version: v4.7.0 changes: @@ -763,7 +768,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.7.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.7.1 requires: - name: "miniz" @@ -829,7 +834,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.7.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.7.1 requires: - name: "miniz" @@ -895,7 +900,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.7.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.7.1 requires: - name: "miniz" @@ -957,7 +962,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.7.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.7.1 requires: - name: "miniz" @@ -1018,7 +1023,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.7.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.7.1 requires: - name: "miniz" @@ -1074,7 +1079,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.7.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.7.1 requires: - name: "miniz" @@ -1127,7 +1132,7 @@ sdks: distribution-type: source code distribution-repository: GitHub release package-name: C-Core - location: https://github.com/pubnub/c-core/releases/tag/v4.7.0 + location: https://github.com/pubnub/c-core/releases/tag/v4.7.1 requires: - name: "miniz" diff --git a/CHANGELOG.md b/CHANGELOG.md index 03bf4650..407f69c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v4.7.1 +November 23 2023 + +#### Fixed +- Handle unencrypted message while getting messages with crypto. + ## v4.7.0 November 20 2023 diff --git a/core/pubnub_ccore_pubsub.c b/core/pubnub_ccore_pubsub.c index f1e01cfa..b14d2057 100644 --- a/core/pubnub_ccore_pubsub.c +++ b/core/pubnub_ccore_pubsub.c @@ -122,7 +122,7 @@ char const* pbcc_get_msg(struct pbcc_context* pb) if (NULL != pb->crypto_module) { char* trimmed = (char*)malloc(strlen(rslt) + 1); // same length as rslt if (NULL == trimmed) { - PUBNUB_LOG_ERROR("pbcc_get_msg(pbcc=%p) - failed to allocate memory for trimmed string. Dropping message!\n", pb); + PUBNUB_LOG_ERROR("pbcc_get_msg(pbcc=%p) - failed to allocate memory for trimmed string. Returning original message!\n", pb); return NULL; } sprintf(trimmed, "%s", rslt); @@ -133,19 +133,19 @@ char const* pbcc_get_msg(struct pbcc_context* pb) free(trimmed); if (NULL == encrypted.ptr) { - PUBNUB_LOG_ERROR("pbcc_get_msg(pbcc=%p) - base64 decoding failed. Dropping message!\n", pb); - return NULL; + PUBNUB_LOG_WARNING("pbcc_get_msg(pbcc=%p) - base64 decoding failed. Returning original message!\n", pb); + return rslt; } pubnub_bymebl_t rslt_block = pb->crypto_module->decrypt(pb->crypto_module, encrypted); free(encrypted.ptr); if (NULL == rslt_block.ptr) { - PUBNUB_LOG_ERROR("pbcc_get_msg(pbcc=%p) - decryption failed. Dropping message!\n", pb); - return NULL; + PUBNUB_LOG_WARNING("pbcc_get_msg(pbcc=%p) - decryption failed. Returning original message!\n", pb); + return rslt; } if (pb->decrypted_message_count >= PUBNUB_MAX_DECRYPTED_MESSAGES) { - PUBNUB_LOG_ERROR("pbcc_get_msg(pbcc=%p) - maximum number of decrypted messages reached. Dropping message!\n", pb); + PUBNUB_LOG_ERROR("pbcc_get_msg(pbcc=%p) - maximum number of decrypted messages reached. Returning original message!\n", pb); return NULL; } diff --git a/core/pubnub_version_internal.h b/core/pubnub_version_internal.h index dd6aaf6d..b8adf3e4 100644 --- a/core/pubnub_version_internal.h +++ b/core/pubnub_version_internal.h @@ -3,7 +3,7 @@ #define INC_PUBNUB_VERSION_INTERNAL -#define PUBNUB_SDK_VERSION "4.7.0" +#define PUBNUB_SDK_VERSION "4.7.1" #endif /* !defined INC_PUBNUB_VERSION_INTERNAL */