The Big Picture: Who Made This Program, and Has It Been Changed?

You download setup.exe. Two questions matter: Who made it? and Is it exactly what they published, or did someone change it on the way? Looking at the file name tells you nothing.

Code signing answers both. The publisher puts a digital signature on the program. Windows checks the signature, and can say "this is from a known publisher and has not been changed", or "unknown publisher", or "tampered".

It is the same idea as a wax seal on a letter. The seal shows who sent it, and a broken seal shows it was opened.

Cryptography words, explained:

WordPlain meaning
HashA fingerprint of data. Any change gives a different fingerprint
Public/private key pairTwo linked keys. The private key is kept secret by its owner. The public key is shared with everyone
SignatureA hash of the data, locked with the private key. Anyone can unlock it with the public key to check it
CertificateA digital ID card. It says "this public key belongs to this publisher", and is itself signed by someone trusted
Certificate Authority (CA)A trusted organisation that checks identities and issues certificates

9.1 Digital Signatures on Executables/Drivers

What it is: Microsoft's format for signing programs is called Authenticode. It is used on .exe, .dll, .sys (drivers), installers (.msi), scripts (.ps1) and more.

How a file gets signed:

 Publisher                                    Result
 ┌────────────────────────────────┐
 │ 1. Hash the program            │
 │ 2. Lock the hash with the      │   ┌──────────────────────────┐
 │    PRIVATE key  = signature    │──►│ program + signature +    │
 │ 3. Attach signature and the    │   │ certificate (public key) │
 │    certificate to the file     │   └──────────────────────────┘
 └────────────────────────────────┘

How Windows checks it:

 Windows receives the signed file
        │
 1. Hash the file again           ──► hash A
 2. Unlock the signature with the
    certificate's PUBLIC key      ──► hash B
        │
 3. Compare:  A equals B ?
        ├── yes ► file is unchanged since signing
        └── no  ► file was altered: signature INVALID

A matching hash proves integrity (unchanged). A trusted certificate proves origin (who signed). Both are needed. Also, a signature does not mean the program is safe. It means this publisher stands behind it. Malware authors do sometimes get certificates (or steal them).

Timestamps. A signature can include a timestamp from a trusted server. If the certificate expires later, the signature is still considered valid, because it was made while the certificate was valid.

Where signing is required or used:

PlaceWhat Windows does
Kernel-mode drivers (64-bit Windows)Must be signed, or Windows will not load them. For current Windows, drivers generally have to go through Microsoft's portal and be signed by Microsoft. (Details depend on version and Secure Boot state.)
Boot filesSecure Boot checks them (Section 3)
Windows files and updatesWindows' own files are signed or "cataloged" and checked
User Account Control (UAC) promptThe elevation prompt shows a verified publisher in blue for signed apps, or "Unknown publisher" for unsigned ones
SmartScreenUses a signature as part of a program's reputation (below)
App Control and AppLockerCan allow programs by publisher (Section 10)
PowerShellExecution policy can require signed scripts

SmartScreen reputation. When you download and run a file, SmartScreen checks it against Microsoft's reputation data. A file with a valid signature from a publisher who is widely used passes quietly. A brand-new, unsigned, rarely-downloaded file may show "Windows protected your PC". You can still click More info → Run anyway, but you should stop and think first. Signed files earn reputation with the publisher over time, instead of per file.

See a signature yourself:

MethodSteps
File PropertiesRight-click a file → Properties → Digital Signatures tab (shown only if the file is signed) → select the signature → Details
PowerShellGet-AuthenticodeSignature C:\Windows\System32\notepad.exe (the path may differ on your Windows version; some programs are Store apps)

The PowerShell output has a Status column. Typical values:

StatusMeaning
ValidSignature is correct and the certificate chain is trusted
NotSignedNo signature at all
HashMismatchThe file was changed after signing
NotTrusted / UnknownErrorThe signer or chain is not trusted

Note on Windows' own files. Many Windows files are not signed inside the file. They are covered by catalog files (.cat), which list the correct hashes of many files and are signed once. Get-AuthenticodeSignature may show NotSigned for such a file unless it checks the catalog. Use the Properties tab or the sigcheck tool from Sysinternals when in doubt.

9.2 Certificate Chain Validation

A certificate is only useful if you trust the one who issued it. But who vouches for them? The answer is a chain.

 ┌───────────────────────────────────────────────┐
 │ ROOT CA                                       │
 │ (self-signed; already in Windows' trusted     │
 │  store, so Windows trusts it directly)        │
 └───────────────────────┬───────────────────────┘
                         │ signs
 ┌───────────────────────▼───────────────────────┐
 │ INTERMEDIATE CA                               │
 │ (issues certificates day to day)              │
 └───────────────────────┬───────────────────────┘
                         │ signs
 ┌───────────────────────▼───────────────────────┐
 │ LEAF (end-entity) certificate                 │
 │ "Example Software Ltd" signing certificate    │
 └───────────────────────────────────────────────┘

What Windows checks, step by step:

StepQuestion
1Is the signature on the file correct (hash match)?
2Does each certificate in the chain have a valid signature from the one above it?
3Does the chain end at a trusted root? Windows keeps a store of these (Trusted Root Certification Authorities)
4Is each certificate within its validity dates (or was the file timestamped in time)?
5Is the certificate meant for code signing (its "usage" field says so)?
6Has any certificate been revoked (cancelled because the key was stolen or misused)? Windows may check a CRL (revocation list) or OCSP (an online "is this still good?" check)

If any step fails, the signature is not trusted.

Trusted publishers. Windows also has a Trusted Publishers store. A certificate placed there is trusted for things like policies that say "run only from trusted publishers". Do not add anything to it unless you are sure.

See the stores: Press Win + R, run certmgr.msc for your user certificates, or certlm.msc for the whole computer.

Why this is a big deal, and why it can fail:

RiskWhat happens
Stolen signing keyAn attacker can sign malware that looks legitimate. The CA revokes the certificate once discovered
Weak or fraudulent CAA bad certificate could be issued. Browsers and Windows remove untrustworthy CAs from their stores
Expired certificateOld signatures without a timestamp stop validating
Vulnerable but signed driverA legitimately signed driver with a bug can be abused. That is why Windows can block known vulnerable drivers by name (Section 1.2)

Security tip: Do not install a root certificate that a random website or program tells you to install. A root you trust can vouch for anything, including fake sites and fake software.

Summary

TermPlain meaning
Code signingA publisher's digital seal on a program
AuthenticodeMicrosoft's signing format for exe, dll, sys, msi, ps1
HashFingerprint: proves the file is unchanged
SignatureThe hash locked with the publisher's private key
CertificateDigital ID linking a public key to a publisher
CA / rootTrusted issuer / the top of the trust chain
Chain validationEvery link checked up to a trusted root, dates and revocation too
TimestampProof the file was signed while the certificate was valid
Driver signing64-bit Windows refuses unsigned kernel drivers
SmartScreenUses signatures and reputation to warn about unknown downloads
Get-AuthenticodeSignaturePowerShell command to read a file's signature status
Valid signatureMeans "unchanged and from this publisher", not "safe"