示例#1
0
        public void SetKeyPair(string publicKey, string privateKeyEnc)
        {
            if (string.IsNullOrEmpty(publicKey))
            {
                throw new ArgumentNullException("publicKey");
            }
            if (string.IsNullOrEmpty(privateKeyEnc))
            {
                throw new ArgumentNullException("privateKeyEnc");
            }

            var user = UserManager.GetUsers(AuthContext.CurrentAccount.ID);

            if (!AuthContext.IsAuthenticated || user.IsVisitor(UserManager))
            {
                throw new System.Security.SecurityException();
            }

            var keyPair = new EncryptionKeyPair
            {
                PrivateKeyEnc = privateKeyEnc,
                PublicKey     = publicKey,
                UserId        = user.ID,
            };

            var keyPairString = JsonSerializer.Serialize(keyPair);

            EncryptionLoginProvider.SetKeys(user.ID, keyPairString);
        }
示例#2
0
        public IEnumerable <EncryptionKeyPair> GetKeyPair <T>(T fileId, FileStorageService <T> FileStorageService)
        {
            var fileDao = DaoFactory.GetFileDao <T>();

            fileDao.InvalidateCache(fileId);

            var file = fileDao.GetFile(fileId);

            if (file == null)
            {
                throw new System.IO.FileNotFoundException(FilesCommonResource.ErrorMassage_FileNotFound);
            }
            if (!FileSecurity.CanEdit(file))
            {
                throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
            }
            if (file.RootFolderType != FolderType.Privacy)
            {
                throw new NotSupportedException();
            }

            var fileShares = FileStorageService.GetSharedInfo(new List <T> {
                fileId
            }, new List <T> {
            }).ToList();

            fileShares = fileShares.Where(share => !share.SubjectGroup &&
                                          !share.SubjectId.Equals(FileConstant.ShareLinkId) &&
                                          share.Share == FileShare.ReadWrite).ToList();

            var fileKeysPair = fileShares.Select(share =>
            {
                var fileKeyPairString = EncryptionLoginProvider.GetKeys(share.SubjectId);
                if (string.IsNullOrEmpty(fileKeyPairString))
                {
                    return(null);
                }


                var options = new JsonSerializerOptions
                {
                    AllowTrailingCommas         = true,
                    PropertyNameCaseInsensitive = true
                };
                var fileKeyPair = JsonSerializer.Deserialize <EncryptionKeyPair>(fileKeyPairString, options);
                if (fileKeyPair.UserId != share.SubjectId)
                {
                    return(null);
                }

                fileKeyPair.PrivateKeyEnc = null;

                return(fileKeyPair);
            })
                               .Where(keyPair => keyPair != null);

            return(fileKeysPair);
        }
        public static IEnumerable <string> GetAddresses(string fileId)
        {
            var fileShares = Global.FileStorageService.GetSharedInfo(new ItemList <string> {
                String.Format("file_{0}", fileId)
            }).ToList();

            fileShares = fileShares.Where(share => !share.SubjectGroup && !share.SubjectId.Equals(FileConstant.ShareLinkId) && share.Share == FileShare.ReadWrite).ToList();
            var accountsString = fileShares.Select(share => EncryptionLoginProvider.GetAddress(share.SubjectId)).Where(address => !string.IsNullOrEmpty(address));

            return(accountsString);
        }
示例#4
0
 public EncryptionKeyPairHelper(
     UserManager userManager,
     AuthContext authContext,
     EncryptionLoginProvider encryptionLoginProvider,
     FileSecurity fileSecurity,
     IDaoFactory daoFactory)
 {
     UserManager             = userManager;
     AuthContext             = authContext;
     EncryptionLoginProvider = encryptionLoginProvider;
     FileSecurity            = fileSecurity;
     DaoFactory = daoFactory;
 }
示例#5
0
        public static IEnumerable <EncryptionKeyPair> GetKeyPair(string fileId)
        {
            using (var fileDao = Global.DaoFactory.GetFileDao())
            {
                fileDao.InvalidateCache(fileId);

                var file = fileDao.GetFile(fileId);
                if (file == null)
                {
                    throw new System.IO.FileNotFoundException(FilesCommonResource.ErrorMassage_FileNotFound);
                }
                if (!Global.GetFilesSecurity().CanEdit(file))
                {
                    throw new System.Security.SecurityException(FilesCommonResource.ErrorMassage_SecurityException_EditFile);
                }
                if (file.RootFolderType != FolderType.Privacy)
                {
                    throw new NotSupportedException();
                }
            }

            var fileShares = Global.FileStorageService.GetSharedInfo(new ItemList <string> {
                String.Format("file_{0}", fileId)
            }).ToList();

            fileShares = fileShares.Where(share => !share.SubjectGroup &&
                                          !share.SubjectId.Equals(FileConstant.ShareLinkId) &&
                                          share.Share == FileShare.ReadWrite).ToList();

            var fileKeysPair = fileShares.Select(share =>
            {
                var fileKeyPairString = EncryptionLoginProvider.GetKeys(share.SubjectId);
                if (string.IsNullOrEmpty(fileKeyPairString))
                {
                    return(null);
                }

                var fileKeyPair = JsonConvert.DeserializeObject <EncryptionKeyPair>(fileKeyPairString);
                if (fileKeyPair.UserId != share.SubjectId)
                {
                    return(null);
                }

                fileKeyPair.PrivateKeyEnc = null;

                return(fileKeyPair);
            })
                               .Where(keyPair => keyPair != null);

            return(fileKeysPair);
        }
示例#6
0
 public EncryptionController(
     PermissionContext permissionContext,
     AuthContext authContext,
     EncryptionLoginProvider encryptionLoginProvider,
     IOptionsMonitor <ILog> monitor,
     EncryptionAddressHelper encryptionAddressHelper,
     EncryptedDataDao encryptedDataDao)
 {
     PermissionContext       = permissionContext;
     AuthContext             = authContext;
     EncryptionLoginProvider = encryptionLoginProvider;
     EncryptionAddressHelper = encryptionAddressHelper;
     EncryptedDataDao        = encryptedDataDao;
     Log = monitor.Get("ASC.Api.Documents");
 }
示例#7
0
        public EncryptionKeyPair GetKeyPair()
        {
            var currentAddressString = EncryptionLoginProvider.GetKeys();

            if (string.IsNullOrEmpty(currentAddressString))
            {
                return(null);
            }

            var keyPair = JsonSerializer.Deserialize <EncryptionKeyPair>(currentAddressString);

            if (keyPair.UserId != AuthContext.CurrentAccount.ID)
            {
                return(null);
            }
            return(keyPair);
        }
示例#8
0
        public static EncryptionKeyPair GetKeyPair()
        {
            var currentAddressString = EncryptionLoginProvider.GetKeys();

            if (string.IsNullOrEmpty(currentAddressString))
            {
                return(null);
            }

            var keyPair = JsonConvert.DeserializeObject <EncryptionKeyPair>(currentAddressString);

            if (keyPair.UserId != SecurityContext.CurrentAccount.ID)
            {
                return(null);
            }
            return(keyPair);
        }
        public object UpdateAddress(string address, string publicKey)
        {
            SecurityContext.DemandPermissions(new UserSecurityProvider(SecurityContext.CurrentAccount.ID), Core.Users.Constants.Action_EditUser);

            if (string.IsNullOrEmpty(address))
            {
                throw new ArgumentNullException("address");
            }
            if (string.IsNullOrEmpty(publicKey))
            {
                throw new ArgumentNullException("publicKey");
            }

            var currentAddressString = EncryptionLoginProvider.GetAddress();

            if (!string.IsNullOrEmpty(currentAddressString))
            {
                var currentAddress = JsonConvert.DeserializeObject <EncryptionAddress>(currentAddressString);
                if (currentAddress != null &&
                    !string.IsNullOrEmpty(currentAddress.PublicKey) &&
                    currentAddress.PublicKey.Equals(publicKey))
                {
                    return(new { isset = true });
                }

                LogManager.GetLogger("ASC.Api.Documents").InfoFormat("User {0} updates address", SecurityContext.CurrentAccount.ID);
            }

            var account = new EncryptionAddress {
                Address = address, PublicKey = publicKey
            };
            var accountString = JsonConvert.SerializeObject(account);

            EncryptionLoginProvider.UpdateAddress(accountString);

            return(new
            {
                isset = !string.IsNullOrEmpty(EncryptionLoginProvider.GetAddress())
            });
        }
示例#10
0
        public EncryptionKeyPair GetKeyPair()
        {
            var currentAddressString = EncryptionLoginProvider.GetKeys();

            if (string.IsNullOrEmpty(currentAddressString))
            {
                return(null);
            }

            var options = new JsonSerializerOptions
            {
                AllowTrailingCommas         = true,
                PropertyNameCaseInsensitive = true
            };
            var keyPair = JsonSerializer.Deserialize <EncryptionKeyPair>(currentAddressString, options);

            if (keyPair.UserId != AuthContext.CurrentAccount.ID)
            {
                return(null);
            }
            return(keyPair);
        }
示例#11
0
 public EncryptionAddressHelper(FileSharing fileSharing, EncryptionLoginProvider encryptionLoginProvider)
 {
     FileSharing             = fileSharing;
     EncryptionLoginProvider = encryptionLoginProvider;
 }