We should use SecTrustCopyCertificateChain and then access the CFArray instead of using the deprecated SecTrustGetCertificateCount
Use xpc_connection_send_message_with_reply_sync instead of xpc_connection_send_message_with_reply.
This also gives us the added benefit of not risking priority inversion, since xpc_connection_send_message_with_reply_sync takes care of that already.
Finally, use RtlGetVersion instead of deprecated GetVersionExA.
xpc_connection_t conn; /* Connection to XPC service */
xpc_object_t request; /* Request message dictionary */
__block xpc_object_t response; /* Response message dictionary */
- dispatch_semaphore_t sem; /* Semaphore for waiting for response */
int status = CUPS_BACKEND_FAILED;
/* Status of request */
xpc_dictionary_set_fd(request, "stderr", 2);
xpc_dictionary_set_fd(request, "side-channel", CUPS_SC_FD);
- sem = dispatch_semaphore_create(0);
- response = NULL;
+ response = xpc_connection_send_message_with_reply_sync(conn, request);
- xpc_connection_send_message_with_reply(conn, request,
- dispatch_get_global_queue(0,0),
- ^(xpc_object_t reply)
- {
- /* Save the response and wake up */
- if (xpc_get_type(reply)
- == XPC_TYPE_DICTIONARY)
- response = xpc_retain(reply);
-
- dispatch_semaphore_signal(sem);
- });
-
- dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
xpc_release(request);
- dispatch_release(sem);
if (response)
{
xpc_dictionary_set_int64(request, "command", kPMWaitForJob);
xpc_dictionary_set_fd(request, "stderr", 2);
- sem = dispatch_semaphore_create(0);
- response = NULL;
-
- xpc_connection_send_message_with_reply(conn, request,
- dispatch_get_global_queue(0,0),
- ^(xpc_object_t reply)
- {
- /* Save the response and wake up */
- if (xpc_get_type(reply)
- == XPC_TYPE_DICTIONARY)
- response = xpc_retain(reply);
-
- dispatch_semaphore_signal(sem);
- });
-
- dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
+ response = xpc_connection_send_message_with_reply_sync(conn, request);
xpc_release(request);
- dispatch_release(sem);
if (response)
{
{
OSStatus error; /* Error code */
SecTrustRef peerTrust; /* Peer trust reference */
- CFIndex count; /* Number of credentials */
- SecCertificateRef secCert; /* Certificate reference */
CFDataRef data; /* Certificate data */
- int i; /* Looping var */
DEBUG_printf(("httpCopyCredentials(http=%p, credentials=%p)", (void *)http, (void *)credentials));
if (!(error = SSLCopyPeerTrust(http->tls, &peerTrust)) && peerTrust)
{
- DEBUG_printf(("2httpCopyCredentials: Peer provided %d certificates.", (int)SecTrustGetCertificateCount(peerTrust)));
-
if ((*credentials = cupsArrayNew(NULL, NULL)) != NULL)
{
- count = SecTrustGetCertificateCount(peerTrust);
+ CFArrayRef secArray = SecTrustCopyCertificateChain(peerTrust);
+ CFIndex i, count = CFArrayGetCount(secArray);
+ DEBUG_printf(("2httpCopyCredentials: Peer provided %ld certificates.", (long)count));
+
for (i = 0; i < count; i ++)
{
- secCert = SecTrustGetCertificateAtIndex(peerTrust, i);
+ const SecCertificateRef secCert = CFArrayGetValueAtIndex(secArray, i);
#ifdef DEBUG
CFStringRef cf_name = SecCertificateCopySubjectSummary(secCert);
else
strlcpy(name, "unknown", sizeof(name));
- DEBUG_printf(("2httpCopyCredentials: Certificate %d name is \"%s\".", i, name));
+ DEBUG_printf(("2httpCopyCredentials: Certificate %ld name is \"%s\".", (long)i, name));
#endif /* DEBUG */
if ((data = SecCertificateCopyData(secCert)) != NULL)
{
- DEBUG_printf(("2httpCopyCredentials: Adding %d byte certificate blob.", (int)CFDataGetLength(data)));
+ DEBUG_printf(("2httpCopyCredentials: Adding %ld byte certificate blob.", (long)CFDataGetLength(data)));
httpAddCredential(*credentials, CFDataGetBytePtr(data), (size_t)CFDataGetLength(data));
CFRelease(data);
}
}
+ CFRelease(secArray);
}
CFRelease(peerTrust);
* Gather Windows version information for the User-Agent string...
*/
- version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionExA(&version);
+ typedef LONG NTSTATUS, *PNTSTATUS;
+ typedef NTSTATUS(WINAPI * RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
+
+ RtlGetVersionPtr RtlGetVersionInternal = (RtlGetVersionPtr)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion");
+ if (RtlGetVersionInternal)
+ {
+ version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ RtlGetVersionInternal((PRTL_OSVERSIONINFOW)&version);
+ }
+ else
+ {
+ ZeroMemory(&version, sizeof(version));
+ }
GetNativeSystemInfo(&sysinfo);
switch (sysinfo.wProcessorArchitecture)
* this later.
*/
- bzero(&timerContext, sizeof(timerContext));
+ memset(&timerContext, 0, sizeof(timerContext));
timerContext.info = &threadData;
threadData.timerRef =