Skip to content

Commit

Permalink
Add --bearer-token and --client-name options to ipptool.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Nov 20, 2024
1 parent 42b6140 commit 43a875f
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 5 deletions.
30 changes: 29 additions & 1 deletion doc/ipptool.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ <h2 id="ipptool-1.synopsis">Synopsis</h2>
[
<strong>--help</strong>
] [
<strong>--bearer-token</strong>
<em>BEARER-TOKEN</em>
] [
<strong>--client-name</strong>
<em>CLIENT-NAME</em>
] [
<strong>--ippfile</strong>
<em>FILENAME</em>
] [
Expand Down Expand Up @@ -186,6 +192,13 @@ <h2 id="ipptool-1.description">Description</h2>
<h2 id="ipptool-1.options">Options</h2>
<p>The following options are recognized by
<strong>ipptool:</strong>
</p>
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>--bearer-token </strong><em>BEARER-TOKEN</em><br>
Specifies the OAuth 2.0 token to use for HTTP Bearer authentication (RFC 6750).
</p>
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>--client-namne </strong><em>CLIENT-NAME</em><br>
Specifies the client name to use for the TLS client certificate.
If not specified, no client certificate is used during negotiation.
</p>
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>--help</strong><br>
Shows program help.
Expand Down Expand Up @@ -329,6 +342,8 @@ <h2 id="ipptool-1.files">Files</h2>
identify-printer-display.test - Identify a printer via the display
ipp-1.1.test - Run IPP/1.1 conformance tests
ipp-2.0.test - Run IPP/2.0 conformance tests
ipp-2.1.test - Run IPP/2.1 conformance tests
ipp-2.2.test - Run IPP/2.2 conformance tests
print-job.test - Print a file
print-job-and-wait.test - Print a file and wait for completion
print-job-deflate.test - Print a file with deflate compression
Expand All @@ -341,8 +356,21 @@ <h2 id="ipptool-1.files">Files</h2>
print-job-password.test - Print a file with a password/PIN
print-job-raster.test - Print a generated raster file
print-uri.test - Print a URI/URL
pwg5100.1.test - Test PWG 5100.1 (Finishings) conformance
pwg5100.2.test - Test PWG 5100.2 (output-bin) conformance
pwg5100.3.test - Test PWG 5100.3 (Production) conformance
pwg5100.5.test - Test PWG 5100.5 (Document Object) conformance
pwg5100.6.test - Test PWG 5100.6 (Page Overrides) conformance
pwg5100.7.test - Test PWG 5100.7 (Job Extensions) conformance
pwg5100.8.test - Test PWG 5100.8 (-actuals) conformance
pwg5100.9.test - Test PWG 5100.9 (Alerts) conformance
pwg5100.11.test - Test PWG 5100.11 (Enterprise) conformance
rfc3380.test - Test RFC 3380 (Job and Printer Set) conformance
rfc3995-3996.test - Test RFC 3995/3996 (Notifications) conformance
rfc3998.test - Test RFC 3998 (Admin) conformance
set-attrs-hold.test - Test setting job-hold-until to hold a job
validate-job.test - Validate a job ticket
validate-resources.test - Validate printer resource files and web pages
</pre>
<p>The following standard document files are available:
</p>
Expand Down Expand Up @@ -390,6 +418,6 @@ <h2 id="ipptool-1.see-also">See Also</h2>
RFC 8011 (<a href="https://datatracker.ietf.org/doc/html/rfc8011">https://datatracker.ietf.org/doc/html/rfc8011</a>)
</p>
<h2 id="ipptool-1.copyright">Copyright</h2>
<p>Copyright &copy; 2021-2023 by OpenPrinting.
<p>Copyright &copy; 2021-2024 by OpenPrinting.
</body>
</html>
5 changes: 4 additions & 1 deletion doc/ipptoolfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ <h3 id="ipptoolfile-5.description.expect-predicates">Expect Predicates</h3>
</p>
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>WITH-CONTENT valid</strong><br>
Requires that all &quot;http&quot; and &quot;https&quot; URI values be accessible and provide valid content.
Currently
<strong>ipptool</strong>
is able to validate CSS, HTML, ICC, IPP, JPEG, PDF, PNG, and Apple .strings files.
</p>
<p style="margin-left: 2.5em; text-indent: -2.5em;"><strong>WITH-ALL-CONTENT valid-icon</strong><br>
</p>
Expand Down Expand Up @@ -1005,6 +1008,6 @@ <h2 id="ipptoolfile-5.see-also">See Also</h2>
<p>RFC 8011 (<a href="https://datatracker.ietf.org/doc/html/rfc8011">https://datatracker.ietf.org/doc/html/rfc8011</a>)
</p>
<h2 id="ipptoolfile-5.copyright">Copyright</h2>
<p>Copyright &copy; 2021-2023 by OpenPrinting.
<p>Copyright &copy; 2021-2024 by OpenPrinting.
</body>
</html>
15 changes: 14 additions & 1 deletion man/ipptool.1
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
.\" Licensed under Apache License v2.0. See the file "LICENSE" for more
.\" information.
.\"
.TH ipptool 1 "CUPS" "2024-09-12" "OpenPrinting"
.TH ipptool 1 "CUPS" "2024-11-20" "OpenPrinting"
.SH NAME
ipptool \- perform internet printing protocol requests
.SH SYNOPSIS
.B ipptool
[
.B \-\-help
] [
.B \-\-bearer\-token
.I BEARER-TOKEN
] [
.B \-\-client\-name
.I CLIENT-NAME
] [
.B \-\-ippfile
.I FILENAME
] [
Expand Down Expand Up @@ -95,6 +101,13 @@ format is described in
The following options are recognized by
.B ipptool:
.TP 5
\fB\-\-bearer\-token \fIBEARER-TOKEN\fR
Specifies the OAuth 2.0 token to use for HTTP Bearer authentication (RFC 6750).
.TP 5
\fB\-\-client\-namne \fICLIENT-NAME\fR
Specifies the client name to use for the TLS client certificate.
If not specified, no client certificate is used during negotiation.
.TP 5
.B \-\-help
Shows program help.
.TP 5
Expand Down
2 changes: 1 addition & 1 deletion pdfio
Submodule pdfio updated 2 files
+1 −1 CHANGES.md
+1 −1 pdfio.h
64 changes: 63 additions & 1 deletion tools/ipptool.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ typedef struct ipptool_test_s // Test Data
bool validate_headers; // Validate HTTP headers in response?
int verbosity; // Show all attributes?

char *bearer_token, // HTTP Bearer token
*client_name; // TLS client certificate name

// Test Defaults
bool def_ignore_errors; // Default IGNORE-ERRORS value
ipptool_transfer_t def_transfer; // Default TRANSFER value
Expand Down Expand Up @@ -251,6 +254,7 @@ static ipp_attribute_t *print_line(ipptool_test_t *data, ipp_t *ipp, ipp_attribu
static void print_xml_header(ipptool_test_t *data);
static void print_xml_string(cups_file_t *outfile, const char *element, const char *s);
static void print_xml_trailer(ipptool_test_t *data, int success, const char *message);
static void set_client_certificate(ipptool_test_t *data);
#ifndef _WIN32
static void sigterm_handler(int sig);
#endif // _WIN32
Expand Down Expand Up @@ -311,7 +315,33 @@ main(int argc, // I - Number of command-line args

for (i = 1; i < argc; i ++)
{
if (!strcmp(argv[i], "--help"))
if (!strcmp(argv[i], "--bearer-token"))
{
i ++;

if (i >= argc)
{
cupsLangPrintf(stderr, _("%s: Missing token after '--bearer-token'."), "ipptool");
free_data(data);
return (usage(stderr));
}

data->bearer_token = argv[i];
}
else if (!strcmp(argv[i], "--client-name"))
{
i ++;

if (i >= argc)
{
cupsLangPrintf(stderr, _("%s: Missing client name after '--client-name'."), "ipptool");
free_data(data);
return (usage(stderr));
}

data->client_name = argv[i];
}
else if (!strcmp(argv[i], "--help"))
{
free_data(data);
return (usage(stdout));
Expand Down Expand Up @@ -1006,6 +1036,9 @@ connect_printer(ipptool_test_t *data) // I - Test data
return (NULL);
}

if (data->client_name)
set_client_certificate(data);

if (!_cups_strcasecmp(scheme, "https") || !_cups_strcasecmp(scheme, "ipps") || atoi(port) == 443)
encryption = HTTP_ENCRYPTION_ALWAYS;
else
Expand All @@ -1017,6 +1050,9 @@ connect_printer(ipptool_test_t *data) // I - Test data
return (NULL);
}

if (data->bearer_token)
httpSetAuthString(data->http, "Bearer", data->bearer_token);

httpSetDefaultField(data->http, HTTP_FIELD_ACCEPT_ENCODING, "deflate, gzip, identity");

if (data->timeout > 0.0)
Expand Down Expand Up @@ -5087,6 +5123,29 @@ print_xml_trailer(
}


//
// 'set_client_certificate()' - Set the client certificate and private key.
//

static void
set_client_certificate(
ipptool_test_t *data) // I - Test data
{
char *creds, // Public key/certificate
*key; // Private key


// Copy and set the client credentials for the given name...
creds = cupsCopyCredentials(/*path*/NULL, data->client_name);
key = cupsCopyCredentials(/*path*/NULL, data->client_name);

cupsSetClientCredentials(creds, key);

free(creds);
free(key);
}


#ifndef _WIN32
//
// 'sigterm_handler()' - Handle SIGINT and SIGTERM.
Expand Down Expand Up @@ -6532,6 +6591,9 @@ usage(FILE *out)
{
cupsLangPuts(out, _("Usage: ipptool [OPTIONS] URI FILENAME [ ... FILENAME ]"));
cupsLangPuts(out, _("Options:"));
cupsLangPuts(out, _("--bearer-token BEARER-TOKEN Set the OAuth Bearer token for authentication"));
cupsLangPuts(out, _("--client-name CLIENT-NAME Set the TLS client certificate name"));
cupsLangPuts(out, _("--help Show this help"));
cupsLangPuts(out, _("--help Show this help"));
cupsLangPuts(out, _("--ippfile FILENAME Produce IPP attribute file"));
cupsLangPuts(out, _("--stop-after-include-error Stop tests after a failed INCLUDE"));
Expand Down

0 comments on commit 43a875f

Please sign in to comment.