xref: /rk3399_rockchip-uboot/doc/uImage.FIT/signature.txt (revision 32619fbebcbd9090064c224f314aaa51b37e650d)
13e569a6bSSimon GlassU-Boot FIT Signature Verification
23e569a6bSSimon Glass=================================
33e569a6bSSimon Glass
43e569a6bSSimon GlassIntroduction
53e569a6bSSimon Glass------------
63e569a6bSSimon GlassFIT supports hashing of images so that these hashes can be checked on
73e569a6bSSimon Glassloading. This protects against corruption of the image. However it does not
83e569a6bSSimon Glassprevent the substitution of one image for another.
93e569a6bSSimon Glass
103e569a6bSSimon GlassThe signature feature allows the hash to be signed with a private key such
113e569a6bSSimon Glassthat it can be verified using a public key later. Provided that the private
123e569a6bSSimon Glasskey is kept secret and the public key is stored in a non-volatile place,
133e569a6bSSimon Glassany image can be verified in this way.
143e569a6bSSimon Glass
153e569a6bSSimon GlassSee verified-boot.txt for more general information on verified boot.
163e569a6bSSimon Glass
173e569a6bSSimon Glass
183e569a6bSSimon GlassConcepts
193e569a6bSSimon Glass--------
203e569a6bSSimon GlassSome familiarity with public key cryptography is assumed in this section.
213e569a6bSSimon Glass
223e569a6bSSimon GlassThe procedure for signing is as follows:
233e569a6bSSimon Glass
243e569a6bSSimon Glass   - hash an image in the FIT
253e569a6bSSimon Glass   - sign the hash with a private key to produce a signature
263e569a6bSSimon Glass   - store the resulting signature in the FIT
273e569a6bSSimon Glass
283e569a6bSSimon GlassThe procedure for verification is:
293e569a6bSSimon Glass
303e569a6bSSimon Glass   - read the FIT
313e569a6bSSimon Glass   - obtain the public key
323e569a6bSSimon Glass   - extract the signature from the FIT
333e569a6bSSimon Glass   - hash the image from the FIT
343e569a6bSSimon Glass   - verify (with the public key) that the extracted signature matches the
353e569a6bSSimon Glass       hash
363e569a6bSSimon Glass
373e569a6bSSimon GlassThe signing is generally performed by mkimage, as part of making a firmware
383e569a6bSSimon Glassimage for the device. The verification is normally done in U-Boot on the
393e569a6bSSimon Glassdevice.
403e569a6bSSimon Glass
413e569a6bSSimon Glass
423e569a6bSSimon GlassAlgorithms
433e569a6bSSimon Glass----------
443e569a6bSSimon GlassIn principle any suitable algorithm can be used to sign and verify a hash.
453e569a6bSSimon GlassAt present only one class of algorithms is supported: SHA1 hashing with RSA.
463e569a6bSSimon GlassThis works by hashing the image to produce a 20-byte hash.
473e569a6bSSimon Glass
483e569a6bSSimon GlassWhile it is acceptable to bring in large cryptographic libraries such as
493e569a6bSSimon Glassopenssl on the host side (e.g. mkimage), it is not desirable for U-Boot.
503e569a6bSSimon GlassFor the run-time verification side, it is important to keep code and data
513e569a6bSSimon Glasssize as small as possible.
523e569a6bSSimon Glass
533e569a6bSSimon GlassFor this reason the RSA image verification uses pre-processed public keys
543e569a6bSSimon Glasswhich can be used with a very small amount of code - just some extraction
553e569a6bSSimon Glassof data from the FDT and exponentiation mod n. Code size impact is a little
563e569a6bSSimon Glassunder 5KB on Tegra Seaboard, for example.
573e569a6bSSimon Glass
583e569a6bSSimon GlassIt is relatively straightforward to add new algorithms if required. If
593e569a6bSSimon Glassanother RSA variant is needed, then it can be added to the table in
603e569a6bSSimon Glassimage-sig.c. If another algorithm is needed (such as DSA) then it can be
613e569a6bSSimon Glassplaced alongside rsa.c, and its functions added to the table in image-sig.c
623e569a6bSSimon Glassalso.
633e569a6bSSimon Glass
643e569a6bSSimon Glass
654c1d5c29SAndreas DannenbergCreating an RSA key pair and certificate
664c1d5c29SAndreas Dannenberg----------------------------------------
674c1d5c29SAndreas DannenbergTo create a new public/private key pair, size 2048 bits:
683e569a6bSSimon Glass
69e0f2f155SMichael van der Westhuizen$ openssl genpkey -algorithm RSA -out keys/dev.key \
70e0f2f155SMichael van der Westhuizen    -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537
713e569a6bSSimon Glass
724c1d5c29SAndreas DannenbergTo create a certificate for this containing the public key:
733e569a6bSSimon Glass
743e569a6bSSimon Glass$ openssl req -batch -new -x509 -key keys/dev.key -out keys/dev.crt
753e569a6bSSimon Glass
763e569a6bSSimon GlassIf you like you can look at the public key also:
773e569a6bSSimon Glass
783e569a6bSSimon Glass$ openssl rsa -in keys/dev.key -pubout
793e569a6bSSimon Glass
803e569a6bSSimon Glass
813e569a6bSSimon GlassDevice Tree Bindings
823e569a6bSSimon Glass--------------------
833e569a6bSSimon GlassThe following properties are required in the FIT's signature node(s) to
84e43f74acSMasahiro Yamadaallow the signer to operate. These should be added to the .its file.
853e569a6bSSimon GlassSignature nodes sit at the same level as hash nodes and are called
863e569a6bSSimon Glasssignature@1, signature@2, etc.
873e569a6bSSimon Glass
88*32619fbeSMasahiro Yamada- algo: Algorithm name (e.g. "sha1,rsa2048")
893e569a6bSSimon Glass
903e569a6bSSimon Glass- key-name-hint: Name of key to use for signing. The keys will normally be in
913e569a6bSSimon Glassa single directory (parameter -k to mkimage). For a given key <name>, its
923e569a6bSSimon Glassprivate key is stored in <name>.key and the certificate is stored in
933e569a6bSSimon Glass<name>.crt.
943e569a6bSSimon Glass
953e569a6bSSimon GlassWhen the image is signed, the following properties are added (mandatory):
963e569a6bSSimon Glass
973e569a6bSSimon Glass- value: The signature data (e.g. 256 bytes for 2048-bit RSA)
983e569a6bSSimon Glass
993e569a6bSSimon GlassWhen the image is signed, the following properties are optional:
1003e569a6bSSimon Glass
1013e569a6bSSimon Glass- timestamp: Time when image was signed (standard Unix time_t format)
1023e569a6bSSimon Glass
1033e569a6bSSimon Glass- signer-name: Name of the signer (e.g. "mkimage")
1043e569a6bSSimon Glass
1053e569a6bSSimon Glass- signer-version: Version string of the signer (e.g. "2013.01")
1063e569a6bSSimon Glass
1073e569a6bSSimon Glass- comment: Additional information about the signer or image
1083e569a6bSSimon Glass
1094d098529SSimon GlassFor config bindings (see Signed Configurations below), the following
1104d098529SSimon Glassadditional properties are optional:
1113e569a6bSSimon Glass
1124d098529SSimon Glass- sign-images: A list of images to sign, each being a property of the conf
1134d098529SSimon Glassnode that contains then. The default is "kernel,fdt" which means that these
1144d098529SSimon Glasstwo images will be looked up in the config and signed if present.
1154d098529SSimon Glass
1164d098529SSimon GlassFor config bindings, these properties are added by the signer:
1174d098529SSimon Glass
1184d098529SSimon Glass- hashed-nodes: A list of nodes which were hashed by the signer. Each is
1194d098529SSimon Glass	a string - the full path to node. A typical value might be:
1204d098529SSimon Glass
1214d098529SSimon Glass	hashed-nodes = "/", "/configurations/conf@1", "/images/kernel@1",
1224d098529SSimon Glass		"/images/kernel@1/hash@1", "/images/fdt@1",
1234d098529SSimon Glass		"/images/fdt@1/hash@1";
1244d098529SSimon Glass
1254d098529SSimon Glass- hashed-strings: The start and size of the string region of the FIT that
1264d098529SSimon Glass	was hashed
1274d098529SSimon Glass
1284d098529SSimon GlassExample: See sign-images.its for an example image tree source file and
1294d098529SSimon Glasssign-configs.its for config signing.
1303e569a6bSSimon Glass
1313e569a6bSSimon Glass
1323e569a6bSSimon GlassPublic Key Storage
1333e569a6bSSimon Glass------------------
1343e569a6bSSimon GlassIn order to verify an image that has been signed with a public key we need to
1353e569a6bSSimon Glasshave a trusted public key. This cannot be stored in the signed image, since
1363e569a6bSSimon Glassit would be easy to alter. For this implementation we choose to store the
1373e569a6bSSimon Glasspublic key in U-Boot's control FDT (using CONFIG_OF_CONTROL).
1383e569a6bSSimon Glass
1393e569a6bSSimon GlassPublic keys should be stored as sub-nodes in a /signature node. Required
1403e569a6bSSimon Glassproperties are:
1413e569a6bSSimon Glass
142*32619fbeSMasahiro Yamada- algo: Algorithm name (e.g. "sha1,rsa2048")
1433e569a6bSSimon Glass
1443e569a6bSSimon GlassOptional properties are:
1453e569a6bSSimon Glass
1463e569a6bSSimon Glass- key-name-hint: Name of key used for signing. This is only a hint since it
1473e569a6bSSimon Glassis possible for the name to be changed. Verification can proceed by checking
1483e569a6bSSimon Glassall available signing keys until one matches.
1493e569a6bSSimon Glass
1503e569a6bSSimon Glass- required: If present this indicates that the key must be verified for the
1513e569a6bSSimon Glassimage / configuration to be considered valid. Only required keys are
1523e569a6bSSimon Glassnormally verified by the FIT image booting algorithm. Valid values are
153e43f74acSMasahiro Yamada"image" to force verification of all images, and "conf" to force verification
1543e569a6bSSimon Glassof the selected configuration (which then relies on hashes in the images to
1553e569a6bSSimon Glassverify those).
1563e569a6bSSimon Glass
1573e569a6bSSimon GlassEach signing algorithm has its own additional properties.
1583e569a6bSSimon Glass
1593e569a6bSSimon GlassFor RSA the following are mandatory:
1603e569a6bSSimon Glass
1613e569a6bSSimon Glass- rsa,num-bits: Number of key bits (e.g. 2048)
1623e569a6bSSimon Glass- rsa,modulus: Modulus (N) as a big-endian multi-word integer
163e0f2f155SMichael van der Westhuizen- rsa,exponent: Public exponent (E) as a 64 bit unsigned integer
1643e569a6bSSimon Glass- rsa,r-squared: (2^num-bits)^2 as a big-endian multi-word integer
1653e569a6bSSimon Glass- rsa,n0-inverse: -1 / modulus[0] mod 2^32
1663e569a6bSSimon Glass
1673e569a6bSSimon Glass
1684d098529SSimon GlassSigned Configurations
1694d098529SSimon Glass---------------------
1704d098529SSimon GlassWhile signing images is useful, it does not provide complete protection
1714d098529SSimon Glassagainst several types of attack. For example, it it possible to create a
1724d098529SSimon GlassFIT with the same signed images, but with the configuration changed such
1734d098529SSimon Glassthat a different one is selected (mix and match attack). It is also possible
1744d098529SSimon Glassto substitute a signed image from an older FIT version into a newer FIT
1754d098529SSimon Glass(roll-back attack).
1764d098529SSimon Glass
1774d098529SSimon GlassAs an example, consider this FIT:
1784d098529SSimon Glass
1794d098529SSimon Glass/ {
1804d098529SSimon Glass	images {
1814d098529SSimon Glass		kernel@1 {
1824d098529SSimon Glass			data = <data for kernel1>
1834d098529SSimon Glass			signature@1 {
1844d098529SSimon Glass				algo = "sha1,rsa2048";
1854d098529SSimon Glass				value = <...kernel signature 1...>
1864d098529SSimon Glass			};
1874d098529SSimon Glass		};
1884d098529SSimon Glass		kernel@2 {
1894d098529SSimon Glass			data = <data for kernel2>
1904d098529SSimon Glass			signature@1 {
1914d098529SSimon Glass				algo = "sha1,rsa2048";
1924d098529SSimon Glass				value = <...kernel signature 2...>
1934d098529SSimon Glass			};
1944d098529SSimon Glass		};
1954d098529SSimon Glass		fdt@1 {
1964d098529SSimon Glass			data = <data for fdt1>;
1974d098529SSimon Glass			signature@1 {
1984d098529SSimon Glass				algo = "sha1,rsa2048";
1994d098529SSimon Glass				vaue = <...fdt signature 1...>
2004d098529SSimon Glass			};
2014d098529SSimon Glass		};
2024d098529SSimon Glass		fdt@2 {
2034d098529SSimon Glass			data = <data for fdt2>;
2044d098529SSimon Glass			signature@1 {
2054d098529SSimon Glass				algo = "sha1,rsa2048";
2064d098529SSimon Glass				vaue = <...fdt signature 2...>
2074d098529SSimon Glass			};
2084d098529SSimon Glass		};
2094d098529SSimon Glass	};
2104d098529SSimon Glass	configurations {
2114d098529SSimon Glass		default = "conf@1";
2124d098529SSimon Glass		conf@1 {
2134d098529SSimon Glass			kernel = "kernel@1";
2144d098529SSimon Glass			fdt = "fdt@1";
2154d098529SSimon Glass		};
2164d098529SSimon Glass		conf@1 {
2174d098529SSimon Glass			kernel = "kernel@2";
2184d098529SSimon Glass			fdt = "fdt@2";
2194d098529SSimon Glass		};
2204d098529SSimon Glass	};
2214d098529SSimon Glass};
2224d098529SSimon Glass
2234d098529SSimon GlassSince both kernels are signed it is easy for an attacker to add a new
2244d098529SSimon Glassconfiguration 3 with kernel 1 and fdt 2:
2254d098529SSimon Glass
2264d098529SSimon Glass	configurations {
2274d098529SSimon Glass		default = "conf@1";
2284d098529SSimon Glass		conf@1 {
2294d098529SSimon Glass			kernel = "kernel@1";
2304d098529SSimon Glass			fdt = "fdt@1";
2314d098529SSimon Glass		};
2324d098529SSimon Glass		conf@1 {
2334d098529SSimon Glass			kernel = "kernel@2";
2344d098529SSimon Glass			fdt = "fdt@2";
2354d098529SSimon Glass		};
2364d098529SSimon Glass		conf@3 {
2374d098529SSimon Glass			kernel = "kernel@1";
2384d098529SSimon Glass			fdt = "fdt@2";
2394d098529SSimon Glass		};
2404d098529SSimon Glass	};
2414d098529SSimon Glass
2424d098529SSimon GlassWith signed images, nothing protects against this. Whether it gains an
2434d098529SSimon Glassadvantage for the attacker is debatable, but it is not secure.
2444d098529SSimon Glass
245e43f74acSMasahiro YamadaTo solve this problem, we support signed configurations. In this case it
2464d098529SSimon Glassis the configurations that are signed, not the image. Each image has its
2474d098529SSimon Glassown hash, and we include the hash in the configuration signature.
2484d098529SSimon Glass
2494d098529SSimon GlassSo the above example is adjusted to look like this:
2504d098529SSimon Glass
2514d098529SSimon Glass/ {
2524d098529SSimon Glass	images {
2534d098529SSimon Glass		kernel@1 {
2544d098529SSimon Glass			data = <data for kernel1>
2554d098529SSimon Glass			hash@1 {
2564d098529SSimon Glass				algo = "sha1";
2574d098529SSimon Glass				value = <...kernel hash 1...>
2584d098529SSimon Glass			};
2594d098529SSimon Glass		};
2604d098529SSimon Glass		kernel@2 {
2614d098529SSimon Glass			data = <data for kernel2>
2624d098529SSimon Glass			hash@1 {
2634d098529SSimon Glass				algo = "sha1";
2644d098529SSimon Glass				value = <...kernel hash 2...>
2654d098529SSimon Glass			};
2664d098529SSimon Glass		};
2674d098529SSimon Glass		fdt@1 {
2684d098529SSimon Glass			data = <data for fdt1>;
2694d098529SSimon Glass			hash@1 {
2704d098529SSimon Glass				algo = "sha1";
2714d098529SSimon Glass				value = <...fdt hash 1...>
2724d098529SSimon Glass			};
2734d098529SSimon Glass		};
2744d098529SSimon Glass		fdt@2 {
2754d098529SSimon Glass			data = <data for fdt2>;
2764d098529SSimon Glass			hash@1 {
2774d098529SSimon Glass				algo = "sha1";
2784d098529SSimon Glass				value = <...fdt hash 2...>
2794d098529SSimon Glass			};
2804d098529SSimon Glass		};
2814d098529SSimon Glass	};
2824d098529SSimon Glass	configurations {
2834d098529SSimon Glass		default = "conf@1";
2844d098529SSimon Glass		conf@1 {
2854d098529SSimon Glass			kernel = "kernel@1";
2864d098529SSimon Glass			fdt = "fdt@1";
2874d098529SSimon Glass			signature@1 {
2884d098529SSimon Glass				algo = "sha1,rsa2048";
2894d098529SSimon Glass				value = <...conf 1 signature...>;
2904d098529SSimon Glass			};
2914d098529SSimon Glass		};
2924d098529SSimon Glass		conf@2 {
2934d098529SSimon Glass			kernel = "kernel@2";
2944d098529SSimon Glass			fdt = "fdt@2";
2954d098529SSimon Glass			signature@1 {
2964d098529SSimon Glass				algo = "sha1,rsa2048";
2974d098529SSimon Glass				value = <...conf 1 signature...>;
2984d098529SSimon Glass			};
2994d098529SSimon Glass		};
3004d098529SSimon Glass	};
3014d098529SSimon Glass};
3024d098529SSimon Glass
3034d098529SSimon Glass
3044d098529SSimon GlassYou can see that we have added hashes for all images (since they are no
3054d098529SSimon Glasslonger signed), and a signature to each configuration. In the above example,
3064d098529SSimon Glassmkimage will sign configurations/conf@1, the kernel and fdt that are
3074d098529SSimon Glasspointed to by the configuration (/images/kernel@1, /images/kernel@1/hash@1,
3084d098529SSimon Glass/images/fdt@1, /images/fdt@1/hash@1) and the root structure of the image
3094d098529SSimon Glass(so that it isn't possible to add or remove root nodes). The signature is
3104d098529SSimon Glasswritten into /configurations/conf@1/signature@1/value. It can easily be
3114d098529SSimon Glassverified later even if the FIT has been signed with other keys in the
3124d098529SSimon Glassmeantime.
3134d098529SSimon Glass
3144d098529SSimon Glass
3153e569a6bSSimon GlassVerification
3163e569a6bSSimon Glass------------
3173e569a6bSSimon GlassFITs are verified when loaded. After the configuration is selected a list
3183e569a6bSSimon Glassof required images is produced. If there are 'required' public keys, then
3193e569a6bSSimon Glasseach image must be verified against those keys. This means that every image
3203e569a6bSSimon Glassthat might be used by the target needs to be signed with 'required' keys.
3213e569a6bSSimon Glass
3223e569a6bSSimon GlassThis happens automatically as part of a bootm command when FITs are used.
3233e569a6bSSimon Glass
3243e569a6bSSimon Glass
3253e569a6bSSimon GlassEnabling FIT Verification
3263e569a6bSSimon Glass-------------------------
3273e569a6bSSimon GlassIn addition to the options to enable FIT itself, the following CONFIGs must
3283e569a6bSSimon Glassbe enabled:
3293e569a6bSSimon Glass
330e43f74acSMasahiro YamadaCONFIG_FIT_SIGNATURE - enable signing and verification in FITs
3313e569a6bSSimon GlassCONFIG_RSA - enable RSA algorithm for signing
3323e569a6bSSimon Glass
33321d29f7fSHeiko SchocherWARNING: When relying on signed FIT images with required signature check
33421d29f7fSHeiko Schocherthe legacy image format is default disabled by not defining
33521d29f7fSHeiko SchocherCONFIG_IMAGE_FORMAT_LEGACY
3363e569a6bSSimon Glass
3373e569a6bSSimon GlassTesting
3383e569a6bSSimon Glass-------
339e43f74acSMasahiro YamadaAn easy way to test signing and verification is to use the test script
3403e569a6bSSimon Glassprovided in test/vboot/vboot_test.sh. This uses sandbox (a special version
3413e569a6bSSimon Glassof U-Boot which runs under Linux) to show the operation of a 'bootm'
3423e569a6bSSimon Glasscommand loading and verifying images.
3433e569a6bSSimon Glass
3443e569a6bSSimon GlassA sample run is show below:
3453e569a6bSSimon Glass
3463e569a6bSSimon Glass$ make O=sandbox sandbox_config
3473e569a6bSSimon Glass$ make O=sandbox
3483e569a6bSSimon Glass$ O=sandbox ./test/vboot/vboot_test.sh
3493e569a6bSSimon GlassSimple Verified Boot Test
3503e569a6bSSimon Glass=========================
3513e569a6bSSimon Glass
3523e569a6bSSimon GlassPlease see doc/uImage.FIT/verified-boot.txt for more information
3533e569a6bSSimon Glass
354646257d1SHeiko Schocher/home/hs/ids/u-boot/sandbox/tools/mkimage -D -I dts -O dtb -p 2000
3553e569a6bSSimon GlassBuild keys
356646257d1SHeiko Schocherdo sha1 test
3573e569a6bSSimon GlassBuild FIT with signed images
3583e569a6bSSimon GlassTest Verified Boot Run: unsigned signatures:: OK
3593e569a6bSSimon GlassSign images
3603e569a6bSSimon GlassTest Verified Boot Run: signed images: OK
3613e569a6bSSimon GlassBuild FIT with signed configuration
3623e569a6bSSimon GlassTest Verified Boot Run: unsigned config: OK
3633e569a6bSSimon GlassSign images
3643e569a6bSSimon GlassTest Verified Boot Run: signed config: OK
36529a23f9dSHeiko Schochercheck signed config on the host
366ce1400f6SSimon GlassSignature check OK
36729a23f9dSHeiko SchocherOK
36829a23f9dSHeiko SchocherTest Verified Boot Run: signed config: OK
369646257d1SHeiko SchocherTest Verified Boot Run: signed config with bad hash: OK
370646257d1SHeiko Schocherdo sha256 test
371646257d1SHeiko SchocherBuild FIT with signed images
372646257d1SHeiko SchocherTest Verified Boot Run: unsigned signatures:: OK
373646257d1SHeiko SchocherSign images
374646257d1SHeiko SchocherTest Verified Boot Run: signed images: OK
375646257d1SHeiko SchocherBuild FIT with signed configuration
376646257d1SHeiko SchocherTest Verified Boot Run: unsigned config: OK
377646257d1SHeiko SchocherSign images
378646257d1SHeiko SchocherTest Verified Boot Run: signed config: OK
37929a23f9dSHeiko Schochercheck signed config on the host
380ce1400f6SSimon GlassSignature check OK
38129a23f9dSHeiko SchocherOK
38229a23f9dSHeiko SchocherTest Verified Boot Run: signed config: OK
383646257d1SHeiko SchocherTest Verified Boot Run: signed config with bad hash: OK
3843e569a6bSSimon Glass
3853e569a6bSSimon GlassTest passed
3863e569a6bSSimon Glass
387ce1400f6SSimon Glass
388f1ca1fdeSGeorge McCollisterHardware Signing with PKCS#11
389f1ca1fdeSGeorge McCollister-----------------------------
390f1ca1fdeSGeorge McCollister
391f1ca1fdeSGeorge McCollisterSecurely managing private signing keys can challenging, especially when the
392f1ca1fdeSGeorge McCollisterkeys are stored on the file system of a computer that is connected to the
393f1ca1fdeSGeorge McCollisterInternet. If an attacker is able to steal the key, they can sign malicious FIT
394f1ca1fdeSGeorge McCollisterimages which will appear genuine to your devices.
395f1ca1fdeSGeorge McCollister
396f1ca1fdeSGeorge McCollisterAn alternative solution is to keep your signing key securely stored on hardware
397f1ca1fdeSGeorge McCollisterdevice like a smartcard, USB token or Hardware Security Module (HSM) and have
398f1ca1fdeSGeorge McCollisterthem perform the signing. PKCS#11 is standard for interfacing with these crypto
399f1ca1fdeSGeorge McCollisterdevice.
400f1ca1fdeSGeorge McCollister
401f1ca1fdeSGeorge McCollisterRequirements:
402f1ca1fdeSGeorge McCollisterSmartcard/USB token/HSM which can work with the pkcs11 engine
403f1ca1fdeSGeorge McCollisteropenssl
404f1ca1fdeSGeorge McCollisterlibp11 (provides pkcs11 engine)
405f1ca1fdeSGeorge McCollisterp11-kit (recommended to simplify setup)
406f1ca1fdeSGeorge McCollisteropensc (for smartcards and smartcard like USB devices)
407f1ca1fdeSGeorge McCollistergnutls (recommended for key generation, p11tool)
408f1ca1fdeSGeorge McCollister
409f1ca1fdeSGeorge McCollisterThe following examples use the Nitrokey Pro. Instructions for other devices may vary.
410f1ca1fdeSGeorge McCollister
411f1ca1fdeSGeorge McCollisterNotes on pkcs11 engine setup:
412f1ca1fdeSGeorge McCollister
413f1ca1fdeSGeorge McCollisterMake sure p11-kit, opensc are installed and that p11-kit is setup to use opensc.
414f1ca1fdeSGeorge McCollister/usr/share/p11-kit/modules/opensc.module should be present on your system.
415f1ca1fdeSGeorge McCollister
416f1ca1fdeSGeorge McCollister
417f1ca1fdeSGeorge McCollisterGenerating Keys On the Nitrokey:
418f1ca1fdeSGeorge McCollister
419f1ca1fdeSGeorge McCollister$ gpg --card-edit
420f1ca1fdeSGeorge McCollister
421f1ca1fdeSGeorge McCollisterReader ...........: Nitrokey Nitrokey Pro (xxxxxxxx0000000000000000) 00 00
422f1ca1fdeSGeorge McCollisterApplication ID ...: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
423f1ca1fdeSGeorge McCollisterVersion ..........: 2.1
424f1ca1fdeSGeorge McCollisterManufacturer .....: ZeitControl
425f1ca1fdeSGeorge McCollisterSerial number ....: xxxxxxxx
426f1ca1fdeSGeorge McCollisterName of cardholder: [not set]
427f1ca1fdeSGeorge McCollisterLanguage prefs ...: de
428f1ca1fdeSGeorge McCollisterSex ..............: unspecified
429f1ca1fdeSGeorge McCollisterURL of public key : [not set]
430f1ca1fdeSGeorge McCollisterLogin data .......: [not set]
431f1ca1fdeSGeorge McCollisterSignature PIN ....: forced
432f1ca1fdeSGeorge McCollisterKey attributes ...: rsa2048 rsa2048 rsa2048
433f1ca1fdeSGeorge McCollisterMax. PIN lengths .: 32 32 32
434f1ca1fdeSGeorge McCollisterPIN retry counter : 3 0 3
435f1ca1fdeSGeorge McCollisterSignature counter : 0
436f1ca1fdeSGeorge McCollisterSignature key ....: [none]
437f1ca1fdeSGeorge McCollisterEncryption key....: [none]
438f1ca1fdeSGeorge McCollisterAuthentication key: [none]
439f1ca1fdeSGeorge McCollisterGeneral key info..: [none]
440f1ca1fdeSGeorge McCollister
441f1ca1fdeSGeorge McCollistergpg/card> generate
442f1ca1fdeSGeorge McCollisterMake off-card backup of encryption key? (Y/n) n
443f1ca1fdeSGeorge McCollister
444f1ca1fdeSGeorge McCollisterPlease note that the factory settings of the PINs are
445f1ca1fdeSGeorge McCollister  PIN = '123456' Admin PIN = '12345678'
446f1ca1fdeSGeorge McCollisterYou should change them using the command --change-pin
447f1ca1fdeSGeorge McCollister
448f1ca1fdeSGeorge McCollisterWhat keysize do you want for the Signature key? (2048) 4096
449f1ca1fdeSGeorge McCollisterThe card will now be re-configured to generate a key of 4096 bits
450f1ca1fdeSGeorge McCollisterNote: There is no guarantee that the card supports the requested size.
451f1ca1fdeSGeorge McCollister  If the key generation does not succeed, please check the
452f1ca1fdeSGeorge McCollister  documentation of your card to see what sizes are allowed.
453f1ca1fdeSGeorge McCollisterWhat keysize do you want for the Encryption key? (2048) 4096
454f1ca1fdeSGeorge McCollisterThe card will now be re-configured to generate a key of 4096 bits
455f1ca1fdeSGeorge McCollisterWhat keysize do you want for the Authentication key? (2048) 4096
456f1ca1fdeSGeorge McCollisterThe card will now be re-configured to generate a key of 4096 bits
457f1ca1fdeSGeorge McCollisterPlease specify how long the key should be valid.
458f1ca1fdeSGeorge McCollister  0 = key does not expire
459f1ca1fdeSGeorge McCollister  <n> = key expires in n days
460f1ca1fdeSGeorge McCollister  <n>w = key expires in n weeks
461f1ca1fdeSGeorge McCollister  <n>m = key expires in n months
462f1ca1fdeSGeorge McCollister  <n>y = key expires in n years
463f1ca1fdeSGeorge McCollisterKey is valid for? (0)
464f1ca1fdeSGeorge McCollisterKey does not expire at all
465f1ca1fdeSGeorge McCollisterIs this correct? (y/N) y
466f1ca1fdeSGeorge McCollister
467f1ca1fdeSGeorge McCollisterGnuPG needs to construct a user ID to identify your key.
468f1ca1fdeSGeorge McCollister
469f1ca1fdeSGeorge McCollisterReal name: John Doe
470f1ca1fdeSGeorge McCollisterEmail address: john.doe@email.com
471f1ca1fdeSGeorge McCollisterComment:
472f1ca1fdeSGeorge McCollisterYou selected this USER-ID:
473f1ca1fdeSGeorge McCollister  "John Doe <john.doe@email.com>"
474f1ca1fdeSGeorge McCollister
475f1ca1fdeSGeorge McCollisterChange (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
476f1ca1fdeSGeorge McCollister
477f1ca1fdeSGeorge McCollister
478f1ca1fdeSGeorge McCollisterUsing p11tool to get the token URL:
479f1ca1fdeSGeorge McCollister
480f1ca1fdeSGeorge McCollisterDepending on system configuration, gpg-agent may need to be killed first.
481f1ca1fdeSGeorge McCollister
482f1ca1fdeSGeorge McCollister$ p11tool --provider /usr/lib/opensc-pkcs11.so --list-tokens
483f1ca1fdeSGeorge McCollisterToken 0:
484f1ca1fdeSGeorge McCollisterURL: pkcs11:model=PKCS%2315%20emulated;manufacturer=ZeitControl;serial=000xxxxxxxxx;token=OpenPGP%20card%20%28User%20PIN%20%28sig%29%29
485f1ca1fdeSGeorge McCollisterLabel: OpenPGP card (User PIN (sig))
486f1ca1fdeSGeorge McCollisterType: Hardware token
487f1ca1fdeSGeorge McCollisterManufacturer: ZeitControl
488f1ca1fdeSGeorge McCollisterModel: PKCS#15 emulated
489f1ca1fdeSGeorge McCollisterSerial: 000xxxxxxxxx
490f1ca1fdeSGeorge McCollisterModule: (null)
491f1ca1fdeSGeorge McCollister
492f1ca1fdeSGeorge McCollister
493f1ca1fdeSGeorge McCollisterToken 1:
494f1ca1fdeSGeorge McCollisterURL: pkcs11:model=PKCS%2315%20emulated;manufacturer=ZeitControl;serial=000xxxxxxxxx;token=OpenPGP%20card%20%28User%20PIN%29
495f1ca1fdeSGeorge McCollisterLabel: OpenPGP card (User PIN)
496f1ca1fdeSGeorge McCollisterType: Hardware token
497f1ca1fdeSGeorge McCollisterManufacturer: ZeitControl
498f1ca1fdeSGeorge McCollisterModel: PKCS#15 emulated
499f1ca1fdeSGeorge McCollisterSerial: 000xxxxxxxxx
500f1ca1fdeSGeorge McCollisterModule: (null)
501f1ca1fdeSGeorge McCollister
502f1ca1fdeSGeorge McCollisterUse the portion of the signature token URL after "pkcs11:" as the keydir argument (-k) to mkimage below.
503f1ca1fdeSGeorge McCollister
504f1ca1fdeSGeorge McCollister
505f1ca1fdeSGeorge McCollisterUse the URL of the token to list the private keys:
506f1ca1fdeSGeorge McCollister
507f1ca1fdeSGeorge McCollister$ p11tool --login --provider /usr/lib/opensc-pkcs11.so --list-privkeys \
508f1ca1fdeSGeorge McCollister"pkcs11:model=PKCS%2315%20emulated;manufacturer=ZeitControl;serial=000xxxxxxxxx;token=OpenPGP%20card%20%28User%20PIN%20%28sig%29%29"
509f1ca1fdeSGeorge McCollisterToken 'OpenPGP card (User PIN (sig))' with URL 'pkcs11:model=PKCS%2315%20emulated;manufacturer=ZeitControl;serial=000xxxxxxxxx;token=OpenPGP%20card%20%28User%20PIN%20%28sig%29%29' requires user PIN
510f1ca1fdeSGeorge McCollisterEnter PIN:
511f1ca1fdeSGeorge McCollisterObject 0:
512f1ca1fdeSGeorge McCollisterURL: pkcs11:model=PKCS%2315%20emulated;manufacturer=ZeitControl;serial=000xxxxxxxxx;token=OpenPGP%20card%20%28User%20PIN%20%28sig%29%29;id=%01;object=Signature%20key;type=private
513f1ca1fdeSGeorge McCollisterType: Private key
514f1ca1fdeSGeorge McCollisterLabel: Signature key
515f1ca1fdeSGeorge McCollisterFlags: CKA_PRIVATE; CKA_NEVER_EXTRACTABLE; CKA_SENSITIVE;
516f1ca1fdeSGeorge McCollisterID: 01
517f1ca1fdeSGeorge McCollister
518f1ca1fdeSGeorge McCollisterUse the label, in this case "Signature key" as the key-name-hint in your FIT.
519f1ca1fdeSGeorge McCollister
520f1ca1fdeSGeorge McCollisterCreate the fitImage:
521f1ca1fdeSGeorge McCollister$ ./tools/mkimage -f fit-image.its fitImage
522f1ca1fdeSGeorge McCollister
523f1ca1fdeSGeorge McCollister
524f1ca1fdeSGeorge McCollisterSign the fitImage with the hardware key:
525f1ca1fdeSGeorge McCollister
526f1ca1fdeSGeorge McCollister$ ./tools/mkimage -F -k \
527f1ca1fdeSGeorge McCollister"model=PKCS%2315%20emulated;manufacturer=ZeitControl;serial=000xxxxxxxxx;token=OpenPGP%20card%20%28User%20PIN%20%28sig%29%29" \
528f1ca1fdeSGeorge McCollister-K u-boot.dtb -N pkcs11 -r fitImage
529f1ca1fdeSGeorge McCollister
530f1ca1fdeSGeorge McCollister
5313e569a6bSSimon GlassFuture Work
5323e569a6bSSimon Glass-----------
5333e569a6bSSimon Glass- Roll-back protection using a TPM is done using the tpm command. This can
5343e569a6bSSimon Glassbe scripted, but we might consider a default way of doing this, built into
5353e569a6bSSimon Glassbootm.
5363e569a6bSSimon Glass
5373e569a6bSSimon Glass
5383e569a6bSSimon GlassPossible Future Work
5393e569a6bSSimon Glass--------------------
5403e569a6bSSimon Glass- Add support for other RSA/SHA variants, such as rsa4096,sha512.
5413e569a6bSSimon Glass- Other algorithms besides RSA
5423e569a6bSSimon Glass- More sandbox tests for failure modes
5433e569a6bSSimon Glass- Passwords for keys/certificates
5443e569a6bSSimon Glass- Perhaps implement OAEP
5453e569a6bSSimon Glass- Enhance bootm to permit scripted signature verification (so that a script
5463e569a6bSSimon Glasscan verify an image but not actually boot it)
5473e569a6bSSimon Glass
5483e569a6bSSimon Glass
5493e569a6bSSimon GlassSimon Glass
5503e569a6bSSimon Glasssjg@chromium.org
5513e569a6bSSimon Glass1-1-13
552