2023-02-23 15:13:46 +00:00
|
|
|
|
using System;
|
2023-02-15 12:27:41 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Cryptography;
|
2023-02-16 23:54:23 +00:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2023-02-15 12:00:00 +00:00
|
|
|
|
|
|
|
|
|
namespace Pal.Client.Configuration
|
2023-02-15 01:38:04 +00:00
|
|
|
|
{
|
|
|
|
|
internal static class ConfigurationData
|
|
|
|
|
{
|
2023-02-16 23:54:23 +00:00
|
|
|
|
private static readonly ILogger _logger =
|
|
|
|
|
DependencyInjectionContext.LoggerProvider.CreateLogger(typeof(ConfigurationData));
|
|
|
|
|
|
2023-02-15 12:00:00 +00:00
|
|
|
|
[Obsolete("for V1 import")]
|
|
|
|
|
internal static readonly byte[] FixedV1Entropy = { 0x22, 0x4b, 0xe7, 0x21, 0x44, 0x83, 0x69, 0x55, 0x80, 0x38 };
|
2023-02-15 12:27:41 +00:00
|
|
|
|
|
2023-02-23 08:38:33 +00:00
|
|
|
|
public const string ConfigFileName = "palace-pal.config.json";
|
|
|
|
|
|
2023-02-15 12:27:41 +00:00
|
|
|
|
private static bool? _supportsDpapi = null;
|
|
|
|
|
public static bool SupportsDpapi
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_supportsDpapi == null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
byte[] input = RandomNumberGenerator.GetBytes(32);
|
|
|
|
|
byte[] entropy = RandomNumberGenerator.GetBytes(16);
|
|
|
|
|
byte[] temp = ProtectedData.Protect(input, entropy, DataProtectionScope.CurrentUser);
|
|
|
|
|
byte[] output = ProtectedData.Unprotect(temp, entropy, DataProtectionScope.CurrentUser);
|
|
|
|
|
_supportsDpapi = input.SequenceEqual(output);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
_supportsDpapi = false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-16 23:54:23 +00:00
|
|
|
|
_logger.LogTrace("DPAPI support: {Supported}", _supportsDpapi);
|
2023-02-15 12:27:41 +00:00
|
|
|
|
}
|
|
|
|
|
return _supportsDpapi.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-15 01:38:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|