Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8347067: Load certificates without explicit trust settings in KeyChainStore #22911

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
11 changes: 2 additions & 9 deletions src/java.base/macosx/classes/apple/security/KeychainStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -878,15 +878,8 @@ private void createTrustedCertEntry(String alias, List<String> inputTrust,
}

if (tce.trustSettings.isEmpty()) {
if (isSelfSigned) {
// If a self-signed certificate has trust settings without specific entries,
// trust it for all purposes
tce.trustedKeyUsageValue = KnownOIDs.anyExtendedKeyUsage.value();
} else {
// Otherwise, return immediately. The certificate is not
// added into entries.
return;
}
// If there is no trust settings then trust the certificate
tce.trustedKeyUsageValue = KnownOIDs.anyExtendedKeyUsage.value();
} else {
List<String> values = new ArrayList<>();
for (var oneTrust : tce.trustSettings) {
Expand Down
20 changes: 8 additions & 12 deletions src/java.base/macosx/native/libosxsecurity/KeystoreImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,16 @@ static bool loadTrustSettings(JNIEnv *env,
jmethodID jm_listAdd,
jobject *inputTrust) {
CFArrayRef trustSettings;
// Load trustSettings into inputTrust
if (SecTrustSettingsCopyTrustSettings(certRef, domain, &trustSettings) == errSecSuccess && trustSettings != NULL) {
if (*inputTrust == NULL) {
Copy link
Author

@timja timja Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved so that the empty ArrayList is always created

*inputTrust = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons);
if (*inputTrust == NULL) {
*inputTrust = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons);
if (*inputTrust == NULL) {
CFRelease(trustSettings);
return false;
}
CFRelease(trustSettings);
return false;
}
}

// Load trustSettings into inputTrust
if (SecTrustSettingsCopyTrustSettings(certRef, domain, &trustSettings) == errSecSuccess && trustSettings != NULL) {
addTrustSettingsToInputTrust(env, jm_listAdd, trustSettings, *inputTrust);
CFRelease(trustSettings);
}
Expand Down Expand Up @@ -492,11 +493,6 @@ static void addCertificatesToKeystore(JNIEnv *env, jobject keyStore,
goto errOut;
}

// Only add certificates with trust settings
if (inputTrust == NULL) {
timja marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

// Create java object for certificate with trust settings
if (!createTrustedCertEntry(env, keyStore, certRef, jm_createTrustedCertEntry, inputTrust)) {
goto errOut;
Expand Down