diff --git a/src/Core/Services/Implementations/RsaLicensingService.cs b/src/Core/Services/Implementations/RsaLicensingService.cs index 0a4203f36..f6ebe6efc 100644 --- a/src/Core/Services/Implementations/RsaLicensingService.cs +++ b/src/Core/Services/Implementations/RsaLicensingService.cs @@ -3,6 +3,7 @@ using Bit.Core.Models.Table; using Bit.Core.Repositories; using Bit.Core.Utilities; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -20,18 +21,20 @@ namespace Bit.Core.Services private readonly GlobalSettings _globalSettings; private readonly IUserRepository _userRepository; private readonly IOrganizationRepository _organizationRepository; + private readonly ILogger _logger; private IDictionary _userCheckCache = new Dictionary(); - private DateTime? _organizationCheckCache = null; public RsaLicensingService( IUserRepository userRepository, IOrganizationRepository organizationRepository, IHostingEnvironment environment, + ILogger logger, GlobalSettings globalSettings) { _userRepository = userRepository; _organizationRepository = organizationRepository; + _logger = logger; var certThumbprint = "‎207e64a231e8aa32aaf68a61037c075ebebd553f"; _globalSettings = globalSettings; @@ -56,19 +59,17 @@ namespace Bit.Core.Services return; } - var now = DateTime.UtcNow; - if(_organizationCheckCache.HasValue && now - _organizationCheckCache.Value < TimeSpan.FromDays(1)) - { - return; - } - _organizationCheckCache = now; - var orgs = await _organizationRepository.GetManyAsync(); + _logger.LogInformation("Validating licenses for {0} organizations.", orgs.Count); + foreach(var org in orgs.Where(o => o.Enabled)) { var license = ReadOrganiztionLicense(org); if(license == null || !license.VerifyData(org, _globalSettings) || !license.VerifySignature(_certificate)) { + _logger.LogInformation("Organization {0}({1}) has an invalid license and is being disabled.", + org.Id, org.Name); + org.Enabled = false; org.ExpirationDate = license.Expires; org.RevisionDate = DateTime.UtcNow; @@ -108,10 +109,15 @@ namespace Bit.Core.Services _userCheckCache.Add(user.Id, now); } + _logger.LogInformation("Validating premium license for user {0}({1}).", user.Id, user.Email); + var license = ReadUserLicense(user); var licensedForPremium = license != null && license.VerifyData(user) && license.VerifySignature(_certificate); if(!licensedForPremium) { + _logger.LogInformation("User {0}({1}) has an invalid license and premium is being disabled.", + user.Id, user.Email); + user.Premium = false; user.PremiumExpirationDate = license.Expires; user.RevisionDate = DateTime.UtcNow; diff --git a/src/Jobs/Program.cs b/src/Jobs/Program.cs index 2ec1173b1..23e42fc8c 100644 --- a/src/Jobs/Program.cs +++ b/src/Jobs/Program.cs @@ -71,6 +71,8 @@ namespace Bit.Jobs _logger.LogError(2, e, "Error performing job."); throw e; } + + _logger.LogInformation("Finished job '{0}'.", parameters["j"]); } private static IDictionary ParseParameters(string[] args)