Authenticode

Authenticode consists of programs to digitally sign files and programs to check that the files were, indeed, successfully signed. Before you begin, first check that the underlying CryptoAPI is running. To do this, type:

c:>api *

This should generate SUCCESS messages until its stopped.

The programs are:

We will now discuss these programs in more detail.

MakeCert

Use the MakeCert program to generate a test X.509 certificate. The program does the following:

  1. It creates a public/private key pair for digital signatures and associates it with a name that you choose.
  2. It associates the key pair with a publisher's name that you choose.
  3. It creates an X.509 certificate, signed by the root key or one you specifiy, that binds your name to the public part of the key pair. If you do not specify a root key, MakeCert generates one for you.

The syntax for invoking MakeCert is:

MAKECERT [options] outputfile where the options are:

Here is an example:

>MakeCert -u:MyKey -n:CN=MySoftwareCompany Cert.cer

This generates a certificate file called Cert.cer. The public part of the key pair called KeyName is bound to the publisher, MySoftwareCompany.

This utility program should not be used once the software publisher obtains a valid X.509 software publisher certificate from the appropriate CA.

Cert2SPC

After you have generated a certificate, you must create an SPC with the Cert2SPC program. This program wraps the X.509 certificate and the root certificate into a PKCS#7 signed-data object. PKCS#7 objects are commonly used to carry certificates because it is possible to put several of them into a single object. Again, this program is for test purposes only. A valid SPC is obtained from a CA.

The syntax for Cert2SPC is:

Cert2SPC cert1.cer cert2.cer .... certN.cer output.spc

where:

Here is an example:

>Cert2Spc root.cer cert.cer cert.spc

This combines Cert.cer and Root.cer to make an SPC called Cert.spc.

SignCode

The final step is to use the SPC to actually sign a file. This is done with the SignCode program. This program will:

  1. Create a cryptographic digest of the file.
  2. Sign the digest with your private key.
  3. Extract the X.509 certificates from the SPC.
  4. Create a new PKCS#7 signed-data object that contains the serial numbers of the certificates and the signed digest information.
  5. Embed the object into the file.

If you have a valid SPC, then you can use this program to actually sign your code. The SignCode program has a wizard to help you do this. To sign code using the wizard, simply type SignCode, without any options. If you want to sign your code manually, the syntax is:

SignCode [-prog filename -spc credentials -pvk privateKeyFile

[-name opusName [-info opusInfo]]] [-gui] [-nocerts]

where:

Here is an example of how to sign a file:

>SignCode -prog MyProgram.exe -spc cert.spc -pvk MyKey

This embeds a PKCS#7 object, Cert.spc, into the digest of file, MyProgram. The digest is signed with the private key of the MyKey key pair.

Once this is done (assuming you have a valid certificate), the file can be distributed to your customers.

PeSigMgr

The PeSigMgr program checks to see if SignCode was successful. This means the file should have a PKCS#7 object embedded in it. Here is the syntax:

PESIGMGR [options] signedfile

where:

Here is an example:

>PeSigMgr -l MyProgram.exe

A sample response is:

>Certificate 0 Revision 256 Type PKCS#7

This means a certificate was embedded in the file.

ChkTrust

The ChkTrust program checks the validity of the file. It does this by:

  1. Extracting the PKCS#7 signed-data object
  2. Extracting the X.509 certificates from the PKCS#7 signed-data object.
  3. Computing a new hash of the file and comparing it with the signed hash in the PKCS#7 object.

If the hashes agree, ChkTrust then verifies that the signer's X.509 certificate points back to the root certificate and that the correct root key was used.

If all these steps are successful, the file has not been tampered with, and the vendor was authorized to publish the file by the root authority.

Here is the syntax:

CHKTRUST [type] signedfile

where:

Here is an example:

ChkTrust MyProgram.exe

A successful response is:

Result: 0

© 1996 Microsoft Corporation