Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for client certificates on non-windows machines #1202

Merged
merged 2 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions connoptions.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ inherited ConnOptionsForm: TConnOptionsForm
Position = poMainFormCenter
object Page: TPageControl[0]
Left = 8
Height = 283
Height = 329
Top = 69
Width = 513
ActivePage = tabConnection
Expand Down Expand Up @@ -94,9 +94,10 @@ inherited ConnOptionsForm: TConnOptionsForm
object cbSSL: TCheckBox
Left = 260
Height = 19
Top = 75
Top = 77
Width = 60
Caption = 'Use SSL'
OnClick = cbSSLClick
TabOrder = 2
end
object edHost: TEdit
Expand Down Expand Up @@ -171,6 +172,38 @@ inherited ConnOptionsForm: TConnOptionsForm
Caption = 'Always auto-reconnect'
TabOrder = 7
end
object txCertFile: TLabel
Left = 8
Height = 18
Top = 245
Width = 105
Caption = 'Client Certificate:'
ParentColor = False
end
object edCertFile: TEdit
Left = 180
Height = 32
Top = 242
Width = 316
TabOrder = 10
end
object txCertPass: TLabel
Left = 8
Height = 18
Top = 274
Width = 72
Caption = 'Private Key:'
ParentColor = False
end
object edCertPass: TEdit
Left = 180
Height = 32
Top = 271
Width = 316
EchoMode = emPassword
PasswordChar = '*'
TabOrder = 11
end
end
object tabProxy: TTabSheet
Caption = 'Proxy'
Expand Down
40 changes: 40 additions & 0 deletions connoptions.pas
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ TConnOptionsForm = class(TBaseForm)
edPort: TSpinEdit;
txHost: TLabel;
txPassword: TLabel;
txCertFile: TLabel;
edCertFile: TEdit;
txCertPass: TLabel;
edCertPass: TEdit;
procedure btDelClick(Sender: TObject);
procedure btNewClick(Sender: TObject);
procedure btOKClick(Sender: TObject);
Expand All @@ -110,6 +114,7 @@ TConnOptionsForm = class(TBaseForm)
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure tabPathsShow(Sender: TObject);
procedure cbSSLClick(Sender: TObject);
private
FCurConn: string;
FCurHost: string;
Expand Down Expand Up @@ -168,6 +173,15 @@ procedure TConnOptionsForm.cbAuthClick(Sender: TObject);
cbAskPasswordClick(nil);
end;

procedure TConnOptionsForm.cbSSLClick(Sender: TObject);
begin
{$ifndef windows}
EnableControls(cbSSL.Checked, [txCertFile, edCertFile, txCertPass, edCertPass]);
{$else}
EnableControls(False, [txCertFile, edCertFile, txCertPass, edCertPass]);
{$endif windows}
end;

procedure TConnOptionsForm.cbConnectionSelect(Sender: TObject);
var
i: integer;
Expand Down Expand Up @@ -201,6 +215,10 @@ procedure TConnOptionsForm.cbShowAdvancedClick(Sender: TObject);
begin
txRpcPath.Visible:=cbShowAdvanced.Checked;
edRpcPath.Visible:=cbShowAdvanced.Checked;
txCertFile.Visible:=cbShowAdvanced.Checked;
edCertFile.Visible:=cbShowAdvanced.Checked;
txCertPass.Visible:=cbShowAdvanced.Checked;
edCertPass.Visible:=cbShowAdvanced.Checked;
{$ifndef LCLgtk2}
tabConnection.TabVisible:=cbShowAdvanced.Checked;
{$endif LCLgtk2}
Expand Down Expand Up @@ -506,6 +524,12 @@ procedure TConnOptionsForm.LoadConnSettings(const ConnName: string);
FCurHost:=edHost.Text;
edPort.Value:=ReadInteger(Sec, 'Port', 9091);
cbSSL.Checked:=ReadBool(Sec, 'UseSSL', False);
edCertFile.Text:=ReadString(Sec, 'CertFile', '');
if cbSSL.Checked then
if ReadString(Sec, 'CertPass', '') <> '' then
edCertPass.Text:='******'
else
edCertPass.Text:='';
cbAutoReconnect.Checked:=ReadBool(Sec, 'Autoreconnect', False);
edUserName.Text:=ReadString(Sec, 'UserName', '');
s:=ReadString(Sec, 'Password', '');
Expand All @@ -519,6 +543,7 @@ procedure TConnOptionsForm.LoadConnSettings(const ConnName: string);
edPassword.Text:='';
end;
cbAuthClick(nil);
cbSSLClick(nil);
edRpcPath.Text:=ReadString(Sec, 'RpcPath', DefaultRpcPath);
cbUseProxy.Checked:=ReadBool(Sec, 'UseProxy', False);
cbUseSocks5.Checked:=ReadBool(Sec, 'UseSockProxy', False);
Expand Down Expand Up @@ -562,6 +587,18 @@ procedure TConnOptionsForm.SaveConnSettings(const ConnName: string);
Sec:='Connection.' + ConnName;
WriteString(Sec, 'Host', Trim(edHost.Text));
WriteBool(Sec, 'UseSSL', cbSSL.Checked);
if not cbSSL.Checked then begin
edCertFile.Text:='';
edCertPass.Text:='';
end;
WriteString(Sec, 'CertFile', edCertFile.Text);
if edCertPass.Text <> '******' then begin
if edCertPass.Text = '' then
s:=''
else
s:=EncodeBase64(edCertPass.Text);
WriteString(Sec, 'CertPass', s);
end;
WriteBool(Sec, 'Autoreconnect', cbAutoReconnect.Checked);
WriteInteger(Sec, 'Port', edPort.Value);
if not cbAuth.Checked then begin
Expand Down Expand Up @@ -631,6 +668,9 @@ function TConnOptionsForm.IsConnSettingsChanged(const ConnName: string): boolean
Result:=(edPort.Value <> ReadInteger(Sec, 'Port', 9091)) or
(edHost.Text <> ReadString(Sec, 'Host', '')) or
(cbSSL.Checked <> ReadBool(Sec, 'UseSSL', False)) or
(edCertFile.Text <> ReadString(Sec, 'CertFile', '')) or
((ReadString(Sec, 'CertPass', '') = '') and (edCertPass.Text <> '')) or
((ReadString(Sec, 'CertPass', '') <> '') and (edCertPass.Text <> '******')) or
(cbAutoReconnect.Checked <> ReadBool(Sec, 'Autoreconnect', False)) or
(edUserName.Text <> ReadString(Sec, 'UserName', '')) or
((ReadString(Sec, 'Password', '') = '') and (edPassword.Text <> '')) or
Expand Down
4 changes: 4 additions & 0 deletions main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4985,8 +4985,12 @@ function TMainForm.DoConnect: boolean;
if i >= 0 then
FPasswords.Delete(i);

RpcObj.Http.Sock.SSL.PFXfile:='';
RpcObj.Http.Sock.SSL.KeyPassword:='';
if Ini.ReadBool(Sec, 'UseSSL', False) then begin
RpcObj.InitSSL;
RpcObj.Http.Sock.SSL.PFXfile:=Ini.ReadString(Sec, 'CertFile', '');
RpcObj.Http.Sock.SSL.KeyPassword:=DecodeBase64(Ini.ReadString(Sec, 'CertPass', ''));
if not IsSSLloaded then begin
MessageDlg(Format(sSSLLoadError, [DLLSSLName, DLLUtilName]), mtError, [mbOK], 0);
exit;
Expand Down
2 changes: 1 addition & 1 deletion options.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ inherited OptionsForm: TOptionsForm
Position = poMainFormCenter
object Page: TPageControl[0]
Left = 8
Height = 281
Height = 329
Top = 8
Width = 548
ActivePage = tabGeneral
Expand Down