signature.txt 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. U-Boot FIT Signature Verification
  2. =================================
  3. Introduction
  4. ------------
  5. FIT supports hashing of images so that these hashes can be checked on
  6. loading. This protects against corruption of the image. However it does not
  7. prevent the substitution of one image for another.
  8. The signature feature allows the hash to be signed with a private key such
  9. that it can be verified using a public key later. Provided that the private
  10. key is kept secret and the public key is stored in a non-volatile place,
  11. any image can be verified in this way.
  12. See verified-boot.txt for more general information on verified boot.
  13. Concepts
  14. --------
  15. Some familiarity with public key cryptography is assumed in this section.
  16. The procedure for signing is as follows:
  17. - hash an image in the FIT
  18. - sign the hash with a private key to produce a signature
  19. - store the resulting signature in the FIT
  20. The procedure for verification is:
  21. - read the FIT
  22. - obtain the public key
  23. - extract the signature from the FIT
  24. - hash the image from the FIT
  25. - verify (with the public key) that the extracted signature matches the
  26. hash
  27. The signing is generally performed by mkimage, as part of making a firmware
  28. image for the device. The verification is normally done in U-Boot on the
  29. device.
  30. Algorithms
  31. ----------
  32. In principle any suitable algorithm can be used to sign and verify a hash.
  33. At present only one class of algorithms is supported: SHA1 hashing with RSA.
  34. This works by hashing the image to produce a 20-byte hash.
  35. While it is acceptable to bring in large cryptographic libraries such as
  36. openssl on the host side (e.g. mkimage), it is not desirable for U-Boot.
  37. For the run-time verification side, it is important to keep code and data
  38. size as small as possible.
  39. For this reason the RSA image verification uses pre-processed public keys
  40. which can be used with a very small amount of code - just some extraction
  41. of data from the FDT and exponentiation mod n. Code size impact is a little
  42. under 5KB on Tegra Seaboard, for example.
  43. It is relatively straightforward to add new algorithms if required. If
  44. another RSA variant is needed, then it can be added to the table in
  45. image-sig.c. If another algorithm is needed (such as DSA) then it can be
  46. placed alongside rsa.c, and its functions added to the table in image-sig.c
  47. also.
  48. Creating an RSA key and certificate
  49. -----------------------------------
  50. To create a new public key, size 2048 bits:
  51. $ openssl genrsa -F4 -out keys/dev.key 2048
  52. To create a certificate for this:
  53. $ openssl req -batch -new -x509 -key keys/dev.key -out keys/dev.crt
  54. If you like you can look at the public key also:
  55. $ openssl rsa -in keys/dev.key -pubout
  56. Device Tree Bindings
  57. --------------------
  58. The following properties are required in the FIT's signature node(s) to
  59. allow thes signer to operate. These should be added to the .its file.
  60. Signature nodes sit at the same level as hash nodes and are called
  61. signature@1, signature@2, etc.
  62. - algo: Algorithm name (e.g. "sha1,rs2048")
  63. - key-name-hint: Name of key to use for signing. The keys will normally be in
  64. a single directory (parameter -k to mkimage). For a given key <name>, its
  65. private key is stored in <name>.key and the certificate is stored in
  66. <name>.crt.
  67. When the image is signed, the following properties are added (mandatory):
  68. - value: The signature data (e.g. 256 bytes for 2048-bit RSA)
  69. When the image is signed, the following properties are optional:
  70. - timestamp: Time when image was signed (standard Unix time_t format)
  71. - signer-name: Name of the signer (e.g. "mkimage")
  72. - signer-version: Version string of the signer (e.g. "2013.01")
  73. - comment: Additional information about the signer or image
  74. Example: See sign-images.its for an example image tree source file.
  75. Public Key Storage
  76. ------------------
  77. In order to verify an image that has been signed with a public key we need to
  78. have a trusted public key. This cannot be stored in the signed image, since
  79. it would be easy to alter. For this implementation we choose to store the
  80. public key in U-Boot's control FDT (using CONFIG_OF_CONTROL).
  81. Public keys should be stored as sub-nodes in a /signature node. Required
  82. properties are:
  83. - algo: Algorithm name (e.g. "sha1,rs2048")
  84. Optional properties are:
  85. - key-name-hint: Name of key used for signing. This is only a hint since it
  86. is possible for the name to be changed. Verification can proceed by checking
  87. all available signing keys until one matches.
  88. - required: If present this indicates that the key must be verified for the
  89. image / configuration to be considered valid. Only required keys are
  90. normally verified by the FIT image booting algorithm. Valid values are
  91. "image" to force verification of all images, and "conf" to force verfication
  92. of the selected configuration (which then relies on hashes in the images to
  93. verify those).
  94. Each signing algorithm has its own additional properties.
  95. For RSA the following are mandatory:
  96. - rsa,num-bits: Number of key bits (e.g. 2048)
  97. - rsa,modulus: Modulus (N) as a big-endian multi-word integer
  98. - rsa,r-squared: (2^num-bits)^2 as a big-endian multi-word integer
  99. - rsa,n0-inverse: -1 / modulus[0] mod 2^32
  100. Verification
  101. ------------
  102. FITs are verified when loaded. After the configuration is selected a list
  103. of required images is produced. If there are 'required' public keys, then
  104. each image must be verified against those keys. This means that every image
  105. that might be used by the target needs to be signed with 'required' keys.
  106. This happens automatically as part of a bootm command when FITs are used.
  107. Enabling FIT Verification
  108. -------------------------
  109. In addition to the options to enable FIT itself, the following CONFIGs must
  110. be enabled:
  111. CONFIG_FIT_SIGNATURE - enable signing and verfication in FITs
  112. CONFIG_RSA - enable RSA algorithm for signing
  113. Testing
  114. -------
  115. An easy way to test signing and verfication is to use the test script
  116. provided in test/vboot/vboot_test.sh. This uses sandbox (a special version
  117. of U-Boot which runs under Linux) to show the operation of a 'bootm'
  118. command loading and verifying images.
  119. A sample run is show below:
  120. $ make O=sandbox sandbox_config
  121. $ make O=sandbox
  122. $ O=sandbox ./test/vboot/vboot_test.sh
  123. Simple Verified Boot Test
  124. =========================
  125. Please see doc/uImage.FIT/verified-boot.txt for more information
  126. Build keys
  127. Build FIT with signed images
  128. Test Verified Boot Run: unsigned signatures:: OK
  129. Sign images
  130. Test Verified Boot Run: signed images: OK
  131. Build FIT with signed configuration
  132. Test Verified Boot Run: unsigned config: OK
  133. Sign images
  134. Test Verified Boot Run: signed config: OK
  135. Test passed
  136. Future Work
  137. -----------
  138. - Roll-back protection using a TPM is done using the tpm command. This can
  139. be scripted, but we might consider a default way of doing this, built into
  140. bootm.
  141. Possible Future Work
  142. --------------------
  143. - Add support for other RSA/SHA variants, such as rsa4096,sha512.
  144. - Other algorithms besides RSA
  145. - More sandbox tests for failure modes
  146. - Passwords for keys/certificates
  147. - Perhaps implement OAEP
  148. - Enhance bootm to permit scripted signature verification (so that a script
  149. can verify an image but not actually boot it)
  150. Simon Glass
  151. sjg@chromium.org
  152. 1-1-13