using Bit.Core.PhishingDomainFeatures.Interfaces; using Bit.Core.Services; using Bit.Core.Settings; using Microsoft.Extensions.Logging; namespace Bit.Core.PhishingDomainFeatures; /// /// Implementation of ICloudPhishingDomainQuery for self-hosted environments /// that relays the request to the Bitwarden cloud API /// public class CloudPhishingDomainRelayQuery : BaseIdentityClientService, ICloudPhishingDomainQuery { private readonly IGlobalSettings _globalSettings; public CloudPhishingDomainRelayQuery( IHttpClientFactory httpFactory, IGlobalSettings globalSettings, ILogger logger) : base( httpFactory, globalSettings.Installation.ApiUri, globalSettings.Installation.IdentityUri, "api.licensing", $"installation.{globalSettings.Installation.Id}", globalSettings.Installation.Key, logger) { _globalSettings = globalSettings; } public async Task> GetPhishingDomainsAsync() { if (!_globalSettings.SelfHosted || !_globalSettings.EnableCloudCommunication) { throw new InvalidOperationException("This query is only for self-hosted installations with cloud communication enabled."); } var result = await SendAsync(HttpMethod.Get, "phishing-domains", null, true); return result?.ToList() ?? new List(); } /// /// Gets the SHA256 checksum of the remote phishing domains list /// /// The SHA256 checksum as a lowercase hex string public async Task GetRemoteChecksumAsync() { if (!_globalSettings.SelfHosted || !_globalSettings.EnableCloudCommunication) { throw new InvalidOperationException("This query is only for self-hosted installations with cloud communication enabled."); } try { // For self-hosted environments, we get the checksum from the Bitwarden cloud API var result = await SendAsync(HttpMethod.Get, "phishing-domains/checksum", null, true); return result ?? string.Empty; } catch (Exception ex) { _logger.LogError(ex, "Error retrieving phishing domain checksum from Bitwarden cloud API"); return string.Empty; } } }