Skip to content

Commit

Permalink
Made ‘sqSetupSSL’ in ‘sqMacSSL.c’ handle the ‘CERTNAME’ property havi…
Browse files Browse the repository at this point in the history
…ng been set (by searching for a valid identity with the property value as its subject through ‘SecItemCopyMatching’ and setting it as the SSL session context’s certificate through ‘SSLSetCertificate’).
  • Loading branch information
Rinzwind committed Jun 15, 2024
1 parent 539aedd commit a675a2b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions extracted/plugins/SqueakSSL/src/osx/sqMacSSL.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,40 @@ OSStatus sqSetupSSL(sqSSL* ssl, int isServer)
}
}

if (ssl->certName) {
CFStringRef certName = CFStringCreateWithCString(kCFAllocatorDefault, ssl->certName, kCFStringEncodingASCII);
if (certName == NULL)
return SQSSL_GENERIC_ERROR;
CFMutableDictionaryRef query = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (query == NULL) {
CFRelease(certName);
return SQSSL_GENERIC_ERROR;
}
CFDictionarySetValue(query, kSecMatchLimit, kSecMatchLimitOne);
CFDictionarySetValue(query, kSecReturnRef, kCFBooleanTrue);
CFDictionarySetValue(query, kSecClass, kSecClassIdentity);
CFDictionarySetValue(query, kSecMatchSubjectWholeString, certName);
CFDictionarySetValue(query, kSecMatchValidOnDate, kCFNull);
CFRelease(certName);
SecIdentityRef identity;
status = SecItemCopyMatching(query, (CFTypeRef*) &identity);
CFRelease(query);
if (status != noErr) {
logStatus(status, status == errSecItemNotFound ? "SecItemCopyMatching had no results" : "SecItemCopyMatching failed");
return status;
}
CFArrayRef certs = CFArrayCreate(kCFAllocatorDefault, (const void **)&identity, 1, &kCFTypeArrayCallBacks);
CFRelease(identity);
if (certs == NULL)
return SQSSL_GENERIC_ERROR;
SSLSetCertificate(ssl->ctx, certs);
CFRelease(certs);
if (status != noErr) {
logStatus(status, "SSLSetCertificate failed");
return status;
}
}

return status;
}

Expand Down

0 comments on commit a675a2b

Please sign in to comment.