Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }