Ver código fonte

安全、压缩-双重密码问题、从压缩入口输入密码未解锁文档的问题

liuaoran 2 anos atrás
pai
commit
386b6bbe45

BIN
PDF Office/ComPDFKit.Desk.dll


+ 1 - 2
PDF Office/Helper/SecurityHelper.cs

@@ -121,8 +121,7 @@ namespace PDF_Master.Helper
             dialogService.ShowDialog(DialogNames.CheckPasswordDialog, value, e =>
             {
                 verifyPasswordResult.IsDiscryptied = e.Parameters.GetValue<bool>(ParameterNames.PasswordResult);
-                verifyPasswordResult.Password = e.Parameters.GetValue<string>(ParameterNames.Password);
-                
+                verifyPasswordResult.Password = e.Parameters.GetValue<string>(ParameterNames.Password); 
             });
             return verifyPasswordResult;
         }

+ 2 - 0
PDF Office/Model/ParameterNames.cs

@@ -44,6 +44,8 @@ namespace PDF_Master.Model
 
         public static string PasswordInfo = "PasswordInfo";
 
+        public static string Tag = "Tag";
+
         /// <summary>
         /// 页码集合
         /// </summary>

+ 70 - 37
PDF Office/ViewModels/Dialog/ToolsDialogs/MergeDialogViewModel.cs

@@ -21,12 +21,19 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
+using static Dropbox.Api.TeamLog.PaperDownloadFormat;
 using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
 
 namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
 {
     class MergeDialogViewModel : BindableBase, IDialogAware
     {
+        // Fix:存储当前程序加载的文档的路径和tag,
+        //如果路径相同则用tag里的密码解锁,
+        //解锁失败再另行提权
+        private string CurrentFilePath = string.Empty;
+        private string currentLoadedPassword = string.Empty;
+
         enum PageSizeType
         {
             kDefault = 0,
@@ -36,7 +43,6 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
             Legal = 4,
             Customized = 5,
         }
-        string CurrentFilePath = "";
 
         #region 框架内容
 
@@ -57,7 +63,22 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
         public void OnDialogOpened(IDialogParameters parameters)
         {
             CPDFViewer pdfViewer = null;
-            parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
+            if (parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer))
+            {
+                VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(pdfViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
+                if (condition.IsDiscryptied)
+                {
+                    if (!string.IsNullOrEmpty(condition.Password))
+                    {
+                        if (pdfViewer.Document.UnlockWithPassword(condition.Password))
+                        {
+                            pdfViewer.Document.CheckOwnerPassword(condition.Password);
+                        }
+                    }
+                }
+                currentLoadedPassword = pdfViewer.Document.Password;
+            }
+
             if (pdfViewer != null)
             {
                 CurrentFilePath = pdfViewer.Document.FilePath;
@@ -111,7 +132,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                 SetProperty(ref inputHeight, value);
             }
         }
-        private int comboBoxSelectedIndex=0;
+        private int comboBoxSelectedIndex = 0;
 
         public int ComboBoxSelectedIndex
         {
@@ -202,7 +223,7 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
         {
             OpenFileDialog openFile = new OpenFileDialog();
             openFile.Multiselect = true;
-            openFile.Filter = Properties.Resources.imageex.ToLower()+"|*";
+            openFile.Filter = Properties.Resources.imageex.ToLower() + "|*";
             if (openFile.ShowDialog() == false)
             {
                 return null;
@@ -261,9 +282,9 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                         //下拉框控件传出来的list是页面索引集合,
                         //此处传给SDK的合并接口的是页码集合,因此需要将集合项遍历+1,只有合并接口是接收页码集合,其余接口是接受页面索引集合
                         List<int> pageIndexs = new List<int>();
-                        for(int j=0;j< MergeObjectlist[i].SetPageRange.Count; j++)
+                        for (int j = 0; j < MergeObjectlist[i].SetPageRange.Count; j++)
                         {
-                            pageIndexs.Add(MergeObjectlist[i].SetPageRange[j]+1);
+                            pageIndexs.Add(MergeObjectlist[i].SetPageRange[j] + 1);
                         }
                         result = SaveDoc.ImportPages(tempDoc, CommonHelper.GetPageParmFromList(pageIndexs));
                     }
@@ -459,51 +480,63 @@ namespace PDF_Master.ViewModels.Dialog.ToolsDialogs
                         //PDF打开失败
                         continue;
                     }
-                    VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(doc, EnumPasswordKind.StatusPermissionsPassword, dialogs);
-                    if (condition.IsDiscryptied)
+
+                    ///Fix:当前情况下,即带着当前文档进入合并,此时可以先行鉴权
+                    ///鉴权完毕后如果有提权行为,还要给原文档提权
+                    if (CurrentFilePath == doc.FilePath && !string.IsNullOrEmpty(currentLoadedPassword) && doc.UnlockWithPassword(currentLoadedPassword)&&doc.CheckOwnerPassword(currentLoadedPassword))
                     {
-                        if (condition.Password != null)
-                        {
-                            mergeObject.Password = condition.Password;
-                            doc.UnlockWithPassword(condition.Password);
-                        }
+                        
                     }
                     else
                     {
-                        doc.Release();
-                        continue;
+                        VerifyPasswordResult condition = SecurityHelper.VerifyPasswordByPasswordKind(doc, EnumPasswordKind.StatusPermissionsPassword, dialogs);
+                        if (condition.IsDiscryptied)
+                        {
+                            if (condition.Password != null)
+                            {
+                                mergeObject.Password = condition.Password;
+                                doc.UnlockWithPassword(condition.Password);
+                            }
+                        }
+                        else
+                        {
+                            doc.Release();
+                            continue;
+                        }
                     }
-                    mergeObject.DocName = doc.FileName;
-                    mergeObject.DocPageCount = doc.PageCount.ToString() +" "+ App.MainPageLoader.GetString("Merge_ItemPages");
-                    mergeObject.SDKPageCount = doc.PageCount;
-                    mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
-
-                    //获取第一页缩略图
-                    CPDFPage page = doc.PageAtIndex(0);
-                    Size size = doc.GetPageSize(0);
-
-                    byte[] bmpData = new byte[(int)(size.Width * size.Height * 4)];
-                    WriteableBitmap WirteBitmap = new WriteableBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Bgra32, null);
-                    page.RenderPageBitmap(0, 0, (int)size.Width, (int)size.Height, 0xFFFFFFFF, bmpData, 1);
-                    WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)size.Width, (int)size.Height), bmpData, WirteBitmap.BackBufferStride, 0);
-                    WirteBitmap.Freeze();
-                    mergeObject.DocThumbnail = WirteBitmap;
-
-                    doc.Release();
-                }
-                MergeObjectlist.Add(mergeObject);
-                UpDataMergeObjectIndex();
+               
+              
+                mergeObject.DocName = doc.FileName;
+                mergeObject.DocPageCount = doc.PageCount.ToString() + " " + App.MainPageLoader.GetString("Merge_ItemPages");
+                mergeObject.SDKPageCount = doc.PageCount;
+                mergeObject.DocSize = CommonHelper.GetFileSize(mergeObject.FilePath);
+
+                //获取第一页缩略图
+                CPDFPage page = doc.PageAtIndex(0);
+                Size size = doc.GetPageSize(0);
+
+                byte[] bmpData = new byte[(int)(size.Width * size.Height * 4)];
+                WriteableBitmap WirteBitmap = new WriteableBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Bgra32, null);
+                page.RenderPageBitmap(0, 0, (int)size.Width, (int)size.Height, 0xFFFFFFFF, bmpData, 1);
+                WirteBitmap.WritePixels(new Int32Rect(0, 0, (int)size.Width, (int)size.Height), bmpData, WirteBitmap.BackBufferStride, 0);
+                WirteBitmap.Freeze();
+                mergeObject.DocThumbnail = WirteBitmap;
+
+                doc.Release();
             }
+            MergeObjectlist.Add(mergeObject);
+            UpDataMergeObjectIndex();
+        }
 
             if (showDialog)
             {
                 AlertsMessage alertsMessage = new AlertsMessage();
-                alertsMessage.ShowDialog("", "The file was not added successfully, please select the file again.", "OK");
+        alertsMessage.ShowDialog("", "The file was not added successfully, please select the file again.", "OK");
                 if (alertsMessage.result == ContentResult.Ok)
                 {
                 }
             }
-        }
+}
         #endregion
     }
 }

+ 8 - 5
PDF Office/ViewModels/HomePanel/PDFTools/QuickToolsContentViewModel.cs

@@ -386,7 +386,7 @@ namespace PDF_Master.ViewModels.HomePanel.PDFTools
                         break;
                     case PDFFnType.Merge:
                         viewer.InitDocument(dlg.FileName);
-                        if (!CheckPassword(viewer)) { return; }
+                       // if (!CheckPassword(viewer)) { return; }
                         DialogParameters merge = new DialogParameters();
                         merge.Add(ParameterNames.PDFViewer, viewer);
                         merge.Add(ParameterNames.FilePath, dlg.FileNames);
@@ -396,7 +396,6 @@ namespace PDF_Master.ViewModels.HomePanel.PDFTools
                         });
                         break;
                 }
-
             }
         }
         //
@@ -414,9 +413,13 @@ namespace PDF_Master.ViewModels.HomePanel.PDFTools
                 {
                     if (result.Password != null)
                     {
-                        string filePath = viewer.Document.FilePath;
-                        viewer.Document.UnlockWithPassword(result.Password);
-                        viewer.Tag = result.Password;
+                       if(viewer.Document.UnlockWithPassword(result.Password))
+                        {
+                            //if (viewer.Document.CheckOwnerPassword(result.Password))
+                            //{
+                               viewer.Tag = result.Password;
+                            //}
+                        }
                     }
                     ///TODO:
                     ///此处填入需要执行的代码

+ 0 - 2
PDF Office/ViewModels/PropertyPanel/AnnotPanel/SnapshotEditMenuViewModel.cs

@@ -38,8 +38,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
 {
     public class SnapshotEditMenuViewModel : BindableBase
     {
-        public IDialogService dialogs;
-
         public CustomIconToggleBtn ToggleBtn { get; set; }
         public SnapshotEditToolArgs SnapToolArgs { get; set; }
         public CPDFViewer PDFViewer { get; set; }

+ 1 - 0
PDF Office/ViewModels/Tools/ToolsBarContentViewModel.cs

@@ -197,6 +197,7 @@ namespace PDF_Master.ViewModels.Tools
         {
             DialogParameters value = new DialogParameters();
             value.Add(ParameterNames.PDFViewer, PDFViewer);
+            value.Add(ParameterNames.FilePath, PDFViewer.Document.FilePath);
             dialogs.ShowDialog(DialogNames.MergeDialog, value, e => { });
         }