2016-03-03 16:32:50 +01:00
|
|
|
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
|
|
|
|
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
|
|
|
|
// JCL_DEBUG_EXPERT_DELETEMAPFILE OFF
|
2014-03-03 14:45:55 +01:00
|
|
|
program SSLSample;
|
|
|
|
{$APPTYPE CONSOLE}
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils,
|
|
|
|
IdHTTPWebBrokerBridge,
|
|
|
|
IdSSLOpenSSL,
|
2018-05-16 19:46:29 +02:00
|
|
|
System.IOUtils,
|
2014-03-03 14:45:55 +01:00
|
|
|
Web.WebReq,
|
|
|
|
Web.HTTPApp,
|
|
|
|
Web.WebBroker,
|
|
|
|
WebModuleUnit1 in 'WebModuleUnit1.pas' {WebModule1: TWebModule} ,
|
|
|
|
MyControllerU in 'MyControllerU.pas',
|
|
|
|
MyObjectsU in 'MyObjectsU.pas';
|
|
|
|
|
|
|
|
{$R *.res}
|
|
|
|
|
|
|
|
type
|
|
|
|
TGetSSLPassword = class
|
2016-03-03 16:32:50 +01:00
|
|
|
procedure OnGetSSLPassword(var APassword: {$IF CompilerVersion < 27}AnsiString{$ELSE}string{$ENDIF});
|
2014-03-03 14:45:55 +01:00
|
|
|
end;
|
|
|
|
|
2016-03-03 16:32:50 +01:00
|
|
|
procedure TGetSSLPassword.OnGetSSLPassword(var APassword: {$IF CompilerVersion < 27}AnsiString{$ELSE}string{$ENDIF});
|
2014-03-03 14:45:55 +01:00
|
|
|
begin
|
|
|
|
APassword := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure RunServer(APort: Integer);
|
|
|
|
var
|
|
|
|
LServer: TIdHTTPWebBrokerBridge;
|
|
|
|
LGetSSLPassword: TGetSSLPassword;
|
|
|
|
LIOHandleSSL: TIdServerIOHandlerSSLOpenSSL;
|
|
|
|
begin
|
|
|
|
Writeln(Format('Starting DMVCFramework HTTPS Server or port %d', [APort]));
|
|
|
|
LGetSSLPassword := nil;
|
|
|
|
LServer := TIdHTTPWebBrokerBridge.Create(nil);
|
|
|
|
try
|
|
|
|
LGetSSLPassword := TGetSSLPassword.Create;
|
|
|
|
LIOHandleSSL := TIdServerIOHandlerSSLOpenSSL.Create(LServer);
|
2017-07-14 17:38:51 +02:00
|
|
|
LIOHandleSSL.SSLOptions.CertFile := 'cacert.pem';
|
2014-03-03 14:45:55 +01:00
|
|
|
LIOHandleSSL.SSLOptions.RootCertFile := '';
|
2017-07-14 17:38:51 +02:00
|
|
|
LIOHandleSSL.SSLOptions.KeyFile := 'privkey.pem';
|
2014-03-03 14:45:55 +01:00
|
|
|
LIOHandleSSL.OnGetPassword := LGetSSLPassword.OnGetSSLPassword;
|
|
|
|
LServer.IOHandler := LIOHandleSSL;
|
|
|
|
LServer.DefaultPort := APort;
|
|
|
|
|
|
|
|
LServer.Active := True;
|
2018-05-16 19:46:29 +02:00
|
|
|
Writeln('Press RETURN to stop the server');
|
|
|
|
ReadLn;
|
2014-03-03 14:45:55 +01:00
|
|
|
finally
|
|
|
|
LServer.Free;
|
|
|
|
LGetSSLPassword.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-05-16 19:46:29 +02:00
|
|
|
const
|
|
|
|
OPENSSL_LIBS: array of string = ['libeay32.dll', 'ssleay32.dll'];
|
|
|
|
|
|
|
|
procedure CheckOPENSSLLibs;
|
|
|
|
var
|
|
|
|
lOpenSSLLib: String;
|
|
|
|
begin
|
|
|
|
// Just a check for
|
|
|
|
for lOpenSSLLib in OPENSSL_LIBS do
|
|
|
|
begin
|
|
|
|
Write('Checking ', lOpenSSLLib, '...');
|
|
|
|
if not TFile.Exists(lOpenSSLLib) then
|
|
|
|
raise Exception.CreateFmt('Required OPENSSL library not found in the exe folder: %s' + sLineBreak +
|
|
|
|
'Download INDY compatible OpenSSL Libraries from http://indy.fulgan.com/SSL/', [lOpenSSLLib]);
|
|
|
|
Writeln('OK');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-03-03 14:45:55 +01:00
|
|
|
begin
|
2018-05-16 19:46:29 +02:00
|
|
|
CheckOPENSSLLibs;
|
2014-03-03 14:45:55 +01:00
|
|
|
try
|
|
|
|
if WebRequestHandler <> nil then
|
|
|
|
WebRequestHandler.WebModuleClass := WebModuleClass;
|
2018-05-16 19:46:29 +02:00
|
|
|
RunServer(443 { standard https port } );
|
2014-03-03 14:45:55 +01:00
|
|
|
except
|
|
|
|
on E: Exception do
|
|
|
|
Writeln(E.ClassName, ': ', E.Message);
|
|
|
|
end
|
|
|
|
|
|
|
|
end.
|