Skip to content

Commit

Permalink
OpenSSL deprecation fix (#160)
Browse files Browse the repository at this point in the history
Co-authored-by: Serhii Mamontov <parfeon@me.com>
  • Loading branch information
Xavrax and parfeon authored May 24, 2023
1 parent f5d46b3 commit 214ebd7
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 19 deletions.
23 changes: 15 additions & 8 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
name: c-core
schema: 1
version: "4.2.1"
version: "4.2.2"
scm: github.com/pubnub/c-core
changelog:
- date: 2023-05-24
version: v4.2.2
changes:
- type: bug
text: "Conditionally use of using newest openssl API Ipv4 parsing is needed for working with proxy. Include object file with that function for proxy builds."
- type: improvement
text: "Use newest openssl API."
- date: 2023-04-26
version: v4.2.1
changes:
Expand Down Expand Up @@ -713,7 +720,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.1
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
requires:
-
name: "miniz"
Expand Down Expand Up @@ -779,7 +786,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.1
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
requires:
-
name: "miniz"
Expand Down Expand Up @@ -845,7 +852,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.1
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
requires:
-
name: "miniz"
Expand Down Expand Up @@ -907,7 +914,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.1
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
requires:
-
name: "miniz"
Expand Down Expand Up @@ -968,7 +975,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.1
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1024,7 +1031,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.1
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
requires:
-
name: "miniz"
Expand Down Expand Up @@ -1077,7 +1084,7 @@ sdks:
distribution-type: source code
distribution-repository: GitHub release
package-name: C-Core
location: https://github.com/pubnub/c-core/releases/tag/v4.2.1
location: https://github.com/pubnub/c-core/releases/tag/v4.2.2
requires:
-
name: "miniz"
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## v4.2.2
May 24 2023

#### Fixed
- Conditionally use of using newest openssl API Ipv4 parsing is needed for working with proxy. Include object file with that function for proxy builds.

#### Modified
- Use newest openssl API.

## v4.2.1
April 26 2023

Expand Down
2 changes: 1 addition & 1 deletion core/pubnub_version_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define INC_PUBNUB_VERSION_INTERNAL


#define PUBNUB_SDK_VERSION "4.2.1"
#define PUBNUB_SDK_VERSION "4.2.2"


#endif /* !defined INC_PUBNUB_VERSION_INTERNAL */
2 changes: 2 additions & 0 deletions cpp/posix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ endif

ifeq ($(USE_DNS_SERVERS), 1)
CALLBACK_INTF_SOURCEFILES += ../core/pubnub_dns_servers.c ../posix/pubnub_dns_system_servers.c ../lib/pubnub_parse_ipv4_addr.c
else ifeq ($(USE_PROXY), 1)
CALLBACK_INTF_SOURCEFILES += ../lib/pubnub_parse_ipv4_addr.c
endif

ifeq ($(USE_IPV6), 1)
Expand Down
2 changes: 2 additions & 0 deletions cpp/posix_openssl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ endif

ifeq ($(USE_DNS_SERVERS), 1)
CALLBACK_INTF_SOURCEFILES += ../core/pubnub_dns_servers.c ../posix/pubnub_dns_system_servers.c ../lib/pubnub_parse_ipv4_addr.c
else ifeq ($(USE_PROXY), 1)
CALLBACK_INTF_SOURCEFILES += ../lib/pubnub_parse_ipv4_addr.c
endif

ifeq ($(USE_IPV6), 1)
Expand Down
4 changes: 4 additions & 0 deletions openssl/pbpal_connect_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ enum pbpal_tls_result pbpal_check_tls(pubnub_t* pb)
PUBNUB_LOG_TRACE("pb=%p: SSL connected\n", pb);
socket_set_rcv_timeout(pb->pal.socket, pb->transaction_timeout_ms);

#if OPENSSL_VERSION_NUMBER < 0x30000000L
cert = SSL_get_peer_certificate(ssl);
#else
cert = SSL_get1_peer_certificate(ssl);
#endif
if (cert != NULL) {
rslt = SSL_get_verify_result(ssl);
X509_free(cert);
Expand Down
21 changes: 11 additions & 10 deletions openssl/pbpal_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
#define HTTP_PORT 80


/** Locks used by OpenSSL */
static pbpal_mutex_t* m_locks;


PUBNUB_STATIC_ASSERT(PUBNUB_TIMERS_API, need_TIMERS_API);


Expand All @@ -37,8 +33,11 @@ static int print_to_pubnub_log(const char* s, size_t len, void* p)
return 0;
}

#if OPENSSL_VERSION_NUMBER < 0x10100000L

/** Locks used by OpenSSL */
static pbpal_mutex_t* m_locks;

#if OPENSSL_API_COMPAT < 0x10100000L
static void locking_callback(int mode, int type, const char* file, int line)
{
PUBNUB_LOG_TRACE("thread=%4lu mode=%s lock=%s %s:%d\n",
Expand All @@ -54,7 +53,6 @@ static void locking_callback(int mode, int type, const char* file, int line)
pbpal_mutex_unlock(m_locks[type]);
}
}
#endif


#if !defined(_WIN32) && (OPENSSL_API_COMPAT < 0x10000000L)
Expand All @@ -75,15 +73,14 @@ static int locks_setup(void)
for (i = 0; i < CRYPTO_num_locks(); ++i) {
pbpal_mutex_init_std(m_locks[i]);
}
#if !defined(_WIN32) && (OPENSSL_API_COMPAT < 0x10000000L)
#if !defined(_WIN32) && (OPENSSL_API_COMPAT < 0x10000000L)
// On Windows, OpenSSL has a suitable default
CRYPTO_set_id_callback(thread_id);
#endif
#if OPENSSL_API_COMPAT < 0x10100000L
#endif
CRYPTO_set_locking_callback(locking_callback);
#endif
return 0;
}
#endif // OPENSSL_VERSION_NUMBER < 0x10100000L


static void buf_setup(pubnub_t* pb)
Expand All @@ -100,6 +97,8 @@ static int pal_init(void)
#if !defined(__UWP__) && (OPENSSL_VERSION_MAJOR < 3)
ERR_load_BIO_strings(); //Per OpenSSL 3.0 this is deprecated. Allowing this stmt for non-UWP as it exists.
#endif

#if OPENSSL_VERSION_NUMBER < 0x10100000L
SSL_load_error_strings();
SSL_library_init();
OpenSSL_add_all_algorithms();
Expand All @@ -111,6 +110,8 @@ static int pal_init(void)
if (locks_setup()) {
return -1;
}
#endif // OPENSSL_VERSION_NUMBER >= 0x10100000L

if (0 != socket_platform_init()) {
return -1;
}
Expand Down
3 changes: 3 additions & 0 deletions openssl/posix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ endif
ifeq ($(USE_DNS_SERVERS), 1)
CALLBACK_INTF_SOURCEFILES += ../core/pubnub_dns_servers.c ../posix/pubnub_dns_system_servers.c ../lib/pubnub_parse_ipv4_addr.c
CALLBACK_INTF_OBJFILES += pubnub_dns_servers.o pubnub_dns_system_servers.o pubnub_parse_ipv4_addr.o
else ifeq ($(USE_PROXY), 1)
CALLBACK_INTF_SOURCEFILES += ../lib/pubnub_parse_ipv4_addr.c
CALLBACK_INTF_OBJFILES += pubnub_parse_ipv4_addr.o
endif

ifeq ($(USE_IPV6), 1)
Expand Down
3 changes: 3 additions & 0 deletions posix/posix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ endif
ifeq ($(USE_DNS_SERVERS), 1)
CALLBACK_INTF_SOURCEFILES += ../core/pubnub_dns_servers.c ../posix/pubnub_dns_system_servers.c ../lib/pubnub_parse_ipv4_addr.c
CALLBACK_INTF_OBJFILES += pubnub_dns_servers.o pubnub_dns_system_servers.o pubnub_parse_ipv4_addr.o
else ifeq ($(USE_PROXY), 1)
CALLBACK_INTF_SOURCEFILES += ../lib/pubnub_parse_ipv4_addr.c
CALLBACK_INTF_OBJFILES += pubnub_parse_ipv4_addr.o
endif

ifeq ($(USE_IPV6), 1)
Expand Down

0 comments on commit 214ebd7

Please sign in to comment.