2020-09-22 14:17:17 +00:00
|
|
|
|
/*
|
|
|
|
|
*
|
2020-10-14 09:11:04 +00:00
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2018
|
|
|
|
|
*
|
|
|
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
|
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
|
|
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
|
|
|
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
|
|
|
|
*
|
|
|
|
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
|
|
|
*
|
|
|
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
|
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
|
|
|
*
|
|
|
|
|
* Pursuant to Section 7 <EFBFBD> 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
|
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
|
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
|
|
|
* in every copy of the program you distribute.
|
|
|
|
|
* Pursuant to Section 7 <EFBFBD> 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
2020-09-22 14:17:17 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using ASC.Common;
|
|
|
|
|
using ASC.Common.Logging;
|
|
|
|
|
using ASC.Core;
|
|
|
|
|
using ASC.Core.Billing;
|
|
|
|
|
using ASC.Core.Common.Settings;
|
|
|
|
|
using ASC.Core.Users;
|
2020-11-05 15:42:23 +00:00
|
|
|
|
using ASC.Files.Core.Model;
|
2020-09-22 14:17:17 +00:00
|
|
|
|
using ASC.MessagingSystem;
|
|
|
|
|
using ASC.Web.Api.Routing;
|
|
|
|
|
using ASC.Web.Core.PublicResources;
|
|
|
|
|
using ASC.Web.Files.Core.Entries;
|
2020-09-25 10:47:21 +00:00
|
|
|
|
using ASC.Web.Files.Services.WCFService;
|
2020-09-22 14:17:17 +00:00
|
|
|
|
using ASC.Web.Studio.Core;
|
|
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
|
|
|
|
|
namespace ASC.Api.Documents
|
|
|
|
|
{
|
2020-10-19 15:53:15 +00:00
|
|
|
|
[Scope]
|
2020-09-22 14:17:17 +00:00
|
|
|
|
[DefaultRoute]
|
|
|
|
|
[ApiController]
|
2020-11-05 15:42:23 +00:00
|
|
|
|
public class PrivacyRoomController : ControllerBase
|
2020-09-22 14:17:17 +00:00
|
|
|
|
{
|
|
|
|
|
private AuthContext AuthContext { get; }
|
|
|
|
|
private PermissionContext PermissionContext { get; }
|
|
|
|
|
private SettingsManager SettingsManager { get; }
|
|
|
|
|
private TenantManager TenantManager { get; }
|
2020-09-25 10:47:21 +00:00
|
|
|
|
private EncryptionKeyPairHelper EncryptionKeyPairHelper { get; }
|
|
|
|
|
private FileStorageService<int> FileStorageServiceInt { get; }
|
|
|
|
|
private FileStorageService<string> FileStorageService { get; }
|
|
|
|
|
private MessageService MessageService { get; }
|
2020-09-22 14:17:17 +00:00
|
|
|
|
private ILog Log { get; }
|
|
|
|
|
|
2020-11-05 15:42:23 +00:00
|
|
|
|
public PrivacyRoomController(
|
2020-09-22 14:17:17 +00:00
|
|
|
|
AuthContext authContext,
|
|
|
|
|
PermissionContext permissionContext,
|
|
|
|
|
SettingsManager settingsManager,
|
|
|
|
|
TenantManager tenantManager,
|
2020-09-25 10:47:21 +00:00
|
|
|
|
EncryptionKeyPairHelper encryptionKeyPairHelper,
|
|
|
|
|
FileStorageService<int> fileStorageServiceInt,
|
|
|
|
|
FileStorageService<string> fileStorageService,
|
2020-09-22 14:17:17 +00:00
|
|
|
|
MessageService messageService,
|
|
|
|
|
IOptionsMonitor<ILog> option)
|
|
|
|
|
{
|
|
|
|
|
AuthContext = authContext;
|
|
|
|
|
PermissionContext = permissionContext;
|
|
|
|
|
SettingsManager = settingsManager;
|
|
|
|
|
TenantManager = tenantManager;
|
|
|
|
|
EncryptionKeyPairHelper = encryptionKeyPairHelper;
|
2020-09-25 10:47:21 +00:00
|
|
|
|
FileStorageServiceInt = fileStorageServiceInt;
|
|
|
|
|
FileStorageService = fileStorageService;
|
2020-09-22 14:17:17 +00:00
|
|
|
|
MessageService = messageService;
|
|
|
|
|
Log = option.Get("ASC.Api.Documents");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
|
[Update("keys")]
|
2020-11-06 10:30:57 +00:00
|
|
|
|
public object SetKeysFromBody([FromBody]PrivacyRoomModel model)
|
|
|
|
|
{
|
|
|
|
|
return SetKeys(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Update("keys")]
|
2020-11-10 10:41:32 +00:00
|
|
|
|
[Consumes("application/x-www-form-urlencoded")]
|
2020-11-06 10:30:57 +00:00
|
|
|
|
public object SetKeysFromForm([FromForm]PrivacyRoomModel model)
|
|
|
|
|
{
|
|
|
|
|
return SetKeys(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private object SetKeys(PrivacyRoomModel model)
|
2020-09-22 14:17:17 +00:00
|
|
|
|
{
|
|
|
|
|
PermissionContext.DemandPermissions(new UserSecurityProvider(AuthContext.CurrentAccount.ID), Constants.Action_EditUser);
|
|
|
|
|
|
|
|
|
|
if (!PrivacyRoomSettings.GetEnabled(SettingsManager)) throw new System.Security.SecurityException();
|
|
|
|
|
|
|
|
|
|
var keyPair = EncryptionKeyPairHelper.GetKeyPair();
|
|
|
|
|
if (keyPair != null)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(keyPair.PublicKey))
|
|
|
|
|
{
|
|
|
|
|
return new { isset = true };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.InfoFormat("User {0} updates address", AuthContext.CurrentAccount.ID);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-05 15:42:23 +00:00
|
|
|
|
EncryptionKeyPairHelper.SetKeyPair(model.PublicKey, model.PrivateKeyEnc);
|
2020-09-22 14:17:17 +00:00
|
|
|
|
|
|
|
|
|
return new
|
|
|
|
|
{
|
|
|
|
|
isset = true
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-11 12:50:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
|
[Read("keys")]
|
|
|
|
|
public EncryptionKeyPair GetKeys()
|
|
|
|
|
{
|
|
|
|
|
PermissionContext.DemandPermissions(new UserSecurityProvider(AuthContext.CurrentAccount.ID), Constants.Action_EditUser);
|
|
|
|
|
|
|
|
|
|
if (!PrivacyRoomSettings.GetEnabled(SettingsManager)) throw new System.Security.SecurityException();
|
|
|
|
|
|
|
|
|
|
return EncryptionKeyPairHelper.GetKeyPair();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 14:17:17 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
|
[Read("access/{fileId}")]
|
|
|
|
|
public IEnumerable<EncryptionKeyPair> GetPublicKeysWithAccess(string fileId)
|
|
|
|
|
{
|
|
|
|
|
if (!PrivacyRoomSettings.GetEnabled(SettingsManager)) throw new System.Security.SecurityException();
|
|
|
|
|
|
2020-09-25 10:47:21 +00:00
|
|
|
|
return EncryptionKeyPairHelper.GetKeyPair(fileId, FileStorageService);
|
2020-09-22 14:17:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Read("access/{fileId:int}")]
|
|
|
|
|
public IEnumerable<EncryptionKeyPair> GetPublicKeysWithAccess(int fileId)
|
|
|
|
|
{
|
|
|
|
|
if (!PrivacyRoomSettings.GetEnabled(SettingsManager)) throw new System.Security.SecurityException();
|
|
|
|
|
|
2020-09-25 10:47:21 +00:00
|
|
|
|
return EncryptionKeyPairHelper.GetKeyPair(fileId, FileStorageServiceInt);
|
2020-09-22 14:17:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
|
[Read("")]
|
|
|
|
|
public bool PrivacyRoom()
|
|
|
|
|
{
|
|
|
|
|
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
|
|
|
|
|
|
|
|
|
return PrivacyRoomSettings.GetEnabled(SettingsManager);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="enable"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <visible>false</visible>
|
|
|
|
|
[Update("")]
|
2020-11-06 10:30:57 +00:00
|
|
|
|
public bool SetPrivacyRoomFromBody([FromBody]PrivacyRoomModel model)
|
|
|
|
|
{
|
|
|
|
|
return SetPrivacyRoom(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Update("")]
|
2020-11-10 10:41:32 +00:00
|
|
|
|
[Consumes("application/x-www-form-urlencoded")]
|
2020-11-06 10:30:57 +00:00
|
|
|
|
public bool SetPrivacyRoomFromForm([FromForm]PrivacyRoomModel model)
|
|
|
|
|
{
|
|
|
|
|
return SetPrivacyRoom(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool SetPrivacyRoom(PrivacyRoomModel model)
|
2020-09-22 14:17:17 +00:00
|
|
|
|
{
|
|
|
|
|
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
|
|
|
|
|
2020-11-05 15:42:23 +00:00
|
|
|
|
if (model.Enable)
|
2020-09-22 14:17:17 +00:00
|
|
|
|
{
|
|
|
|
|
if (!PrivacyRoomSettings.IsAvailable(TenantManager))
|
|
|
|
|
{
|
|
|
|
|
throw new BillingException(Resource.ErrorNotAllowedOption, "PrivacyRoom");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-05 15:42:23 +00:00
|
|
|
|
PrivacyRoomSettings.SetEnabled(TenantManager, SettingsManager, model.Enable);
|
2020-09-22 14:17:17 +00:00
|
|
|
|
|
2020-11-05 15:42:23 +00:00
|
|
|
|
MessageService.Send(model.Enable ? MessageAction.PrivacyRoomEnable : MessageAction.PrivacyRoomDisable);
|
2020-09-22 14:17:17 +00:00
|
|
|
|
|
2020-11-05 15:42:23 +00:00
|
|
|
|
return model.Enable;
|
2020-09-22 14:17:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|