KEYS: PKCS#7 asymmetric key parser
Subsystems (4)
David Howells
maintainercover KEYS: PKCS#7 asymmetric key parser
Here's a set of patches that implements a PKCS#7 message parser in the kernel.
The PKCS#7 message parsing will then be used to limit kexec to authenticated kernels only if so configured.
The patches provide the following facilities:
(1) Parse an ASN.1 PKCS#7 message and pick out useful bits such as the data content and the X.509 certificates used to sign it and all the data signatures.
(2) Verify all the data signatures against the set of X.509 certificates available in the message.
(3) Follow the certificate chains and verify that:
(a) for every self-signed X.509 certificate, check that it validly signed itself, and:
(b) for every non-self-signed certificate, if we have a 'parent' certificate, the former is validly signed by the latter.
(4) Look for intersections between the certificate chains and the trusted keyring, if any intersections are found, verify that the trusted certificates signed the intersection point in the chain.
(5) For testing purposes, a key type can be made available that will take a PKCS#7 message, check that the message is trustworthy, and if so, add its data content into the key.
They can be found on this branch also:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-modsign.git/log/?h=pkcs7
and are tagged with:
keys-pkcs7-20140708
David
---
David Howells (7):
X.509: Export certificate parse and free functions
PKCS#7: Implement a parser [RFC 2315]
PKCS#7: Digest the data in a signed-data message
PKCS#7: Find the right key in the PKCS#7 key list and verify the signature PKCS#7: Verify internal certificate chain
PKCS#7: Find intersection between PKCS#7 message and known, trusted keys PKCS#7: Provide a key type for testing PKCS#7
crypto/asymmetric_keys/Kconfig | 22 ++ crypto/asymmetric_keys/Makefile | 22 ++ crypto/asymmetric_keys/pkcs7.asn1 | 127 +++++++++ crypto/asymmetric_keys/pkcs7_key_type.c | 97 +++++++ crypto/asymmetric_keys/pkcs7_parser.c | 396 +++++++++++++++++++++++++++++ crypto/asymmetric_keys/pkcs7_parser.h | 61 ++++ crypto/asymmetric_keys/pkcs7_trust.c | 219 ++++++++++++++++ crypto/asymmetric_keys/pkcs7_verify.c | 323 ++++++++++++++++++++++++ crypto/asymmetric_keys/x509_cert_parser.c | 3 include/crypto/pkcs7.h | 36 +++ include/linux/oid_registry.h | 1 11 files changed, 1307 insertions(+) create mode 100644 crypto/asymmetric_keys/pkcs7.asn1 create mode 100644 crypto/asymmetric_keys/pkcs7_key_type.c create mode 100644 crypto/asymmetric_keys/pkcs7_parser.c create mode 100644 crypto/asymmetric_keys/pkcs7_parser.h create mode 100644 crypto/asymmetric_keys/pkcs7_trust.c create mode 100644 crypto/asymmetric_keys/pkcs7_verify.c create mode 100644 include/crypto/pkcs7.h
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
David Howells
maintainer[PATCH1/7] X.509: Export certificate parse and free functions
Export certificate parse and free functions for use by modules.
---
crypto/asymmetric_keys/x509_cert_parser.c | 3 +++ 1 file changed, 3 insertions(+)
crypto/asymmetric_keys/x509_cert_parser.c +3 -0
@@ -11,6 +11,7 @@#define pr_fmt (fmt) "X.509: "fmt#include <linux/kernel.h> +#include <linux/export.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/oid_registry.h>
@@ -52,6 +53,7 @@ void x509_free_certificate(struct x509_certificate *cert)kfree (cert); } } +EXPORT_SYMBOL_GPL (x509_free_certificate);/* * Parse an X.509 certificate
@@ -97,6 +99,7 @@ error_no_ctx: error_no_cert:return ERR_PTR (ret); } +EXPORT_SYMBOL_GPL (x509_cert_parse);/* * Note an OID when we find one for later processing when we know how
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
David Howells
maintainer[PATCH2/7] PKCS#7: Implement a parser [RFC 2315]
In reply to David HowellsImplement a parser for a PKCS#7 signed-data message as described in part of RFC 2315.
---
crypto/asymmetric_keys/Kconfig | 9 + crypto/asymmetric_keys/Makefile | 13 + crypto/asymmetric_keys/pkcs7.asn1 | 127 +++++++++++ crypto/asymmetric_keys/pkcs7_parser.c | 396 +++++++++++++++++++++++++++++++++ crypto/asymmetric_keys/pkcs7_parser.h | 61 +++++ include/crypto/pkcs7.h | 23 ++ include/linux/oid_registry.h | 1 7 files changed, 630 insertions(+) create mode 100644 crypto/asymmetric_keys/pkcs7.asn1 create mode 100644 crypto/asymmetric_keys/pkcs7_parser.c create mode 100644 crypto/asymmetric_keys/pkcs7_parser.h create mode 100644 include/crypto/pkcs7.h
crypto/asymmetric_keys/Kconfig +9 -0
@@ -37,4 +37,13 @@ config X509_CERTIFICATE_PARSER data and provides the ability to instantiate a crypto key from a public key packet found inside the certificate. +config PKCS7_MESSAGE_PARSER + tristate "PKCS#7 message parser" + depends on X509_CERTIFICATE_PARSER + select ASN1 + select OID_REGISTRY + help + This option provides support for parsing PKCS#7 format messages for + signature data and provides the ability to verify the signature. + endif # ASYMMETRIC_KEY_TYPE
crypto/asymmetric_keys/Makefile +13 -0
@@ -25,3 +25,16 @@ $(obj)/x509_rsakey-asn1.o: $(obj)/x509_rsakey-asn1.c $(obj)/x509_rsakey-asn1.h clean-files += x509-asn1.c x509-asn1.h clean-files += x509_rsakey-asn1.c x509_rsakey-asn1.h + +# +# PKCS#7 message handling +# +obj-$(CONFIG_PKCS7_MESSAGE_PARSER) += pkcs7_message.o +pkcs7_message-y := \ + pkcs7-asn1.o \ + pkcs7_parser.o + +$(obj)/pkcs7_parser.o: $(obj)/pkcs7-asn1.h +$(obj)/pkcs7-asn1.o: $(obj)/pkcs7-asn1.c $(obj)/pkcs7-asn1.h + +clean-files += pkcs7-asn1.c pkcs7-asn1.h
crypto/asymmetric_keys/pkcs7.asn1 new file +127 -0
127 lines not on this page · raw message
crypto/asymmetric_keys/pkcs7_parser.c new file +396 -0
396 lines not on this page · raw message
crypto/asymmetric_keys/pkcs7_parser.h new file +61 -0
61 lines not on this page · raw message
include/crypto/pkcs7.h new file +23 -0
@@ -0,0 +1,23 @@ +/* PKCS#7 crypto data parser +* +* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ + +struct pkcs7_message ; + +/* +* pkcs7_parser.c +*/ +extern struct pkcs7_message *pkcs7_parse_message (const void *data, +size_t datalen); +extern void pkcs7_free_message (struct pkcs7_message *pkcs7); + +extern int pkcs7_get_content_data (const struct pkcs7_message *pkcs7, +const void **_data,size_t *_datalen, +bool want_wrapper);
include/linux/oid_registry.h +1 -0
@@ -55,6 +55,7 @@ enum OID { OID_certAuthInfoAccess,/* 1.3.6.1.5.5.7.1.1 */ OID_msOutlookExpress,/* 1.3.6.1.4.1.311.16.4 */ OID_sha1,/* 1.3.14.3.2.26 */ + OID_sha256,/* 2.16.840.1.101.3.4.2.1 */ /* Distinguished Name attribute IDs [RFC 2256] */ OID_commonName, /* 2.5.4.3 */
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
David Howells
maintainer[PATCH3/7] PKCS#7: Digest the data in a signed-data message
In reply to David HowellsDigest the data in a PKCS#7 signed-data message and attach to the public_key_signature struct contained in the pkcs7_message struct.
---
crypto/asymmetric_keys/Makefile | 3 - crypto/asymmetric_keys/pkcs7_verify.c | 173 +++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 crypto/asymmetric_keys/pkcs7_verify.c
crypto/asymmetric_keys/Makefile +2 -1
@@ -32,7 +32,8 @@ clean-files += x509_rsakey-asn1.c x509_rsakey-asn1.h obj-$(CONFIG_PKCS7_MESSAGE_PARSER) += pkcs7_message.o pkcs7_message-y := \ pkcs7-asn1.o \ - pkcs7_parser.o + pkcs7_parser.o \ + pkcs7_verify.o $(obj)/pkcs7_parser.o: $(obj)/pkcs7-asn1.h $(obj)/pkcs7-asn1.o: $(obj)/pkcs7-asn1.c $(obj)/pkcs7-asn1.h
crypto/asymmetric_keys/pkcs7_verify.c new file +173 -0
173 lines not on this page · raw message
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
David Howells
maintainer[PATCH4/7] PKCS#7: Find the right key in the PKCS#7 key list and verify the signature
In reply to David HowellsFind the appropriate key in the PKCS#7 key list and verify the signature with it. There may be several keys in there forming a chain. Any link in that chain or the root of that chain may be in our keyrings.
---
crypto/asymmetric_keys/pkcs7_verify.c | 64 +++++++++++++++++++++++++++++++++ include/crypto/pkcs7.h | 5 +++ 2 files changed, 69 insertions(+)
crypto/asymmetric_keys/pkcs7_verify.c +64 -0
@@ -120,6 +120,55 @@ error_no_desc: }/* +* Find the key (X.509 certificate) to use to verify a PKCS#7 message. PKCS#7 +* uses the issuer's name and the issuing certificate serial number for +* matching purposes. These must match the certificate issuer's name (not +* subject's name) and the certificate serial number [RFC 2315 6.7]. +*/ +static int pkcs7_find_key (struct pkcs7_message *pkcs7, +struct pkcs7_signed_info *sinfo) +{ +struct x509_certificate *x509; +unsigned certix =1 ; + +kenter ("%u,%u,%u" , + sinfo->index, sinfo->raw_serial_size, sinfo->raw_issuer_size); + +for (x509 = pkcs7->certs; x509; x509 = x509->next, certix++) { +/* I'm _assuming_ that the generator of the PKCS#7 message will +* encode the fields from the X.509 cert in the same way in the +* PKCS#7 message - but I can't be 100% sure of that. It's +* possible this will need element-by-element comparison. +*/ +if (x509->raw_serial_size != sinfo->raw_serial_size || +memcmp (x509->raw_serial, sinfo->raw_serial, + sinfo->raw_serial_size) !=0 ) +continue ; +pr_devel ("Sig %u: Found cert serial match X.509[%u]\n" , + sinfo->index, certix); + +if (x509->raw_issuer_size != sinfo->raw_issuer_size || +memcmp (x509->raw_issuer, sinfo->raw_issuer, + sinfo->raw_issuer_size) !=0 ) { +pr_warn ("Sig %u: X.509 subject and PKCS#7 issuer don't match\n" , + sinfo->index); +continue ; + } + +if (x509->pub->pkey_algo != sinfo->sig.pkey_algo) { +pr_warn ("Sig %u: X.509 algo and PKCS#7 sig algo don't match\n" , + sinfo->index); +continue ; + } + + sinfo->signer = x509; +return 0 ; + } +pr_warn ("Sig %u: Issuing X.509 cert not found (#%*ph)\n" , + sinfo->index, sinfo->raw_serial_size, sinfo->raw_serial); +return -ENOKEY ; +} +/* * Verify one signed information block from a PKCS#7 message. */
@@ -137,6 +186,21 @@ static int pkcs7_verify_one(struct pkcs7_message *pkcs7,if (ret <0 )return ret; +/* Find the key for the signature */ + ret =pkcs7_find_key (pkcs7, sinfo); +if (ret <0 ) +return ret; + +pr_devel ("Using X.509[%u] for sig %u\n" , + sinfo->signer->index, sinfo->index); + +/* Verify the PKCS#7 binary against the key */ + ret =public_key_verify_signature (sinfo->signer->pub, &sinfo->sig); +if (ret <0 ) +return ret; + +pr_devel ("Verified signature %u\n" , sinfo->index); +return 0 ; }
include/crypto/pkcs7.h +5 -0
@@ -21,3 +21,8 @@ extern void pkcs7_free_message(struct pkcs7_message *pkcs7);extern int pkcs7_get_content_data (const struct pkcs7_message *pkcs7,const void **_data,size_t *_datalen,bool want_wrapper); + +/* +* pkcs7_verify.c +*/ +extern int pkcs7_verify (struct pkcs7_message *pkcs7);
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
David Howells
maintainer[PATCH5/7] PKCS#7: Verify internal certificate chain
In reply to David HowellsVerify certificate chain in the X.509 certificates contained within the PKCS#7 message as far as possible. If any signature that we should be able to verify fails, we reject the whole lot.
---
crypto/asymmetric_keys/pkcs7_verify.c | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+), 1 deletion(-)
crypto/asymmetric_keys/pkcs7_verify.c +87 -1
@@ -170,6 +170,91 @@ static int pkcs7_find_key(struct pkcs7_message *pkcs7, }/* +* Verify the internal certificate chain as best we can. +*/ +static int pkcs7_verify_sig_chain (struct pkcs7_message *pkcs7, +struct pkcs7_signed_info *sinfo) +{ +struct x509_certificate *x509 = sinfo->signer, *p; +int ret; + +kenter ("" ); + +for (p = pkcs7->certs; p; p = p->next) + p->seen = false; + +for (;;) { +pr_debug ("verify %s: %s\n" , x509->subject, x509->fingerprint); + x509->seen = true; + ret =x509_get_sig_params (x509); +if (ret <0 ) +return ret; + +if (x509->issuer) +pr_debug ("- issuer %s\n" , x509->issuer); +if (x509->authority) +pr_debug ("- authkeyid %s\n" , x509->authority); + +if (!x509->authority || + (x509->subject && +strcmp (x509->subject, x509->issuer) ==0 )) { +/* If there's no authority certificate specified, then +* the certificate must be self-signed and is the root +* of the chain. Likewise if the cert is its own +* authority. +*/ +pr_debug ("- no auth?\n" ); +if (x509->raw_subject_size != x509->raw_issuer_size || +memcmp (x509->raw_subject, x509->raw_issuer, + x509->raw_issuer_size) !=0 ) +return 0 ; + + ret =x509_check_signature (x509->pub, x509); +if (ret <0 ) +return ret; + x509->signer = x509; +pr_debug ("- self-signed\n" ); +return 0 ; + } + +/* Look through the X.509 certificates in the PKCS#7 message's +* list to see if the next one is there. +*/ +pr_debug ("- want %s\n" , x509->authority); +for (p = pkcs7->certs; p; p = p->next) { +pr_debug ("- cmp [%u] %s\n" , p->index, p->fingerprint); +if (p->raw_subject_size == x509->raw_issuer_size && +strcmp (p->fingerprint, x509->authority) ==0 && +memcmp (p->raw_subject, x509->raw_issuer, + x509->raw_issuer_size) ==0 ) + goto found_issuer; + } + +/* We didn't find the root of this chain */ +pr_debug ("- top\n" ); +return 0 ; + + found_issuer: +pr_debug ("- issuer %s\n" , p->subject); +if (p->seen) { +pr_warn ("Sig %u: X.509 chain contains loop\n" , + sinfo->index); +return 0 ; + } + ret =x509_check_signature (p->pub, x509); +if (ret <0 ) +return ret; + x509->signer = p; +if (x509 == p) { +pr_debug ("- self-signed\n" ); +return 0 ; + } + x509 = p; +might_sleep (); + } +} + +/* * Verify one signed information block from a PKCS#7 message. */ static int pkcs7_verify_one(struct pkcs7_message *pkcs7,
@@ -201,7 +286,8 @@ static int pkcs7_verify_one(struct pkcs7_message *pkcs7,pr_devel ("Verified signature %u\n" , sinfo->index); -return 0 ; +/* Verify the internal certificate chain */ +return pkcs7_verify_sig_chain (pkcs7, sinfo); }/**
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
David Howells
maintainer[PATCH6/7] PKCS#7: Find intersection between PKCS#7 message and known, trusted keys
In reply to David HowellsFind the intersection between the X.509 certificate chain contained in a PKCS#7 message and a set of keys that we already know and trust.
---
crypto/asymmetric_keys/Makefile | 1 crypto/asymmetric_keys/pkcs7_trust.c | 219 ++++++++++++++++++++++++++++++++++ include/crypto/pkcs7.h | 8 + 3 files changed, 228 insertions(+) create mode 100644 crypto/asymmetric_keys/pkcs7_trust.c
crypto/asymmetric_keys/Makefile +1 -0
@@ -33,6 +33,7 @@ obj-$(CONFIG_PKCS7_MESSAGE_PARSER) += pkcs7_message.o pkcs7_message-y := \ pkcs7-asn1.o \ pkcs7_parser.o \ + pkcs7_trust.o \ pkcs7_verify.o $(obj)/pkcs7_parser.o: $(obj)/pkcs7-asn1.h
crypto/asymmetric_keys/pkcs7_trust.c new file +219 -0
219 lines not on this page · raw message
include/crypto/pkcs7.h +8 -0
@@ -9,6 +9,7 @@* 2 of the Licence, or (at your option) any later version. */ +struct key ;struct pkcs7_message ;/*
@@ -23,6 +24,13 @@ extern int pkcs7_get_content_data(const struct pkcs7_message *pkcs7, bool want_wrapper);/* +* pkcs7_trust.c +*/ +extern int pkcs7_validate_trust (struct pkcs7_message *pkcs7, +struct key *trust_keyring, +bool *_trusted); + +/* * pkcs7_verify.c */ extern int pkcs7_verify (struct pkcs7_message *pkcs7);
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
David Howells
maintainer[PATCH7/7] PKCS#7: Provide a key type for testing PKCS#7
In reply to David HowellsProvide a key type for testing the PKCS#7 parser. It is given a non-detached PKCS#7 message as payload:
keyctl padd pkcs7_test a @s <stuff.pkcs7
The PKCS#7 wrapper is validated against the trusted certificates available and then stripped off. If successful, the key can be read, which will give the data content of the PKCS#7 message.
A suitable message can be created by running make on the attached Makefile. This will produce a file called stuff.pkcs7 for test loading. The key3.x509 file should be put into the kernel source tree before it is built and converted to DER form:
openssl x509 -in .../pkcs7/key3.x509 -outform DER -out key3.x509
###############################################################################
#
# Create a pkcs7 message and sign it twice
#
# openssl x509 -text -inform PEM -noout -in key2.x509
#
###############################################################################
stuff.pkcs7: stuff.txt key2.priv key2.x509 key4.priv key4.x509 certs
$(RM) $@ openssl smime -sign \ -signer key2.x509 \ -inkey key2.priv \ -signer key4.x509 \ -inkey key4.priv \ -in stuff.txt \ -certfile certs \ -out $@ -binary -outform DER -nodetach openssl pkcs7 -inform DER -in stuff.pkcs7 -print_certs -noout openssl asn1parse -inform DER -in stuff.pkcs7 -i >out
stuff.txt:
echo "The quick red fox jumped over the lazy brown dog" >stuff.txt
certs: key1.x509 key2.x509 key3.x509 key4.x509
cat key{1,3}.x509 >$@###############################################################################
#
# Generate a signed key
#
# openssl x509 -text -inform PEM -noout -in key2.x509
#
###############################################################################
key2.x509: key2.x509_unsigned key1.priv key1.x509
openssl x509 \ -req -in key2.x509_unsigned \ -out key2.x509 \ -extfile key2.genkey -extensions myexts \ -CA key1.x509 \ -CAkey key1.priv \ -CAcreateserial
key2.priv key2.x509_unsigned: key2.genkey
openssl req -new -nodes -utf8 -sha1 -days 36500 \ -batch -outform PEM \ -config key2.genkey \ -keyout key2.priv \ -out key2.x509_unsigned
key2.genkey:
@echo Generating X.509 key generation config @echo >$@ "[ req ]" @echo >>$@ "default_bits = 4096" @echo >>$@ "distinguished_name = req_distinguished_name" @echo >>$@ "prompt = no" @echo >>$@ "string_mask = utf8only" @echo >>$@ "x509_extensions = myexts" @echo >>$@ @echo >>$@ "[ req_distinguished_name ]" @echo >>$@ "O = Magrathea" @echo >>$@ "CN = PKCS7 key 2" @echo >>$@ "emailAddress = [email protected]" @echo >>$@ @echo >>$@ "[ myexts ]" @echo >>$@ "basicConstraints=critical,CA:FALSE" @echo >>$@ "keyUsage=digitalSignature" @echo >>$@ "subjectKeyIdentifier=hash" @echo >>$@ "authorityKeyIdentifier=keyid"
###############################################################################
#
# Generate a couple of signing keys
#
# openssl x509 -text -inform PEM -noout -in key1.x509
#
###############################################################################
key1.x509: key1.x509_unsigned key4.priv key4.x509
openssl x509 \ -req -in key1.x509_unsigned \ -out key1.x509 \ -extfile key1.genkey -extensions myexts \ -CA key4.x509 \ -CAkey key4.priv \ -CAcreateserial
key1.priv key1.x509_unsigned: key1.genkey
openssl req -new -nodes -utf8 -sha1 -days 36500 \ -batch -outform PEM \ -config key1.genkey \ -keyout key1.priv \ -out key1.x509_unsigned
key1.genkey:
@echo Generating X.509 key generation config @echo >$@ "[ req ]" @echo >>$@ "default_bits = 4096" @echo >>$@ "distinguished_name = req_distinguished_name" @echo >>$@ "prompt = no" @echo >>$@ "string_mask = utf8only" @echo >>$@ "x509_extensions = myexts" @echo >>$@ @echo >>$@ "[ req_distinguished_name ]" @echo >>$@ "O = Magrathea" @echo >>$@ "CN = PKCS7 key 1" @echo >>$@ "emailAddress = [email protected]" @echo >>$@ @echo >>$@ "[ myexts ]" @echo >>$@ "basicConstraints=critical,CA:TRUE" @echo >>$@ "keyUsage=digitalSignature,keyCertSign" @echo >>$@ "subjectKeyIdentifier=hash" @echo >>$@ "authorityKeyIdentifier=keyid"
###############################################################################
#
# Generate a signed key
#
# openssl x509 -text -inform PEM -noout -in key4.x509
#
###############################################################################
key4.x509: key4.x509_unsigned key3.priv key3.x509
openssl x509 \ -req -in key4.x509_unsigned \ -out key4.x509 \ -extfile key4.genkey -extensions myexts \ -CA key3.x509 \ -CAkey key3.priv \ -CAcreateserial
key4.priv key4.x509_unsigned: key4.genkey
openssl req -new -nodes -utf8 -sha1 -days 36500 \ -batch -outform PEM \ -config key4.genkey \ -keyout key4.priv \ -out key4.x509_unsigned
key4.genkey:
@echo Generating X.509 key generation config @echo >$@ "[ req ]" @echo >>$@ "default_bits = 4096" @echo >>$@ "distinguished_name = req_distinguished_name" @echo >>$@ "prompt = no" @echo >>$@ "string_mask = utf8only" @echo >>$@ "x509_extensions = myexts" @echo >>$@ @echo >>$@ "[ req_distinguished_name ]" @echo >>$@ "O = Magrathea" @echo >>$@ "CN = PKCS7 key 4" @echo >>$@ "emailAddress = [email protected]" @echo >>$@ @echo >>$@ "[ myexts ]" @echo >>$@ "basicConstraints=critical,CA:TRUE" @echo >>$@ "keyUsage=digitalSignature,keyCertSign" @echo >>$@ "subjectKeyIdentifier=hash" @echo >>$@ "authorityKeyIdentifier=keyid"
###############################################################################
#
# Generate a couple of signing keys
#
# openssl x509 -text -inform PEM -noout -in key3.x509
#
###############################################################################
key3.priv key3.x509: key3.genkey
openssl req -new -nodes -utf8 -sha1 -days 36500 \ -batch -x509 -outform PEM \ -config key3.genkey \ -keyout key3.priv \ -out key3.x509
key3.genkey:
@echo Generating X.509 key generation config @echo >$@ "[ req ]" @echo >>$@ "default_bits = 4096" @echo >>$@ "distinguished_name = req_distinguished_name" @echo >>$@ "prompt = no" @echo >>$@ "string_mask = utf8only" @echo >>$@ "x509_extensions = myexts" @echo >>$@ @echo >>$@ "[ req_distinguished_name ]" @echo >>$@ "O = Magrathea" @echo >>$@ "CN = PKCS7 key 3" @echo >>$@ "emailAddress = [email protected]" @echo >>$@ @echo >>$@ "[ myexts ]" @echo >>$@ "basicConstraints=critical,CA:TRUE" @echo >>$@ "keyUsage=digitalSignature,keyCertSign" @echo >>$@ "subjectKeyIdentifier=hash" @echo >>$@ "authorityKeyIdentifier=keyid"
clean:
$(RM) *~ $(RM) key1.* key2.* key3.* key4.* stuff.* out certs
---
crypto/asymmetric_keys/Kconfig | 13 ++++ crypto/asymmetric_keys/Makefile | 7 ++ crypto/asymmetric_keys/pkcs7_key_type.c | 97 +++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 crypto/asymmetric_keys/pkcs7_key_type.c
crypto/asymmetric_keys/Kconfig +13 -0
@@ -46,4 +46,17 @@ config PKCS7_MESSAGE_PARSER This option provides support for parsing PKCS#7 format messages for signature data and provides the ability to verify the signature. +config PKCS7_TEST_KEY + tristate "PKCS#7 testing key type" + depends on PKCS7_MESSAGE_PARSER + select SYSTEM_TRUSTED_KEYRING + help + This option provides a type of key that can be loaded up from a + PKCS#7 message - provided the message is signed by a trusted key. If + it is, the PKCS#7 wrapper is discarded and reading the key returns + just the payload. If it isn't, adding the key will fail with an + error. + + This is intended for testing the PKCS#7 parser. + endif # ASYMMETRIC_KEY_TYPE
crypto/asymmetric_keys/Makefile +7 -0
@@ -40,3 +40,10 @@ $(obj)/pkcs7_parser.o: $(obj)/pkcs7-asn1.h $(obj)/pkcs7-asn1.o: $(obj)/pkcs7-asn1.c $(obj)/pkcs7-asn1.h clean-files += pkcs7-asn1.c pkcs7-asn1.h + +# +# PKCS#7 parser testing key +# +obj-$(CONFIG_PKCS7_TEST_KEY) += pkcs7_test_key.o +pkcs7_test_key-y := \ + pkcs7_key_type.o
crypto/asymmetric_keys/pkcs7_key_type.c new file +97 -0
97 lines not on this page · raw message
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec