Skip to content
代码片段 群组 项目
未验证 提交 d6047b42 编辑于 作者: Adeel Mujahid's avatar Adeel Mujahid 提交者: GitHub
浏览文件

Use GetFolderPath(UserProfile) to obtain HOME dir (#41865)

上级 8a05a97c
No related branches found
No related tags found
无相关合并请求
...@@ -36,8 +36,7 @@ internal sealed class DefaultKeyStorageDirectories : IDefaultKeyStorageDirectori ...@@ -36,8 +36,7 @@ internal sealed class DefaultKeyStorageDirectories : IDefaultKeyStorageDirectori
// Environment.GetFolderPath returns null if the user profile isn't loaded. // Environment.GetFolderPath returns null if the user profile isn't loaded.
var localAppDataFromSystemPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var localAppDataFromSystemPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var localAppDataFromEnvPath = Environment.GetEnvironmentVariable("LOCALAPPDATA"); var localAppDataFromEnvPath = Environment.GetEnvironmentVariable("LOCALAPPDATA");
var userProfilePath = Environment.GetEnvironmentVariable("USERPROFILE"); var homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var homePath = Environment.GetEnvironmentVariable("HOME");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !string.IsNullOrEmpty(localAppDataFromSystemPath)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !string.IsNullOrEmpty(localAppDataFromSystemPath))
{ {
...@@ -49,15 +48,17 @@ internal sealed class DefaultKeyStorageDirectories : IDefaultKeyStorageDirectori ...@@ -49,15 +48,17 @@ internal sealed class DefaultKeyStorageDirectories : IDefaultKeyStorageDirectori
{ {
retVal = GetKeyStorageDirectoryFromBaseAppDataPath(localAppDataFromEnvPath); retVal = GetKeyStorageDirectoryFromBaseAppDataPath(localAppDataFromEnvPath);
} }
else if (userProfilePath != null)
{
retVal = GetKeyStorageDirectoryFromBaseAppDataPath(Path.Combine(userProfilePath, "AppData", "Local"));
}
else if (homePath != null) else if (homePath != null)
{ {
// If LOCALAPPDATA and USERPROFILE are not present but HOME is, if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
// it's a good guess that this is a *NIX machine. Use *NIX conventions for a folder name. {
retVal = new DirectoryInfo(Path.Combine(homePath, ".aspnet", DataProtectionKeysFolderName)); retVal = GetKeyStorageDirectoryFromBaseAppDataPath(Path.Combine(homePath, "AppData", "Local"));
}
else
{
// Use*NIX conventions for a folder name.
retVal = new DirectoryInfo(Path.Combine(homePath, ".aspnet", DataProtectionKeysFolderName));
}
} }
else if (!string.IsNullOrEmpty(localAppDataFromSystemPath)) else if (!string.IsNullOrEmpty(localAppDataFromSystemPath))
{ {
...@@ -92,7 +93,7 @@ internal sealed class DefaultKeyStorageDirectories : IDefaultKeyStorageDirectori ...@@ -92,7 +93,7 @@ internal sealed class DefaultKeyStorageDirectories : IDefaultKeyStorageDirectori
if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID"))) if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID")))
{ {
var homeEnvVar = Environment.GetEnvironmentVariable("HOME"); var homeEnvVar = Environment.GetEnvironmentVariable("HOME");
if (!String.IsNullOrEmpty(homeEnvVar)) if (!string.IsNullOrEmpty(homeEnvVar))
{ {
return GetKeyStorageDirectoryFromBaseAppDataPath(homeEnvVar); return GetKeyStorageDirectoryFromBaseAppDataPath(homeEnvVar);
} }
......
...@@ -493,10 +493,9 @@ public class KestrelConfigurationLoader ...@@ -493,10 +493,9 @@ public class KestrelConfigurationLoader
private bool TryGetCertificatePath([NotNullWhen(true)] out string? path) private bool TryGetCertificatePath([NotNullWhen(true)] out string? path)
{ {
// This will go away when we implement // See https://github.com/aspnet/Hosting/issues/1294
// https://github.com/aspnet/Hosting/issues/1294
var appData = Environment.GetEnvironmentVariable("APPDATA"); var appData = Environment.GetEnvironmentVariable("APPDATA");
var home = Environment.GetEnvironmentVariable("HOME"); var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var basePath = appData != null ? Path.Combine(appData, "ASP.NET", "https") : null; var basePath = appData != null ? Path.Combine(appData, "ASP.NET", "https") : null;
basePath = basePath ?? (home != null ? Path.Combine(home, ".aspnet", "https") : null); basePath = basePath ?? (home != null ? Path.Combine(home, ".aspnet", "https") : null);
path = basePath != null ? Path.Combine(basePath, $"{HostEnvironment.ApplicationName}.pfx") : null; path = basePath != null ? Path.Combine(basePath, $"{HostEnvironment.ApplicationName}.pfx") : null;
......
...@@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Certificates.Generation; ...@@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Certificates.Generation;
internal sealed class MacOSCertificateManager : CertificateManager internal sealed class MacOSCertificateManager : CertificateManager
{ {
private const string CertificateSubjectRegex = "CN=(.*[^,]+).*"; private const string CertificateSubjectRegex = "CN=(.*[^,]+).*";
private static readonly string MacOSUserKeyChain = Environment.GetEnvironmentVariable("HOME") + "/Library/Keychains/login.keychain-db"; private static readonly string MacOSUserKeyChain = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/Library/Keychains/login.keychain-db";
private const string MacOSSystemKeyChain = "/Library/Keychains/System.keychain"; private const string MacOSSystemKeyChain = "/Library/Keychains/System.keychain";
private const string MacOSFindCertificateCommandLine = "security"; private const string MacOSFindCertificateCommandLine = "security";
private const string MacOSFindCertificateCommandLineArgumentsFormat = "find-certificate -c {0} -a -Z -p " + MacOSSystemKeyChain; private const string MacOSFindCertificateCommandLineArgumentsFormat = "find-certificate -c {0} -a -Z -p " + MacOSSystemKeyChain;
...@@ -91,7 +91,7 @@ internal sealed class MacOSCertificateManager : CertificateManager ...@@ -91,7 +91,7 @@ internal sealed class MacOSCertificateManager : CertificateManager
internal override CheckCertificateStateResult CheckCertificateState(X509Certificate2 candidate, bool interactive) internal override CheckCertificateStateResult CheckCertificateState(X509Certificate2 candidate, bool interactive)
{ {
var sentinelPath = Path.Combine(Environment.GetEnvironmentVariable("HOME")!, ".dotnet", $"certificates.{candidate.GetCertHashString(HashAlgorithmName.SHA256)}.sentinel"); var sentinelPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dotnet", $"certificates.{candidate.GetCertHashString(HashAlgorithmName.SHA256)}.sentinel");
if (!interactive && !File.Exists(sentinelPath)) if (!interactive && !File.Exists(sentinelPath))
{ {
return new CheckCertificateStateResult(false, KeyNotAccessibleWithoutUserInteraction); return new CheckCertificateStateResult(false, KeyNotAccessibleWithoutUserInteraction);
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册