mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: Crypt functions (from wfx API 2.0)
This commit is contained in:
parent
c586e06b2a
commit
c8a7e57394
4 changed files with 147 additions and 0 deletions
|
|
@ -150,8 +150,28 @@ const FS_BITMAP_NONE=0;
|
|||
|
||||
FS_BITMAP_CACHE=256;
|
||||
|
||||
{Flags for crypto callback function}
|
||||
|
||||
FS_CRYPT_SAVE_PASSWORD=1;
|
||||
|
||||
FS_CRYPT_LOAD_PASSWORD=2;
|
||||
|
||||
FS_CRYPT_LOAD_PASSWORD_NO_UI=3; {Load password only if master password has already been entered!}
|
||||
|
||||
FS_CRYPT_COPY_PASSWORD=4;
|
||||
|
||||
FS_CRYPT_MOVE_PASSWORD=5;
|
||||
|
||||
FS_CRYPT_DELETE_PASSWORD=6;
|
||||
|
||||
FS_CRYPTOPT_MASTERPASS_SET=1; {The user already has a master password defined}
|
||||
|
||||
{ Some Windows specific stuff }
|
||||
|
||||
const
|
||||
MAXDWORD = DWORD($FFFFFFFF);
|
||||
FILE_ATTRIBUTE_DIRECTORY = 16;
|
||||
FILE_ATTRIBUTE_REPARSE_POINT = $0400;
|
||||
|
||||
type
|
||||
TInt64Rec = packed record
|
||||
|
|
@ -238,6 +258,10 @@ type
|
|||
|
||||
ReturnedText:pchar;maxlen:integer):bool; stdcall;
|
||||
|
||||
TCryptProc=function(PluginNr,CryptoNumber:integer;mode:integer;ConnectionName,
|
||||
|
||||
Password:pchar;maxlen:integer):integer; stdcall;
|
||||
|
||||
{ Function prototypes - the callback functions MUST be implemented exactly like this! }
|
||||
|
||||
{
|
||||
|
|
@ -246,6 +270,8 @@ function FsInit(PluginNr:integer;pProgressProc:tProgressProc;pLogProc:tLogProc;
|
|||
|
||||
pRequestProc:tRequestProc):integer; stdcall;
|
||||
|
||||
procedure FsSetCryptCallback(pCryptProc:TCryptProc;CryptoNr,Flags:integer); stdcall;
|
||||
|
||||
function FsFindFirst(path :pchar;var FindData:tWIN32FINDDATA):thandle; stdcall;
|
||||
|
||||
function FsFindNext(Hdl:thandle;var FindData:tWIN32FINDDATA):bool; stdcall;
|
||||
|
|
|
|||
117
src/ucryptproc.pas
Normal file
117
src/ucryptproc.pas
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
unit uCryptProc;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, uClassesEx;
|
||||
|
||||
type
|
||||
|
||||
{ TPasswordStore }
|
||||
|
||||
TPasswordStore = class(TIniFileEx)
|
||||
private
|
||||
FMasterKey: AnsiString;
|
||||
public
|
||||
function WritePassword(Prefix, Name: UTF8String; const Password: AnsiString): Boolean;
|
||||
function ReadPassword(Prefix, Name: UTF8String; out Password: AnsiString): Boolean;
|
||||
end;
|
||||
|
||||
function Encode(MasterKey, Data: AnsiString): AnsiString;
|
||||
function Decode(MasterKey, Data: AnsiString): AnsiString;
|
||||
|
||||
var
|
||||
PasswordStore: TPasswordStore = nil;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
LCLProc, Base64, BlowFish, uGlobsPaths;
|
||||
|
||||
type
|
||||
TBlowFishKeyRec = record
|
||||
dwSize: LongWord;
|
||||
case Boolean of
|
||||
True: (bBlowFishKey: TBlowFishKey);
|
||||
False: (cBlowFishKey: array [0..SizeOf(TBlowFishKey)] of AnsiChar);
|
||||
end;
|
||||
|
||||
function Encode(MasterKey, Data: AnsiString): AnsiString;
|
||||
var
|
||||
BlowFishKeyRec: TBlowFishKeyRec;
|
||||
StringStream: TStringStream = nil;
|
||||
Base64EncodingStream: TBase64EncodingStream = nil;
|
||||
BlowFishEncryptStream: TBlowFishEncryptStream = nil;
|
||||
begin
|
||||
Result:= EmptyStr;
|
||||
BlowFishKeyRec.cBlowFishKey:= MasterKey;
|
||||
BlowFishKeyRec.dwSize:= Length(MasterKey);
|
||||
|
||||
try
|
||||
StringStream:= TStringStream.Create(EmptyStr);
|
||||
Base64EncodingStream:= TBase64EncodingStream.Create(StringStream);
|
||||
|
||||
BlowFishEncryptStream:= TBlowFishEncryptStream.Create(BlowFishKeyRec.bBlowFishKey, BlowFishKeyRec.dwSize, Base64EncodingStream);
|
||||
BlowFishEncryptStream.Write(PAnsiChar(Data)^, Length(Data));
|
||||
BlowFishEncryptStream.Flush;
|
||||
finally
|
||||
FreeThenNil(BlowFishEncryptStream);
|
||||
FreeThenNil(Base64EncodingStream);
|
||||
Result:= StringStream.DataString;
|
||||
FreeThenNil(StringStream);
|
||||
end;
|
||||
end;
|
||||
|
||||
function Decode(MasterKey, Data: AnsiString): AnsiString;
|
||||
var
|
||||
BlowFishKeyRec: TBlowFishKeyRec;
|
||||
StringStream: TStringStream = nil;
|
||||
Base64DecodingStream: TBase64DecodingStream = nil;
|
||||
BlowFishDeCryptStream: TBlowFishDeCryptStream = nil;
|
||||
begin
|
||||
Result:= EmptyStr;
|
||||
BlowFishKeyRec.cBlowFishKey:= MasterKey;
|
||||
BlowFishKeyRec.dwSize:= Length(MasterKey);
|
||||
|
||||
try
|
||||
StringStream:= TStringStream.Create(Data);
|
||||
Base64DecodingStream:= TBase64DecodingStream.Create(StringStream);
|
||||
|
||||
SetLength(Result, Base64DecodingStream.Size);
|
||||
BlowFishDeCryptStream:= TBlowFishDeCryptStream.Create(BlowFishKeyRec.bBlowFishKey, BlowFishKeyRec.dwSize, Base64DecodingStream);
|
||||
BlowFishDeCryptStream.Read(PAnsiChar(Result)^, Base64DecodingStream.Size);
|
||||
finally
|
||||
FreeThenNil(BlowFishDeCryptStream);
|
||||
FreeThenNil(Base64DecodingStream);
|
||||
FreeThenNil(StringStream);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TPasswordStore }
|
||||
|
||||
function TPasswordStore.WritePassword(Prefix, Name: UTF8String;
|
||||
const Password: AnsiString): Boolean;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
function TPasswordStore.ReadPassword(Prefix, Name: UTF8String; out
|
||||
Password: AnsiString): Boolean;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
initialization
|
||||
try
|
||||
PasswordStore:= TPasswordStore.Create(gpIniDir + 'pwd.ini', fmOpenReadWrite);
|
||||
except
|
||||
DebugLn('Can not create secure password store!');
|
||||
end;
|
||||
|
||||
finalization
|
||||
FreeThenNil(PasswordStore);
|
||||
|
||||
end.
|
||||
|
||||
|
|
@ -54,6 +54,7 @@ type
|
|||
FsFindNext : TFsFindNext;
|
||||
FsFindClose : TFsFindClose;
|
||||
{ Optional }
|
||||
FsSetCryptCallback: TFsSetCryptCallback;
|
||||
FsGetDefRootName : TFsGetDefRootName;
|
||||
FsGetFile : TFsGetFile;
|
||||
FsPutFile : TFsPutFile;
|
||||
|
|
@ -188,6 +189,7 @@ begin
|
|||
FsFindNext := TFsFindNext(GetProcAddress(FModuleHandle,'FsFindNext'));
|
||||
FsFindClose := TFsFindClose(GetProcAddress(FModuleHandle,'FsFindClose'));
|
||||
{ Optional }
|
||||
FsSetCryptCallback:= TFsSetCryptCallback(GetProcAddress(FModuleHandle,'FsSetCryptCallback'));
|
||||
FsGetDefRootName := TFsGetDefRootName(GetProcAddress(FModuleHandle,'FsGetDefRootName'));
|
||||
FsExecuteFile := TFsExecuteFile(GetProcAddress(FModuleHandle,'FsExecuteFile'));
|
||||
FsGetFile := TFsGetFile(GetProcAddress(FModuleHandle,'FsGetFile'));
|
||||
|
|
@ -232,6 +234,7 @@ begin
|
|||
FsFindNext := nil;
|
||||
FsFindClose := nil;
|
||||
{ Optional }
|
||||
FsSetCryptCallback := nil;
|
||||
FsGetDefRootName := nil;
|
||||
FsGetFile := nil;
|
||||
FsPutFile := nil;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ type
|
|||
{R} TFsFindNext=function(Hdl:thandle;var FindData:tWIN32FINDDATA):boolean;stdcall;
|
||||
{R} TFsFindClose=function(Hdl:thandle):integer;stdcall;
|
||||
{Optional}
|
||||
{R} TFsSetCryptCallback = procedure(pCryptProc:TCryptProc;CryptoNr,Flags:integer); stdcall;
|
||||
{R} TFsMkDir = function(RemoteDir:pchar):boolean; stdcall;
|
||||
{R} TFsGetFile = function(RemoteName,LocalName:pchar;CopyFlags:integer; RemoteInfo:pRemoteInfo):integer; stdcall;
|
||||
{R} TFsPutFile=function(LocalName,RemoteName:pchar;CopyFlags:integer):integer; stdcall;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue