Merge branch 'develop' of github.com:ONLYOFFICE/AppServer into feature/sso

This commit is contained in:
Viktor Fomin 2022-06-21 10:22:12 +03:00
commit cc61ac8d82
9 changed files with 48 additions and 27 deletions

View File

@ -130,23 +130,25 @@ public class AppleIdLoginProvider : BaseLoginProvider<AppleIdLoginProvider>
}
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<Claim> { 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<Claim> { 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)

View File

@ -88,9 +88,11 @@ public class GosUslugiLoginProvider : BaseLoginProvider<GosUslugiLoginProvider>
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)
{

View File

@ -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);

View File

@ -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);

View File

@ -164,7 +164,7 @@ class FileDownloadOperation<T> : FileOperation<FileDownloadOperationData<T>, T>
{
private readonly Dictionary<T, string> _files;
private readonly IDictionary<string, StringValues> _headers;
private readonly ItemNameValueCollection<T> _entriesPathId;
private ItemNameValueCollection<T> _entriesPathId;
public override FileOperationType OperationType => FileOperationType.Download;
public FileDownloadOperation(IServiceProvider serviceProvider, FileDownloadOperationData<T> fileDownloadOperationData)
@ -181,7 +181,7 @@ class FileDownloadOperation<T> : FileOperation<FileDownloadOperationData<T>, 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<T> : FileOperation<FileDownloadOperationData<T>, T>
throw new DirectoryNotFoundException(FilesCommonResource.ErrorMassage_FolderNotFound);
}
Total = entriesPathId.Count + 1;
Total = _entriesPathId.Count + 1;
ReplaceLongPath(_entriesPathId);

View File

@ -69,7 +69,7 @@ public class FileConverterQueue<T>
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<T>
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

View File

@ -100,7 +100,9 @@ internal class FileConverterService<T> : BackgroundService
.ToList();
foreach (var converter in filesIsConverting)
{
{
converter.Processed = "1";
var fileId = JsonDocument.Parse(converter.Source).RootElement.GetProperty("id").Deserialize<T>();
var fileVersion = JsonDocument.Parse(converter.Source).RootElement.GetProperty("version").Deserialize<int>();
@ -183,7 +185,7 @@ internal class FileConverterService<T> : 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;

View File

@ -68,12 +68,11 @@ builder.Host.ConfigureDefault(args, (hostContext, config, env, path) =>
diHelper.TryAdd<FileDataQueue>();
services.AddActivePassiveHostedService<FileConverterService<string>>();
diHelper.TryAdd<FileConverterService<string>>();
services.AddActivePassiveHostedService<FileConverterService<int>>();
diHelper.TryAdd<FileConverterService<int>>();
services.AddActivePassiveHostedService<FileConverterService<string>>();
diHelper.TryAdd<FileConverterService<string>>();
services.AddHostedService<ThumbnailBuilderService>();
diHelper.TryAdd<ThumbnailBuilderService>();

View File

@ -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