24 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    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

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 114 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Kate Stewart
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190520170857.552531963@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

17 Aug, 2018

1 commit


16 Nov, 2017

1 commit


11 May, 2016

1 commit


06 Apr, 2016

2 commits

  • Make the determination of the trustworthiness of a key dependent on whether
    a key that can verify it is present in the supplied ring of trusted keys
    rather than whether or not the verifying key has KEY_FLAG_TRUSTED set.

    verify_pkcs7_signature() will return -ENOKEY if the PKCS#7 message trust
    chain cannot be verified.

    Signed-off-by: David Howells

    David Howells
     
  • Generalise system_verify_data() to provide access to internal content
    through a callback. This allows all the PKCS#7 stuff to be hidden inside
    this function and removed from the PE file parser and the PKCS#7 test key.

    If external content is not required, NULL should be passed as data to the
    function. If the callback is not required, that can be set to NULL.

    The function is now called verify_pkcs7_signature() to contrast with
    verify_pefile_signature() and the definitions of both have been moved into
    linux/verification.h along with the key_being_used_for enum.

    Signed-off-by: David Howells

    David Howells
     

13 Aug, 2015

2 commits

  • Add a MODULE_LICENSE() line to the PKCS#7 test key module to fix this
    warning:

    WARNING: modpost: missing MODULE_LICENSE() in
    crypto/asymmetric_keys/pkcs7_test_key.o

    Whilst we're at it, also add a module description.

    Reported-by: James Morris
    Signed-off-by: David Howells

    David Howells
     
  • 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
    Signed-off-by: David Howells
    Reviewed-by: Marcel Holtmann
    Reviewed-by: David Woodhouse

    David Howells
     

17 Jun, 2015

1 commit

  • This driver builds off of the tristate CONFIG_PKCS7_TEST_KEY and calls
    module_init and module_exit. So it should explicitly include module.h
    to avoid compile breakage during header shuffles done in the future.

    Cc: Herbert Xu
    Cc: "David S. Miller"
    Cc: linux-crypto@vger.kernel.org
    Signed-off-by: Paul Gortmaker

    Paul Gortmaker
     

17 Sep, 2014

2 commits

  • A previous patch added a ->match_preparse() method to the key type. This is
    allowed to override the function called by the iteration algorithm.
    Therefore, we can just set a default that simply checks for an exact match of
    the key description with the original criterion data and allow match_preparse
    to override it as needed.

    The key_type::match op is then redundant and can be removed, as can the
    user_match() function.

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal

    David Howells
     
  • Remove key_type::def_lookup_type as it's no longer used. The information now
    defaults to KEYRING_SEARCH_LOOKUP_DIRECT but may be overridden by
    type->match_preparse().

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal

    David Howells
     

28 Jul, 2014

1 commit


25 Jul, 2014

1 commit


23 Jul, 2014

1 commit

  • Here's a set of changes that implement 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 changes 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.

    Note that (5) has to be altered to take account of the preparsing patches
    already committed to this branch.

    Signed-off-by: David Howells

    David Howells
     

08 Jul, 2014

1 commit

  • Provide 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 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 = slartibartfast@magrathea.h2g2"
    @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 = slartibartfast@magrathea.h2g2"
    @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 = slartibartfast@magrathea.h2g2"
    @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 = slartibartfast@magrathea.h2g2"
    @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

    Signed-off-by: David Howells

    David Howells