/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifdef XP_MACOSX # include <CoreFoundation/CoreFoundation.h> # include <Security/Security.h> # include "KeychainSecret.h"// for ScopedCFType #endif// XP_MACOSX
NS_IMETHODIMP
nsClientAuthRemember::GetEntryKey(/*out*/ nsACString& aEntryKey) {
aEntryKey.Assign(mAsciiHost);
aEntryKey.Append(','); // This used to include the SHA-256 hash of the server certificate.
aEntryKey.Append(',');
aEntryKey.Append(mOriginAttributesSuffix); return NS_OK;
}
nsresult nsClientAuthRememberService::Init() { if (!NS_IsMainThread()) {
NS_ERROR("nsClientAuthRememberService::Init called off the main thread"); return NS_ERROR_NOT_SAME_THREAD;
}
nsCOMPtr<nsIDataStorageManager> dataStorageManager(
do_GetService("@mozilla.org/security/datastoragemanager;1")); if (!dataStorageManager) { return NS_ERROR_FAILURE;
}
nsresult rv =
dataStorageManager->Get(nsIDataStorageManager::ClientAuthRememberList,
getter_AddRefs(mClientAuthRememberList)); if (NS_FAILED(rv)) { return rv;
} if (!mClientAuthRememberList) { return NS_ERROR_FAILURE;
}
// aClientCert == nullptr means: remember that user does not want to use a // cert if (aClientCert) {
nsAutoCString dbkey;
nsresult rv = aClientCert->GetDbKey(dbkey); if (NS_FAILED(rv)) { return rv;
} return AddEntryToList(aHostName, aOriginAttributes, dbkey);
} return AddEntryToList(aHostName, aOriginAttributes,
nsClientAuthRemember::SentinelValue);
}
#ifdef XP_MACOSX // On macOS, users can add "identity preference" items in the keychain. These // can be added via the Keychain Access tool. These specify mappings from // URLs/wildcards like "*.mozilla.org" to specific client certificates. This // function retrieves the preferred client certificate for a hostname by // querying a system API that checks for these identity preferences.
nsresult CheckForPreferredCertificate(const nsACString& aHostName,
nsACString& aCertDBKey) {
aCertDBKey.Truncate(); // SecIdentityCopyPreferred seems to expect a proper URI which it can use // for prefix and wildcard matches. // We don't have the full URL but we can turn the hostname into a URI with // an authority section, so that it matches against macOS identity preferences // like `*.foo.com`. If we know that this connection is always going to be // https, then we should put that in the URI as well, so that it matches // identity preferences like `https://foo.com/` as well. If we can plumb // the path or the full URL into this function we could also match identity // preferences like `https://foo.com/bar/` but for now we cannot.
nsPrintfCString fakeUrl("//%s/", PromiseFlatCString(aHostName).get());
ScopedCFType<CFStringRef> host(::CFStringCreateWithCString(
kCFAllocatorDefault, fakeUrl.get(), kCFStringEncodingUTF8)); if (!host) { return NS_ERROR_UNEXPECTED;
}
ScopedCFType<SecIdentityRef> identity(
::SecIdentityCopyPreferred(host.get(), NULL, NULL)); if (!identity) { // No preferred identity for this hostname, leave aCertDBKey empty and // return return NS_OK;
}
SecCertificateRef certRefRaw = NULL;
OSStatus copyResult =
::SecIdentityCopyCertificate(identity.get(), &certRefRaw);
ScopedCFType<SecCertificateRef> certRef(certRefRaw); if (copyResult != errSecSuccess || certRef.get() == NULL) { return NS_ERROR_UNEXPECTED;
}
ScopedCFType<CFDataRef> der(::SecCertificateCopyData(certRef.get())); if (!der) { return NS_ERROR_UNEXPECTED;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.