mirror of
https://github.com/bitwarden/server.git
synced 2025-06-28 06:36:15 -05:00

* Initial stubbing out of the phishing service * Add the phishing domain controller * Add changes for the phishing domain get * Add distributed cache to the phishing domain Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Rename the variable name Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Removed IPhishingDomainService * Feature/phishing detection cronjob (#5512) * Added caching to EF implementation. Added error handling and logging * Refactored update method to use sqlbulkcopy instead of performing a round trip for each new insert * Initial implementation for quartz job to get list of phishing domains * Updated phishing domain settings to be its own interface * Add phishing domain detection with checksum-based updates * Updated auth for phishing domain endpoints to either require api, or licensing claims to support both web and browser clients, and selfhost api clients * [Innovation Sprint] Updated Phishing domains to rely on blob storage (#5517) * Updated phishing detection data layer to rely on azure blob storage instead of sql server * dotnet format * Took rider refactors * Ensuring phishing.testcategory.com exists to test against * Added redis to dev's docker-compose * Removed redis from cloud profile * Remove the Authorize attribute * error whitespace fix whitespace formatting * error WHITESPACE: Fix whitespace formatting * Wrapped phishing detection feature behind feature flag (#5532) * Increased timeout for fetching source list a bunch * Removed PhishingDomains policy --------- Signed-off-by: Cy Okeke <cokeke@bitwarden.com> Co-authored-by: Cy Okeke <cokeke@bitwarden.com>
67 lines
2.4 KiB
C#
67 lines
2.4 KiB
C#
using Bit.Core.PhishingDomainFeatures.Interfaces;
|
|
using Bit.Core.Services;
|
|
using Bit.Core.Settings;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Bit.Core.PhishingDomainFeatures;
|
|
|
|
/// <summary>
|
|
/// Implementation of ICloudPhishingDomainQuery for self-hosted environments
|
|
/// that relays the request to the Bitwarden cloud API
|
|
/// </summary>
|
|
public class CloudPhishingDomainRelayQuery : BaseIdentityClientService, ICloudPhishingDomainQuery
|
|
{
|
|
private readonly IGlobalSettings _globalSettings;
|
|
|
|
public CloudPhishingDomainRelayQuery(
|
|
IHttpClientFactory httpFactory,
|
|
IGlobalSettings globalSettings,
|
|
ILogger<CloudPhishingDomainRelayQuery> logger)
|
|
: base(
|
|
httpFactory,
|
|
globalSettings.Installation.ApiUri,
|
|
globalSettings.Installation.IdentityUri,
|
|
"api.licensing",
|
|
$"installation.{globalSettings.Installation.Id}",
|
|
globalSettings.Installation.Key,
|
|
logger)
|
|
{
|
|
_globalSettings = globalSettings;
|
|
}
|
|
|
|
public async Task<List<string>> 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<object, string[]>(HttpMethod.Get, "phishing-domains", null, true);
|
|
return result?.ToList() ?? new List<string>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the SHA256 checksum of the remote phishing domains list
|
|
/// </summary>
|
|
/// <returns>The SHA256 checksum as a lowercase hex string</returns>
|
|
public async Task<string> 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<object, string>(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;
|
|
}
|
|
}
|
|
}
|