Skip to content

Commit

Permalink
Add support for libcups v3 client credentials API.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Oct 19, 2024
1 parent 0455ce2 commit ddd13fd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
3 changes: 1 addition & 2 deletions cups/cups-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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@
Expand Down
2 changes: 1 addition & 1 deletion cups/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
28 changes: 28 additions & 0 deletions cups/usersys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ddd13fd

Please sign in to comment.