Jump to content
KostasR

MARSWebServer Service config for HTTPS

Recommended Posts

Hello All,

 

I am currently trying to link MARS with an IO handler in order to be able to use HTTPS.
Inspired by this post, stackoverflow indy-ssl-delphi-server

This is what my code looks like. HTTPS is ignored. HTTP requests go through.
Does anyone have MARS running with HTTPS?

 

 

procedure TWEBService.ServiceCreate(Sender: TObject);
var
  LScheduler: TIdSchedulerOfThreadPool;
begin
  Name := TServerEngine.Default.Parameters.ByNameText('ServiceName', Name).AsString;
  DisplayName := TServerEngine.Default.Parameters.ByNameText('ServiceDisplayName', DisplayName).AsString;

  if WebRequestHandler <> nil then
    WebRequestHandler.WebModuleClass := WebModuleClass;

  FServer := TIdHTTPWebBrokerBridge.Create(nil);

  FIOHandler.SSLOptions.CertFile := 'certificate.crt';
  FIOHandler.SSLOptions.KeyFile := 'private.key';
  FIOHandler.SSLOptions.RootCertFile := 'SSLroot.crt';
  FIOHandler.SSLOptions.Method := sslvSSLv23;
  FIOHandler.OnVerifyPeer := IOHandlerVerifyPeer;
  FServer.IOHandler := FIOHandler;
  FServer.OnQuerySSLPort := OnQuerySSLPort;


  try
    FServer.DefaultPort := TServerEngine.Default.Port;

    LScheduler := TIdSchedulerOfThreadPool.Create(FServer);
    try
      LScheduler.PoolSize := TServerEngine.Default.ThreadPoolSize;
      FServer.Scheduler := LScheduler;
      FServer.MaxConnections := LScheduler.PoolSize;
      FServer.OnParseAuthentication := ParseAuthenticationHandler;
    except
      FServer.Scheduler.Free;
      FServer.Scheduler := nil;
      raise;
    end;
  except
    FIOHandler.Free;
    FServer.Free;
    raise;
  end;
end;

 

Regards,

  Kostas

Share this post


Link to post

Hi, sorry for the late, I've just pushed some new feature about this in MARS.

 

Here's also a blog post about it: https://blog.andreamagni.eu/2021/01/mars-1000th-commit-added-support-to-indy-standalone-ssl/

 

Beware: I've also refactored many deployment options available to use TMARSHttpServerIndy and less WebBroker stuff. Let me know if you encounter any issue.

 

Sincerely,

Andrea

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×