File kernel-install-tools-0.3.0.obscpio of Package kernel-install-tools

07070100000000000081A40000000000000000000000016243092800000009000000000000000000000000000000000000002600000000kernel-install-tools-0.3.0/.gitignore*.pem
*~
07070100000001000081A40000000000000000000000016243092800004643000000000000000000000000000000000000002300000000kernel-install-tools-0.3.0/COPYING		    GNU GENERAL PUBLIC LICENSE
		       Version 2, June 1991

 Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

			    Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.)  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

  The precise terms and conditions for copying, distribution and
modification follow.

		    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) You must cause the modified files to carry prominent notices
    stating that you changed the files and the date of any change.

    b) You must cause any work that you distribute or publish, that in
    whole or in part contains or is derived from the Program or any
    part thereof, to be licensed as a whole at no charge to all third
    parties under the terms of this License.

    c) If the modified program normally reads commands interactively
    when run, you must cause it, when started running for such
    interactive use in the most ordinary way, to print or display an
    announcement including an appropriate copyright notice and a
    notice that there is no warranty (or else, saying that you provide
    a warranty) and that users may redistribute the program under
    these conditions, and telling the user how to view a copy of this
    License.  (Exception: if the Program itself is interactive but
    does not normally print such an announcement, your work based on
    the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

    a) Accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of Sections
    1 and 2 above on a medium customarily used for software interchange; or,

    b) Accompany it with a written offer, valid for at least three
    years, to give any third party, for a charge no more than your
    cost of physically performing source distribution, a complete
    machine-readable copy of the corresponding source code, to be
    distributed under the terms of Sections 1 and 2 above on a medium
    customarily used for software interchange; or,

    c) Accompany it with the information you received as to the offer
    to distribute corresponding source code.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form with such
    an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

			    NO WARRANTY

  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

		     END OF TERMS AND CONDITIONS

	    How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) year name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  `Gnomovision' (which makes passes at compilers) written by James Hacker.

  <signature of Ty Coon>, 1 April 1989
  Ty Coon, President of Vice

This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
07070100000002000081A4000000000000000000000001624309280000018F000000000000000000000000000000000000002400000000kernel-install-tools-0.3.0/MakefileSCRIPTS = sbtool-enroll-key sbtool-genkey sbtool-sign-kernel installkernel

install: $(SCRIPTS)
	install -D -m 755 sbtool-genkey \
	       	$(DESTDIR)/usr/bin/sbtool-genkey
	install -D -m 755 sbtool-enroll-key \
		$(DESTDIR)/usr/sbin/sbtool-enroll-key
	install -D -m 755 sbtool-sign-kernel \
		$(DESTDIR)/usr/bin/sbtool-sign-kernel
	install -D -m 755 installkernel \
		$(DESTDIR)/sbin/installkernel
07070100000003000081A4000000000000000000000001624309280000113A000000000000000000000000000000000000002500000000kernel-install-tools-0.3.0/README.md# Kernel Installation Tools

This project contains a few useful scripts to be used primarily by users
building their own kernels outside of their distribution's package management
system.  Most distributions that enable kernels for UEFI Secure Boot have
support for it integrated into the build rules for their kernel packages
but these rules tend to be either inaccessible for direct use or overly
complicated for the simple case of building a kernel for use only on
local systems.

## Dependencies

In order to operate properly, this tool has some dependencies on other tools:

* `openssl`
* `pesign`
* `certutil`
* `pk12util`

On SLE/OpenSUSE, these tools can be found in the `openssl`, `pesign`,
and `mozilla-nss-tools` packages.

## sbtool-keygen

`sbtool-keygen` is used to generate a key suitable for
use in signing kernel modules *and* signing the kernel itself.

Typical usage:

	$ sbtool-keygen /path/to/certificate

The only required argument is the path to the certificate.

Unless otherwise specified, the following defaults will be used:
* Hash: sha256
* Email: `$USER@$(hostname -f)`
* Common Name (CN): `$NAME`'s Secure Boot Signkey
	* `$NAME` is taken from the `getent passwd` output for the current user

The `-f|--force` option can be used to allow overwriting the certificate
if the file already exists.

The `-H|--hash` option can be used to specify an alternate hash.

The `-e|--email` option can be used to specify a different email address.

The `-c|--common-name` option can be used to specify a different CN.


## sbtool-sign-kernel

`sbtool-sign-kernel`  is used to prepare the
kernel for use in a Secure Boot environment. It performs several checks
to ensure the signing key is appropriately configured, signs the kernel,
and writes it to the destination.

Typical usage:

	# sbtool-sign-kernel -e arch/x86/boot/bzImage
	/boot/vmlinuz-5.14-kvmsmall /path/to/certificate

The paths to the input and output files are the only required
arguments. If the path to the certificate is omited, the tool will
attempt to locate it via the `CONFIG_MODULE_SIG_KEY` kernel configuration
option. The current working directory and the directory hierarchy where
the source kernel is located will be checked for the presence of a
`.config` file.

The `-e|--enroll` option is used to automatically call `sbtool-enroll-key`
to queue the public component of the signing key for enrollment with
the system MOK. Root privileges are required to copy the certificate
into place and to queue it for enrollment.

The `-q|--quiet ` option may be used to perform the operations silently
unless there are fatal errors. Missing dependencies will cause the tool
to exit successfully.

## sbtool-enroll-key

`sbtool-enroll-key` is used to queue the public
component of the signing key for enrollment in the system MOK (Machine
Owner Key) database at next reboot. The EFI shim will prompt for a
password. The root password active when the tool was invoked will be
used. If the key is already enrolled or queued for enrollment, the tool
exits successfully.  A copy of the certificate will be installed into
/etc/uefi/certs/ using the short fingerprint of the certificate
as the file name.

Typical usage:

	# sbtool-enroll-key /path/to/certificate

The `-q|--quiet ` option may be used to perform the operations silently
unless there are fatal errors. Missing dependencies will cause the tool
to exit successfully.

## installkernel

`/sbin/installkernel` is used by the kernel build system
during `make install` to copy the kernel and other files into place,
generate the initramfs, and update the bootloader with the new kernel. If
`sbtool-sign-kernel` is available, it will be invoked to sign the kernel
using the key used to sign the modules for the kernel being installed. It
is called with the `-q` and -`e` options. If the kernel cannot be signed
for any reason, the kernel is copied into place instead.

It is important to note that while the kernel build environment will
create a key for itself to sign its own modules if none is provided,
the configuration of that key is insufficient for signing the kernel
for use with Secure Boot and it will not be used.

If the signing key is available and suitable, the automatic invocation of
`sbtool-sign-kernel -q -e` means that the process of installing a kernel
that works with Secure Boot should involve no additional effort beyond
copying the key into place.
07070100000004000081ED000000000000000000000001624309280000100F000000000000000000000000000000000000002900000000kernel-install-tools-0.3.0/installkernel#! /bin/bash
#
# /sbin/installkernel  - written by tyson@rwii.com
#
# May 21, 2003 - agruen@suse.de
# * Adapted for SuSE and cleaned up.
#
# This file is kept in the following CVS repository:
#
# $Source: /suse/yast2/cvsroot/mkinitrd/installkernel,v $
# $Revision: 1.8 $
#

: ${INSTALL_PATH:=/boot}
KERNEL_VERSION=$1
BOOTIMAGE=$2
MAPFILE=$3
CONFIGFILE=config-$KERNEL_VERSION

case "$(uname -m)" in
    s390|s390x)
        BOOTFILE=image
        ;;
    ppc*)
        BOOTFILE=vmlinux
        ;;
    aarch64)
        BOOTFILE=Image
        ;;
    armv*)
	BOOTFILE=zImage
	;;
    *)
        BOOTFILE=vmlinuz
        ;;
esac

#
# Move away files from versions up to SuSE Linux 8.2
#

if [ -f $INSTALL_PATH/$BOOTFILE -a ! -L $INSTALL_PATH/$BOOTFILE ]; then
    mv $INSTALL_PATH/$BOOTFILE $INSTALL_PATH/$BOOTFILE.old
fi

if [ -L $INSTALL_PATH/System.map ]; then
    rm -f $INSTALL_PATH/System.map
elif [ -f $INSTALLPATH/System.map ]; then
    mv $INSTALL_PATH/System.map $INSTALL_PATH/System.map.old
fi

#
# Move away files from after SuSE Linux 8.2
#

if [ -f $INSTALL_PATH/$BOOTFILE-$KERNEL_VERSION ]; then
    mv $INSTALL_PATH/$BOOTFILE-$KERNEL_VERSION \
        $INSTALL_PATH/$BOOTFILE-$KERNEL_VERSION.old
fi

if [ -f $INSTALL_PATH/System.map-$KERNEL_VERSION ]; then
    mv $INSTALL_PATH/System.map-$KERNEL_VERSION \
        $INSTALL_PATH/System.map-$KERNEL_VERSION.old
fi


if [ -f .config ] && [ -f $INSTALL_PATH/$CONFIGFILE ]; then
    mv -v $INSTALL_PATH/$CONFIGFILE \
        $INSTALL_PATH/$CONFIGFILE.old
fi

#
# Install new files
#

#
# Sign the kernel for Secure Boot if possible, otherwise simply copy it
#
kernel_needs_copy=true
INSTALLED_KERNEL="$INSTALL_PATH/$BOOTFILE-$KERNEL_VERSION"
if [ -x /usr/bin/sbtool-sign-kernel ]; then
    if /usr/bin/sbtool-sign-kernel -q -e $BOOTIMAGE $INSTALLED_KERNEL; then
        kernel_needs_copy=false
    fi
fi

if $kernel_needs_copy; then
    cp -fp $BOOTIMAGE $INSTALLED_KERNEL
fi

cp -fp $MAPFILE $INSTALL_PATH/System.map-$KERNEL_VERSION
[ -f .config ] && cp -fp .config $INSTALL_PATH/$CONFIGFILE


# If the kernel has module support, recreate modules.dep using depmod
# since the contents of modules.dep do not have a consistent format across
# releases.

if [ -x /sbin/depmod -a -d /lib/modules/$KERNEL_VERSION ]; then
    /sbin/depmod $KERNEL_VERSION
fi

check_supported()
{
   local MOD_SUPP_FILE="/etc/modprobe.d/10-unsupported-modules.conf"
   local MOD_SUPP_REGEX="^\s*allow_unsupported_modules\s+0\s*$"
   local cfg="$1"

   if [ ! -e "$cfg" ]; then return; fi

   local tmp=$(modprobe --showconfig | grep -Eq $MOD_SUPP_REGEX)
   if [ -n "$tmp" ]; then
       CHECK_SUPPORTED="--check-supported"
       return
   fi

   if grep -q "^CONFIG_SUSE_KERNEL_SUPPORTED=y" $cfg ; then
       if [ -e $MOD_SUPP_FILE ] && grep -Eq $MOD_SUPP_REGEX $MOD_SUPP_FILE; then
           CHECK_SUPPORTED="--check-supported"
       fi
   fi
}

CONFIG=$(dirname $MAPFILE)/.config
CHECK_SUPPORTED=

check_supported $CONFIG

KERNTYPES=$(dirname $MAPFILE)/init/kerntypes.o
if [ -e $KERNTYPES ]; then
    cp -fp $KERNTYPES $INSTALL_PATH/Kerntypes-$KERNEL_VERSION
fi

case "$(uname -m)" in
i?86 | x86_64)
    KERNBIN=$(dirname $MAPFILE)/vmlinux
    if [ -e $KERNBIN ]; then
        if [ -f $INSTALL_PATH/vmlinux-$KERNEL_VERSION.gz ]; then
            mv $INSTALL_PATH/vmlinux-$KERNEL_VERSION.gz \
                $INSTALL_PATH/vmlinux-$KERNEL_VERSION.gz.old
        fi
        gzip -c $KERNBIN > $INSTALL_PATH/vmlinux-$KERNEL_VERSION.gz
    fi
    ;;
esac

#
# Generate initial ramdisk
#
if [ -x /usr/bin/dracut -a -d /lib/modules/$KERNEL_VERSION ]; then
    /usr/bin/dracut --force $CHECK_SUPPORTED \
        $INSTALL_PATH/initrd-$KERNEL_VERSION $KERNEL_VERSION
else
    echo "You may need to create an initial ramdisk now."
fi

#
# Update boot loader
#
if [ -x /sbin/update-bootloader ]; then
    opt_initrd=
    [ -e $INSTALL_PATH/initrd-$KERNEL_VERSION ] \
        && opt_initrd="--initrd $INSTALL_PATH/initrd-$KERNEL_VERSION"
    /sbin/update-bootloader --name $KERNEL_VERSION \
        --image $INSTALL_PATH/$BOOTFILE-$KERNEL_VERSION \
        $opt_initrd --add --force
fi
07070100000005000081A40000000000000000000000016243092800000063000000000000000000000000000000000000003A00000000kernel-install-tools-0.3.0/kernel-install-tools-rpmlintrc# This package is noarch but it requires packages that vary by architecture
addFilter("no-binary")
07070100000006000081A40000000000000000000000016243092800000751000000000000000000000000000000000000003500000000kernel-install-tools-0.3.0/kernel-install-tools.spec#
# spec file for package kernel-install-tools
#
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


Name:           kernel-install-tools
Version:        0.3
Release:        0
Summary:        Useful tools for installing self-built kernels
Group:          Development/Tools/Other
License:        GPL-2.0-only
URL:            https://github.com/jeffmahoney/kernel-install-tools
Source:         %{name}-%{version}.tar.xz
Source1:        %{name}-rpmlintrc
Requires:       openssl
%ifarch ia64 %ix86 x86_64 aarch64 %arm riscv64
Requires:       mozilla-nss-tools
Requires:       pesign
%else
Requires:       kernel-default-devel
%endif

%description
A collection of tools useful for installing self-built kernels.

In addition to the baseline /sbin/installkernel, this package includes
several tools for properly signing and installing kernels and certificates
for use on systems with UEFI Secure Boot enabled.

%prep
%setup -q

%build

%install
%make_install

%if 0%{?usrmerged}
mv %{buildroot}/sbin/installkernel %{buildroot}/usr/sbin/installkernel
%endif

%files
%license COPYING
%doc README.md
%{_bindir}/sbtool-genkey
%{_bindir}/sbtool-sign-kernel
%{_sbindir}/sbtool-enroll-key
%if 0%{?usrmerged}
%{_sbindir}/installkernel
%else
/sbin/installkernel
%endif

%changelog
07070100000007000081ED0000000000000000000000016243092800000CB8000000000000000000000000000000000000002D00000000kernel-install-tools-0.3.0/sbtool-enroll-key#!/bin/bash
set -e

progname="$(basename "$0")"

error() {
    echo "$@" >&2
    exit 1
}

quiet_message() {
    $QUIET || echo "$@"
}

quiet_error() {
    quiet_message "$@" >&2
    exit 1
}

_usage() {
cat <<END
$progname [options] /path/to/certificate

This script will copy the public component of the kernel signing key
to /etc/uefi/certs and queue it for enrollment in the system MOK.

If the certificate is already enrolled, it will be skipped and the script will exit with success.
If the system does not support UEFI Secure Boot, it will be skipped and the script will exit with retval=2.

options:
    -q|--quiet: do not report errors for missing dependencies, if the
                certificate is already enrolled, or if it will be skipped
    -h|--help: display this message
END
}

help() {
    _usage
    exit 0
}

usage() {
    _usage >&2
    exit 1
}

check_commands() {
    for command in "$@"; do
        if ! command -v "$command" > /dev/null; then
            if ! $QUIET; then
                error "$command is missing"
            else
                exit 1
            fi
        fi
    done
}

filter_fingerprints() {
    grep 'SHA1 Fingerprint' | sed -e 's/SHA1 Fingerprint.//' | \
        tr -d ' :' | tr a-z A-Z
}

cert_fingerprint() {
    openssl x509 -inform PEM -fingerprint -noout -in "$1" | filter_fingerprints
}

enrolled_fingerprints() {
    mokutil --list-enrolled | filter_fingerprints
    mokutil --list-new | filter_fingerprints
}

options=$(getopt -o qh --long quiet,help -- "$@")
eval set -- $options

QUIET=false
while true; do
    case "$1" in
    -q|--quiet)
        QUIET=true ;;
    -h|--help)
        help ;;
    --)
        shift
        break
        ;;
    *)
        usage ;;
    esac
    shift
done

# It's typical for systems without UEFI to not have mokutil installed, so
# check for UEFI variable support manually.  The user shouldn't need to
# install mokutil only to discover it would fail anyway.
if ! test -d /sys/firmware/efi/efivars; then
    quiet_message "This system does not use UEFI Secure Boot functionality."
    quiet_message "Exiting."
    exit 2
fi

check_commands openssl mokutil

CERT=$1

if test -z "$CERT"; then
    error "error: No certificate specified."
fi

if test "$EUID" != 0; then
    error "This tool must be run as root."
fi

fingerprint=$(cert_fingerprint "$CERT")
fingerprint8=$(echo $fingerprint | cut -b 1-8)

if test -z "$fingerprint8"; then
    error "Failed to parse fingerprint from $CERT"
fi

for enrolled in $(enrolled_fingerprints); do
    if test "$enrolled" = "$fingerprint"; then
        quiet_message "Signing key $fingerprint8 already enrolled or pending."
        exit 0
    fi
done

if test "$EUID" -ne 0; then
    error "Root privileges are required to queue $CERT for enrollment on reboot."
fi

mkdir -p /etc/uefi/certs
# FIXME: Should handle collisions
if ! openssl x509 -inform PEM -in "$CERT" -outform DER \
                  -out "/etc/uefi/certs/$fingerprint8.crt"; then
    error "Failed to convert ${CERT} to DER format for import."
fi

if ! mokutil --import "/etc/uefi/certs/$fingerprint8.crt" --root-pw; then
    error "Failed to queue certificate for enrollment."
fi

quiet_message "Secure Boot certificate queued for enrollment on reboot."
07070100000008000081ED0000000000000000000000016243092800000B49000000000000000000000000000000000000002900000000kernel-install-tools-0.3.0/sbtool-genkey#!/bin/bash
set -e
progname=$(basename "$0")

cleanup() {
    test -n "$genkey" && rm -f "$genkey"
}

default_common_name() {
    name=$(getent passwd $USER|cut -d : -f 5|cut -d, -f 1)
    if test -z "$name"; then
        name="$USER"
    fi

    echo "${name}'s Secure Boot Signkey"
}

CN=$(default_common_name)
EMAIL="${USER}@$(hostname -f)"
HASH=sha256

_usage() {
cat <<END
$progname [options ...] /path/to/certificate

options:
    -h|--help: This message
    -H|--hash <hash>: Specify which hash to use in the key (default: sha256)
    -f|--force: Force overwrite of existing certificate and ignore warnings
                about mismatched hashes.
    -e|--email: Email address to associate with the key
        (default: $EMAIL)
    -c|--common-name: Common Name to associate with the key.
        (default: $CN)
END
}

warn() {
    echo "$@" 1>&2
}

error() {
    warn "$@"
    exit 1
}

help() {
cat <<END
$progname will generate an x509 key suitable for use in signing kernel
binaries and modules.  It will also generate a certificate suitable for
use by UEFI Secure Boot to validate the kernel and modules at boot time.

END
    _usage
    exit 0
}

usage() {
    _usage 1>&2
    exit 1
}

options=$(getopt -o H:hfc:e: --long hash:,help,force,email:,common-name: -- "$@")
if test $? -ne 0; then
    usage
fi

eval set -- $options

FORCE=false
while true; do
    case "$1" in
    -H|--hash)
        HASH=$2
        shift ;;
    -f|--force)
        FORCE=true
        ;;
    -h|--help)
	help
	;;
    -c|--common-name)
        CN=$2
        shift
        ;;
    -e|--email)
        EMAIL=$2
        shift
        ;;
    --)
        shift
        break ;;
    *)
        usage ;;
    esac
    shift
done

if test $# -eq 0; then
    echo "missing output file"
    usage
fi

OUTPUT=$1

if test -e "$OUTPUT" -a "$FORCE" = "false"; then
    error "$OUTPUT already exists.  Overwrite with --force"
fi

if test -z "$CN"; then
    error "Emtpy CN is not valid."
fi

if test -z "$EMAIL"; then
    error "Empty email is not valid."
fi

if test -z "$HASH"; then
    error "Empty hash is not valid."
fi

trap cleanup EXIT
genkey=$(mktemp /tmp/genkey.XXXXXX)

# Notes on key usage:
# Module signing requries digitalSignature
# Secure Boot requires codeSigning

cat << END > $genkey
[ req ]
default_bits = 2048
distinguished_name = req_distinguished_name
prompt = no
string_mask = utf8only
x509_extensions = myexts

[ req_distinguished_name ]
CN = "${CN}"
emailAddress = "${EMAIL}"

[ myexts ]
basicConstraints=critical,CA:FALSE
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid
keyUsage=critical, digitalSignature
extendedKeyUsage=codeSigning
END

if ! openssl req -new -nodes -utf8 -"$HASH" -days 36500 -batch -x509 \
                 -config "$genkey" -outform PEM -out "$OUTPUT" \
                 -keyout "$OUTPUT"; then
    error "Failed to generate signing key and certificate."
fi
07070100000009000081ED0000000000000000000000016243092800001798000000000000000000000000000000000000002E00000000kernel-install-tools-0.3.0/sbtool-sign-kernel#!/bin/bash
set -e

progname="$(basename "$0")"

error() {
    echo "$@" >&2
    exit 1
}

quiet_message() {
    $QUIET || echo "$@"
}

quiet_error() {
    quiet_message "$@" >&2
    exit 1
}

_usage() {
cat << END
$progname [options] <source> <destination> [signing key]

This script will prepare an unsigned kernel for use on a system with
UEFI Secure Boot enabled.  The kernel located at <source> will be
signed using the signing key and written to <destination>.  It will then
register the public component of the signing key for enrollment in the
system MOK if it is not already enrolled.

If [signing key] is unspecified and the working directory is a kernel
build directory, the signing key will be pulled from .config.

If an autodetected signing key has been autogenerated by the kernel build
process and Secure Boot is not enabled, enrollment will be skipped.

This script has several exit values:
0 - success
1 - failure
2 - skipped - kernel not copied into place

options:
    -q|--quiet: do not report errors for missing dependencies, just exit with
                error
    -e|--enroll: queue certificate for enrollment in system MOK.  If the
                 certificate is autodetected, sbtool-enroll-key -a will be
                 used to skip enrollment of kernel-generated signing keys
    -f|--force: queue the certificate for enrollment even if it is
                kernel-generated and secure boot is disabled
END
}

help() {
    _usage
    exit 0
}

usage() {
    _usage >&2
    exit 1
}

check_commands() {
    for command in "$@"; do
        if ! command -v "$command" > /dev/null; then
            for i in /usr/src/linux-obj/$(uname -m)/*/scripts/"$command" ; do
                if [ -x "$i" ] ; then
                    scriptdir="$(dirname "$i")"
                    quiet_message "Using $command from $scriptdir"
                    PATH="$PATH:$scriptdir"
                    continue 2
                fi
            done
            quiet_error "$command is missing"
        fi
    done
}

cert_subject_hash() {
    local cert=$1
    openssl x509 -in $cert -noout -subject_hash
}

cert_kernel_generated() {
    local cert=$1

    # Based on "CN = Build time autogenerated kernel key"
    # as defined in linux/certs/Makefile
    KERNEL_GENERATED_CERT_HASH=0926ef54

    test "$(cert_subject_hash "$cert")" = "$KERNEL_GENERATED_CERT_HASH"
}

secure_boot_enabled() {
    mokutil --sb-state | grep -q "enabled"
}

options=$(getopt -o qhef --long quiet,help,enroll,force -- "$@")

eval set -- $options

QUIET=false
ENROLL=false
FORCE=false
while true; do
    case "$1" in
    -q|--quiet)
        QUIET=true
        ;;
    -e|--enroll)
        ENROLL=true
        ;;
    -f|--force)
        FORCE=true
        ;;
    -h|--help)
        help ;;
    --)
        shift
        break ;;
    *)
        usage ;;
    esac
    shift
done

arch="$(rpm -E %{_arch})"
case "$arch" in
    i?86|x86_64|aarch64|arm*|ia64|riscv64) sign_tools="pesign pk12util certutil" ;;
    ppc*|s390*) sign_tools=sign-file ;;
    *) echo "Don't know how to sign a kernel on architecture '$arch'."
        exit 1
        ;;
esac

check_commands $sign_tools openssl

UNSIGNED=$1
SIGNED=$2
CERT=$3

test -z "$UNSIGNED" -o -z "$SIGNED" && usage 1
test -f "$UNSIGNED" || error "$UNSIGNED does not exist."
test -d "$(dirname "$SIGNED")" || error "Target directory for $SIGNED does not exist."

read_cert_config() {
    sed -n '/^CONFIG_MODULE_SIG_KEY=/s///p' $1 |tr -d '"'
}

DETECTED_KEY=false
FOUND_CONFIG=false
if test -z "$CERT"; then
    for path in .config "$(dirname "$UNSIGNED")/.config"; do
        if test -e $path; then
            FOUND_CONFIG=true
            CERT=$(read_cert_config $path)
            if test -n "$CERT"; then
                DETECTED_KEY=true
                break
            fi
        fi
    done
    if test -z "$CERT"; then
        if $FOUND_CONFIG; then
            echo "Module signing not enabled for this kernel.  Skipping."
            exit 2
        else
            error "Couldn't autodetect signing key, no config found."
        fi
    elif ! test -f "$CERT"; then
        error "Certificate \"$CERT\" found in config but does not exist."
    fi
fi

cleanup() {
	test -n "$tmpdir" && rm -rf "$tmpdir"
}

trap cleanup EXIT
tmpdir=$(mktemp -d /tmp/signkernel.XXXXXX)

if ! openssl x509 -in $CERT -ext keyUsage,extendedKeyUsage -noout | \
	grep -q "Code Signing"; then
    error "Certificate must have Code Signing extended key usage defined for Secure Boot."
fi

# certutil has no facility to import a private key directly, so we have to
# use the pkcs12 interface instead.
certutil_import_key() {
    local certdir=$1
    local cert=$2
    local P12="$tmpdir/cert.p12"

    uuidgen > $tmpdir/passwd
    openssl pkcs12 -export -password "file:$tmpdir/passwd" -inkey $cert \
                   -in $cert -name kernel-cert -out $P12

    # pk12util has no silent mode
    if ! pk12util -w $tmpdir/passwd -d $certdir -i $P12 > $tmpdir/output; then
        cat $tmpdir/output
        exit 1
    fi
    rm -f $tmpdir/passwd $P12 $tmpdir/output
}

case "$sign_tools" in
    pesign*)
        certutil -N -d $tmpdir --empty-password
        certutil_import_key $tmpdir $CERT

        pesign -n $tmpdir -c kernel-cert -i $UNSIGNED -o $SIGNED -s --force

        ;;
    sign-file)
        openssl x509 -in $CERT -outform DER -out "$tmpdir/cert.crt"
        sign-file sha256 $CERT $tmpdir/cert.crt $UNSIGNED $SIGNED
        ;;
esac

echo "Signed $UNSIGNED with $CERT and installed to $SIGNED"

$ENROLL || exit 0

if $QUIET; then
    ARGS="-q"
fi

if $DETECTED_KEY && ! $FORCE && \
   cert_kernel_generated "$CERT" && ! secure_boot_enabled; then
    echo "Skipping enrollment of kernel-generated certificate on" \
         "system without Secure Boot enabled."
    quiet_message "Override with --force."
    echo ""
    exit 0
fi

/usr/sbin/sbtool-enroll-key $ARGS $CERT
ret=$?

# Skipping enrollment doesn't mean we've skipped
# signing and copying so return 0.
if test $? -eq 2; then
    ret=0
fi

exit $ret
07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!84 blocks
openSUSE Build Service is sponsored by