1
0
Fork 0
alistair23-linux/include/crypto
David Howells 99db443506 PKCS#7: Appropriately restrict authenticated attributes and content type
A PKCS#7 or CMS message can have per-signature authenticated attributes
that are digested as a lump and signed by the authorising key for that
signature.  If such attributes exist, the content digest isn't itself
signed, but rather it is included in a special authattr which then
contributes to the signature.

Further, we already require the master message content type to be
pkcs7_signedData - but there's also a separate content type for the data
itself within the SignedData object and this must be repeated inside the
authattrs for each signer [RFC2315 9.2, RFC5652 11.1].

We should really validate the authattrs if they exist or forbid them
entirely as appropriate.  To this end:

 (1) Alter the PKCS#7 parser to reject any message that has more than one
     signature where at least one signature has authattrs and at least one
     that does not.

 (2) Validate authattrs if they are present and strongly restrict them.
     Only the following authattrs are permitted and all others are
     rejected:

     (a) contentType.  This is checked to be an OID that matches the
     	 content type in the SignedData object.

     (b) messageDigest.  This must match the crypto digest of the data.

     (c) signingTime.  If present, we check that this is a valid, parseable
     	 UTCTime or GeneralTime and that the date it encodes fits within
     	 the validity window of the matching X.509 cert.

     (d) S/MIME capabilities.  We don't check the contents.

     (e) Authenticode SP Opus Info.  We don't check the contents.

     (f) Authenticode Statement Type.  We don't check the contents.

     The message is rejected if (a) or (b) are missing.  If the message is
     an Authenticode type, the message is rejected if (e) is missing; if
     not Authenticode, the message is rejected if (d) - (f) are present.

     The S/MIME capabilities authattr (d) unfortunately has to be allowed
     to support kernels already signed by the pesign program.  This only
     affects kexec.  sign-file suppresses them (CMS_NOSMIMECAP).

     The message is also rejected if an authattr is given more than once or
     if it contains more than one element in its set of values.

 (3) Add a parameter to pkcs7_verify() to select one of the following
     restrictions and pass in the appropriate option from the callers:

     (*) VERIFYING_MODULE_SIGNATURE

	 This requires that the SignedData content type be pkcs7-data and
	 forbids authattrs.  sign-file sets CMS_NOATTR.  We could be more
	 flexible and permit authattrs optionally, but only permit minimal
	 content.

     (*) VERIFYING_FIRMWARE_SIGNATURE

	 This requires that the SignedData content type be pkcs7-data and
	 requires authattrs.  In future, this will require an attribute
	 holding the target firmware name in addition to the minimal set.

     (*) VERIFYING_UNSPECIFIED_SIGNATURE

	 This requires that the SignedData content type be pkcs7-data but
	 allows either no authattrs or only permits the minimal set.

     (*) VERIFYING_KEXEC_PE_SIGNATURE

	 This only supports the Authenticode SPC_INDIRECT_DATA content type
	 and requires at least an SpcSpOpusInfo authattr in addition to the
	 minimal set.  It also permits an SPC_STATEMENT_TYPE authattr (and
	 an S/MIME capabilities authattr because the pesign program doesn't
	 remove these).

     (*) VERIFYING_KEY_SIGNATURE
     (*) VERIFYING_KEY_SELF_SIGNATURE

	 These are invalid in this context but are included for later use
	 when limiting the use of X.509 certs.

 (4) The pkcs7_test key type is given a module parameter to select between
     the above options for testing purposes.  For example:

	echo 1 >/sys/module/pkcs7_test_key/parameters/usage
	keyctl padd pkcs7_test foo @s </tmp/stuff.pkcs7

     will attempt to check the signature on stuff.pkcs7 as if it contains a
     firmware blob (1 being VERIFYING_FIRMWARE_SIGNATURE).

Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: David Woodhouse <David.Woodhouse@intel.com>
2015-08-12 17:01:01 +01:00
..
internal crypto: rng - Do not free default RNG when it becomes unused 2015-06-22 15:49:18 +08:00
ablk_helper.h crypto: create generic version of ablk_helper 2013-09-24 06:02:24 +10:00
aead.h crypto: doc - Fix typo in crypto-API.xml 2015-06-04 15:05:08 +08:00
aes.h crypto: aes - Move key_length in struct crypto_aes_ctx to be the last field 2009-02-18 16:48:04 +08:00
akcipher.h crypto: akcipher - add PKE API 2015-06-17 17:03:14 +08:00
algapi.h crypto: aead - Convert top level interface to new style 2015-05-13 10:31:53 +08:00
authenc.h crypto: authenc - Export key parsing helper function 2013-10-16 20:56:25 +08:00
b128ops.h [CRYPTO] lib: some common 128-bit block operations, nicely centralized 2006-12-06 18:38:55 -08:00
blowfish.h crypto: blowfish - split generic and common c code 2011-09-22 21:25:25 +10:00
cast5.h crypto: cast5/cast6 - move lookup tables to shared module 2012-12-06 17:16:26 +08:00
cast6.h crypto: cast5/cast6 - move lookup tables to shared module 2012-12-06 17:16:26 +08:00
cast_common.h crypto: cast5/cast6 - move lookup tables to shared module 2012-12-06 17:16:26 +08:00
compress.h crypto: pcomp - Constify (de)compression parameters 2015-05-01 11:16:37 +08:00
cryptd.h crypto: cryptd - Add missing aead.h inclusion 2015-05-13 10:31:46 +08:00
crypto_wq.h crypto: api - Use dedicated workqueue for crypto subsystem 2009-02-19 14:33:40 +08:00
ctr.h [CRYPTO] ctr: Refactor into ctr and rfc3686 2008-01-11 08:16:41 +11:00
des.h crypto: des_3des - add x86-64 assembly implementation 2014-06-20 21:27:58 +08:00
drbg.h crypto: drbg - reseed often if seedsource is degraded 2015-06-10 19:14:05 +08:00
gf128mul.h Update broken web addresses in the kernel. 2010-10-18 11:03:14 +02:00
hash.h crypto: doc - Fix typo in crypto-API.xml 2015-06-04 15:05:08 +08:00
hash_info.h crypto: provide single place for hash algo information 2013-10-25 17:14:03 -04:00
if_alg.h crypto: af_alg - Allow to link sgl 2015-03-23 16:41:37 -04:00
lrw.h crypto: lrw - add interface for parallelized cipher implementions 2011-11-09 11:50:31 +08:00
mcryptd.h crypto: sha-mb - multibuffer crypto infrastructure 2014-08-25 20:32:25 +08:00
md5.h crypto: md5 - add MD5 initial vectors 2015-05-18 12:20:18 +08:00
null.h crypto: null - Add default null skcipher 2015-05-22 11:25:55 +08:00
padlock.h crypto: padlock - Move padlock.h into include/crypto 2011-01-07 14:52:00 +11:00
pcrypt.h crypto: pcrypt - Add pcrypt crypto parallelization wrapper 2010-01-07 15:57:19 +11:00
pkcs7.h PKCS#7: Appropriately restrict authenticated attributes and content type 2015-08-12 17:01:01 +01:00
public_key.h PKCS#7: Appropriately restrict authenticated attributes and content type 2015-08-12 17:01:01 +01:00
rng.h crypto: doc - Fix typo in crypto-API.xml 2015-06-04 15:05:08 +08:00
scatterwalk.h crypto: scatterwalk - Add scatterwalk_ffwd helper 2015-05-22 11:25:50 +08:00
serpent.h crypto: serpent-sse2 - add lrw support 2011-11-21 16:13:24 +08:00
sha.h crypto: sha512-generic - move to generic glue implementation 2015-04-10 21:39:41 +08:00
sha1_base.h crypto: sha1 - implement base layer for SHA-1 2015-04-10 21:39:39 +08:00
sha256_base.h crypto: sha256 - implement base layer for SHA-256 2015-04-10 21:39:39 +08:00
sha512_base.h crypto: sha512 - implement base layer for SHA-512 2015-04-10 21:39:39 +08:00
skcipher.h crypto: Resolve shadow warnings 2014-08-01 22:35:55 +08:00
twofish.h crypto: twofish-x86_64-3way - add lrw support 2011-11-09 11:53:32 +08:00
vmac.h crypto: vmac - Make VMAC work when blocks aren't aligned 2012-10-15 22:33:20 +08:00
xts.h crypto: xts: add interface for parallelized cipher implementations 2011-11-09 11:56:06 +08:00