Contents · Forum Home · StreamSec Tools 4.1.5.364 documentation

Choose a component tier

A TLS connection needs a TLS engine: the component that holds the trust anchors, the client certificate if there is one, and the TLS options. The client components come in two tiers that differ only in who owns that engine.

Both do the same requests the same way: everything in Download a page over HTTPS applies to either.

The components on this page are normally placed on a form or a data module at design time and set up in the Object Inspector. The sample creates them in code instead, because code shows at a glance which properties are changed from their default values.
The client checks, on every connection, that the server's certificate is issued for the host name it connects to. Give it the DNS name the certificate carries, not the server's IP address: with an address the connection fails although the server's certificate is valid. To connect by address, set ServerName to the name in the certificate - see Download a page over HTTPS.

When to share an engine

constructor tTwoServices.Create(const aCAFile, aOrdersHost, aStockHost: string;
  aPort: Integer);
begin
  inherited Create;
  { One engine: the trust anchors (and, with mutual TLS, the client
    certificate) are set once, and what the engine learns - fetched
    revocation lists, for one - serves every client that uses it. }
  Engine := TsmSimpleTLSInternalServer.Create(nil);
  if Engine.LoadRootCertsFromFile(aCAFile) = 0 then
    raise eHTTPSClientError.CreateFmt('No certificate in %s', [aCAFile]);
  { Two clients, two servers, one engine. }
  Orders := TsmAdvancedHTTPSClient.Create(nil);
  Orders.TLSServer := Engine;
  Orders.Host := aOrdersHost;
  Orders.Port := aPort;
  Stock := TsmAdvancedHTTPSClient.Create(nil);
  Stock.TLSServer := Engine;
  Stock.Host := aStockHost;
  Stock.Port := aPort;
end;

destructor tTwoServices.Destroy;
begin
  { The clients first, then the engine they use. }
  Orders.Free;
  Stock.Free;
  Engine.Free;
  inherited;
end;

A TsmAdvancedHTTPSClient whose TLSServer is left empty uses the application-wide engine GlobalServer, and refuses to connect when there is none.

On a form

Drop a TsmSimpleTLSInternalServer and the clients, and pick the engine in each client's TLSServer property in the Object Inspector. To give that engine the public web roots, add a TsmCCADBTrustAnchors and set its Engine - see Choose which servers a client trusts.

Reference

TsmHTTPSClient · TsmAdvancedHTTPSClient · TsmSimpleTLSInternalServer · StreamSec.Mobile.HTTPSClient · StreamSec.Mobile.TlsInternalServer