<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    Hi,<br>
    <br>
    Out of the info on the wiki I created a simple Webserver with a
    server-certificate.<br>
    To get this code working you need to create the necessary
    certificate.<br>
    For this I used xca from <a class="moz-txt-link-freetext" href="https://hohnstaedt.de">https://hohnstaedt.de</a> but you can use
    OpenSSL to do the same.<br>
     <br>
    <br>
    [code=pascal]<br>
    program webserver;<br>
    <br>
    {$mode objfpc}{$H+}<br>
    <br>
    uses<br>
      {$ifdef UNIX}<br>
      cthreads, cmem,<br>
      {$endif}<br>
      fphttpapp,<br>
      httpdefs,<br>
      httproute,<br>
      opensslsockets;<br>
    <br>
    var<br>
      fUseSSL: boolean;<br>
    const<br>
      fCertificatePassword: string = 'hello';<br>
      fCertificateHostName: string = 'localhost';<br>
      fCertificateFileName: string = 'Server.crt';<br>
      fCertificatePrivateKey: string = 'Server.key';<br>
    <br>
      procedure route1(aReq: TRequest; aResp: TResponse);<br>
      begin<br>
        aResp.Content := '<html><body><h1>Route 1 The
    Default</h1></body></html>';<br>
      end;<br>
    <br>
      procedure route2(aReq: TRequest; aResp: TResponse);<br>
      begin<br>
        aResp.Content := '<html><body><h1>Route
    2</h1></body></html>';<br>
      end;<br>
    <br>
    begin<br>
      HTTPRouter.RegisterRoute('/', @route1);<br>
      HTTPRouter.RegisterRoute('/2', @route2);<br>
      Application.Port := 1999;<br>
      fUseSSL :=true;<br>
      Application.UseSSL := fUseSSL;<br>
      if fUseSSL then<br>
      begin<br>
        Application.CertificateData.KeyPassword := fCertificatePassword;<br>
        Application.CertificateData.HostName := fCertificateHostName;<br>
        Application.CertificateData.Certificate.FileName :=
    fCertificateFileName;<br>
        Application.CertificateData.PrivateKey.FileName :=
    fCertificatePrivateKey;<br>
      end;<br>
      Application.Threaded := True;<br>
      Application.Initialize;<br>
      Application.Run;<br>
    end.<br>
    [/code]<br>
    <br>
    My questions are: <br>
    <b>- How can I modify this example to enforce the use of a client
      certificate?<br>
      - How can I verify a client certificate in the server?</b><br>
    <br>
    In the TLS handshake a client certificate is optional but the server
    can ensure that it is mandatory.<br>
    <br>
    Any help, pointers, sample code is appreciated.<br>
    <br>
    Sincerely,<br>
    <br>
    Jos<br>
  </body>
</html>