MCPcopy Create free account
hub / github.com/OpenPrinting/cups / httpLoadCredentials

Function httpLoadCredentials

cups/tls-openssl.c:704–826  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

702 */
703
704int // O - 0 on success, -1 on error
705httpLoadCredentials(
706 const char *path, // I - Keychain/PKCS#12 path
707 cups_array_t **credentials, // IO - Credentials
708 const char *common_name) // I - Common name for credentials
709{
710 cups_file_t *fp; // Certificate file
711 char filename[1024], // filename.crt
712 temp[1024], // Temporary string
713 line[256]; // Base64-encoded line
714 unsigned char *data = NULL; // Buffer for cert data
715 size_t alloc_data = 0, // Bytes allocated
716 num_data = 0; // Bytes used
717 int decoded; // Bytes decoded
718 int in_certificate = 0;
719 // In a certificate?
720
721
722 if (!credentials || !common_name)
723 return (-1);
724
725 if (!path)
726 path = http_default_path(temp, sizeof(temp));
727 if (!path)
728 return (-1);
729
730 http_make_path(filename, sizeof(filename), path, common_name, "crt");
731
732 if ((fp = cupsFileOpen(filename, "r")) == NULL)
733 return (-1);
734
735 while (cupsFileGets(fp, line, sizeof(line)))
736 {
737 if (!strcmp(line, "-----BEGIN CERTIFICATE-----"))
738 {
739 if (in_certificate)
740 {
741 /*
742 * Missing END CERTIFICATE...
743 */
744
745 httpFreeCredentials(*credentials);
746 *credentials = NULL;
747 break;
748 }
749
750 in_certificate = 1;
751 }
752 else if (!strcmp(line, "-----END CERTIFICATE-----"))
753 {
754 if (!in_certificate || !num_data)
755 {
756 /*
757 * Missing data...
758 */
759
760 httpFreeCredentials(*credentials);
761 *credentials = NULL;

Callers 1

httpCredentialsGetTrustFunction · 0.70

Calls 9

http_default_pathFunction · 0.85
http_make_pathFunction · 0.85
cupsFileOpenFunction · 0.85
cupsFileGetsFunction · 0.85
httpFreeCredentialsFunction · 0.85
cupsArrayNewFunction · 0.85
httpAddCredentialFunction · 0.85
httpDecode64_2Function · 0.85
cupsFileCloseFunction · 0.85

Tested by

no test coverage detected