فهرست منبع

ADD: Plugins - SetCryptCallback push correct flags

Alexander Koblov 7 سال پیش
والد
کامیت
2c140fe29e
3فایلهای تغییر یافته به همراه25 افزوده شده و 11 حذف شده
  1. 7 7
      src/filesources/wcxarchive/uwcxarchivefilesource.pas
  2. 10 2
      src/filesources/wfxplugin/uwfxpluginfilesource.pas
  3. 8 2
      src/ucryptproc.pas

+ 7 - 7
src/filesources/wcxarchive/uwcxarchivefilesource.pas

@@ -540,14 +540,14 @@ end;
 
 procedure TWcxArchiveFileSource.SetCryptCallback;
 var
-  iFlags: Integer;
+  AFlags: Integer;
 begin
-  if not PasswordStore.HasMasterKey then
-    iFlags:= 0
-  else
-    iFlags:= PK_CRYPTOPT_MASTERPASS_SET;
-
-  FWcxModule.WcxSetCryptCallback(0, iFlags, @CryptProcA, @CryptProcW);
+  if not PasswordStore.MasterKeySet then
+    AFlags:= 0
+  else begin
+    AFlags:= PK_CRYPTOPT_MASTERPASS_SET;
+  end;
+  FWcxModule.WcxSetCryptCallback(0, AFlags, @CryptProcA, @CryptProcW);
 end;
 
 function TWcxArchiveFileSource.GetArcFileList: TObjectList;

+ 10 - 2
src/filesources/wfxplugin/uwfxpluginfilesource.pas

@@ -482,6 +482,8 @@ end;
 { TWfxPluginFileSource }
 
 constructor TWfxPluginFileSource.Create(aModuleFileName, aPluginRootName: String);
+var
+  AFlags: Integer;
 begin
   inherited Create;
   FPluginNumber:= -1;
@@ -508,10 +510,16 @@ begin
 
       VFSInit;
 
+      if not PasswordStore.MasterKeySet then
+        AFlags:= 0
+      else begin
+        AFlags:= FS_CRYPTOPT_MASTERPASS_SET;
+      end;
+
       if Assigned(FsSetCryptCallbackW) then
-        FsSetCryptCallbackW(@CryptProcW, FPluginNumber, 0);
+        FsSetCryptCallbackW(@CryptProcW, FPluginNumber, AFlags);
       if Assigned(FsSetCryptCallback) then
-        FsSetCryptCallback(@CryptProcA, FPluginNumber, 0);
+        FsSetCryptCallback(@CryptProcA, FPluginNumber, AFlags);
     end;
   end;
 

+ 8 - 2
src/ucryptproc.pas

@@ -54,6 +54,7 @@ type
   public
     constructor Create(const AFileName: String); reintroduce;
   public
+    function MasterKeySet: Boolean;
     function HasMasterKey: Boolean;
     function CheckMasterKey: Boolean;
     function WritePassword(Prefix, Name, Connection: String; const Password: AnsiString): TCryptStoreResult;
@@ -348,6 +349,11 @@ begin
   FMasterStrong:= (Length(FMasterKeyHash) = 0) or (FMasterKeyHash[1] = '!');
 end;
 
+function TPasswordStore.MasterKeySet: Boolean;
+begin
+  Result:= (Length(FMasterKeyHash) <> 0);
+end;
+
 function TPasswordStore.HasMasterKey: Boolean;
 begin
   Result:= (Length(FMasterKey) <> 0);
@@ -392,7 +398,7 @@ var
   Data: AnsiString;
 begin
   if ReadOnly then Exit(csrWriteError);
-  if CheckMasterKey = False then Exit(csrNoMasterKey);
+  if CheckMasterKey = False then Exit(csrFailed);
   if not FMasterStrong then
     Data:= Encode(FMasterKey, Password)
   else begin
@@ -412,7 +418,7 @@ function TPasswordStore.ReadPassword(Prefix, Name, Connection: String;
 var
   Data: AnsiString = '';
 begin
-  if CheckMasterKey = False then Exit(csrNoMasterKey);
+  if CheckMasterKey = False then Exit(csrFailed);
   Data:= ReadString(Prefix + '_' + Name, Connection, Data);
   if Length(Data) = 0 then Exit(csrNotFound);
   if not FMasterStrong then