File shim.spec of Package shim
334
1
#
2
# spec file for package shim
3
#
4
# Copyright (c) 2021 SUSE LLC
5
#
6
# All modifications and additions to the file contributed by third parties
7
# remain the property of their copyright owners, unless otherwise agreed
8
# upon. The license for this file, and modifications and additions to the
9
# file, is the same license as for the pristine package itself (unless the
10
# license for the pristine package is not an Open Source License, in which
11
# case the license is the MIT License). An "Open Source License" is a
12
# license that conforms to the Open Source Definition (Version 1.9)
13
# published by the Open Source Initiative.
14
15
# Please submit bugfixes or comments via https://bugs.opensuse.org/
16
#
17
# needssslcertforbuild
18
19
20
%undefine _debuginfo_subpackages
21
%undefine _build_create_debug
22
%ifarch aarch64
23
%define grubplatform arm64-efi
24
%else
25
%define grubplatform %{_target_cpu}-efi
26
%endif
27
%if %{defined sle_version} && 0%{?sle_version} <= 150000
28
%define sysefidir /usr/lib64/efi
29
%else
30
%define sysefibasedir %{_datadir}/efi
31
%define sysefidir %{sysefibasedir}/%{_target_cpu}
32
%if "%{grubplatform}" == "x86_64-efi" && 0%{?suse_version} < 1600
33
# provide compatibility sym-link for residual kiwi, etc.
34
%define shim_lib64_share_compat 1
35
%endif
36
%endif
37
38
Name: shim
39
Version: 15.4
40
Release: 0
41
Summary: UEFI shim loader
42
License: BSD-2-Clause
43
Group: System/Boot
44
URL: https://github.com/rhboot/shim
45
Source: %{name}-%{version}.tar.bz2
46
# run "extract_signature.sh shim.efi" where shim.efi is the binary
47
# with the signature from the UEFI signing service.
48
# Note: For signature requesting, check SIGNATURE_UPDATE.txt
49
Source1: signature-opensuse.x86_64.asc
50
Source2: openSUSE-UEFI-CA-Certificate.crt
51
Source3: shim-install
52
Source4: SLES-UEFI-CA-Certificate.crt
53
Source5: extract_signature.sh
54
Source6: attach_signature.sh
55
Source7: show_hash.sh
56
Source8: show_signatures.sh
57
Source9: timestamp.pl
58
Source10: strip_signature.sh
59
Source11: signature-sles.x86_64.asc
60
Source12: signature-opensuse.aarch64.asc
61
Source13: signature-sles.aarch64.asc
62
Source50: dbx-cert.tar.xz
63
# vendor-dbx.bin is generated by generate-vendor-dbx.sh in dbx-cert.tar.xz
64
Source51: vendor-dbx.bin
65
Source99: SIGNATURE_UPDATE.txt
66
# PATCH-FIX-SUSE shim-arch-independent-names.patch glin@suse.com -- Use the Arch-independent names
67
Patch1: shim-arch-independent-names.patch
68
# PATCH-FIX-OPENSUSE shim-change-debug-file-path.patch glin@suse.com -- Change the default debug file path
69
Patch2: shim-change-debug-file-path.patch
70
# PATCH-FIX-SUSE shim-bsc1177315-verify-eku-codesign.patch bsc#1177315 glin@suse.com -- Verify CodeSign in the signer's EKU
71
Patch3: shim-bsc1177315-verify-eku-codesign.patch
72
# PATCH-FIX-UPSTREAM shim-bsc1177789-fix-null-pointer-deref-AuthenticodeVerify.patch bsc#1177789 glin@suse.com -- Fix the NULL pointer dereference in AuthenticodeVerify()
73
Patch4: shim-bsc1177789-fix-null-pointer-deref-AuthenticodeVerify.patch
74
# PATCH-FIX-SUSE remove_build_id.patch -- Remove the build ID to make the binary reproducible when building with AArch64 container
75
Patch5: remove_build_id.patch
76
# PATCH-FIX-UPSTREAM shim-bsc1184454-allocate-mok-config-table-BS.patch bsc#1184454 glin@suse.com -- Allocate MOK config table as BootServicesData to avoid the error message from linux kernel
77
Patch6: shim-bsc1184454-allocate-mok-config-table-BS.patch
78
BuildRequires: dos2unix
79
BuildRequires: mozilla-nss-tools
80
BuildRequires: openssl >= 0.9.8
81
BuildRequires: pesign
82
BuildRequires: pesign-obs-integration
83
%ifarch aarch64
84
# Pull in shim-susesigned for bsc#1185621
85
BuildRequires: shim-susesigned
86
%endif
87
%if 0%{?suse_version} > 1320
88
BuildRequires: update-bootloader-rpm-macros
89
%endif
90
%if 0%{?update_bootloader_requires:1}
91
%update_bootloader_requires
92
%else
93
Requires: perl-Bootloader
94
%endif
95
BuildRoot: %{_tmppath}/%{name}-%{version}-build
96
# For shim-install script
97
Requires: grub2-%{grubplatform}
98
ExclusiveArch: x86_64 aarch64
99
100
%description
101
shim is a trivial EFI application that, when run, attempts to open and
102
execute another application.
103
104
%package -n shim-debuginfo
105
Summary: UEFI shim loader - debug symbols
106
Group: Development/Debug
107
108
%description -n shim-debuginfo
109
The debug symbols of UEFI shim loader
110
111
%package -n shim-debugsource
112
Summary: UEFI shim loader - debug source
113
Group: Development/Debug
114
115
%description -n shim-debugsource
116
The source code of UEFI shim loader
117
118
119
%prep
120
%setup -q
121
%patch1 -p1
122
%patch2 -p1
123
%patch3 -p1
124
%patch4 -p1
125
%patch5 -p1
126
%patch6 -p1
127
128
%build
129
# generate the vendor SBAT metadata
130
%if 0%{?is_opensuse} == 1 || 0%{?sle_version} == 0
131
distro_id="opensuse"
132
distro_name="The openSUSE project"
133
%else
134
distro_id="sle"
135
distro_name="SUSE Linux Enterprise"
136
%endif
137
distro_sbat=1
138
sbat="shim.${distro_id},${distro_sbat},${distro_name},%{name},%{version},mail:security-team@suse.de"
139
echo "${sbat}" > data/sbat.vendor.csv
140
141
# first, build MokManager and fallback as they don't depend on a
142
# specific certificate
143
make RELEASE=0 \
144
MMSTEM=MokManager FBSTEM=fallback \
145
MokManager.efi.debug fallback.efi.debug \
146
MokManager.efi fallback.efi
147
148
# now build variants of shim that embed different certificates
149
default=''
150
suffixes=(opensuse sles)
151
# check whether the project cert is a known one. If it is we build
152
# just one shim that embeds this specific cert. If it's a devel
153
# project we build all variants to simplify testing.
154
if test -e %{_sourcedir}/_projectcert.crt ; then
155
prjsubject=$(openssl x509 -in %{_sourcedir}/_projectcert.crt -noout -subject_hash)
156
prjissuer=$(openssl x509 -in %{_sourcedir}/_projectcert.crt -noout -issuer_hash)
157
opensusesubject=$(openssl x509 -in %{SOURCE2} -noout -subject_hash)
158
slessubject=$(openssl x509 -in %{SOURCE4} -noout -subject_hash)
159
if test "$prjissuer" = "$opensusesubject" ; then
160
suffixes=(opensuse)
161
elif test "$prjissuer" = "$slessubject" ; then
162
suffixes=(sles)
163
elif test "$prjsubject" = "$prjissuer" ; then
164
suffixes=(devel opensuse sles)
165
fi
166
fi
167
168
for suffix in "${suffixes[@]}"; do
169
if test "$suffix" = "opensuse"; then
170
cert=%{SOURCE2}
171
verify='openSUSE Secure Boot CA1'
172
%ifarch x86_64
173
signature=%{SOURCE1}
174
%else
175
# AArch64 signature
176
# Disable AArch64 signature attachment temporarily
177
# until we get a real one.
178
#signature=%{SOURCE12}
179
%endif
180
elif test "$suffix" = "sles"; then
181
cert=%{SOURCE4}
182
verify='SUSE Linux Enterprise Secure Boot CA1'
183
%ifarch x86_64
184
signature=%{SOURCE11}
185
%else
186
# AArch64 signature
187
signature=%{SOURCE13}
188
%endif
189
elif test "$suffix" = "devel"; then
190
cert=%{_sourcedir}/_projectcert.crt
191
verify=`openssl x509 -in "$cert" -noout -email`
192
signature=''
193
test -e "$cert" || continue
194
else
195
echo "invalid suffix"
196
false
197
fi
198
199
openssl x509 -in $cert -outform DER -out shim-$suffix.der
200
make RELEASE=0 SHIMSTEM=shim \
201
VENDOR_CERT_FILE=shim-$suffix.der ENABLE_HTTPBOOT=1 \
202
DEFAULT_LOADER="\\\\\\\\grub.efi" \
203
VENDOR_DBX_FILE=%{SOURCE51} \
204
shim.efi.debug shim.efi
205
#
206
# assert correct certificate embedded
207
grep -q "$verify" shim.efi
208
# make VENDOR_CERT_FILE=cert.der VENDOR_DBX_FILE=dbx
209
chmod 755 %{SOURCE9}
210
# alternative: verify signature
211
#sbverify --cert MicCorThiParMarRoo_2010-10-05.pem shim-signed.efi
212
if test -n "$signature"; then
213
head -1 "$signature" > hash1
214
cp shim.efi shim.efi.bak
215
# pe header contains timestamp and checksum. we need to
216
# restore that
217
%{SOURCE9} --set-from-file "$signature" shim.efi
218
pesign -h -P -i shim.efi > hash2
219
cat hash1 hash2
220
if ! cmp -s hash1 hash2; then
221
echo "ERROR: $suffix binary changed, need to request new signature!"
222
%if %{defined shim_enforce_ms_signature} && 0%{?shim_enforce_ms_signature} > 0
223
false
224
%endif
225
mv shim.efi.bak shim-$suffix.efi
226
rm shim.efi
227
else
228
# attach signature
229
pesign -m "$signature" -i shim.efi -o shim-$suffix.efi
230
rm -f shim.efi
231
fi
232
else
233
mv shim.efi shim-$suffix.efi
234
fi
235
mv shim.efi.debug shim-$suffix.debug
236
# remove the build cert if exists
237
rm -f shim_cert.h shim.cer shim.crt
238
# make sure all object files gets rebuilt
239
rm -f *.o
240
done
241
242
ln -s shim-${suffixes[0]}.efi shim.efi
243
mv shim-${suffixes[0]}.debug shim.debug
244
245
# Collect the source for debugsource
246
mkdir ../source
247
find . \( -name "*.c" -o -name "*.h" \) -type f -exec cp --parents -a {} ../source/ \;
248
mv ../source .
249
250
%install
251
export BRP_PESIGN_FILES='%{sysefidir}/shim*.efi %{sysefidir}/MokManager.efi %{sysefidir}/fallback.efi'
252
install -d %{buildroot}/%{sysefidir}
253
cp -a shim*.efi %{buildroot}/%{sysefidir}
254
install -m 444 shim-*.der %{buildroot}/%{sysefidir}
255
install -m 644 MokManager.efi %{buildroot}/%{sysefidir}/MokManager.efi
256
install -m 644 fallback.efi %{buildroot}/%{sysefidir}/fallback.efi
257
install -d %{buildroot}/%{_sbindir}
258
install -m 755 %{SOURCE3} %{buildroot}/%{_sbindir}/
259
# install SUSE certificate
260
install -d %{buildroot}/%{_sysconfdir}/uefi/certs/
261
for file in shim-*.der; do
262
fpr=$(openssl x509 -sha1 -fingerprint -inform DER -noout -in $file | cut -c 18- | cut -d ":" -f 1,2,3,4 | sed 's/://g')
263
install -m 644 $file %{buildroot}/%{_sysconfdir}/uefi/certs/${fpr}-shim.crt
264
done
265
%if %{defined shim_lib64_share_compat}
266
[ "%{sysefidir}" != "/usr/lib64/efi" ] || exit 1
267
# provide compatibility sym-link for residual "consumers"
268
install -d %{buildroot}/usr/lib64/efi
269
ln -srf %{buildroot}/%{sysefidir}/*.efi %{buildroot}/usr/lib64/efi/
270
%endif
271
272
# install the debug symbols
273
install -d %{buildroot}/usr/lib/debug/%{sysefidir}
274
install -m 644 shim.debug %{buildroot}/usr/lib/debug/%{sysefidir}
275
install -m 644 MokManager.efi.debug %{buildroot}/usr/lib/debug/%{sysefidir}/MokManager.debug
276
install -m 644 fallback.efi.debug %{buildroot}/usr/lib/debug/%{sysefidir}/fallback.debug
277
278
# install the debug source
279
install -d %{buildroot}/usr/src/debug/%{name}-%{version}
280
cp -r source/* %{buildroot}/usr/src/debug/%{name}-%{version}
281
282
%ifarch aarch64
283
# install suse-signed shim (bsc#1185621)
284
install -m 444 %{sysefidir}/shim-susesigned.* %{buildroot}/%{sysefidir}
285
%endif
286
287
%clean
288
%{?buildroot:%__rm -rf "%{buildroot}"}
289
290
%post
291
%if 0%{?update_bootloader_check_type_reinit_post:1}
292
%update_bootloader_check_type_reinit_post grub2-efi
293
%else
294
/sbin/update-bootloader --reinit || true
295
%endif
296
297
%if %{defined update_bootloader_posttrans}
298
%posttrans
299
%{?update_bootloader_posttrans}
300
%endif
301
302
%files
303
%defattr(-,root,root)
304
%doc COPYRIGHT
305
%dir %{?sysefibasedir}
306
%dir %{sysefidir}
307
%{sysefidir}/shim.efi
308
%{sysefidir}/shim-*.efi
309
%{sysefidir}/shim-*.der
310
%{sysefidir}/MokManager.efi
311
%{sysefidir}/fallback.efi
312
%{_sbindir}/shim-install
313
%dir %{_sysconfdir}/uefi/
314
%dir %{_sysconfdir}/uefi/certs/
315
%{_sysconfdir}/uefi/certs/*.crt
316
%if %{defined shim_lib64_share_compat}
317
# provide compatibility sym-link for previous kiwi, etc.
318
%dir /usr/lib64/efi
319
/usr/lib64/efi/*.efi
320
%endif
321
322
%files -n shim-debuginfo
323
%defattr(-,root,root,-)
324
/usr/lib/debug%{sysefidir}/shim.debug
325
/usr/lib/debug%{sysefidir}/MokManager.debug
326
/usr/lib/debug%{sysefidir}/fallback.debug
327
328
%files -n shim-debugsource
329
%defattr(-,root,root,-)
330
%dir /usr/src/debug/%{name}-%{version}
331
/usr/src/debug/%{name}-%{version}/*
332
333
%changelog
334