diff --git a/common/ASC.FederatedLogin/LoginProviders/AppleIdLoginProvider.cs b/common/ASC.FederatedLogin/LoginProviders/AppleIdLoginProvider.cs index 9fbf3aa2f4..6d0383070d 100644 --- a/common/ASC.FederatedLogin/LoginProviders/AppleIdLoginProvider.cs +++ b/common/ASC.FederatedLogin/LoginProviders/AppleIdLoginProvider.cs @@ -130,23 +130,25 @@ public class AppleIdLoginProvider : BaseLoginProvider } private string GenerateSecret() - { - using (var cngKey = CngKey.Import(Convert.FromBase64String(PrivateKey), CngKeyBlobFormat.Pkcs8PrivateBlob)) - { - var handler = new JwtSecurityTokenHandler(); - var token = handler.CreateJwtSecurityToken( - issuer: TeamId, - audience: "https://appleid.apple.com", - subject: new ClaimsIdentity(new List { new Claim("sub", ClientID) }), - issuedAt: DateTime.UtcNow, - notBefore: DateTime.UtcNow, - expires: DateTime.UtcNow.AddMinutes(5), - signingCredentials: new SigningCredentials(new ECDsaSecurityKey(new ECDsaCng(cngKey)), SecurityAlgorithms.EcdsaSha256) - ); - token.Header.Add("kid", KeyId); - - return handler.WriteToken(token); - } + { + using var ecdsa = ECDsa.Create(); + + ecdsa.ImportPkcs8PrivateKey(Convert.FromBase64String(PrivateKey), out _); + + var handler = new JwtSecurityTokenHandler(); + var token = handler.CreateJwtSecurityToken( + issuer: TeamId, + audience: "https://appleid.apple.com", + subject: new ClaimsIdentity(new List { new Claim("sub", ClientID) }), + issuedAt: DateTime.UtcNow, + notBefore: DateTime.UtcNow, + expires: DateTime.UtcNow.AddMinutes(5), + signingCredentials: new SigningCredentials(new ECDsaSecurityKey(ecdsa), SecurityAlgorithms.EcdsaSha256) + ); + + token.Header.Add("kid", KeyId); + + return handler.WriteToken(token); } private ClaimsPrincipal ValidateIdToken(string idToken) diff --git a/common/ASC.FederatedLogin/LoginProviders/GosUslugiLoginProvider.cs b/common/ASC.FederatedLogin/LoginProviders/GosUslugiLoginProvider.cs index c398ee66e7..b7798c2668 100644 --- a/common/ASC.FederatedLogin/LoginProviders/GosUslugiLoginProvider.cs +++ b/common/ASC.FederatedLogin/LoginProviders/GosUslugiLoginProvider.cs @@ -88,9 +88,11 @@ public class GosUslugiLoginProvider : BaseLoginProvider public override LoginProfile GetLoginProfile(string accessToken) { +#pragma warning disable CS0618 // Type or member is obsolete var tokenPayloadString = JwtBuilder.Create() .WithAlgorithm(new HMACSHA256Algorithm()) .Decode(accessToken); +#pragma warning restore CS0618 // Type or member is obsolete var tokenPayload = JObject.Parse(tokenPayloadString); if (tokenPayload == null) { diff --git a/products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs b/products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs index df44074253..c58e2ccd8c 100644 --- a/products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs +++ b/products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs @@ -655,12 +655,14 @@ public class FileHandlerService header = header.Substring("Bearer ".Length); +#pragma warning disable CS0618 // Type or member is obsolete var stringPayload = JwtBuilder.Create() .WithAlgorithm(new HMACSHA256Algorithm()) .WithSerializer(new JwtSerializer()) .WithSecret(_fileUtility.SignatureSecret) .MustVerifySignature() .Decode(header); +#pragma warning restore CS0618 // Type or member is obsolete _logger.DebugDocServiceStreamFilePayload(stringPayload); //var data = JObject.Parse(stringPayload); @@ -767,12 +769,14 @@ public class FileHandlerService header = header.Substring("Bearer ".Length); +#pragma warning disable CS0618 // Type or member is obsolete var stringPayload = JwtBuilder.Create() .WithAlgorithm(new HMACSHA256Algorithm()) .WithSerializer(new JwtSerializer()) .WithSecret(_fileUtility.SignatureSecret) .MustVerifySignature() .Decode(header); +#pragma warning restore CS0618 // Type or member is obsolete _logger.DebugDocServiceStreamFilePayload(stringPayload); //var data = JObject.Parse(stringPayload); @@ -1428,12 +1432,14 @@ public class FileHandlerService { try { +#pragma warning disable CS0618 // Type or member is obsolete var dataString = JwtBuilder.Create() .WithAlgorithm(new HMACSHA256Algorithm()) .WithSerializer(new JwtSerializer()) .WithSecret(_fileUtility.SignatureSecret) .MustVerifySignature() .Decode(fileData.Token); +#pragma warning restore CS0618 // Type or member is obsolete var data = JObject.Parse(dataString); if (data == null) @@ -1461,12 +1467,14 @@ public class FileHandlerService try { +#pragma warning disable CS0618 // Type or member is obsolete var stringPayload = JwtBuilder.Create() .WithAlgorithm(new HMACSHA256Algorithm()) .WithSerializer(new JwtSerializer()) .WithSecret(_fileUtility.SignatureSecret) .MustVerifySignature() .Decode(header); +#pragma warning restore CS0618 // Type or member is obsolete _logger.DebugDocServiceTrackPayload(stringPayload); var jsonPayload = JObject.Parse(stringPayload); diff --git a/products/ASC.Files/Core/Services/DocumentService/DocumentServiceHelper.cs b/products/ASC.Files/Core/Services/DocumentService/DocumentServiceHelper.cs index 86c53aa05a..6ebf02358f 100644 --- a/products/ASC.Files/Core/Services/DocumentService/DocumentServiceHelper.cs +++ b/products/ASC.Files/Core/Services/DocumentService/DocumentServiceHelper.cs @@ -355,9 +355,11 @@ public class DocumentServiceHelper return null; } +#pragma warning disable CS0618 // Type or member is obsolete var encoder = new JwtEncoder(new HMACSHA256Algorithm(), new JwtSerializer(), new JwtBase64UrlEncoder()); +#pragma warning restore CS0618 // Type or member is obsolete return encoder.Encode(payload, _fileUtility.SignatureSecret); diff --git a/products/ASC.Files/Core/Services/WCFService/FileOperations/FileDownloadOperation.cs b/products/ASC.Files/Core/Services/WCFService/FileOperations/FileDownloadOperation.cs index 65458853d2..e67859415a 100644 --- a/products/ASC.Files/Core/Services/WCFService/FileOperations/FileDownloadOperation.cs +++ b/products/ASC.Files/Core/Services/WCFService/FileOperations/FileDownloadOperation.cs @@ -164,7 +164,7 @@ class FileDownloadOperation : FileOperation, T> { private readonly Dictionary _files; private readonly IDictionary _headers; - private readonly ItemNameValueCollection _entriesPathId; + private ItemNameValueCollection _entriesPathId; public override FileOperationType OperationType => FileOperationType.Download; public FileDownloadOperation(IServiceProvider serviceProvider, FileDownloadOperationData fileDownloadOperationData) @@ -181,7 +181,7 @@ class FileDownloadOperation : FileOperation, T> return; } - var (entriesPathId, filesForSend, folderForSend) = await GetEntriesPathIdAsync(scope); + (_entriesPathId, var filesForSend, var folderForSend) = await GetEntriesPathIdAsync(scope); if (_entriesPathId == null || _entriesPathId.Count == 0) { @@ -193,7 +193,7 @@ class FileDownloadOperation : FileOperation, T> throw new DirectoryNotFoundException(FilesCommonResource.ErrorMassage_FolderNotFound); } - Total = entriesPathId.Count + 1; + Total = _entriesPathId.Count + 1; ReplaceLongPath(_entriesPathId); diff --git a/products/ASC.Files/Core/Utils/FileConverter.cs b/products/ASC.Files/Core/Utils/FileConverter.cs index 6b92158c9b..0176b31093 100644 --- a/products/ASC.Files/Core/Utils/FileConverter.cs +++ b/products/ASC.Files/Core/Utils/FileConverter.cs @@ -69,7 +69,7 @@ public class FileConverterQueue TenantId = tenantId, Account = account.ID, Delete = deleteAfter, - StartDateTime = DateTime.Now, + StartDateTime = DateTime.UtcNow, Url = url, Password = password, ServerRootPath = serverRootPath @@ -185,6 +185,8 @@ public class FileConverterQueue private bool Contains(FileConverterOperationResult val) { + if (val == null) return false; + var queueTasks = LoadFromCache(); return queueTasks.Any(x => @@ -478,7 +480,7 @@ public class FileConverter TenantId = _tenantManager.GetCurrentTenant().Id, Account = _authContext.CurrentAccount.ID, Delete = false, - StartDateTime = DateTime.Now, + StartDateTime = DateTime.UtcNow, Url = _httpContextAccesor?.HttpContext != null ? _httpContextAccesor.HttpContext.Request.GetUrlRewriter().ToString() : null, Password = null, ServerRootPath = _baseCommonLinkUtility.ServerRootPath diff --git a/products/ASC.Files/Service/FileConverterService.cs b/products/ASC.Files/Service/FileConverterService.cs index 9022e664c0..793eac5803 100644 --- a/products/ASC.Files/Service/FileConverterService.cs +++ b/products/ASC.Files/Service/FileConverterService.cs @@ -100,7 +100,9 @@ internal class FileConverterService : BackgroundService .ToList(); foreach (var converter in filesIsConverting) - { + { + converter.Processed = "1"; + var fileId = JsonDocument.Parse(converter.Source).RootElement.GetProperty("id").Deserialize(); var fileVersion = JsonDocument.Parse(converter.Source).RootElement.GetProperty("version").Deserialize(); @@ -183,7 +185,7 @@ internal class FileConverterService : BackgroundService { var operationResult = converter; - if (DateTime.Now - operationResult.StartDateTime > TimeSpan.FromMinutes(10)) + if (DateTime.UtcNow - operationResult.StartDateTime > TimeSpan.FromMinutes(10)) { operationResult.StopDateTime = DateTime.UtcNow; operationResult.Error = FilesCommonResource.ErrorMassage_ConvertTimeout; diff --git a/products/ASC.Files/Service/Program.cs b/products/ASC.Files/Service/Program.cs index e72e2aab7d..27f5473b6a 100644 --- a/products/ASC.Files/Service/Program.cs +++ b/products/ASC.Files/Service/Program.cs @@ -68,12 +68,11 @@ builder.Host.ConfigureDefault(args, (hostContext, config, env, path) => diHelper.TryAdd(); - services.AddActivePassiveHostedService>(); - diHelper.TryAdd>(); - services.AddActivePassiveHostedService>(); diHelper.TryAdd>(); + services.AddActivePassiveHostedService>(); + diHelper.TryAdd>(); services.AddHostedService(); diHelper.TryAdd(); diff --git a/web/ASC.Web.Core/Files/DocumentService.cs b/web/ASC.Web.Core/Files/DocumentService.cs index dfe633af75..d3be421386 100644 --- a/web/ASC.Web.Core/Files/DocumentService.cs +++ b/web/ASC.Web.Core/Files/DocumentService.cs @@ -173,9 +173,11 @@ public static class DocumentService { "payload", body } }; +#pragma warning disable CS0618 // Type or member is obsolete var encoder = new JwtEncoder(new HMACSHA256Algorithm(), new JsonNetSerializer(), new JwtBase64UrlEncoder()); +#pragma warning restore CS0618 // Type or member is obsolete var token = encoder.Encode(payload, signatureSecret); //todo: remove old scheme @@ -302,9 +304,11 @@ public static class DocumentService { "payload", body } }; +#pragma warning disable CS0618 // Type or member is obsolete var encoder = new JwtEncoder(new HMACSHA256Algorithm(), new JsonNetSerializer(), new JwtBase64UrlEncoder()); +#pragma warning restore CS0618 // Type or member is obsolete var token = encoder.Encode(payload, signatureSecret); //todo: remove old scheme