LoadLeafFromPFX
function LoadLeafFromPFX(const aFileName, aPassword: string; out aLeafDer: tBytes): Boolean;
THE INVERSE OF InstallIssuedCertificate: reads the END-ENTITY certificate back out of a PFX it wrote, as DER. False when the file is absent, unreadable, or holds no end-entity certificate; aLeafDer is empty then. It never raises for an absent or malformed file - "there is no usable certificate here" is an answer, not an error, and every caller has a sensible thing to do with it.
IT EXISTS SO A RESTART DOES NOT RE-ISSUE. TsmAcmeRenewalManager schedules from the leaf it is given, so a host restarting with a perfectly good certificate on disk must hand that leaf back rather than register "nothing yet" - which is due immediately and would obtain a fresh certificate every time the process started. Against Let's Encrypt's duplicate-certificate limit that is five restarts a week before issuance starts failing.
WHICH CERTIFICATE IS THE LEAF, in order: the one whose SUBJECT PUBLIC KEY is the private key in the file, matched through GetPKI (the RFC 5280 method-1 key identifier); failing that, the single certificate that is not a CA, which is how InstallIssuedCertificate splits a chain when it WRITES one.
Deliberately NOT the PKCS#12 localKeyId - optional, and real files omit it; the deployed Let's Encrypt PFX this was first run against carries none at all, on the key or the certificates. And deliberately not "the first certificate", which picks an intermediate whenever a chain happens to be stored issuer-first.