| 779 | */ |
| 780 | |
| 781 | size_t /* O - Total size of credentials string */ |
| 782 | httpCredentialsString( |
| 783 | cups_array_t *credentials, /* I - Credentials */ |
| 784 | char *buffer, /* I - Buffer or @code NULL@ */ |
| 785 | size_t bufsize) /* I - Size of buffer */ |
| 786 | { |
| 787 | http_credential_t *first; /* First certificate */ |
| 788 | SecCertificateRef secCert; /* Certificate reference */ |
| 789 | |
| 790 | |
| 791 | DEBUG_printf(("httpCredentialsString(credentials=%p, buffer=%p, bufsize=" CUPS_LLFMT ")", (void *)credentials, (void *)buffer, CUPS_LLCAST bufsize)); |
| 792 | |
| 793 | if (!buffer) |
| 794 | return (0); |
| 795 | |
| 796 | if (bufsize > 0) |
| 797 | *buffer = '\0'; |
| 798 | |
| 799 | if ((first = (http_credential_t *)cupsArrayFirst(credentials)) != NULL && |
| 800 | (secCert = http_cdsa_create_credential(first)) != NULL) |
| 801 | { |
| 802 | /* |
| 803 | * Copy certificate (string) values from the SecCertificateRef and produce |
| 804 | * a one-line summary. The API for accessing certificate values like the |
| 805 | * issuer name is, um, "interesting"... |
| 806 | */ |
| 807 | |
| 808 | # if TARGET_OS_OSX |
| 809 | CFDictionaryRef cf_dict; /* Dictionary for certificate */ |
| 810 | # endif /* TARGET_OS_OSX */ |
| 811 | CFStringRef cf_string; /* CF string */ |
| 812 | char commonName[256],/* Common name associated with cert */ |
| 813 | issuer[256], /* Issuer name */ |
| 814 | sigalg[256]; /* Signature algorithm */ |
| 815 | time_t expiration; /* Expiration date of cert */ |
| 816 | unsigned char md5_digest[16]; /* MD5 result */ |
| 817 | |
| 818 | if (SecCertificateCopyCommonName(secCert, &cf_string) == noErr) |
| 819 | { |
| 820 | CFStringGetCString(cf_string, commonName, (CFIndex)sizeof(commonName), kCFStringEncodingUTF8); |
| 821 | CFRelease(cf_string); |
| 822 | } |
| 823 | else |
| 824 | { |
| 825 | strlcpy(commonName, "unknown", sizeof(commonName)); |
| 826 | } |
| 827 | |
| 828 | strlcpy(issuer, "unknown", sizeof(issuer)); |
| 829 | strlcpy(sigalg, "UnknownSignature", sizeof(sigalg)); |
| 830 | |
| 831 | # if TARGET_OS_OSX |
| 832 | if ((cf_dict = SecCertificateCopyValues(secCert, NULL, NULL)) != NULL) |
| 833 | { |
| 834 | CFDictionaryRef cf_issuer = CFDictionaryGetValue(cf_dict, kSecOIDX509V1IssuerName); |
| 835 | CFDictionaryRef cf_sigalg = CFDictionaryGetValue(cf_dict, kSecOIDX509V1SignatureAlgorithm); |
| 836 | |
| 837 | if (cf_issuer) |
| 838 | { |
no test coverage detected