MODSIGN: Use PKCS#7 for module signatures
Subsystems (4)
David Howells
maintainercover MODSIGN: Use PKCS#7 for module signatures
Here's a set of patches that does the following:
(1) Extracts both parts of an X.509 AuthorityKeyIdentifier (AKID) extension. We already extract the bit that can match the subjectKeyIdentifier (SKID) of the parent X.509 cert, but we currently ignore the bits that can match the issuer and serialNumber.
Looks up an X.509 cert by issuer and serialNumber if those are provided in the AKID. If the keyIdentifier is also provided, checks that the subjectKeyIdentifier of the cert found matches that also.
If no issuer and serialNumber are provided in the AKID, looks up an X.509 cert by SKID using the AKID keyIdentifier.
This allows module signing to be done with certificates that don't have an SKID by which they can be looked up.
(2) Makes use of the PKCS#7 facility to provide module signatures.
sign-file is replaced with a program that generates a PKCS#7 message that has no X.509 certs embedded and that has detached data (the module content) and adds it onto the message with magic string and descriptor.
(3) The PKCS#7 message (and matching X.509 cert) supply all the information that is needed to select the X.509 cert to be used to verify the signature by standard means (including selection of digest algorithm and public key algorithm). No kernel-specific magic values are required.
Note that the revised sign-file program no longer supports the "-s <signature>" option as I'm not sure what the best way to deal with this is. Do we generate a PKCS#7 cert from the signature given, or do we get given a PKCS#7 cert? I lean towards the latter.
They can be found here also:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=modsign-pkcs7
These patches are based on the security tree's next branch.
David
---
David Howells (5):
X.509: Extract both parts of the AuthorityKeyIdentifier X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier PKCS#7: Allow detached data to be supplied for signature checking purposes
MODSIGN: Provide a utility to append a PKCS#7 signature to a module
MODSIGN: Use PKCS#7 messages as module signatures
crypto/asymmetric_keys/Makefile | 8 - crypto/asymmetric_keys/pkcs7_trust.c | 10 - crypto/asymmetric_keys/pkcs7_verify.c | 81 ++++-- crypto/asymmetric_keys/x509_akid.asn1 | 35 ++ crypto/asymmetric_keys/x509_cert_parser.c | 142 ++++++---- crypto/asymmetric_keys/x509_parser.h | 3 crypto/asymmetric_keys/x509_public_key.c | 85 ++++-- include/crypto/pkcs7.h | 3 include/crypto/public_key.h | 4 init/Kconfig | 1 kernel/module_signing.c | 220 +++------------ scripts/Makefile | 2 scripts/sign-file | 421 ----------------------------- scripts/sign-file.c | 189 +++++++++++++ 14 files changed, 505 insertions(+), 699 deletions(-) create mode 100644 crypto/asymmetric_keys/x509_akid.asn1 delete mode 100755 scripts/sign-file create mode 100755 scripts/sign-file.c
David Howells
maintainerPATCH 1/5 X.509: Extract both parts of the AuthorityKeyIdentifier
Extract both parts of the AuthorityKeyIdentifier, not just the keyIdentifier, as the second part can be used to match X.509 certificates by issuer and serialNumber.
---
crypto/asymmetric_keys/Makefile | 8 +- crypto/asymmetric_keys/pkcs7_trust.c | 4 - crypto/asymmetric_keys/pkcs7_verify.c | 12 +- crypto/asymmetric_keys/x509_akid.asn1 | 35 +++++++ crypto/asymmetric_keys/x509_cert_parser.c | 142 ++++++++++++++++++----------- crypto/asymmetric_keys/x509_parser.h | 3 - crypto/asymmetric_keys/x509_public_key.c | 8 +- 7 files changed, 144 insertions(+), 68 deletions(-) create mode 100644 crypto/asymmetric_keys/x509_akid.asn1
crypto/asymmetric_keys/Makefile +7 -1
@@ -15,15 +15,21 @@ obj-$(CONFIG_PUBLIC_KEY_ALGO_RSA) += rsa.o obj-$(CONFIG_X509_CERTIFICATE_PARSER) += x509_key_parser.o x509_key_parser-y := \ x509-asn1.o \ + x509_akid-asn1.o \ x509_rsakey-asn1.o \ x509_cert_parser.o \ x509_public_key.o -$(obj)/x509_cert_parser.o: $(obj)/x509-asn1.h $(obj)/x509_rsakey-asn1.h +$(obj)/x509_cert_parser.o: \ + $(obj)/x509-asn1.h \ + $(obj)/x509_akid-asn1.h \ + $(obj)/x509_rsakey-asn1.h $(obj)/x509-asn1.o: $(obj)/x509-asn1.c $(obj)/x509-asn1.h +$(obj)/x509_akid-asn1.o: $(obj)/x509_akid-asn1.c $(obj)/x509_akid-asn1.h $(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_akid-asn1.c x509_akid-asn1.h clean-files += x509_rsakey-asn1.c x509_rsakey-asn1.h #
crypto/asymmetric_keys/pkcs7_trust.c +2 -2
@@ -85,8 +85,8 @@ static int pkcs7_validate_trust_one(struct pkcs7_message *pkcs7,/* No match - see if the root certificate has a signer amongst the * trusted keys. */ -if (last && last->authority) { - key =x509_request_asymmetric_key (trust_keyring, last->authority, +if (last && last->auth_skid) { + key =x509_request_asymmetric_key (trust_keyring, last->auth_skid, false);if (!IS_ERR (key)) { x509 = last;
crypto/asymmetric_keys/pkcs7_verify.c +5 -7
@@ -187,11 +187,11 @@ static int pkcs7_verify_sig_chain(struct pkcs7_message *pkcs7, goto maybe_missing_crypto_in_x509;pr_debug ("- issuer %s\n" , x509->issuer); -if (x509->authority) +if (x509->auth_skid)pr_debug ("- authkeyid %*phN\n" , - x509->authority->len, x509->authority->data); + x509->auth_skid->len, x509->auth_skid->data); -if (!x509->authority || +if (!x509->auth_skid ||strcmp (x509->subject, x509->issuer) ==0 ) {/* If there's no authority certificate specified, then * the certificate must be self-signed and is the root
@@ -216,13 +216,13 @@ static int pkcs7_verify_sig_chain(struct pkcs7_message *pkcs7,* list to see if the next one is there. */ pr_debug ("- want %*phN\n" , - x509->authority->len, x509->authority->data); + x509->auth_skid->len, x509->auth_skid->data);for (p = pkcs7->certs; p; p = p->next) {if (!p->skid)continue ;pr_debug ("- cmp [%u] %*phN\n" , p->index, p->skid->len, p->skid->data); -if (asymmetric_key_id_same (p->skid, x509->authority)) +if (asymmetric_key_id_same (p->skid, x509->auth_skid)) goto found_issuer; }
@@ -338,8 +338,6 @@ int pkcs7_verify(struct pkcs7_message *pkcs7) ret =x509_get_sig_params (x509);if (ret <0 )return ret; -pr_debug ("X.509[%u] %*phN\n" , - n, x509->authority->len, x509->authority->data); }for (sinfo = pkcs7->signed_infos; sinfo; sinfo = sinfo->next) {
crypto/asymmetric_keys/x509_akid.asn1 new file +35 -0
@@ -0,0 +1,35 @@ +-- X.509 AuthorityKeyIdentifier +-- rfc5280 section 4.2.1.1 + +AuthorityKeyIdentifier ::= SEQUENCE { + keyIdentifier [0] IMPLICIT KeyIdentifier OPTIONAL, + authorityCertIssuer [1] IMPLICIT GeneralNames OPTIONAL, + authorityCertSerialNumber [2] IMPLICIT CertificateSerialNumber OPTIONAL + } + +KeyIdentifier ::= OCTET STRING ({ x509_akid_note_kid }) + +CertificateSerialNumber ::= INTEGER ({ x509_akid_note_serial }) + +GeneralNames ::= SEQUENCE OF GeneralName + +GeneralName ::= CHOICE { + otherName [0] ANY, + rfc822Name [1] IA5String, + dNSName [2] IA5String, + x400Address [3] ANY, + directoryName [4] Name ({ x509_akid_note_name }), + ediPartyName [5] ANY, + uniformResourceIdentifier [6] IA5String, + iPAddress [7] OCTET STRING, + registeredID [8] OBJECT IDENTIFIER + } + +Name ::= SEQUENCE OF RelativeDistinguishedName + +RelativeDistinguishedName ::= SET OF AttributeValueAssertion + +AttributeValueAssertion ::= SEQUENCE { + attributeType OBJECT IDENTIFIER ({ x509_note_OID }), + attributeValue ANY ({ x509_extract_name_segment }) + }
crypto/asymmetric_keys/x509_cert_parser.c +89 -53
181 lines not on this page · raw message
crypto/asymmetric_keys/x509_parser.h +2 -1
@@ -21,7 +21,8 @@ struct x509_certificate {char *subject;/* Name of certificate subject */ struct asymmetric_key_id *id;/* Serial number + issuer */ struct asymmetric_key_id *skid;/* Subject + subjectKeyId (optional) */ -struct asymmetric_key_id *authority;/* Authority key identifier (optional) */ +struct asymmetric_key_id *auth_id;/* CA AuthKeyId matching ->id (optional) */ +struct asymmetric_key_id *auth_skid;/* CA AuthKeyId matching ->skid (optional) */ struct tm valid_from;struct tm valid_to;const void *tbs;/* Signed data */
crypto/asymmetric_keys/x509_public_key.c +4 -4
@@ -214,10 +214,10 @@ static int x509_validate_trust(struct x509_certificate *cert,if (!trust_keyring)return -EOPNOTSUPP ; -if (ca_keyid && !asymmetric_key_id_partial (cert->authority, ca_keyid)) +if (ca_keyid && !asymmetric_key_id_partial (cert->auth_skid, ca_keyid))return -EPERM ; - key =x509_request_asymmetric_key (trust_keyring, cert->authority, + key =x509_request_asymmetric_key (trust_keyring, cert->auth_skid, false);if (!IS_ERR (key)) { if (!use_builtin_keys
@@ -274,8 +274,8 @@ static int x509_key_preparse(struct key_preparsed_payload *prep) cert->pub->id_type =PKEY_ID_X509 ;/* Check the signature on the key if it appears to be self-signed */ -if (!cert->authority || -asymmetric_key_id_same (cert->skid, cert->authority)) { +if (!cert->auth_skid || +asymmetric_key_id_same (cert->skid, cert->auth_skid)) { ret =x509_check_signature (cert->pub, cert);/* self-signed */ if (ret <0 ) goto error_free_cert;
Re: [PATCH 1/5] X.509: Extract both parts of the AuthorityKeyIdentifier
On Thu, Nov 20, 2014 at 04:54:03PM +0000, David Howells wrote:
[..]
crypto/asymmetric_keys/x509_parser.h struct x509_certificate { · line 25
Quoted 11 lines
crypto/asymmetric_keys/x509_parser.h +2
-1@@ -21,7 +21,8 @@ struct x509_certificate {char *subject;/* Name of certificate subject */ struct asymmetric_key_id *id;/* Serial number + issuer */ struct asymmetric_key_id *skid;/* Subject + subjectKeyId (optional) */ -struct asymmetric_key_id *authority;/* Authority key identifier (optional) */ +struct asymmetric_key_id *auth_id;/* CA AuthKeyId matching ->id (optional) */ +struct asymmetric_key_id *auth_skid;/* CA AuthKeyId matching ->skid (optional) */
A very minor nit. It might help if we put additional comment to explain what auth_id and auth_skid are composed of (like other key ids).
auth_id /* akid issuer + akid serial */auth_skid /* issuer + akid keyid */
Thanks
Vivek
David Howells
maintainerRe: [PATCH 1/5] X.509: Extract both parts of the AuthorityKeyIdentifier
Quoted 2 lines · Vivek Goyal
A very minor nit. It might help if we put additional comment to explain what
auth_idandauth_skidare composed of (like other key ids).
I thought it better to show what they match - ie. auth_id matches id and auth_skid matches skid from the same structure. The id and skid members show their composition (and I should fix the comment on id so that the bits are the right way round).
David
Re: [PATCH 1/5] X.509: Extract both parts of the AuthorityKeyIdentifier
In reply to Vivek GoyalQuoted 17 lines · Vivek Goyal
On Thu, Nov 20, 2014 at 04:54:03PM +0000, David Howells wrote:
[..]
crypto/asymmetric_keys/x509_parser.h struct x509_certificate { · line 25
Quoted 11 lines
crypto/asymmetric_keys/x509_parser.h +2
-1@@ -21,7 +21,8 @@ struct x509_certificate {char *subject;/* Name of certificate subject */ struct asymmetric_key_id *id;/* Serial number + issuer */ struct asymmetric_key_id *skid;/* Subject + subjectKeyId (optional) */ -struct asymmetric_key_id *authority;/* Authority key identifier (optional) */ +struct asymmetric_key_id *auth_id;/* CA AuthKeyId matching ->id (optional) */ +struct asymmetric_key_id *auth_skid;/* CA AuthKeyId matching ->skid (optional) */ A very minor nit. It might help if we put additional comment to explain what
auth_idandauth_skidare composed of (like other key ids).
Quoted 6 lines
auth_id/* akid issuer + akid serial */auth_skid/* issuer + akid keyid */Thanks
Vivek
Right,
David did not address this in his v2 patchset...
- Dmitry
David Howells
maintainerRe: [PATCH 1/5] X.509: Extract both parts of the AuthorityKeyIdentifier
Quoted 9 lines · Dmitry Kasatkin
Quoted 9 lines
crypto/asymmetric_keys/x509_parser.h struct x509_certificate { · line 25
Quoted 3 lines
crypto/asymmetric_keys/x509_parser.h +2
-1-struct asymmetric_key_id *authority;/* Authority key identifier (optional) */ +struct asymmetric_key_id *auth_id;/* CA AuthKeyId matching ->id (optional) */ +struct asymmetric_key_id *auth_skid;/* CA AuthKeyId matching ->skid (optional) */ A very minor nit. It might help if we put additional comment to explain what
auth_idandauth_skidare composed of (like other key ids).
auth_id/* akid issuer + akid serial */auth_skid/* issuer + akid keyid */
Quoted 7 lines
Quoted 3 lines
Thanks
VivekRight,
David did not address this in his v2 patchset...
I decided against changing them on the basis that I'd prefer to show what they match over the way they are fabricated. The id and skid members do show how they are fabricated. If you really want, I can show both - but my thought is that if you look at how AuthorityKeyIdentifier is constructed, you can work it out reasonably easily.
David
David Howells
maintainerPATCH 2/5 X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier
In reply to David HowellsIf an X.509 certificate has an AuthorityKeyIdentifier extension that provides an issuer and serialNumber, then make it so that these are used in preference to the keyIdentifier field also held therein for searching for the signing certificate.
If both the issuer+serialNumber and the keyIdentifier are supplied, then the certificate is looked up by the former but the latter is checked as well. If the latter doesn't match the subjectKeyIdentifier of the parent certificate, EKEYREJECTED is returned.
This makes it possible to chain X.509 certificates based on the issuer and serialNumber fields rather than on subjectKeyIdentifier. This is necessary as we are having to deal with keys that are represented by X.509 certificates that lack a subjectKeyIdentifier.
---
crypto/asymmetric_keys/pkcs7_trust.c | 10 +++- crypto/asymmetric_keys/pkcs7_verify.c | 47 +++++++++++++---- crypto/asymmetric_keys/x509_public_key.c | 83 +++++++++++++++++++++--------- include/crypto/public_key.h | 3 + 4 files changed, 102 insertions(+), 41 deletions(-)
crypto/asymmetric_keys/pkcs7_trust.c +7 -3
@@ -54,7 +54,8 @@ static int pkcs7_validate_trust_one(struct pkcs7_message *pkcs7,/* Look to see if this certificate is present in the trusted * keys. */ - key =x509_request_asymmetric_key (trust_keyring, x509->id, + key =x509_request_asymmetric_key (trust_keyring, + x509->id, x509->skid, false);if (!IS_ERR (key)) {/* One of the X.509 certificates in the PKCS#7 message
@@ -85,8 +86,10 @@ static int pkcs7_validate_trust_one(struct pkcs7_message *pkcs7,/* No match - see if the root certificate has a signer amongst the * trusted keys. */ -if (last && last->auth_skid) { - key =x509_request_asymmetric_key (trust_keyring, last->auth_skid, +if (last && (last->auth_id || last->auth_skid)) { + key =x509_request_asymmetric_key (trust_keyring, + last->auth_id, + last->auth_skid, false);if (!IS_ERR (key)) { x509 = last;
@@ -103,6 +106,7 @@ static int pkcs7_validate_trust_one(struct pkcs7_message *pkcs7,*/ key =x509_request_asymmetric_key (trust_keyring, sinfo->signing_cert_id, +NULL , false);if (!IS_ERR (key)) { pr_devel("sinfo %u: Direct signer is key %x\n",
crypto/asymmetric_keys/pkcs7_verify.c +36 -11
74 lines not on this page · raw message
crypto/asymmetric_keys/x509_public_key.c +57 -26
127 lines not on this page · raw message
include/crypto/public_key.h +2 -1
@@ -101,7 +101,8 @@ extern int verify_signature(const struct key *key,struct asymmetric_key_id ;extern struct key *x509_request_asymmetric_key (struct key *keyring, -const struct asymmetric_key_id *kid, +const struct asymmetric_key_id *id, +const struct asymmetric_key_id *skid,bool partial);#endif /* _LINUX_PUBLIC_KEY_H */
Re: [PATCH 2/5] X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier
On Thu, Nov 20, 2014 at 04:54:14PM +0000, David Howells wrote:
[..]
Quoted 39 lines
crypto/asymmetric_keys/pkcs7_verify.c +20
-9@@ -215,21 +219,42 @@ static int pkcs7_verify_sig_chain(struct pkcs7_message *pkcs7,/* Look through the X.509 certificates in the PKCS#7 message's * list to see if the next one is there. */ -pr_debug ("- want %*phN\n" , - x509->auth_skid->len, x509->auth_skid->data); -for (p = pkcs7->certs; p; p = p->next) { -if (!p->skid) -continue ; -pr_debug ("- cmp [%u] %*phN\n" , - p->index, p->skid->len, p->skid->data); -if (asymmetric_key_id_same (p->skid, x509->auth_skid)) - goto found_issuer; + auth = x509->auth_id; +if (auth) { +pr_debug ("- want %*phN\n" , auth->len, auth->data); +for (p = pkcs7->certs; p; p = p->next) { +pr_debug ("- cmp [%u] %*phN\n" , + p->index, p->id->len, p->id->data); +if (asymmetric_key_id_same (p->id, auth)) + goto found_issuer_check_skid; + } + }else { + auth = x509->auth_skid; +pr_debug ("- want %*phN\n" , auth->len, auth->data); +for (p = pkcs7->certs; p; p = p->next) { +if (!p->skid) +continue ; +pr_debug ("- cmp [%u] %*phN\n" , + p->index, p->skid->len, p->skid->data); +if (asymmetric_key_id_same (p->skid, auth)) + goto found_issuer; + } }/* We didn't find the root of this chain */ pr_debug ("- top\n" );return 0 ;
crypto/asymmetric_keys/pkcs7_verify.c static int pkcs7_verify_sig_chain(struct pkcs7_message *pkcs7, · line 257
Quoted 10 lines
crypto/asymmetric_keys/pkcs7_verify.c +10
-0+ found_issuer_check_skid: +/* We matched issuer + serialNumber, but if there's an +* authKeyId.keyId, that must match the CA subjKeyId also. +*/ +if (x509->auth_skid && + !asymmetric_key_id_same (p->skid, x509->auth_skid)) { +pr_warn ("Sig %u: X.509 chain contains auth-skid nonmatch (%u->%u)\n" , + sinfo->index, x509->index, p->index); +return -EKEYREJECTED ; + }
Hi David,
A minor nit.
pkcs7_verify_sig_chain() is getting big with multiple goto labels. Will it make sense to introduce a helper function to see if cert B is authority cert of cert A or not. And then we should be able to get rid of labels like found_issuer_check_skid() and some of the inline code also go away.
Thanks
Vivek
Re: [PATCH 2/5] X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier
In reply to David HowellsDon't assume that the issuer & serialNumber are specified.
---crypto/asymmetric_keys/x509_public_key.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
(quoted diff) +0 -0
b/crypto/asymmetric_keys/x509_public_key.c
index 9c1a3d6..510269f 100644
crypto/asymmetric_keys/x509_public_key.c +1 -0
@@ -9,6 +9,7 @@* 2 of the Licence, or (at your option) any later version. */ +#define DEBUG 1
#define pr_fmt(fmt) "X.509: "fmt
#include <linux/module.h>
#include <linux/kernel.h>
@@ -68,12 +69,14 @@ struct key *x509_request_asymmetric_key(struct key *keyring,
{
struct key *key;key_ref_t ref;
- const char *lookup;
+ const char *lookup = NULL;
char *req, *p;
- int len;
+ int len = 0;
- lookup = id->data;
- len = id->len;
+ if (id) {
+ lookup = id->data;
+ len = id->len;
+ }
if (!lookup) {
lookup = skid->data;
len = skid->len;
Signature · 1 line
1.8.1.4
Re: [Keyrings] [PATCH 2/5] X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier
Previous post was mangled. Reposting ...
---
Don't assume that the issuer & serialNumber are specified.
--- crypto/asymmetric_keys/x509_public_key.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
crypto/asymmetric_keys/x509_public_key.c +7 -4
@@ -9,6 +9,7 @@* 2 of the Licence, or (at your option) any later version. */ +#define DEBUG 1#define pr_fmt (fmt) "X.509: "fmt#include <linux/module.h> #include <linux/kernel.h>
@@ -68,12 +69,14 @@ struct key *x509_request_asymmetric_key(struct key *keyring, {struct key *key;key_ref_t ref; -const char *lookup; +const char *lookup =NULL ;char *req, *p; -int len; +int len =0 ; - lookup = id->data; - len = id->len; +if (id) { + lookup = id->data; + len = id->len; + }if (!lookup) { lookup = skid->data; len = skid->len;
Signature · 1 line
1.8.1.4
David Howells
maintainerRe: [Keyrings] [PATCH 2/5] X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier
Quoted 1 line · Mimi Zohar
Don't assume that the issuer & serialNumber are specified.
Bah... I didn't assume, I just did it wrong.
Quoted 1 line
+#define DEBUG 1
Shouldn't be in the patch.
Quoted 1 line
+ if (id) {
Tab, not spaces.
I'll fix these up and merge your patch into mine to avoid the issues coming out in bisection.
David
Re: [Keyrings] [PATCH 2/5] X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier
Quoted 8 lines · David Howells
Quoted 1 line · Mimi Zohar
Don't assume that the issuer & serialNumber are specified.
Bah... I didn't assume, I just did it wrong.
Quoted 1 line
+#define DEBUG 1
Quoted 8 lines
Shouldn't be in the patch.
Quoted 1 line
+ if (id) {
Tab, not spaces.
I'll fix these up and merge your patch into mine to avoid the issues coming out in bisection.
Thanks!
Mimi
David Howells
maintainerRe: [Keyrings] [PATCH 2/5] X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier
In reply to Mimi ZoharMimi Zohar <[email protected]> wrote:
crypto/asymmetric_keys/x509_public_key.c struct key *x509_request_asymmetric_key(struct key *keyring, · line 80
Quoted 5 lines · Mimi Zohar
crypto/asymmetric_keys/x509_public_key.c +4
-0+if (id) { + lookup = id->data; + len = id->len; + }if (!lookup) {
The last line here can then just be replaced by an else-clause.
David
Re: [Keyrings] [PATCH 2/5] X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier
Quoted 11 lines · David Howells
Mimi Zohar <[email protected]> wrote:
crypto/asymmetric_keys/x509_public_key.c struct key *x509_request_asymmetric_key(struct key *keyring, · line 80
Quoted 5 lines · Mimi Zohar
crypto/asymmetric_keys/x509_public_key.c +4
-0+if (id) { + lookup = id->data; + len = id->len; + }if (!lookup) {The last line here can then just be replaced by an else-clause.
I would assume so, but the original code looked like "id->data" could have been null.
Mimi
David Howells
maintainerRe: [Keyrings] [PATCH 2/5] X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier
Quoted 2 lines · Mimi Zohar
I would assume so, but the original code looked like "
id->data" could have been null.
It can't be - it's an embedded array.
David
David Howells
maintainerPATCH 3/5 PKCS#7: Allow detached data to be supplied for signature checking purposes
In reply to David HowellsIt is possible for a PKCS#7 message to have detached data. However, to verify the signatures on a PKCS#7 message, we have to be able to digest the data. Provide a function to supply that data. An error is given if the PKCS#7 message included embedded data.
---
crypto/asymmetric_keys/pkcs7_verify.c | 26 ++++++++++++++++++++++++++ include/crypto/pkcs7.h | 3 +++ 2 files changed, 29 insertions(+)
crypto/asymmetric_keys/pkcs7_verify.c +26 -0
@@ -382,3 +382,29 @@ int pkcs7_verify(struct pkcs7_message *pkcs7)return enopkg; }EXPORT_SYMBOL_GPL (pkcs7_verify); + +/** +* pkcs7_supply_detached_data - Supply the data needed to verify a PKCS#7 message +* @pkcs7: The PKCS#7 message +* @data: The data to be verified +* @datalen: The amount of data +* +* Supply the detached data needed to verify a PKCS#7 message. Note that no +* attempt to retain/pin the data is made. That is left to the caller. The +* data will not be modified by pkcs7_verify() and will not be freed when the +* PKCS#7 message is freed. +* +* Returns -EINVAL if data is already supplied in the message, 0 otherwise. +*/ +int pkcs7_supply_detached_data (struct pkcs7_message *pkcs7, +const void *data,size_t datalen) +{ +if (pkcs7->data) { +pr_debug ("Data already supplied\n" ); +return -EINVAL ; + } + pkcs7->data = data; + pkcs7->data_len = datalen; +return 0 ; +} +EXPORT_SYMBOL_GPL (pkcs7_supply_detached_data);
include/crypto/pkcs7.h +3 -0
@@ -34,3 +34,6 @@ extern int pkcs7_validate_trust(struct pkcs7_message *pkcs7,* pkcs7_verify.c */ extern int pkcs7_verify (struct pkcs7_message *pkcs7); + +extern int pkcs7_supply_detached_data (struct pkcs7_message *pkcs7, +const void *data,size_t datalen);
Re: [PATCH 3/5] PKCS#7: Allow detached data to be supplied for signature checking purposes
Quoted 6 lines · David Howells
It is possible for a PKCS#7 message to have detached data. However, to verify the signatures on a PKCS#7 message, we have to be able to digest the data. Provide a function to supply that data. An error is given if the PKCS#7 message included embedded data.
Signed-off-by David Howells <[email protected]>
Ok, PCKS#7 supports detached data. I assume this is not needed for kernel modules. What is the motivation for adding this support to the kernel?
Mimi
Quoted 57 lines
---
crypto/asymmetric_keys/pkcs7_verify.c | 26 ++++++++++++++++++++++++++ include/crypto/pkcs7.h | 3 +++ 2 files changed, 29 insertions(+)crypto/asymmetric_keys/pkcs7_verify.c +26
-0@@ -382,3 +382,29 @@ int pkcs7_verify(struct pkcs7_message *pkcs7)return enopkg; }EXPORT_SYMBOL_GPL (pkcs7_verify); + +/** +* pkcs7_supply_detached_data - Supply the data needed to verify a PKCS#7 message +* @pkcs7: The PKCS#7 message +* @data: The data to be verified +* @datalen: The amount of data +* +* Supply the detached data needed to verify a PKCS#7 message. Note that no +* attempt to retain/pin the data is made. That is left to the caller. The +* data will not be modified by pkcs7_verify() and will not be freed when the +* PKCS#7 message is freed. +* +* Returns -EINVAL if data is already supplied in the message, 0 otherwise. +*/ +int pkcs7_supply_detached_data (struct pkcs7_message *pkcs7, +const void *data,size_t datalen) +{ +if (pkcs7->data) { +pr_debug ("Data already supplied\n" ); +return -EINVAL ; + } + pkcs7->data = data; + pkcs7->data_len = datalen; +return 0 ; +} +EXPORT_SYMBOL_GPL (pkcs7_supply_detached_data);include/crypto/pkcs7.h +3
-1@@ -34,3 +34,6 @@ extern int pkcs7_validate_trust(struct pkcs7_message *pkcs7,* pkcs7_verify.c */ extern int pkcs7_verify (struct pkcs7_message *pkcs7); + +extern int pkcs7_supply_detached_data (struct pkcs7_message *pkcs7, +const void *data,size_t datalen); --To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
David Howells
maintainerRe: [PATCH 3/5] PKCS#7: Allow detached data to be supplied for signature checking purposes
Quoted 3 lines · Mimi Zohar
Ok, PCKS#7 supports detached data. I assume this is not needed for kernel modules. What is the motivation for adding this support to the kernel?
See patch #5. I should probably note that in the commit message.
David
Re: [PATCH 3/5] PKCS#7: Allow detached data to be supplied for signature checking purposes
Quoted 7 lines · David Howells
Quoted 3 lines · Mimi Zohar
Ok, PCKS#7 supports detached data. I assume this is not needed for kernel modules. What is the motivation for adding this support to the kernel?
See patch #5. I should probably note that in the commit message.
This patch set does not change the syscall. The signature is still appended to the kernel module. In fact, the call from kernel/module_signing.c: mod_verify_pkcs7() calls pkcs7_supply_detached_data() with a pointer to the module and the module length to set the data field. pkcs7_supply_detached_data() would not be defined or exported, unless it was going to be called elsewhere. How else are you planning on using pkcs7_supply_detached_data()?
Mimi
David Howells
maintainerRe: [PATCH 3/5] PKCS#7: Allow detached data to be supplied for signature checking purposes
Quoted 8 lines · Mimi Zohar
Quoted 5 lines
Quoted 3 lines
Ok, PCKS#7 supports detached data. I assume this is not needed for kernel modules. What is the motivation for adding this support to the kernel?
See patch #5. I should probably note that in the commit message.
This patch set does not change the syscall. The signature is still appended to the kernel module.
Ummm, yes, so?
Quoted 5 lines
In fact, the call from
kernel/module_signing.c:mod_verify_pkcs7()callspkcs7_supply_detached_data()with a pointer to the module and the module length to set the data field.pkcs7_supply_detached_data()would not be defined or exported, unless it was going to be called elsewhere. How else are you planning on usingpkcs7_supply_detached_data()?
Is your point that I exported it unnecessarily? That I have now fixed.
David
Re: [PATCH 3/5] PKCS#7: Allow detached data to be supplied for signature checking purposes
Quoted 13 lines · David Howells
Quoted 8 lines · Mimi Zohar
Quoted 5 lines
Quoted 3 lines
Ok, PCKS#7 supports detached data. I assume this is not needed for kernel modules. What is the motivation for adding this support to the kernel?
See patch #5. I should probably note that in the commit message.
This patch set does not change the syscall. The signature is still appended to the kernel module.
Ummm, yes, so?
Quoted 7 lines
Quoted 5 lines
In fact, the call from
kernel/module_signing.c:mod_verify_pkcs7()callspkcs7_supply_detached_data()with a pointer to the module and the module length to set the data field.pkcs7_supply_detached_data()would not be defined or exported, unless it was going to be called elsewhere. How else are you planning on usingpkcs7_supply_detached_data()?Is your point that I exported it unnecessarily? That I have now fixed.
No, it was more a comment on the function name pkcs7_supply_detached_data() being a bit weird, as the signature is appended to the data.
Mimi
David Howells
maintainerRe: [PATCH 3/5] PKCS#7: Allow detached data to be supplied for signature checking purposes
Quoted 5 lines · Mimi Zohar
No, it was more a comment on the function name
pkcs7_supply_detached_data()being a bit weird, as the signature is appended to the data.From the point of view of the PKCS#7 message it's detached.
David
David Howells
maintainerPATCH 4/5 MODSIGN: Provide a utility to append a PKCS#7 signature to a module
In reply to David HowellsProvide a utility that:
(1) Digests a module using the specified hash algorithm (typically sha256).
[The digest can be dumped into a file by passing the '-d' flag]
(2) Generates a PKCS#7 message that:
(a) Has detached data (ie. the module content).
(b) Is signed with the specified private key.
(c) Refers to the specified X.509 certificate.
(d) Has an empty X.509 certificate list.
[The PKCS#7 message can be dumped into a file by passing the '-p' flag]
(3) Generates a signed module by concatenating the old module, the PKCS#7 message, a descriptor and a magic string. The descriptor contains the size of the PKCS#7 message and indicates the id_type as PKEY_ID_PKCS7.
(4) Either writes the signed module to the specified destination or renames it over the source module.
This allows module signing to reuse the PKCS#7 handling code that was added for PE file parsing for signed kexec.
Note that the utility is written in C and must be linked against the OpenSSL crypto library.
Note further that I have temporarily dropped support for handling externally created signatures until we can work out the best way to do those. Hopefully, whoever creates the signature can give me a PKCS#7 certificate.
---
include/crypto/public_key.h | 1 scripts/sign-file.c | 189 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100755 scripts/sign-file.c
include/crypto/public_key.h +1 -0
@@ -33,6 +33,7 @@ extern const struct public_key_algorithm *pkey_algo[PKEY_ALGO__LAST];enum pkey_id_type {PKEY_ID_PGP ,/* OpenPGP generated key ID */ PKEY_ID_X509 ,/* X.509 arbitrary subjectKeyIdentifier */ +PKEY_ID_PKCS7 ,/* Signature in PKCS#7 message */ PKEY_ID_TYPE__LAST };
scripts/sign-file.c new file +189 -0
189 lines not on this page · raw message
David Howells
maintainerPATCH 5/5 MODSIGN: Use PKCS#7 messages as module signatures
In reply to David HowellsMove to using PKCS#7 messages as module signatures because:
(1) We have to be able to support the use of X.509 certificates that don't have a subjKeyId set. We're currently relying on this to look up the X.509 certificate in the trusted keyring list.
(2) PKCS#7 message signed information blocks have a field that supplies the data required to match with the X.509 certificate that signed it.
(3) The PKCS#7 certificate carries fields that specify the digest algorithm used to generate the signature in a standardised way and the X.509 certificates specify the public key algorithm in a standardised way - so we don't need our own methods of specifying these.
(4) We now have PKCS#7 message support in the kernel for signed kexec purposes and we can make use of this.
To make this work, the old sign-file script has been replaced with a program that needs compiling in a previous patch. The rules to build it are added here.
---
init/Kconfig | 1 kernel/module_signing.c | 220 +++++-------------------- scripts/Makefile | 2 scripts/sign-file | 421 ----------------------------------------------- 4 files changed, 47 insertions(+), 597 deletions(-) delete mode 100755 scripts/sign-file
init/Kconfig +1 -0
@@ -1840,6 +1840,7 @@ config MODULE_SIG select ASN1 select OID_REGISTRY select X509_CERTIFICATE_PARSER + select PKCS7_MESSAGE_PARSER help Check modules for valid signatures upon load: the signature is simply appended to the module. For more information see
kernel/module_signing.c +44 -176
269 lines not on this page · raw message
scripts/Makefile +2 -0
@@ -16,9 +16,11 @@ hostprogs-$(CONFIG_VT) += conmakehash hostprogs-$(BUILD_C_RECORDMCOUNT) += recordmcount hostprogs-$(CONFIG_BUILDTIME_EXTABLE_SORT) += sortextable hostprogs-$(CONFIG_ASN1) += asn1_compiler +hostprogs-$(CONFIG_MODULE_SIG) += sign-file HOSTCFLAGS_sortextable.o = -I$(srctree)/tools/include HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include +HOSTLOADLIBES_sign-file = -lcrypto always := $(hostprogs-y) $(hostprogs-m)
scripts/sign-file deleted +0 -421
421 lines not on this page · raw message
Re: [PATCH 5/5] MODSIGN: Use PKCS#7 messages as module signatures
Quoted 26 lines · David Howells
/*
kernel/module_signing.c +0
-10@@ -186,12 +81,8 @@ static struct key *request_asymmetric_key(const char *signer, size_t signer_len,*/ int mod_verify_sig (const void *mod,unsigned long *_modlen) { -struct public_key_signature *pks;struct module_signature ms; -struct key *key; -const void *sig;size_t modlen = *_modlen, sig_len; -int ret;pr_devel ("==>%s(,%zu)\n" , __func__, modlen);@@ -205,46 +96,23 @@ int mod_verify_sig(const void *mod, unsigned long *_modlen)if (sig_len >= modlen)return -EBADMSG ; modlen -= sig_len; -if ((size_t )ms.signer_len + ms.key_id_len >= modlen) -return -EBADMSG ; - modlen -= (size_t )ms.signer_len + ms.key_id_len; - *_modlen = modlen; - sig = mod + modlen; -
kernel/module_signing.c int mod_verify_sig(const void *mod, unsigned long *_modlen) · line 103
Quoted 10 lines
kernel/module_signing.c +2
-6-/* For the moment, only support RSA and X.509 identifiers */ -if (ms.algo !=PKEY_ALGO_RSA || - ms.id_type !=PKEY_ID_X509 ) -return -ENOPKG ; -if (ms.hash >=PKEY_HASH__LAST || - !hash_algo_name[ms.hash]) +if (ms.id_type !=PKEY_ID_PKCS7 ) { +pr_err ("Module is not signed with expected PKCS#7 message\n" );return -ENOPKG ;
Perhaps because modules are resigned with each kernel build, it is acceptable to totally replace one signature format with another like this, and fail the old method.
Mimi
Hi David,
Before I go into reviewing the patches just want to let you know that Integrity stuff seems to work fine with these changes.
Thanks,
Dmitry
Quoted 69 lines · David Howells
Here's a set of patches that does the following:
(1) Extracts both parts of an X.509 AuthorityKeyIdentifier (AKID) extension. We already extract the bit that can match the subjectKeyIdentifier (SKID) of the parent X.509 cert, but we currently ignore the bits that can match the issuer and serialNumber.
Looks up an X.509 cert by issuer and serialNumber if those are provided in the AKID. If the keyIdentifier is also provided, checks that the subjectKeyIdentifier of the cert found matches that also.
If no issuer and serialNumber are provided in the AKID, looks up an X.509 cert by SKID using the AKID keyIdentifier.
This allows module signing to be done with certificates that don't have an SKID by which they can be looked up.
(2) Makes use of the PKCS#7 facility to provide module signatures.
sign-file is replaced with a program that generates a PKCS#7 message that has no X.509 certs embedded and that has detached data (the module content) and adds it onto the message with magic string and descriptor.
(3) The PKCS#7 message (and matching X.509 cert) supply all the information that is needed to select the X.509 cert to be used to verify the signature by standard means (including selection of digest algorithm and public key algorithm). No kernel-specific magic values are required.
Note that the revised sign-file program no longer supports the "-s <signature>" option as I'm not sure what the best way to deal with this is. Do we generate a PKCS#7 cert from the signature given, or do we get given a PKCS#7 cert? I lean towards the latter.
They can be found here also:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=modsign-pkcs7
These patches are based on the security tree's next branch.
David
---
David Howells (5):
X.509: Extract both parts of the AuthorityKeyIdentifier X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier PKCS#7: Allow detached data to be supplied for signature checking purposes
MODSIGN: Provide a utility to append a PKCS#7 signature to a module
MODSIGN: Use PKCS#7 messages as module signaturescrypto/asymmetric_keys/Makefile | 8 - crypto/asymmetric_keys/pkcs7_trust.c | 10 - crypto/asymmetric_keys/pkcs7_verify.c | 81 ++++-- crypto/asymmetric_keys/x509_akid.asn1 | 35 ++ crypto/asymmetric_keys/x509_cert_parser.c | 142 ++++++---- crypto/asymmetric_keys/x509_parser.h | 3 crypto/asymmetric_keys/x509_public_key.c | 85 ++++-- include/crypto/pkcs7.h | 3 include/crypto/public_key.h | 4 init/Kconfig | 1 kernel/module_signing.c | 220 +++------------ scripts/Makefile | 2 scripts/sign-file | 421 ----------------------------- scripts/sign-file.c | 189 +++++++++++++ 14 files changed, 505 insertions(+), 699 deletions(-) create mode 100644 crypto/asymmetric_keys/x509_akid.asn1 delete mode 100755 scripts/sign-file create mode 100755 scripts/sign-file.c
Quoted 4 lines · Dmitry Kasatkin
Hi David,
Before I go into reviewing the patches just want to let you know that Integrity stuff seems to work fine with these changes.
Actually after cleaning the tree and re-signing the modules, I get following
Unrecognized character \x7F; marked by <-- HERE after <-- HERE near column 1 at ./scripts/sign-file line 1.
make[1]: *** [arch/x86/crypto/aes-x86_64.ko] Error 255
- Dmitry
Quoted 78 lines
Thanks,
DmitryQuoted 59 lines · David Howells
Here's a set of patches that does the following:
(1) Extracts both parts of an X.509 AuthorityKeyIdentifier (AKID) extension. We already extract the bit that can match the subjectKeyIdentifier (SKID) of the parent X.509 cert, but we currently ignore the bits that can match the issuer and serialNumber.
Looks up an X.509 cert by issuer and serialNumber if those are provided in the AKID. If the keyIdentifier is also provided, checks that the subjectKeyIdentifier of the cert found matches that also.
If no issuer and serialNumber are provided in the AKID, looks up an X.509 cert by SKID using the AKID keyIdentifier.
This allows module signing to be done with certificates that don't have an SKID by which they can be looked up.
(2) Makes use of the PKCS#7 facility to provide module signatures.
sign-file is replaced with a program that generates a PKCS#7 message that has no X.509 certs embedded and that has detached data (the module content) and adds it onto the message with magic string and descriptor.
(3) The PKCS#7 message (and matching X.509 cert) supply all the information that is needed to select the X.509 cert to be used to verify the signature by standard means (including selection of digest algorithm and public key algorithm). No kernel-specific magic values are required.
Note that the revised sign-file program no longer supports the "-s <signature>" option as I'm not sure what the best way to deal with this is. Do we generate a PKCS#7 cert from the signature given, or do we get given a PKCS#7 cert? I lean towards the latter.
They can be found here also:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=modsign-pkcs7
These patches are based on the security tree's next branch.
David
---
David Howells (5):
X.509: Extract both parts of the AuthorityKeyIdentifier X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier PKCS#7: Allow detached data to be supplied for signature checking purposes
MODSIGN: Provide a utility to append a PKCS#7 signature to a module
MODSIGN: Use PKCS#7 messages as module signaturescrypto/asymmetric_keys/Makefile | 8 - crypto/asymmetric_keys/pkcs7_trust.c | 10 - crypto/asymmetric_keys/pkcs7_verify.c | 81 ++++-- crypto/asymmetric_keys/x509_akid.asn1 | 35 ++ crypto/asymmetric_keys/x509_cert_parser.c | 142 ++++++---- crypto/asymmetric_keys/x509_parser.h | 3 crypto/asymmetric_keys/x509_public_key.c | 85 ++++-- include/crypto/pkcs7.h | 3 include/crypto/public_key.h | 4 init/Kconfig | 1Quoted 10 lines
kernel/module_signing.c | 220 +++------------ scripts/Makefile | 2 scripts/sign-file | 421 ----------------------------- scripts/sign-file.c | 189 +++++++++++++ 14 files changed, 505 insertions(+), 699 deletions(-) create mode 100644 crypto/asymmetric_keys/x509_akid.asn1 delete mode 100755 scripts/sign-file create mode 100755 scripts/sign-file.c--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
David Howells
maintainerQuoted 5 lines · Dmitry Kasatkin
Actually after cleaning the tree and re-signing the modules, I get following
Unrecognized character \x7F; marked by <-- HERE after <-- HERE near column 1 at
./scripts/sign-fileline 1.
make[1]: *** [arch/x86/crypto/aes-x86_64.ko] Error 255
warthog>grep -r sign-file Makefilemod_sign_cmd = perl $(srctree)/scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY)
Because of that. I need to remove the 'perl' bit.
David
David Howells
maintainerQuoted 10 lines · David Howells
Quoted 5 lines
Actually after cleaning the tree and re-signing the modules, I get following
Unrecognized character \x7F; marked by <-- HERE after <-- HERE near column 1 at
./scripts/sign-fileline 1.
make[1]: *** [arch/x86/crypto/aes-x86_64.ko] Error 255warthog>grep -r sign-file
Makefilemod_sign_cmd= perl $(srctree)/scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY)Because of that. I need to remove the 'perl' bit.
It's a little more involved than that. The X.509 cert being passed to the program is binary, whereas the one I've been testing with is PEM encoded - and libssl has separate routines that don't work out for themselves which encoding is in force. Proposed changes below.
David
---
Makefile +1 -1
@@ -859,7 +859,7 @@ ifdef CONFIG_MODULE_SIG_ALL MODSECKEY = ./signing_key.priv MODPUBKEY = ./signing_key.x509 export MODPUBKEY -mod_sign_cmd = perl $(srctree)/scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY) +mod_sign_cmd = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY) else mod_sign_cmd = true endif
scripts/sign-file.c +25 -8
@@ -61,14 +61,24 @@ static void display_openssl_errors(int l) } } +static void drain_openssl_errors (void ) +{ +const char *file; +int line; + +if (ERR_peek_error () ==0 ) +return ; +while (ERR_get_error_line (&file, &line)) {} +} -#define ERR (cond, ...) \ - do { \ - bool __cond = (cond); \ - display_openssl_errors(__LINE__); \ - if (__cond) { \ - err(1, ## __VA_ARGS__); \ - } \ + +#define ERR (cond, ...) \ + do { \ + bool __cond = (cond); \ + display_openssl_errors(__LINE__); \ + if (__cond) { \ + err(1, ## __VA_ARGS__); \ + } \ } while(0)int main (int argc,char **argv)
@@ -126,8 +136,15 @@ int main(int argc, char **argv) b =BIO_new_file (x509_name,"rb" );ERR (!b,"%s" , x509_name); - x509 =PEM_read_bio_X509 (b,NULL ,NULL ,NULL ); + x509 =d2i_X509_bio (b,NULL );/* Binary encoded X.509 */ +if (!x509) { +BIO_reset (b); + x509 =PEM_read_bio_X509 (b,NULL ,NULL ,NULL );/* PEM encoded X.509 */ +if (x509) +drain_openssl_errors (); + }BIO_free (b); +ERR (!x509,"%s" , x509_name);/* Open the destination file now so that we can shovel the module data * across as we read it.
Quoted 11 lines · David Howells
Quoted 9 lines · David Howells
Quoted 5 lines
Actually after cleaning the tree and re-signing the modules, I get following
Unrecognized character \x7F; marked by <-- HERE after <-- HERE near column 1 at
./scripts/sign-fileline 1.
make[1]: *** [arch/x86/crypto/aes-x86_64.ko] Error 255warthog>grep -r sign-file
Makefilemod_sign_cmd= perl $(srctree)/scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY)
Quoted 6 lines
Quoted 1 line
Because of that. I need to remove the 'perl' bit.
It's a little more involved than that. The X.509 cert being passed to the program is binary, whereas the one I've been testing with is PEM encoded - and libssl has separate routines that don't work out for themselves which encoding is in force. Proposed changes below.
With this patch, I'm now able to install and boot the new kernel and modules.
Mimi
Quoted 14 lines · David Howells
Here's a set of patches that does the following:
(1) Extracts both parts of an X.509 AuthorityKeyIdentifier (AKID) extension. We already extract the bit that can match the subjectKeyIdentifier (SKID) of the parent X.509 cert, but we currently ignore the bits that can match the issuer and serialNumber.
Looks up an X.509 cert by issuer and serialNumber if those are provided in the AKID. If the keyIdentifier is also provided, checks that the subjectKeyIdentifier of the cert found matches that also.
If no issuer and serialNumber are provided in the AKID, looks up an X.509 cert by SKID using the AKID keyIdentifier.
Quoted 8 lines
This allows module signing to be done with certificates that don't have an SKID by which they can be looked up.
(2) Makes use of the PKCS#7 facility to provide module signatures.
sign-file is replaced with a program that generates a PKCS#7 message that has no X.509 certs embedded and that has detached data (the module content) and adds it onto the message with magic string and descriptor.
Why do you highlight that X509 is not embedded?
Current module signing does not embed X509 also.
- Dmitry
Quoted 50 lines
(3) The PKCS#7 message (and matching X.509 cert) supply all the information that is needed to select the X.509 cert to be used to verify the signature by standard means (including selection of digest algorithm and public key algorithm). No kernel-specific magic values are required.
Note that the revised sign-file program no longer supports the "-s <signature>" option as I'm not sure what the best way to deal with this is. Do we generate a PKCS#7 cert from the signature given, or do we get given a PKCS#7 cert? I lean towards the latter.
They can be found here also:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=modsign-pkcs7
These patches are based on the security tree's next branch.
David
---
David Howells (5):
X.509: Extract both parts of the AuthorityKeyIdentifier X.509: Support X.509 lookup by Issuer+Serial form AuthorityKeyIdentifier PKCS#7: Allow detached data to be supplied for signature checking purposes
MODSIGN: Provide a utility to append a PKCS#7 signature to a module
MODSIGN: Use PKCS#7 messages as module signaturescrypto/asymmetric_keys/Makefile | 8 - crypto/asymmetric_keys/pkcs7_trust.c | 10 - crypto/asymmetric_keys/pkcs7_verify.c | 81 ++++-- crypto/asymmetric_keys/x509_akid.asn1 | 35 ++ crypto/asymmetric_keys/x509_cert_parser.c | 142 ++++++---- crypto/asymmetric_keys/x509_parser.h | 3 crypto/asymmetric_keys/x509_public_key.c | 85 ++++-- include/crypto/pkcs7.h | 3 include/crypto/public_key.h | 4 init/Kconfig | 1 kernel/module_signing.c | 220 +++------------ scripts/Makefile | 2 scripts/sign-file | 421 ----------------------------- scripts/sign-file.c | 189 +++++++++++++ 14 files changed, 505 insertions(+), 699 deletions(-) create mode 100644 crypto/asymmetric_keys/x509_akid.asn1 delete mode 100755 scripts/sign-file create mode 100755 scripts/sign-file.c--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
David Howells
maintainerQuoted 9 lines · Dmitry Kasatkin
Quoted 6 lines
(2) Makes use of the PKCS#7 facility to provide module signatures.
sign-file is replaced with a program that generates a PKCS#7 message that has no X.509 certs embedded and that has detached data (the module content) and adds it onto the message with magic string and descriptor.
Why do you highlight that X509 is not embedded?
Current module signing does not embed X509 also.
A PKCS#7 message can have X.509 certs embedded within it - but it's optional within the spec. Given that we expect to have the appropriate cert available to verify the signature on the PKCS#7 message directly, there's no need to actually embed the X.509 cert therein.
Unfortunately, it doesn't appear that you can do this with the openssl command line utility - hence why I moved to C.
David