20ce0f
%global debug_package %{nil}
20ce0f
%global __brp_mangle_shebangs_exclude_from_file %{expand:%{_builddir}/shim-%{efi_arch}-%{version}-%{release}.%{_target_cpu}-shebangs.txt}
20ce0f
%global vendor_token_str %{expand:%%{nil}%%{?vendor_token_name:-t "%{vendor_token_name}"}}
20ce0f
%global vendor_cert_str %{expand:%%{!?vendor_cert_nickname:-c "Red Hat Test Certificate"}%%{?vendor_cert_nickname:-c "%%{vendor_cert_nickname}"}}
20ce0f
20ce0f
%global bootcsvaa64 %{expand:%{SOURCE10}}
20ce0f
%global bootcsvia32 %{expand:%{SOURCE11}}
20ce0f
%global bootcsvx64 %{expand:%{SOURCE12}}
20ce0f
#%%global bootcsvarm %%{expand:%%{SOURCE13}}
20ce0f
20ce0f
%global shimefiaa64 %{expand:%{SOURCE20}}
20ce0f
%global shimefiia32 %{expand:%{SOURCE21}}
20ce0f
%global shimefix64 %{expand:%{SOURCE22}}
20ce0f
#%%global shimefiarm %%{expand:%%{SOURCE23}
20ce0f
9a36fd
%global fbefiaa64 %{expand:%{SOURCE30}}
9a36fd
%global fbefiia32 %{expand:%{SOURCE31}}
9a36fd
%global fbefix64 %{expand:%{SOURCE32}}
9a36fd
#%%global fbefiarm %%{expand:%%{SOURCE33}
9a36fd
9a36fd
%global mmefiaa64 %{expand:%{SOURCE40}}
9a36fd
%global mmefiia32 %{expand:%{SOURCE41}}
9a36fd
%global mmefix64 %{expand:%{SOURCE42}}
9a36fd
#%%global mmefiarm %%{expand:%%{SOURCE43}
9a36fd
7aa403
%global shimveraa64 15-7.el8_1
9a36fd
%global shimveria32 15.5-1.el8
9a36fd
%global shimverx64 15.5-1.el8
20ce0f
#%%global shimverarm 15-1.el8
20ce0f
20ce0f
%global shimdiraa64 %{_datadir}/shim/%{shimveraa64}/aa64
20ce0f
%global shimdiria32 %{_datadir}/shim/%{shimveria32}/ia32
20ce0f
%global shimdirx64 %{_datadir}/shim/%{shimverx64}/x64
20ce0f
#%%global shimdirarm %%{_datadir}/shim/%%{shimverarm}/arm
20ce0f
20ce0f
%global unsignedaa64 shim-unsigned-aarch64
20ce0f
%global unsignedia32 shim-unsigned-ia32
20ce0f
%global unsignedx64 shim-unsigned-x64
20ce0f
#%%global unsignedarm shim-unsigned-arm
20ce0f
20ce0f
%global bootcsv %{expand:%{bootcsv%{efi_arch}}}
20ce0f
%global bootcsvalt %{expand:%{bootcsv%{?efi_alt_arch}}}
20ce0f
%global shimefi %{expand:%{shimefi%{efi_arch}}}
20ce0f
%global shimefialt %{expand:%{shimefi%{?efi_alt_arch}}}
20ce0f
%global shimver %{expand:%{shimver%{efi_arch}}}
20ce0f
%global shimveralt %{expand:%{shimver%{?efi_alt_arch}}}
20ce0f
%global shimdir %{expand:%{shimdir%{efi_arch}}}
20ce0f
%global shimdiralt %{expand:%{shimdir%{?efi_alt_arch}}}
9a36fd
%global fbefi %{expand:%{fbefi%{efi_arch}}}
9a36fd
%global fbefialt %{expand:%{fbefi%{?efi_alt_arch}}}
9a36fd
%global mmefi %{expand:%{mmefi%{efi_arch}}}
9a36fd
%global mmefialt %{expand:%{mmefi%{?efi_alt_arch}}}
20ce0f
20ce0f
%global unsignednone shim-unsigned-none
20ce0f
%global unsigned %{expand:%%{unsigned%{efi_arch}}}
20ce0f
%global unsignedalt %{expand:%%{unsigned%{efi_alt_arch}}}
20ce0f
20ce0f
%define define_pkg(a:p:)						\
20ce0f
%{expand:%%package -n shim-%{-a*}}					\
20ce0f
Summary: First-stage UEFI bootloader					\
20ce0f
Requires: mokutil >= 1:0.3.0-1						\
20ce0f
Requires: efi-filesystem						\
20ce0f
Provides: shim-signed-%{-a*} = %{version}-%{release}			\
20ce0f
Requires: dbxtool >= 0.6-3						\
20ce0f
%{expand:%%if 0%%{-p*}							\
20ce0f
Provides: shim = %{version}-%{release}					\
20ce0f
Provides: shim-signed = %{version}-%{release}				\
20ce0f
Obsoletes: shim-signed < %{version}-%{release}				\
20ce0f
Obsoletes: shim < %{version}-%{release}					\
20ce0f
%%endif}								\
20ce0f
# Shim uses OpenSSL, but cannot use the system copy as the UEFI ABI	\
20ce0f
# is not compatible with SysV (there's no red zone under UEFI) and	\
20ce0f
# there isn't a POSIX-style C library.					\
20ce0f
# BuildRequires: OpenSSL						\
20ce0f
Provides: bundled(openssl) = 1.0.2j					\
20ce0f
									\
20ce0f
%{expand:%%description -n shim-%{-a*}}					\
20ce0f
Initial UEFI bootloader that handles chaining to a trusted full		\
20ce0f
bootloader under secure boot environments. This package contains the	\
20ce0f
version signed by the UEFI signing service.				\
20ce0f
%{nil}
20ce0f
20ce0f
# -a <efiarch>
20ce0f
# -i <input>
9a36fd
%define hash(a:i:d:)								\
9a36fd
	if [ 0%{?_unsigned_test_build:%{_unsigned_test_build}} -ne 0 ] ; then	\
9a36fd
		pesign -i %{-i*} -h -P > shim.hash				\
9a36fd
		read file0 hash0 < shim.hash					\
9a36fd
		read file1 hash1 < %{-d*}/shim%{-a*}.hash			\
9a36fd
		if ! [ "$hash0" = "$hash1" ] ; then				\
9a36fd
			echo Invalid signature\! > /dev/stderr			\
9a36fd
			echo $hash0 vs $hash1					\
9a36fd
			exit 1							\
9a36fd
		fi								\
9a36fd
	fi									\
20ce0f
	%{nil}
20ce0f
20ce0f
# -i <input>
20ce0f
# -o <output>
20ce0f
%define sign(i:o:n:a:c:)									\
20ce0f
	%{expand:%%pesign -s -i %{-i*} -o %{-o*} %{-n} %{-n*} %{-a} %{-a*} %{-c} %{-c*}}	\
20ce0f
	%{nil}
20ce0f
20ce0f
# -b <binary prefix>
20ce0f
# -a <efiarch>
20ce0f
# -i <input>
9a36fd
%define distrosign(b:a:d:)							\
9a36fd
	if [ 0%{?_unsigned_test_build:%{_unsigned_test_build}} -ne 0 ] ; then	\
9a36fd
		if [ "%{-b*}%{-a*}" = "shim%{efi_arch}" ] ; then		\
9a36fd
			cp -av "%{shimefi}" %{-b*}%{-a*}-unsigned.efi		\
9a36fd
		elif [ "%{-b*}%{-a*}" = "shim%{efi_alt_arch}" ] ; then		\
9a36fd
			cp -av "%{shimefialt}" %{-b*}%{-a*}-unsigned.efi	\
9a36fd
		elif [ "%{-b*}%{-a*}" = "mm%{efi_arch}" ] ; then		\
9a36fd
			cp -av "%{mmefi}" %{-b*}%{-a*}-unsigned.efi		\
9a36fd
		elif [ "%{-b*}%{-a*}" = "mm%{efi_alt_arch}" ] ; then		\
9a36fd
			cp -av "%{mmefialt}" %{-b*}%{-a*}-unsigned.efi		\
9a36fd
		elif [ "%{-b*}%{-a*}" = "fb%{efi_arch}" ] ; then		\
9a36fd
			cp -av "%{fbefi}" %{-b*}%{-a*}-unsigned.efi		\
9a36fd
		elif [ "%{-b*}%{-a*}" = "fb%{efi_alt_arch}" ] ; then		\
9a36fd
			cp -av "%{fbefialt}" %{-b*}%{-a*}-unsigned.efi		\
9a36fd
		fi								\
9a36fd
	else									\
9a36fd
		cp -av %{-d*}/%{-b*}%{-a*}.efi %{-b*}%{-a*}-unsigned.efi	\
9a36fd
	fi									\
9a36fd
	%{expand:%%sign -i %{-b*}%{-a*}-unsigned.efi -o %{-b*}%{-a*}-signed.efi -n redhatsecureboot501 -a %{SOURCE2} -c %{SOURCE1} } \
20ce0f
	%{nil}
20ce0f
20ce0f
# -a <efiarch>
20ce0f
# -A <EFIARCH>
20ce0f
# -b <1|0> # signed by this builder?
20ce0f
# -c <1|0> # signed by UEFI CA?
20ce0f
# -i <shimARCH.efi>
9a36fd
# -d /usr/share dir for this build (full path)
20ce0f
%define define_build(a:A:b:c:i:d:)					\
20ce0f
if [ "%{-c*}" = "yes-temporarily-disabled-20180723" ]; then		\
20ce0f
	%{expand:%%hash -i %{-i*} -a %{-a*} -d %{-d*}}			\
20ce0f
fi									\
20ce0f
cp %{-i*} shim%{-a*}.efi						\
9a36fd
if [ "%{-b*}" = "yes" ] ; then						\
20ce0f
	%{expand:%%distrosign -b shim -a %{-a*} -d %{-d*}}		\
20ce0f
	mv shim%{-a*}-signed.efi shim%{-a*}-%{efi_vendor}.efi		\
20ce0f
fi									\
9a36fd
if [ "%{-c*}" = "no" ] ||						\
9a36fd
   [ 0%{?_unsigned_test_build:%{_unsigned_test_build}} -ne 0 ] ; then	\
20ce0f
	cp shim%{-a*}-%{efi_vendor}.efi shim%{-a*}.efi			\
20ce0f
fi									\
20ce0f
%{expand:%%distrosign -b mm -a %{-a*} -d %{-d*}}			\
20ce0f
mv mm%{-a*}-signed.efi mm%{-a*}.efi					\
20ce0f
%{expand:%%distrosign -b fb -a %{-a*} -d %{-d*}}			\
20ce0f
mv fb%{-a*}-signed.efi fb%{-a*}.efi					\
20ce0f
rm -vf									\\\
20ce0f
	mm%{-a*}-unsigned.efi						\\\
20ce0f
	fb%{-a*}-unsigned.efi						\\\
20ce0f
	shim%{-a*}-unsigned.efi						\
20ce0f
%{nil}
20ce0f
20ce0f
# -a <efiarch>
20ce0f
# -A <EFIARCH>
20ce0f
# -b <BOOTCSV>
20ce0f
%define do_install(a:A:b:)						\
20ce0f
install -m 0700 shim%{-a*}.efi						\\\
20ce0f
	$RPM_BUILD_ROOT%{efi_esp_dir}/shim%{-a*}.efi			\
20ce0f
install -m 0700 shim%{-a*}-%{efi_vendor}.efi				\\\
20ce0f
	$RPM_BUILD_ROOT%{efi_esp_dir}/shim%{-a*}-%{efi_vendor}.efi	\
20ce0f
install -m 0700 mm%{-a*}.efi						\\\
20ce0f
	$RPM_BUILD_ROOT%{efi_esp_dir}/mm%{-a*}.efi			\
20ce0f
install -m 0700 %{-b*}							\\\
20ce0f
	$RPM_BUILD_ROOT%{efi_esp_dir}/BOOT%{-A*}.CSV			\
20ce0f
install -m 0700 shim%{-a*}.efi						\\\
20ce0f
	$RPM_BUILD_ROOT%{efi_esp_boot}/BOOT%{-A*}.EFI			\
20ce0f
install -m 0700 fb%{-a*}.efi						\\\
20ce0f
	$RPM_BUILD_ROOT%{efi_esp_boot}/fb%{-a*}.efi			\
20ce0f
%nil
20ce0f
20ce0f
# -a <efiarch>
20ce0f
# -A <EFIARCH>
20ce0f
%define define_files(a:A:)						\
20ce0f
%{expand:%%files -n shim-%{-a*}}					\
20ce0f
%{efi_esp_dir}/*%{-a*}*.efi						\
20ce0f
%{efi_esp_dir}/BOOT%{-A*}.CSV						\
20ce0f
%{efi_esp_boot}/*%{-a*}.efi						\
20ce0f
%{efi_esp_boot}/*%{-A*}.EFI						\
20ce0f
%{nil}
20ce0f
20ce0f
%ifarch x86_64
20ce0f
%global is_signed yes
20ce0f
%global is_alt_signed yes
20ce0f
%global provide_legacy_shim 1
20ce0f
%endif
20ce0f
%ifarch aarch64
20ce0f
%global is_signed no
20ce0f
%global is_alt_signed no
20ce0f
%global provide_legacy_shim 1
20ce0f
%endif
20ce0f
%ifnarch x86_64 aarch64
20ce0f
%global is_signed no
20ce0f
%global is_alt_signed no
20ce0f
%global provide_legacy_shim 0
20ce0f
%endif
20ce0f
20ce0f
%if ! 0%{?vendor:1}
20ce0f
%global vendor nopenopenope
20ce0f
%endif
20ce0f
20ce0f
# vim:filetype=rpmmacros