]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testcreds.c
2 * HTTP credentials test program for CUPS.
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include "cups-private.h"
18 * 'main()' - Main entry.
21 int /* O - Exit status */
22 main(int argc
, /* I - Number of command-line arguments */
23 char *argv
[]) /* I - Command-line arguments */
25 http_t
*http
; /* HTTP connection */
26 char scheme
[HTTP_MAX_URI
], /* Scheme from URI */
27 hostname
[HTTP_MAX_URI
], /* Hostname from URI */
28 username
[HTTP_MAX_URI
], /* Username:password from URI */
29 resource
[HTTP_MAX_URI
]; /* Resource from URI */
30 int port
; /* Port number from URI */
31 http_trust_t trust
; /* Trust evaluation for connection */
32 cups_array_t
*hcreds
, /* Credentials from connection */
33 *tcreds
; /* Credentials from trust store */
34 char hinfo
[1024], /* String for connection credentials */
35 tinfo
[1024]; /* String for trust store credentials */
36 static const char *trusts
[] = /* Trust strings */
37 { "OK", "Invalid", "Changed", "Expired", "Renewed", "Unknown" };
41 * Check command-line...
46 puts("Usage: ./testcreds hostname");
47 puts(" ./testcreds https://hostname[:port]");
51 if (!strncmp(argv
[1], "https://", 8))
54 * Connect to the host and validate credentials...
57 if (httpSeparateURI(HTTP_URI_CODING_MOST
, argv
[1], scheme
, sizeof(scheme
), username
, sizeof(username
), hostname
, sizeof(hostname
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
59 printf("ERROR: Bad URI \"%s\".\n", argv
[1]);
63 if ((http
= httpConnect2(hostname
, port
, NULL
, AF_UNSPEC
, HTTP_ENCRYPTION_ALWAYS
, 1, 30000, NULL
)) == NULL
)
65 printf("ERROR: Unable to connect to \"%s\" on port %d: %s\n", hostname
, port
, cupsLastErrorString());
69 puts("HTTP Credentials:");
70 if (!httpCopyCredentials(http
, &hcreds
))
72 trust
= httpCredentialsGetTrust(hcreds
, hostname
);
74 httpCredentialsString(hcreds
, hinfo
, sizeof(hinfo
));
76 printf(" Certificate Count: %d\n", cupsArrayCount(hcreds
));
77 if (trust
== HTTP_TRUST_OK
)
80 printf(" Trust: %s (%s)\n", trusts
[trust
], cupsLastErrorString());
81 printf(" Expiration: %s\n", httpGetDateString(httpCredentialsGetExpiration(hcreds
)));
82 printf(" IsValidName: %d\n", httpCredentialsAreValidForName(hcreds
, hostname
));
83 printf(" String: \"%s\"\n", hinfo
);
85 httpFreeCredentials(hcreds
);
88 puts(" Not present (error).");
95 * Load stored credentials...
98 strlcpy(hostname
, argv
[1], sizeof(hostname
));
101 printf("Trust Store for \"%s\":\n", hostname
);
103 if (!httpLoadCredentials(NULL
, &tcreds
, hostname
))
105 httpCredentialsString(tcreds
, tinfo
, sizeof(tinfo
));
107 printf(" Certificate Count: %d\n", cupsArrayCount(tcreds
));
108 printf(" Expiration: %s\n", httpGetDateString(httpCredentialsGetExpiration(tcreds
)));
109 printf(" IsValidName: %d\n", httpCredentialsAreValidForName(tcreds
, hostname
));
110 printf(" String: \"%s\"\n", tinfo
);
112 httpFreeCredentials(tcreds
);
115 puts(" Not present.");