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

JDK-8303465: KeyStore of type KeychainStore, provider Apple shows different behavior after 8278449 #12829

Closed
wants to merge 1 commit into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Mar 2, 2023

After 8278449, we seem to ignore in the call

if (SecTrustSettingsCopyTrustSettings(certRef, kSecTrustSettingsDomainUser, &trustSettings) == errSecItemNotFound)

all trusted certs from admin and system domains, so a lot more certs are ignored than necessary.
Probably we should take at least the certs with trust settings from kSecTrustSettingsDomainUser, kSecTrustSettingsDomainAdmin and kSecTrustSettingsDomainSystem domains .


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8303465: KeyStore of type KeychainStore, provider Apple shows different behavior after 8278449

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/12829/head:pull/12829
$ git checkout pull/12829

Update a local copy of the PR:
$ git checkout pull/12829
$ git pull https://git.openjdk.org/jdk.git pull/12829/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12829

View PR using the GUI difftool:
$ git pr show -t 12829

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12829.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 2, 2023

👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Mar 2, 2023
@openjdk
Copy link

openjdk bot commented Mar 2, 2023

@MBaesken The following label will be automatically applied to this pull request:

  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the security security-dev@openjdk.org label Mar 2, 2023
@mlbridge
Copy link

mlbridge bot commented Mar 2, 2023

Webrevs

@wangweij
Copy link
Contributor

wangweij commented Mar 2, 2023

I'd like to contribute a test. Update: recalled. Update: fixed.

/*
 * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

import java.security.KeyStore;
import java.util.ArrayList;
import java.util.List;

/*
 * @test
 * @bug 8303465
 * @library /test/lib
 * @requires os.family == "mac"
 * @summary list more trusted certificates
 */
public class ListKeyChain {


    public static void main(String[] args) throws Throwable {
        List<String> trusted = new ArrayList<>();
        populate(true, trusted);
        populate(false, trusted);
        System.out.println(trusted);
        KeyStore ks = KeyStore.getInstance("KEYCHAINSTORE");
        ks.load(null, null);
        for (String alias : trusted) {
            if (!ks.containsAlias(alias)) {
                throw new RuntimeException("Not found: " + alias);
            }
        }
    }

    static void populate(boolean admin, List<String> trusted) throws Throwable {
        OutputAnalyzer output = admin
                ? ProcessTools.executeProcess("security", "dump-trust-setting", "-d")
                : ProcessTools.executeProcess("security", "dump-trust-setting");
        if (output.getExitValue() != 0) {
            return; // No Trust Settings were found
        }
        String certName = null;
        for (String line : output.asLines()) {
            if (line.startsWith("Cert ")) {
                certName = line.split(":", 2)[1].trim().toLowerCase();
            } else if (line.contains("Number of trust settings :")) {
                if (line.endsWith(": 0")) { // we only list trusted-for-all certs
                    trusted.add(certName);
                }
            }
        }
    }
}

@MBaesken
Copy link
Member Author

MBaesken commented Mar 2, 2023

I'd like to contribute a test.

Thanks for contributing the test. Any suggestion where to place the test ?

@wangweij
Copy link
Contributor

wangweij commented Mar 2, 2023

I'd like to contribute a test.

Thanks for contributing the test. Any suggestion where to place the test ?

Maybe just in test/jdk/java/security/KeyStore/. Otherwise needs to create a new dir and add it into some groups.

@wangweij
Copy link
Contributor

wangweij commented Mar 2, 2023

Oops, seems the security command is failing when running the test on our testing clients. Maybe no user privilege? I'll do more investigation and maybe have to make it an internal test or manual one.

@wangweij
Copy link
Contributor

wangweij commented Mar 2, 2023

It does run fine on my own machine.

@MBaesken
Copy link
Member Author

MBaesken commented Mar 3, 2023

dump-trust-setting

I have found some errors with dump-trust-settings like this one wbond/package_control#1017 but not sure if this is related to what you saw on your test infrastructure.

@wangweij
Copy link
Contributor

wangweij commented Mar 3, 2023

The command shows SecTrustSettingsCopyCertificates: No Trust Settings were found. and exits with 1.

@wangweij
Copy link
Contributor

wangweij commented Mar 3, 2023

Maybe it's only the testing machines are too clean and simply do not have any trusted settings. I tried security dump-trust-settings -s there and it shows all root CAs.

I've made a small change to the test and it will not fail when exit value is not 0.

@MBaesken
Copy link
Member Author

MBaesken commented Mar 7, 2023

Hi Weijun, besides the test issue you mentioned, is this patch fine with you?

@wangweij
Copy link
Contributor

wangweij commented Mar 7, 2023

Hi Weijun, besides the test issue you mentioned, is this patch fine with you?

I'll think about it more and discuss with my colleagues.

@MBaesken
Copy link
Member Author

I'll think about it more and discuss with my colleagues.

Hi Weijun, is there some news from your colleagues ?

@wangweij
Copy link
Contributor

I'll think about it more and discuss with my colleagues.

Hi Weijun, is there some news from your colleagues ?

Done some experiments. I'll contact you offline.

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 13, 2023

@MBaesken This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@MBaesken
Copy link
Member Author

Hi Weijun, here I found an example from Apple OpenSource
https://opensource.apple.com/source/Security/Security-59754.80.3/OSX/libsecurity_keychain/lib/SecTrustSettings.cpp.auto.html
and
https://opensource.apple.com/source/Security/Security-57740.51.3/trust/SecTrustSettingsPriv.h.auto.html

they have there a " wrapper around SecTrustSettingsCopyCertificates that combines user and admin domain outputs."
(SecTrustSettingsCopyCertificatesForUserAdminDomains). Seems at least those 2 domains need to be considered.
That#s what I found also in some other projects (e.g. Go).

@bridgekeeper
Copy link

bridgekeeper bot commented May 12, 2023

@MBaesken This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@MBaesken MBaesken closed this May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfr Pull request is ready for review security security-dev@openjdk.org
2 participants