Skip to content

Commit 187243a

Browse files
committed
Fix crash in unit tests.
Fix mapping of HTTP_STATUS_NOT_MODIFIED to IPP_STATUS_OK_EVENTS_COMPLETE. Only test pinning for self-signed certs. Fix sanity check for cupsSaveCredentials (copy/paste error)
1 parent bbd2f70 commit 187243a

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

cups/request.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,10 @@ _cupsSetHTTPError(http_t *http, /* I - HTTP connection */
11561156
{
11571157
switch (status)
11581158
{
1159+
case HTTP_STATUS_NOT_MODIFIED :
1160+
_cupsSetError(IPP_STATUS_OK_EVENTS_COMPLETE, httpStatus(status), 0);
1161+
break;
1162+
11591163
case HTTP_STATUS_NOT_FOUND :
11601164
_cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, httpStatus(status), 0);
11611165
break;

cups/tls-gnutls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ cupsGetCredentialsTrust(
829829
}
830830

831831
// Look this common name up in the default keychains...
832-
if ((tcreds = cupsCopyCredentials(path, common_name)) != NULL)
832+
if (num_certs == 1 && (tcreds = cupsCopyCredentials(path, common_name)) != NULL)
833833
{
834834
char credentials_str[1024], // String for incoming credentials
835835
tcreds_str[1024]; // String for saved credentials

cups/tls-openssl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,8 @@ cupsGetCredentialsTrust(
777777
_cups_globals_t *cg = _cupsGlobals(); // Per-thread globals
778778

779779

780+
DEBUG_printf("cupsGetCredentialsTrust(path=\"%s\", common_name=\"%s\", credentials=\"%lu bytes\", require_ca=%s)", path, common_name, (unsigned long)(credentials ? strlen(credentials) : 0), require_ca ? "true" : "false");
781+
780782
// Range check input...
781783
if (!path)
782784
path = http_default_path(defpath, sizeof(defpath));
@@ -796,14 +798,16 @@ cupsGetCredentialsTrust(
796798

797799
cert = sk_X509_value(certs, 0);
798800

801+
DEBUG_printf("1cupsGetCredentialsGetTrust: certs=%p, sk_X509_num(certs)=%d", (void *)certs, sk_X509_num(certs));
802+
799803
if (cg->any_root < 0)
800804
{
801805
_cupsSetDefaults();
802806
// openssl_load_crl();
803807
}
804808

805809
// Look this common name up in the default keychains...
806-
if ((tcreds = cupsCopyCredentials(path, common_name)) != NULL)
810+
if (sk_X509_num(certs) == 1 && (tcreds = cupsCopyCredentials(path, common_name)) != NULL)
807811
{
808812
char credentials_str[1024], // String for incoming credentials
809813
tcreds_str[1024]; // String for saved credentials

cups/tls.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ cupsSaveCredentials(
140140
if (credentials)
141141
{
142142
// Make sure it looks like a PEM-encoded cert...
143-
if (strncmp(credentials, "-----BEGIN CERTIFICATE-----", 27) || strstr(key, "-----END CERTIFICATE-----") == NULL)
143+
if (strncmp(credentials, "-----BEGIN CERTIFICATE-----", 27) || strstr(credentials, "-----END CERTIFICATE-----") == NULL)
144144
return (false);
145145
}
146146

@@ -266,6 +266,8 @@ http_check_roots(const char *creds) // I - Credentials
266266
bool ret = false; // Return value
267267

268268

269+
DEBUG_printf("3http_check_roots(creds=\"%s\")", creds);
270+
269271
#ifdef __APPLE__
270272
// Apple hides all of the keychain stuff (all deprecated) so the best we can
271273
// do is use the SecTrust API to evaluate the certificate...
@@ -327,11 +329,19 @@ http_check_roots(const char *creds) // I - Credentials
327329
// Test the certificate list against the macOS/iOS trust store...
328330
if ((policy = SecPolicyCreateBasicX509()) != NULL)
329331
{
332+
DEBUG_puts("4http_check_roots: SecPolicyCreateBasicX509 succeeded.");
333+
330334
if (SecTrustCreateWithCertificates(certs, policy, &trust) == noErr)
331335
{
332336
ret = SecTrustEvaluateWithError(trust, NULL);
333337
CFRelease(trust);
338+
339+
DEBUG_printf("4http_check_roots: SecTrustEvaluateWithError returned %d.", ret);
334340
}
341+
#ifdef DEBUG
342+
else
343+
DEBUG_printf("4http_check_roots: SecTrustCreateWithCertificates returned %d.", SecTrustCreateWithCertificates(certs, policy, &trust));
344+
#endif // DEBUG
335345

336346
CFRelease(policy);
337347
}

0 commit comments

Comments
 (0)