Skip to content

Commit

Permalink
WIP for encoding hnadling in waptconsole
Browse files Browse the repository at this point in the history
inc to 1.5.1.20
  • Loading branch information
htouvet committed Mar 12, 2018
1 parent 70f2d90 commit d9de3c1
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 109 deletions.
20 changes: 6 additions & 14 deletions wapt-get/waptcommon.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ interface
constructor Create(const msg: string;AHTTPStatus:Integer);
end;

function GetWaptPersonalCertificatePath: Utf8String;

Function GetWaptLocalURL:String;

function AppLocalDir: Utf8String; // returns Users/<user>/local/appdata/<application_name>
Expand Down Expand Up @@ -209,6 +207,9 @@ TWaptRepo = class(TPersistent)

HideUnavailableActions:Boolean = False;

WaptPersonalCertificatePath: String ='';


WAPTServerMinVersion='1.5.1.13';

FAppIniFilename:Utf8String = '';
Expand Down Expand Up @@ -414,8 +415,6 @@ procedure TWaptRepo.SetTimeOut(AValue: Integer);
end;

procedure TWaptRepo.LoadFromInifile(IniFilename: String; Section: String;Reset:Boolean=True);
var
ini:TIniFile;
begin
if Section ='' then
Section := Name;
Expand Down Expand Up @@ -447,8 +446,6 @@ procedure TWaptRepo.SetTimeOut(AValue: Integer);
end;

procedure TWaptRepo.SaveToInifile(IniFilename: String; Section: String);
var
ini:TIniFile;
begin
if Section ='' then
Section := Name;
Expand Down Expand Up @@ -1268,11 +1265,6 @@ function GetWaptRepoURL: Utf8String;
end;


function GetWaptPersonalCertificatePath: Utf8String;
begin
result := utf8Decode(IniReadString(WaptIniFilename,'global','personal_certificate_path'));
end;

function GetWaptLocalURL: String;
begin
if waptservice_port >0 then
Expand Down Expand Up @@ -1417,6 +1409,8 @@ function ReadWaptConfig(inifilename:String = ''): Boolean;
DefaultPackagePrefix := ReadString('global','default_package_prefix','');
DefaultSourcesRoot := ReadString('global','default_sources_root','');

WaptPersonalCertificatePath := ReadString('global','personal_certificate_path','');

Result := True

finally
Expand All @@ -1433,8 +1427,6 @@ function WaptDBPath: Utf8String;
result := ExtractFilePath(ParamStr(0))+'db\waptdb.sqlite'
end;



//////

function VarArrayToStr(const vArray: variant): string;
Expand Down Expand Up @@ -1838,7 +1830,7 @@ function CreateWaptSetup(default_public_cert:Utf8String='';default_repo_url:Utf8
Run(format('"%s" "%s"',[inno_fn,custom_iss]),'',3600000,'','','',OnProgress);
Result := AppendPathDelim(destination) + WaptEdition + '.exe';
signtool := AppendPathDelim(wapt_base_dir) + 'utils\signtool.exe';
p12keyPath := ChangeFileExt(GetWaptPersonalCertificatePath,'.p12');
p12keyPath := ChangeFileExt(WaptPersonalCertificatePath,'.p12');
if FileExists(signtool) and FileExists(p12keypath) then
Run(format('"%s" sign /f "%s" "%s"',[signtool,p12keypath,Result]),'',3600000,'','','',OnProgress);

Expand Down
2 changes: 1 addition & 1 deletion wapt-get/waptget.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<MajorVersionNr Value="1"/>
<MinorVersionNr Value="5"/>
<RevisionNr Value="1"/>
<BuildNr Value="19"/>
<BuildNr Value="20"/>
<StringTable CompanyName="Tranquil IT Systems" ProductName="WAPT Installation" ProductVersion="1.5.0"/>
</VersionInfo>
<BuildModes Count="1" Active="Default">
Expand Down
29 changes: 26 additions & 3 deletions wapt-get/waptget.psproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ FileName=C:\tranquilit\wapt\waptdevutils.py

[Project\ChildNodes\Node0\ChildNodes\Node7]
ClassName=TProjectFileNode
FileName=C:\tranquilit\wapt\wapt-get.py
FileName=C:\tranquilit\wapt\wapt-get.ini

[Project\ChildNodes\Node0\ChildNodes\Node8]
ClassName=TProjectFileNode
FileName=C:\tranquilit\wapt\wapt-get.ini
FileName=C:\tranquilit\wapt\wapt-get.py

[Project\ChildNodes\Node0\ChildNodes\Node9]
ClassName=TProjectFileNode
Expand Down Expand Up @@ -1462,8 +1462,31 @@ WorkingDirectory=$[ActiveScript-Dir]
ShortCut=0
MessagesFormat=$[FileName] $[LineNumber]

[Project\ChildNodes\Node1\ChildNodes\Node58]
ClassName=TProjectRunConfiguationNode
Name=lists été

[Project\ChildNodes\Node1\ChildNodes\Node58\RunConfig]
ScriptName=C:\tranquilit\wapt\wapt-get.py
EngineType=peRemote
ReinitializeBeforeRun=TRUE
Parameters=remove été
WorkingDir=$[ActiveScript-Dir]
WriteOutputToFile=FALSE
OutputFileName=$[ActiveScript-NoExt].log
AppendToFile=FALSE

[Project\ChildNodes\Node1\ChildNodes\Node58\RunConfig\ExternalRun]
Caption=External Run
Description=Run script using an external Python Interpreter
ApplicationName=$[PythonExe-Short]
Parameters=$[ActiveScript-Short]
WorkingDirectory=$[ActiveScript-Dir]
ShortCut=0
MessagesFormat=$[FileName] $[LineNumber]

[Project\ChildNodes\Node1\ChildNodes]
Count=58
Count=59

[Project\ChildNodes]
Count=2
Expand Down
32 changes: 20 additions & 12 deletions waptconsole/dmwaptpython.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface

uses
Classes, SysUtils, FileUtil, LazFileUtils, PythonEngine, PythonGUIInputOutput,
Classes, SysUtils, FileUtil, LazFileUtils, LazUTF8, PythonEngine, PythonGUIInputOutput,
VarPyth, vte_json, superobject, fpjson, jsonparser, DefaultTranslator,
Controls, WrapDelphi;

Expand Down Expand Up @@ -115,6 +115,7 @@ TDMPython = class(TDataModule)

function ExtractResourceString(Ident:String):RawByteString;

function PyUTF8Decode(s:RawByteString):UnicodeString;

var
DMPython: TDMPython;
Expand Down Expand Up @@ -258,7 +259,6 @@ function CheckGetLicence(LicenceFilename: String): Variant;

procedure TDMPython.SetWaptConfigFileName(AValue: Utf8String);
var
St:TStringList;
ini : TInifile;
i: integer;
begin
Expand Down Expand Up @@ -325,10 +325,13 @@ procedure TDMPython.SetLanguage(AValue: String);
function TDMPython.CertificateIsCodeSigning(crtfilename: String): Boolean;
var
crt: Variant;
vcrt_filename: Variant;

begin
if (crtfilename<>'') and FileExists(crtfilename) then
if (crtfilename<>'') and FileExistsUTF8(crtfilename) then
begin
crt := dmpython.waptcrypto.SSLCertificate(crt_filename:=crtfilename);
vcrt_filename := PyUTF8Decode(crtfilename);
crt := dmpython.waptcrypto.SSLCertificate(crt_filename:=vcrt_filename);
result := VarPythonAsString(crt.has_usage('code_signing')) <> '';
end
else
Expand Down Expand Up @@ -467,19 +470,21 @@ function TDMPython.getprivateKeyPassword: Ansistring;
PrivateKeyPath:String;
Password:String;
RetryCount:integer;
vcrt_filename: Variant;
begin
if not FileExists(GetWaptPersonalCertificatePath) then
if not FileExistsUTF8(WaptPersonalCertificatePath) then
FCachedPrivateKeyPassword := ''
else
begin
vcrt_filename:=PyUTF8Decode(WaptPersonalCertificatePath);
RetryCount:=3;
Password:= '';
// try without password
PrivateKeyPath := DMPython.waptdevutils.get_private_key_encrypted(certificate_path:=GetWaptPersonalCertificatePath(),password:=Password);
PrivateKeyPath := UTF8Encode(VarPythonAsString(DMPython.waptdevutils.get_private_key_encrypted(certificate_path:=vcrt_filename,password:=Password)));
if (PrivateKeyPath ='') and (FCachedPrivateKeyPassword<>'') then
begin
Password := FCachedPrivateKeyPassword;
PrivateKeyPath := DMPython.waptdevutils.get_private_key_encrypted(certificate_path:=GetWaptPersonalCertificatePath(),password:=Password);
PrivateKeyPath := UTF8Encode(VarPythonAsString(DMPython.waptdevutils.get_private_key_encrypted(certificate_path:=vcrt_filename,password:=Password)));
// not found any keys, reset pwd cache to empty.
if PrivateKeyPath='' then
FCachedPrivateKeyPassword := '';
Expand All @@ -490,11 +495,11 @@ function TDMPython.getprivateKeyPassword: Ansistring;
begin
with TvisPrivateKeyAuth.Create(Application.MainForm) do
try
laKeyPath.Caption := GetWaptPersonalCertificatePath;
laKeyPath.Caption := WaptPersonalCertificatePath;
if ShowModal = mrOk then
begin
Password := edPasswordKey.Text;
PrivateKeyPath := DMPython.waptdevutils.get_private_key_encrypted(certificate_path:=GetWaptPersonalCertificatePath(),password:=Password);
PrivateKeyPath := UTF8Encode(VarPythonAsString(DMPython.waptdevutils.get_private_key_encrypted(certificate_path:=vcrt_filename,password:=Password)));
if PrivateKeyPath<>'' then
begin
FCachedPrivateKeyPassword:=edPasswordKey.Text;
Expand All @@ -513,7 +518,7 @@ function TDMPython.getprivateKeyPassword: Ansistring;
end;

if PrivateKeyPath='' then
Raise Exception.CreateFmt('Unable to find and/or decrypt private key for personal certificate %s',[GetWaptPersonalCertificatePath]);
Raise Exception.CreateFmt('Unable to find and/or decrypt private key for personal certificate %s',[WaptPersonalCertificatePath]);
end;
Result := FCachedPrivateKeyPassword;
end;
Expand Down Expand Up @@ -587,7 +592,6 @@ function TDMPython.Getlicencing: Variant;

function TDMPython.GetMainWaptRepo: Variant;
var
ini:TIniFile;
section:String;
begin
if VarIsEmpty(FMainWaptRepo) then
Expand All @@ -613,7 +617,6 @@ function TDMPython.GetMainWaptRepo: Variant;

function TDMPython.GetWaptHostRepo: Variant;
var
ini:TIniFile;
section:String;
begin
if VarIsEmpty(FWaptHostRepo) then
Expand Down Expand Up @@ -770,5 +773,10 @@ function CreateSignedCert(keyfilename,
result := utf8encode(destcrt);
end;

function PyUTF8Decode(s:RawByteString):UnicodeString;
begin
result := UTF8Decode(s);
end;

end.

4 changes: 2 additions & 2 deletions waptconsole/uvischangekeypassword.pas
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ implementation
procedure TVisChangeKeyPassword.FormCreate(Sender: TObject);
begin
ScaleDPI(Self,96); // 96 is the DPI you designed
EdKeyFilename.text := VarPythonAsString(DMPython.waptdevutils.get_private_key_encrypted(certificate_path:=GetWaptPersonalCertificatePath(),password:=DMPython.privateKeyPassword));
EdKeyFilename.text := VarPythonAsString(DMPython.waptdevutils.get_private_key_encrypted(certificate_path:=FileExistsUTF8(WaptPersonalCertificatePath),password:=DMPython.privateKeyPassword));
if EdKeyFilename.Text <>'' then
edOldKeyPassword.Text:= DMPython.privateKeyPassword;
end;
Expand Down Expand Up @@ -90,7 +90,7 @@ procedure TVisChangeKeyPassword.FormCloseQuery(Sender: TObject;
CanClose:=FileExists(filename);
if CanClose then
begin
if EdKeyFilename.text = GetWaptPersonalCertificatePath then
if EdKeyFilename.text = WaptPersonalCertificatePath then
DMPython.privateKeyPassword := EdKeyPassword.Text;
ShowMessage('Password changed successfully');
end;
Expand Down
2 changes: 1 addition & 1 deletion waptconsole/uviscreatekey.pas
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ procedure TVisCreateKey.FormCreate(Sender: TObject);
pkey:Utf8String;
begin
ScaleDPI(Self,96); // 96 is the DPI you designed
pkey := GetWaptPersonalCertificatePath;
pkey := WaptPersonalCertificatePath;
if pkey<>'' then
DirectoryCert.Text:=ExtractFileDir(pkey)
else
Expand Down
Loading

0 comments on commit d9de3c1

Please sign in to comment.