Code signing concepts and definitions

Before getting into the details of what happens when code is signed, you must first understand a few key concepts and definitions that come into play during the code signing process. Understanding these concepts will help you understand the process described in What happens when code is signed.

Signing

In the code signing context, to sign means to encrypt.

Hash functions

Hash functions are a method of cryptography whereby a short and irreversible representation of a file is made using a mathematical algorithm. In code signing, hash functions are used to verify that the code the publisher signed is identical to the code the recipient received.

When code is signed, a hash algorithm is run over the code. The resulting hash is what gets signed. A common misconception in code signing is that the code itself is what gets signed.

Keys and certificates

Code signing relies on the same Public Key Infrastructure (PKI) that is widely used to protect machine-to-machine communication. PKI relies on key pairs, one of which remains private and the other is made public. In code signing, the private key is used to sign (or encrypt) the hash. When the code is distributed, the public key is used to decrypt the hash.

In most cases, the public key used to sign code will be included as part of a code signing certificate. A code signing certificate includes a software publisher’s public key, some additional information about the publisher, and a validity period. A code signing certificate can be issued by a third-party certificate authority, or it can be self-signed. A certificate issued by a certificate authority carries a higher level of trust than one that is self-signed. Whether to use a certificate issued by a certificate authority or to use a self-signed certificate depends largely on the purpose of the code being signed.

Protecting private code signing keys is critical to establishing and maintaining a software publisher's reputation. Compromised keys or unauthorized use of the key can allow potentially malicious software to appear safe to the software distributor's customers.

Digital signatures

The code signing process results in a digital signature that is bundled with the code when the code is distributed. At a minimum, the digital signature includes the signed hash of the code and the certificate that was used to sign the code. The digital signature is bundled with the code and is included when the code is distributed. The data in the digital signature allows the recipient's operating system to confirm the software’s author and verify that the code itself hasn’t changed since it was signed.

Root certificates

You can think of code signing certificates sort of like a family tree. In order to verify where they have come from, you can trace them back to see what signing certificate is at the root of the tree—your root certificate. The root certificate determines if the code signing certificates are trustworthy because you can trace the “chain of trust” back to the original signing authority.

If the operating system cannot find a trustworthy root certificate, then the system will advise you not to trust the code signing certificate. Sometimes even a trusted root certificate may not be recognized because it has not been installed. In these instances, the user must manually install the root certificate on the system so the server recognizes the root certificate as trustworthy and valid.