@@ -62,6 +62,14 @@ typedef struct tport_nat_s tport_nat_t;
6262#include <errno.h>
6363#include <limits.h>
6464
65+ #if HAVE_WIN32
66+ #include <io.h>
67+ #define access (_filename , _mode ) _access(_filename, _mode)
68+ #define R_OK (04)
69+ #else
70+ #include <unistd.h>
71+ #endif
72+
6573#ifndef IPPROTO_SCTP
6674#define IPPROTO_SCTP (132)
6775#endif
@@ -71,6 +79,8 @@ typedef struct tport_nat_s tport_nat_t;
7179#include <sofia-sip/rbtree.h>
7280
7381#include "tport_internal.h"
82+ #include "tport_tls.h"
83+ #include "tport_ws.h"
7484
7585#if HAVE_FUNC
7686#elif HAVE_FUNCTION
@@ -280,6 +290,59 @@ int tport_is_verified(tport_t const *self)
280290 return tport_has_tls (self ) && self -> tp_is_connected && self -> tp_verified ;
281291}
282292
293+ /** Reload TLS certificates on all TLS primary transports. */
294+ int tport_reload_tls (tport_t * self , char const * cert_dir )
295+ {
296+ su_home_t autohome [SU_HOME_AUTO_SIZE (1024 )];
297+ tls_issues_t ti = {0 };
298+ tport_t * tp ;
299+ int reloaded = 0 ;
300+
301+ if (!self || !cert_dir )
302+ return -1 ;
303+
304+ su_home_auto (autohome , sizeof autohome );
305+
306+ ti .key = su_sprintf (autohome , "%s/%s" , cert_dir , "agent.pem" );
307+ if (access (ti .key , R_OK ) != 0 )
308+ ti .key = su_sprintf (autohome , "%s/%s" , cert_dir , "tls.pem" );
309+ ti .cert = ti .key ;
310+ ti .CAfile = su_sprintf (autohome , "%s/%s" , cert_dir , "cafile.pem" );
311+ if (access (ti .CAfile , R_OK ) != 0 )
312+ ti .CAfile = su_sprintf (autohome , "%s/%s" , cert_dir , "tls.pem" );
313+ ti .CApath = su_strdup (autohome , cert_dir );
314+ ti .randFile = su_sprintf (autohome , "%s/%s" , cert_dir , "tls_seed.dat" );
315+ ti .configured = 1 ;
316+
317+ for (tp = tport_primaries (self ); tp ; tp = tport_next (tp )) {
318+ /* Reload WSS transport certificates */
319+ if (tp -> tp_protoname && strcasecmp (tp -> tp_protoname , "wss" ) == 0 ) {
320+ tport_ws_primary_t * wspri = (tport_ws_primary_t * )tp -> tp_pri ;
321+ if (wspri -> ssl_ctx ) {
322+ SSL_CTX * new_ctx = tport_wss_create_ssl_ctx (cert_dir );
323+ if (new_ctx ) {
324+ SSL_CTX_free (wspri -> ssl_ctx );
325+ wspri -> ssl_ctx = new_ctx ;
326+ reloaded ++ ;
327+ SU_DEBUG_3 (("tport_reload_tls: WSS certificates reloaded successfully\n" VA_NONE ));
328+ } else {
329+ SU_DEBUG_1 (("tport_reload_tls: WSS certificate reload failed\n" VA_NONE ));
330+ }
331+ }
332+ } else if (tport_has_tls (tp )) {
333+ tport_tls_primary_t * tlspri = (tport_tls_primary_t * )tp -> tp_pri ;
334+ if (tlspri -> tlspri_master ) {
335+ if (tls_reload_cert (tlspri -> tlspri_master , & ti ) == 0 )
336+ reloaded ++ ;
337+ }
338+ }
339+ }
340+
341+ su_home_deinit (autohome );
342+
343+ return reloaded ;
344+ }
345+
283346/** Return true if transport is being updated. */
284347int tport_is_updating (tport_t const * self )
285348{
0 commit comments