@@ -102,6 +102,14 @@ LIBCOUCHBASE_API lcb_STATUS lcb_createopts_meter(lcb_CREATEOPTS *options, const
102102 return LCB_SUCCESS ;
103103}
104104
105+ LIBCOUCHBASE_API lcb_STATUS lcb_createopts_tls_key_password (lcb_CREATEOPTS * options , const char * password ,
106+ size_t password_len )
107+ {
108+ options -> tls_key_password = password ;
109+ options -> tls_key_password_len = password_len ;
110+ return LCB_SUCCESS ;
111+ }
112+
105113LIBCOUCHBASE_API
106114const char * lcb_get_version (lcb_uint32_t * version )
107115{
@@ -313,7 +321,7 @@ static lcb_STATUS init_providers(lcb_INSTANCE *obj, const Connspec &spec)
313321 return LCB_SUCCESS ;
314322}
315323
316- static lcb_STATUS setup_ssl (lcb_INSTANCE * obj , const Connspec & params )
324+ static lcb_STATUS setup_ssl (lcb_INSTANCE * obj , const Connspec & params , const char * keypass , size_t keypass_len )
317325{
318326 char optbuf [4096 ];
319327 long env_policy = -1 ;
@@ -368,8 +376,8 @@ static lcb_STATUS setup_ssl(lcb_INSTANCE *obj, const Connspec ¶ms)
368376 lcb_log (LOGARGS (obj , ERR ), "SSL key have to be specified with certificate" );
369377 return LCB_ERR_INVALID_ARGUMENT ;
370378 }
371- settings -> ssl_ctx = lcbio_ssl_new (settings -> truststorepath , settings -> certpath , settings -> keypath ,
372- settings -> sslopts & LCB_SSL_NOVERIFY , & err , settings );
379+ settings -> ssl_ctx = lcbio_ssl_new (settings -> truststorepath , settings -> certpath , settings -> keypath , keypass ,
380+ keypass_len , settings -> sslopts & LCB_SSL_NOVERIFY , & err , settings );
373381 if (!settings -> ssl_ctx ) {
374382 return err ;
375383 }
@@ -452,11 +460,18 @@ lcb_STATUS lcb_create(lcb_INSTANCE **instance, const lcb_CREATEOPTS *options)
452460 lcb_INSTANCE * obj = nullptr ;
453461 lcb_STATUS err ;
454462 lcb_settings * settings ;
463+ std ::string effective_connstr ;
464+ const char * keypass = nullptr ;
465+ std ::size_t keypass_len = 0 ;
455466
456467 if (options ) {
457468 io_priv = options -> io ;
458469 type = options -> type ;
459470 err = spec .load (* options );
471+ if (options -> tls_key_password != nullptr && options -> tls_key_password_len > 0 ) {
472+ keypass = options -> tls_key_password ;
473+ keypass_len = options -> tls_key_password_len ;
474+ }
460475 } else {
461476 const char * errmsg ;
462477 const char * default_connstr = "couchbase://" ;
@@ -543,8 +558,26 @@ lcb_STATUS lcb_create(lcb_INSTANCE **instance, const lcb_CREATEOPTS *options)
543558 }
544559
545560 lcb_log (LOGARGS (obj , INFO ), "Version=%s, Changeset=%s" , lcb_get_version (nullptr ), LCB_VERSION_CHANGESET );
561+ effective_connstr = spec .connstr ();
562+ {
563+ std ::vector < std ::string > sensitive_params {
564+ "password=" ,
565+ };
566+
567+ for (const auto & param : sensitive_params ) {
568+ auto start = effective_connstr .find (param );
569+ if (start != std ::string ::npos ) {
570+ auto value_start = start + param .size ();
571+ auto end = effective_connstr .find ('&' , value_start );
572+ if (end == std ::string ::npos ) {
573+ end = effective_connstr .size ();
574+ }
575+ effective_connstr .replace (value_start , end - value_start , "[REDACTED]" );
576+ }
577+ }
578+ }
546579 lcb_log (LOGARGS (obj , INFO ), "Effective connection string: " LCB_LOG_SPEC ("%s" ) ". Bucket=" LCB_LOG_SPEC ("%s" ),
547- settings -> log_redaction ? LCB_LOG_SD_OTAG : "" , spec . connstr () .c_str (),
580+ settings -> log_redaction ? LCB_LOG_SD_OTAG : "" , effective_connstr .c_str (),
548581 settings -> log_redaction ? LCB_LOG_SD_CTAG : "" , settings -> log_redaction ? LCB_LOG_MD_OTAG : "" ,
549582 settings -> bucket , settings -> log_redaction ? LCB_LOG_MD_CTAG : "" );
550583
@@ -580,7 +613,7 @@ lcb_STATUS lcb_create(lcb_INSTANCE **instance, const lcb_CREATEOPTS *options)
580613 lcb_aspend_init (& obj -> pendops );
581614 obj -> collcache = new lcb ::CollectionCache ();
582615
583- if ((err = setup_ssl (obj , spec )) != LCB_SUCCESS ) {
616+ if ((err = setup_ssl (obj , spec , keypass , keypass_len )) != LCB_SUCCESS ) {
584617 goto GT_DONE ;
585618 }
586619
0 commit comments