Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

StreamSec.DSI.PkixOcspServer

Feature notes: PKIX / CMS implementation notes

Classes, interfaces and records

classTstOcspServer — component reference

(no public members)

recordTOcspCacheEntry

TOcspCacheEntry is one pre-produced, signed, nonce-less OCSPResponse held in the RFC 5019 lightweight-mode cache, keyed by the request CertID. It carries the stamped producedAt (== thisUpdate) and nextUpdate so the HTTP layer can emit Last-Modified / Expires / Cache-Control from it, plus a precomputed ETag. A record (value type) so the TDictionary manages its lifetime automatically.

RespDER: OctetString; ProducedAtUTC: TDateTime; NextUpdateUTC: TDateTime; ETag: string;

classTOcspListener

inherits from TThread

TOcspListener is the private accept loop. It listens on the server Address / Port and dispatches each accepted connection to a TOcspConnThread worker, polling its Terminated flag so that Active := False stops it promptly. The accept loop never touches a client socket itself, so a slow or hostile client cannot stall it.

constructor Create(aServer: TstOcspServer);

classTOcspConnThread

inherits from TThread

TOcspConnThread services a single accepted connection off the accept loop, so one slow or malicious client cannot block the responder from answering everyone else. It is FreeOnTerminate and decrements the server's active- connection counter when it exits. The connection is owned by the worker: the worker closes and frees it.

constructor Create(aServer: TstOcspServer; aConn: tAbstractSocket);

classTstOcspServer — component reference

inherits from TComponent

TstOcspServer

OCSP responder component. Configure CertificateManager, Index, CRLFilter, Address and Port, then set Active to True.

constructor Create(AOwner: TComponent); override;
Create constructs the responder with its published defaults (Port 80, ResponseValidity 3600 s, Nonce True, Timeout 15000 ms). Apps normally drop the component on a form or create it in code, then assign CertificateManager / Index / CRLFilter before setting Active. » member page
destructor Destroy; override;
Destroy stops the listener first (SetActive(False), which terminates and joins the accept thread) and then frees the component, so an app can free the responder without first setting Active := False. » member page
function ProcessRequest(const aRequestDER: OctetString): OctetString; virtual;
ProcessRequest answers a DER OCSPRequest and returns a DER OCSPResponse. Expected error conditions are turned into OCSPResponse error statuses rather than exceptions: a parse failure yields malformedRequest, a CertID whose issuer hashes do not match the CA yields unauthorized, and a missing CertificateManager / CA certificate (or a failed signature) yields internalError. » member page
procedure FlushCache;
FlushCache empties the RFC 5019 lightweight-mode pre-produced response cache. It is called automatically when LightweightMode toggles or the signing certificate / index / CRL filter changes; call it after a revocation to force the next request to re-sign instead of serving a cached "good" up to nextUpdate. » member page
property Active: Boolean read FActive write SetActive default False;
Active starts (True) or stops (False) the listener. » member page
property Address: string read FAddress write FAddress;
Address is the local interface to bind, e.g. '0.0.0.0' for all. » member page
property Port: Word read FPort write FPort default 80;
Port is the TCP port to listen on (OCSP commonly uses 80). » member page
property CertificateManager: TstCustomCertificateManager read FCertificateManager write SetCertificateManager;
CertificateManager resolves the CA certificate and, when ResponderKey is not supplied, the signing key. It is NOT required when CACertificate and ResponderKey are both assigned - which is the offline pre-signing case, where there is no CA key on this machine to find. » member page
property CACertificate: iCertificate read FCACert write FCACert;
OPTIONAL EXTRA FILTERING: answer only for certificates issued by THIS CA. Assigning it implies no key custody - it is an identity, not a credential, and none of what a responder does with it is a signing operation. Full description »
property Index: TstBaseKeyIndexCertUnique read FIndex write SetIndex;
Index decides whether a requested certificate is known. » member page
property CRLFilter: TstCustomKeyFilterCRL read FCRLFilter write SetCRLFilter;
CRLFilter decides whether a known certificate is revoked. » member page
property ResponderCertificate: iCertificate read FResponderCert write FResponderCert;
DELEGATED RESPONDER. nil (the default) means the CA signs its own responses - the historical behaviour, which needs the CA certificate to carry digitalSignature. Full description »
property ResponderKey: IInterface read FResponderKey write FResponderKey; property OnCheckAuthority: tOcspAuthorityEvent read FOnCheckAuthority write FOnCheckAuthority;
Decides whether this responder answers for a CertID at all. Unassigned, the RFC 6960 s4.2.2.2 issuer-hash rule alone decides. See tOcspAuthorityEvent. » member page
property ResponseValidity: Cardinal read FResponseValidity write FResponseValidity default 3600;
ResponseValidity is the lifetime, in seconds, stamped into nextUpdate (default 3600). » member page
property Nonce: Boolean read FNonce write FNonce default True;
Nonce echoes a request nonce in the response (RFC 8954). Default True. » member page
property Timeout: Cardinal read FTimeout write FTimeout default 15000;
Timeout is the TOTAL time budget, in milliseconds, for reading one request off a connection (default 15000). It bounds slow-loris clients: a connection that has not delivered a complete request within this window is dropped. A client that then takes none of the response for this long is dropped too. » member page
property MaxConnections: Integer read FMaxConnections write FMaxConnections default 64;
MaxConnections caps the number of connections handled concurrently (default 64). Each accepted connection runs on its own short-lived worker thread; connections arriving above this cap are shed (closed immediately) rather than allowed to exhaust threads under a flood. » member page
property LightweightMode: TOcspLightweightMode read FLightweightMode write SetLightweightMode default olmDisabled;
LightweightMode selects the RFC 5019 "Lightweight OCSP Profile for High-Volume Environments" policy - see TOcspLightweightMode: olmDisabled (default) full RFC 6960 per-request: nonce echoed per Nonce, no caching headers, byte-for-byte the pre-lightweight behaviour; olmAlways every cacheable (good... Full description »

Types (enumerations, sets, aliases)

enumTOcspLightweightMode

TOcspLightweightMode selects the responder's RFC 5019 (Lightweight OCSP) policy. HTTP GET requests are decoded in every mode (transport is orthogonal); the mode only controls the RESPONSE style. A "lightweight" response is a pre-produced, nonce-less, cached BasicOCSPResponse with the RFC 5019 sec.6.2 HTTP caching headers; a "standard" response is freshly signed, echoes the request nonce if the request carries one and the Nonce property is set, and carries no caching headers. Only good/revoked answers are ever cacheable: an unknown or error answer is always built fresh with no caching headers, in EVERY mode. The mode decides, per request:
olmDisabled - always standard. (Default.)
olmAlways - lightweight for a good/revoked answer, standard otherwise; the request nonce is ignored (never echoed).
olmAsRequested - adaptive: a request that carries NO nonce is answered lightweight (if good/revoked); a request that carries a nonce is answered standard (fresh, nonce echoed) because it asked for freshness.

  TOcspLightweightMode = (olmDisabled, olmAlways, olmAsRequested);

proctOcspAuthorityEvent

THE LAST WORD ON WHETHER THIS RESPONDER ANSWERS FOR THIS CERTIFICATE.

It is asked only AFTER the certificate has been found in the key manager, so aCert is never nil: a CertID naming something the manager does not hold was already refused, and no handler is consulted about it. aAuthoritative arrives True, so a handler that only wants to refuse some of what it holds need not restate the rule that got it here.

In principle the certificate manager is where this belongs - its stores, indexes and filters are what decide which certificates exist for this responder, and configuring them is the intended way to scope it. The event is for the policy that cannot be expressed as a store: a CA that publishes status for its sub-CAs and deliberately NOT for its end entities, say, where the right answer is a refusal rather than "unknown", because "unknown" invites the client to ask again for ever.

  tOcspAuthorityEvent = procedure(Sender: TObject;
                                  const aCertID: iCertID;
                                  const aCert  : iCertificate;
                                    var aAuthoritative: Boolean) of object;