Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
7.1 KiB

  1. General Introduction to Code Signing
  2. -----------------
  3. Document Overview
  4. -----------------
  5. This guide presents general information about how to use the tools provided
  6. with IE30 to generate and use cryptographic certificates with IE30. It does
  7. not attempt to provide an in-depth discussion of public key cryptography,
  8. X.509 certificates, or certification policy. See the recommended reading
  9. list for suggested books and documents that will help you understand those
  10. and other background issues.
  11. Following this introduction, this guide is divided into the following
  12. sections:
  13. - Terminology
  14. Describes the terms used in this document that may be new to you.
  15. - Procedural Overview
  16. This section gives a brief description of each step of the signing
  17. procedure and an example of how it would be used by walking through a
  18. sample session from start to finish.
  19. - Required Files List
  20. - Recommended Reading
  21. Terminology
  22. -----------
  23. X.509 Certificate - A cryptographic certificate that associates an entity's
  24. name with its public key.
  25. PKCS 7 "SIGNED DATA" - A widely used convention for containing the data used
  26. to sign an image or a document, typically including the certificate of the
  27. signer and a statement about the image made by the signer.
  28. WIN_CERTIFICATE - A new Win32 defined data structure that contains either a
  29. PKCS 7 signed data object or an X.509 Certificate.
  30. Certification Authority (CA) - An entity that is making a statement
  31. (represented by an X.509 Certificate) about the authenticity of some
  32. other certificate.
  33. SPC - Software Publishing Certificate. A statement that the recipient is an
  34. approved software vendor, represented as an X.509 certificate.
  35. PE Image - Portable Executable Image, the standard Win32 executable
  36. format.
  37. Trust provider - A part of the operating system that verifies whether or not
  38. a given image is trusted based on the certificates it contains.
  39. Procedural Overview
  40. -------------------
  41. We will now walk through an example of how to sign an image. Assume we are
  42. going to sign an image named image.exe.
  43. This procedure is meant to illustrate the steps involved in signing an image
  44. file. Since creating a verifiable certificate assumes the existance of a
  45. fairly complex CA infrastructure, it is not possible to provide all of the
  46. pieces necessary for a fully trustworthy signature at this time. In
  47. particular, there does not exist a "top-level" certifying authority, which
  48. would ultimately vouch for the integrity of the entire certificate chain.
  49. Since such a top-level authority is a necessary part of the signing and
  50. verification operations, the toolkit provided will create a pseudo top-level
  51. entity when necessary. This will be called the root authority or root key.
  52. The present tools therefore allow any user of this development release to
  53. authorize themselves as a "Software Publisher" for test purposes and to
  54. sign their code, allowing for extensive testing of the tools and code
  55. used but not actually providing a secure infrastructure. In future releases,
  56. the tools will require software publishers to obtain certificates from
  57. companies whose function is to verify the identity of the publishers,
  58. providing end-users with a high level of assurance about the authenticity
  59. and origin of code that they recieve.
  60. This sample root key will be used to generate an SPC (Software Publishing
  61. Certificate), which is used to actually sign image files.
  62. [
  63. note: before proceeding, verify that the underlying crypto-api is
  64. functioning by running:
  65. c:>init * (will generate keys)
  66. c:>api * (will spew out SUCCESS messages until killed)
  67. ]
  68. 1) The first step is to run the MakeCert utility. MakeCert will perform the
  69. following tasks:
  70. - Create the end-user's public/private keypair suitable for digital
  71. signatures, and associate the keypair with a friendly name.
  72. - Associate the new keypair with an X.500 Distinguished Name, and
  73. - Create an X.509 certificate signed by the root key that binds your name to
  74. the public part of the newly created keypair.
  75. A typical invocation of MakeCert is as follows:
  76. c:\>makecert -u:MyKey -n:CN=MySoftwareCompany Cert.cer
  77. Cert.crt now contains an X.509 certificate that binds your newly created key
  78. with your name. This certificate is itself signed by the example root key
  79. described above.
  80. A public key/private key pair will be generated and assigned the name
  81. specified in the "-u" switch, or if such a key already exists, it will
  82. be re-used.
  83. Note that the name must be of the form "CN=[name-string]", as required by
  84. the ITU x.509 standard.
  85. 2) The next step is to wrap the X.509 certificate created in step 1 into a
  86. PKCS 7 signed-data object. PKCS 7 objects are commonly used as "carriers" for
  87. X.509 certificates, because it is possible to put several X.509 certificates
  88. in a single PKCS 7 object.
  89. In addition to the users's certificate, the root certificate will also be
  90. inserted into the PKCS 7 object. This will allow passing around the entire
  91. certificate chain in a single container.
  92. Do this with the Cert2SPC utility, as follows:
  93. c:\>Cert2SPC Root.cer Cert.cer Cert.spc
  94. Cert.spc now contains the Software Publishing Certificate in the correct
  95. format.
  96. 3) The next step is to use the certificate just created to sign an actual
  97. image file. Do this with the SignCode tool. It takes as input the Cert.spc
  98. file created in step 2, the name of the key pair created in step 1, and the
  99. name of the image file to sign.
  100. SignCode will perform the following tasks:
  101. - Create a cryptographic digest of the passed image file.
  102. - Sign the digest with the passed private key information.
  103. - Extract the X.509 certificates from the passed Cert.spc file.
  104. - Create a new PKCS 7 signed-data object containing the serial number of the
  105. passed X.509 certificate and the signed digest information.
  106. - Embed the PKCS 7 object into the passed image file.
  107. c:\>SignCode -prog image.exe -spc cert.spc -pvk MyKey
  108. If SignCode is successful, image.exe will have a PKCS7 certificate embedded in
  109. it. Verify this by running PeSigMgr.exe on the image:
  110. c:\>PeSigMgr -l image.exe
  111. Certificate 0 Revision 256 Type PKCS7
  112. 4) Now, check the validity of the image. Do this with the ChkTrust utility.
  113. c:\>ChkTrust image.exe
  114. ChkTrust performs the following tasks:
  115. - Extract the PKCS 7 signed data object from the image.
  116. - Extract the X.509 certificates from the PKCS 7 object.
  117. - Compute a new cryptographic checksum of the image file and compare it with
  118. the signed checksum in the PKCS 7 object.
  119. - If the image checks out, validate that the signer's X.509 certificate
  120. points back to the root certificate, and that the root key used was correct.
  121. If all this succeeds, the system has verified that the image has not been
  122. tampered with, and that whoever published this piece of software was
  123. authorized to do so by the root authority.
  124. List of Required Files
  125. ----------------------
  126. WINTRUST.DLL
  127. DIGSIG.DLL
  128. OSSAPI.DLL
  129. OSSMEM.DLL
  130. SOEDBER.DLL
  131. MSVCRT20.DLL
  132. MSVCRT40.DLL
  133. MAKECERT.EXE
  134. CERT2SPC.EXE
  135. SIGNCODE.EXE
  136. PESIGMGR.EXE
  137. CHKTRUST.EXE
  138. ROOT.CER
  139. ROOT.PVK