Skip to content

Commit 8c38f92

Browse files
committed
Updated Test Programs
1 parent 48b8204 commit 8c38f92

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Test/openssl-client/TestClient.pas

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ interface
2929

3030
uses
3131
Classes, SysUtils, {$IFDEF FPC}CustApp,{$ENDIF}IdIOHandler, IdHTTP,
32-
IdSSL, IdSSLOpenSSL;
32+
IdSSL, IdSSLOpenSSL, IdSSLOpenSSLX509;
3333

3434
const
35-
remoteSource = 'https://www.mwasoftware.co.uk/openssltest.txt';
35+
remoteSource = 'https://test.mwasoftware.co.uk/openssltest.txt';
3636
sGetException = 'Error: Status = %d returned when GETting %s';
3737
rcAccept = 'Application/txt';
3838
{$if not declared(DirectorySeparator)}
@@ -82,6 +82,7 @@ TBasicHttpsClient = class(TCustomApplication)
8282
function CertificateType(Certificate: TIdX509): string;
8383
function ClientVerifyPeer(Certificate: TIdX509; AOk: Boolean; ADepth, AError: Integer): Boolean;
8484
procedure ShowCertificate(Certificate : TIdX509);
85+
procedure HandleStatusInfo(const AMsg: String);
8586
protected
8687
procedure DoRun; override;
8788
public
@@ -102,7 +103,7 @@ TResponseTextBuffer = class(TMemoryStream)
102103

103104
implementation
104105

105-
uses IdSSLOpenSSLAPI;
106+
uses IdSSLOpenSSLAPI, IdSSLOpenSSLOptions, IdSSLOpenSSLSocket;
106107

107108
{$IFDEF LOCAL_TCUSTOMAPP}
108109
function TCustomApplication.Exename: string;
@@ -207,6 +208,7 @@ function TBasicHttpsClient.GetSSLHandler(AOwner: TComponent): TIdIOHandler;
207208
else
208209
IOHandler.SSLOptions.VerifyMode := [];
209210
IOHandler.OnVerifyPeer := ClientVerifyPeer;
211+
IOHandler.OnStatusInfo := HandleStatusInfo;
210212
FSSLHandler := IOHandler;
211213
Result := IOHandler;
212214
end;
@@ -286,6 +288,11 @@ procedure TBasicHttpsClient.ShowCertificate(Certificate : TIdX509);
286288
writeln;
287289
end;
288290

291+
procedure TBasicHttpsClient.HandleStatusInfo(const AMsg: String);
292+
begin
293+
writeln('Status Info: ',AMsg);
294+
end;
295+
289296
procedure TBasicHttpsClient.DoRun;
290297

291298
var i: integer;

Test/openssl-server/testserver.pas

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ interface
2323
uses
2424
Classes, SysUtils, {$IFDEF FPC}CustApp,{$ENDIF}IdIOHandler, IdHTTP,
2525
IdSSL, IdSSLOpenSSL, IdHeaderList, IdContext,
26-
IdCustomHTTPServer, IdHTTPServer, IdServerIOHandler, IdGlobal;
26+
IdCustomHTTPServer, IdHTTPServer, IdServerIOHandler, IdGlobal,
27+
IdSSLOpenSSLX509;
2728

2829
const
2930
SSLServerPort = 8080;
@@ -77,6 +78,7 @@ TOpenSSLServerTest = class(TCustomApplication)
7778
function IsDirectoryEmpty(Path: string): boolean;
7879
procedure HandleCommandGet(AContext: TIdContext;
7980
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
81+
procedure HandleStatusInfo(const AMsg: String);
8082
procedure GetMyPassword(var Password: String);
8183
procedure QuerySSLPort(APort: TIdPort; var VUseSSL: Boolean);
8284
function CertificateType(Certificate: TIdX509): string;
@@ -103,7 +105,7 @@ TResponseTextBuffer = class(TMemoryStream)
103105

104106
implementation
105107

106-
uses IdSSLOpenSSLAPI;
108+
uses IdSSLOpenSSLAPI, IdSSLOpenSSLOptions;
107109

108110
{$IFDEF LOCAL_TCUSTOMAPP}
109111
function TCustomApplication.Exename: string;
@@ -217,9 +219,12 @@ function TOpenSSLServerTest.GetSSLServerHandler(AOwner : TComponent
217219
IOHandler.SSLOptions.RootCertFile := MyRootCertFile;
218220
IOHandler.SSLOptions.CertFile := MyCertFile;
219221
IOHandler.SSLOptions.KeyFile := MyKeyFile;
222+
{$IFDEF LEGACY_VERSION}
220223
IOHandler.SSLOptions.Method := sslvTLSv1_2;
224+
{$ENDIF}
221225
IOHandler.OnGetPassword := GetMyPassword;
222226
IOHandler.OnVerifyPeer := ServerVerifyPeer;
227+
IOHandler.OnStatusInfo := HandleStatusInfo;
223228
if FClientVerification then
224229
begin
225230
IOHandler.SSLOptions.VerifyMode := [sslvrfPeer,sslvrfFailIfNoPeerCert];
@@ -257,6 +262,11 @@ procedure TOpenSSLServerTest.HandleCommandGet(AContext: TIdContext;
257262
AResponseInfo.ContentStream.Position := 0;
258263
end;
259264

265+
procedure TOpenSSLServerTest.HandleStatusInfo(const AMsg: String);
266+
begin
267+
writeln('Server Status Info: ',AMsg);
268+
end;
269+
260270
procedure TOpenSSLServerTest.GetMyPassword(var Password : String);
261271
begin
262272
Password := myPassword;
@@ -326,8 +336,6 @@ procedure TOpenSSLServerTest.DoRun;
326336
writeln('LibCrypto: ',GetIOpenSSLDDL.GetLibCryptoFilePath);
327337
writeln('LibSSL: ',GetIOpenSSLDDL.GetLibSSLFilePath);
328338
end;
329-
if not LoadOpenSSLLibrary then
330-
raise Exception.Create('OpenSSL Library Failed to load');
331339

332340
if GetIOpenSSLDDL <> nil then
333341
with GetIOpenSSLDDL.GetFailedToLoadList do

0 commit comments

Comments
 (0)