From ddd13fdc56c714c2e12c02daaff80be6348482e6 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Sat, 19 Oct 2024 15:26:35 -0400 Subject: [PATCH] Add support for libcups v3 client credentials API. --- cups/cups-private.h | 3 +-- cups/globals.c | 2 +- cups/usersys.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/cups/cups-private.h b/cups/cups-private.h index 98c7aa2c2..ec5f0f602 100644 --- a/cups/cups-private.h +++ b/cups/cups-private.h @@ -166,8 +166,7 @@ typedef struct _cups_globals_s // CUPS global state data void *oauth_data; // OAuth user data cups_password_cb2_t password_cb; // Password callback void *password_data; // Password user data - _http_tls_credentials_t *tls_credentials; - // Default client credentials, if any + _http_tls_credentials_t *credentials; // Default client credentials, if any cups_client_cert_cb_t client_cert_cb; // Client certificate callback @deprecated@ void *client_cert_data; // Client certificate user data @deprecated@ diff --git a/cups/globals.c b/cups/globals.c index fe7a2adc1..724611bea 100644 --- a/cups/globals.c +++ b/cups/globals.c @@ -425,7 +425,7 @@ cups_globals_free(_cups_globals_t *cg) /* I - Pointer to global data */ httpClose(cg->http); - _httpFreeCredentials(cg->tls_credentials); + _httpFreeCredentials(cg->credentials); cupsFileClose(cg->stdio_files[0]); cupsFileClose(cg->stdio_files[1]); diff --git a/cups/usersys.c b/cups/usersys.c index 9a9b69013..1a000e642 100644 --- a/cups/usersys.c +++ b/cups/usersys.c @@ -330,6 +330,34 @@ cupsSetClientCertCB( } +// +// 'cupsSetClientCredentials()' - Set the default credentials to be used for TLS connections. +// +// Note: The default credentials are tracked separately for each thread in a +// program. Multi-threaded programs that override the setting need to do so in +// each thread for the same setting to be used. +// +// @since CUPS 2.5@ +// + +bool // O - `true` on success, `false` on failure +cupsSetClientCredentials( + const char *credentials, // I - PEM-encoded X.509 credentials string + const char *key) // I - PEM-encoded private key +{ + _cups_globals_t *cg = _cupsGlobals(); // Pointer to library globals + + + if (!credentials || !*credentials || !key || !*key) + return (false); + + _httpFreeCredentials(cg->credentials); + cg->credentials = _httpCreateCredentials(credentials, key); + + return (cg->credentials != NULL); +} + + /* * 'cupsSetCredentials()' - Set the default credentials to be used for SSL/TLS * connections.