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,
|
|
|
|
Winapi.Windows,
|
|
|
|
IdHTTPWebBrokerBridge,
|
|
|
|
IdSSLOpenSSL,
|
|
|
|
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
|
|
|
|
LInputRecord: TInputRecord;
|
|
|
|
LEvent: DWord;
|
|
|
|
LHandle: THandle;
|
|
|
|
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);
|
|
|
|
LIOHandleSSL.SSLOptions.CertFile := '..\..\cacert.pem';
|
|
|
|
LIOHandleSSL.SSLOptions.RootCertFile := '';
|
|
|
|
LIOHandleSSL.SSLOptions.KeyFile := '..\..\privkey.pem';
|
|
|
|
LIOHandleSSL.OnGetPassword := LGetSSLPassword.OnGetSSLPassword;
|
|
|
|
LServer.IOHandler := LIOHandleSSL;
|
|
|
|
LServer.DefaultPort := APort;
|
|
|
|
|
|
|
|
LServer.Active := True;
|
|
|
|
Writeln('Press ESC to stop the server');
|
|
|
|
|
|
|
|
LHandle := GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
while True do
|
|
|
|
begin
|
|
|
|
Win32Check(ReadConsoleInput(LHandle, LInputRecord, 1, LEvent));
|
|
|
|
if (LInputRecord.EventType = KEY_EVENT) and
|
|
|
|
LInputRecord.Event.KeyEvent.bKeyDown and
|
|
|
|
(LInputRecord.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE) then
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
LServer.Free;
|
|
|
|
LGetSSLPassword.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
if WebRequestHandler <> nil then
|
|
|
|
WebRequestHandler.WebModuleClass := WebModuleClass;
|
|
|
|
RunServer(8080);
|
|
|
|
except
|
|
|
|
on E: Exception do
|
|
|
|
Writeln(E.ClassName, ': ', E.Message);
|
|
|
|
end
|
|
|
|
|
|
|
|
end.
|