/* * * (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 § 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 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks. * */ 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; using ASC.Files.Core.Model; using ASC.MessagingSystem; using ASC.Web.Api.Routing; using ASC.Web.Core.PublicResources; using ASC.Web.Files.Core.Entries; using ASC.Web.Files.Services.WCFService; using ASC.Web.Studio.Core; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; namespace ASC.Api.Documents { [Scope] [DefaultRoute] [ApiController] public class PrivacyRoomController : ControllerBase { private AuthContext AuthContext { get; } private PermissionContext PermissionContext { get; } private SettingsManager SettingsManager { get; } private TenantManager TenantManager { get; } private EncryptionKeyPairHelper EncryptionKeyPairHelper { get; } private FileStorageService FileStorageServiceInt { get; } private FileStorageService FileStorageService { get; } private MessageService MessageService { get; } private ILog Log { get; } public PrivacyRoomController( AuthContext authContext, PermissionContext permissionContext, SettingsManager settingsManager, TenantManager tenantManager, EncryptionKeyPairHelper encryptionKeyPairHelper, FileStorageService fileStorageServiceInt, FileStorageService fileStorageService, MessageService messageService, IOptionsMonitor option) { AuthContext = authContext; PermissionContext = permissionContext; SettingsManager = settingsManager; TenantManager = tenantManager; EncryptionKeyPairHelper = encryptionKeyPairHelper; FileStorageServiceInt = fileStorageServiceInt; FileStorageService = fileStorageService; MessageService = messageService; Log = option.Get("ASC.Api.Documents"); } /// /// /// /// false [Update("keys")] public object SetKeys(PrivacyRoomModel model) { 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); } EncryptionKeyPairHelper.SetKeyPair(model.PublicKey, model.PrivateKeyEnc); return new { isset = true }; } /// /// /// /// false [Read("access/{fileId}")] public IEnumerable GetPublicKeysWithAccess(string fileId) { if (!PrivacyRoomSettings.GetEnabled(SettingsManager)) throw new System.Security.SecurityException(); return EncryptionKeyPairHelper.GetKeyPair(fileId, FileStorageService); } [Read("access/{fileId:int}")] public IEnumerable GetPublicKeysWithAccess(int fileId) { if (!PrivacyRoomSettings.GetEnabled(SettingsManager)) throw new System.Security.SecurityException(); return EncryptionKeyPairHelper.GetKeyPair(fileId, FileStorageServiceInt); } /// /// /// /// /// false [Read("")] public bool PrivacyRoom() { PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings); return PrivacyRoomSettings.GetEnabled(SettingsManager); } /// /// /// /// /// /// false [Update("")] public bool SetPrivacyRoom(PrivacyRoomModel model) { PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings); if (model.Enable) { if (!PrivacyRoomSettings.IsAvailable(TenantManager)) { throw new BillingException(Resource.ErrorNotAllowedOption, "PrivacyRoom"); } } PrivacyRoomSettings.SetEnabled(TenantManager, SettingsManager, model.Enable); MessageService.Send(model.Enable ? MessageAction.PrivacyRoomEnable : MessageAction.PrivacyRoomDisable); return model.Enable; } } }