2013-02-05 11:41:47 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# This specfile unpacks the original RPMs, runs pesign-gen-repackage-spec
|
|
|
|
# to create a second repackage specfile, and runs another rpmbuild to
|
|
|
|
# actually do the repackaging.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2013 SUSE Linux Products GmbH, Nuernberg, Germany.
|
|
|
|
#
|
|
|
|
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
# Do not generate any debug packages from the repackage specfile
|
|
|
|
%undefine _build_create_debug
|
|
|
|
|
|
|
|
Name: pesign-repackage
|
|
|
|
Version: 1.0
|
|
|
|
Release: 1
|
|
|
|
BuildRequires: openssl mozilla-nss-tools
|
|
|
|
%ifarch %ix86 x86_64 ia64
|
|
|
|
BuildRequires: pesign
|
|
|
|
%endif
|
2013-03-15 07:19:57 +01:00
|
|
|
License: GPL-2.0
|
2013-02-05 11:41:47 +01:00
|
|
|
Group: Development/Tools/Other
|
|
|
|
Summary: Spec file to rebuild RPMs with signatures
|
|
|
|
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
|
|
|
%description
|
|
|
|
Rebuilds RPMs with signatures
|
|
|
|
|
|
|
|
%prep
|
|
|
|
%setup -c -T
|
|
|
|
|
|
|
|
%build
|
|
|
|
|
|
|
|
%install
|
|
|
|
|
2014-08-05 04:30:29 +02:00
|
|
|
# avoid loops
|
|
|
|
export BRP_PESIGN_FILES=""
|
|
|
|
|
2013-02-05 11:41:47 +01:00
|
|
|
pushd %buildroot
|
|
|
|
disturl=
|
|
|
|
rpms=()
|
|
|
|
for rpm in %_sourcedir/*.rpm; do
|
|
|
|
case "$rpm" in
|
|
|
|
*.src.rpm | *.nosrc.rpm)
|
|
|
|
cp "$rpm" %_srcrpmdir/
|
|
|
|
continue
|
2013-03-05 10:55:45 +01:00
|
|
|
;;
|
|
|
|
# Do not repackage debuginfo packages (bnc#806637)
|
|
|
|
*-debuginfo-*.rpm | *-debugsource-*.rpm)
|
2013-06-14 23:59:33 +02:00
|
|
|
mkdir -p "%_topdir/OTHER"
|
|
|
|
cp "$rpm" "$_"
|
2013-03-05 10:55:45 +01:00
|
|
|
continue
|
|
|
|
;;
|
2013-02-05 11:41:47 +01:00
|
|
|
esac
|
2013-03-05 08:41:57 +01:00
|
|
|
# do not repackage baselibs packages
|
|
|
|
# FIXME: needs more generic test (if architecture has different
|
|
|
|
# bitness => skip)
|
|
|
|
case "$(rpm -qp --qf '%%{name}/%%{arch}' "$rpm")" in
|
|
|
|
*-32bit/x86_64 | *-32bit/s390x | *-32bit/ppc64 | \
|
|
|
|
*-64bit/ppc | *-x86/ia64)
|
|
|
|
mkdir -p "%_topdir/OTHER"
|
|
|
|
cp "$rpm" "$_"
|
|
|
|
continue
|
|
|
|
esac
|
2013-02-05 11:41:47 +01:00
|
|
|
rpm2cpio "$rpm" | cpio -idm
|
|
|
|
d=$(rpm -qp --qf '%%{disturl}' "$rpm")
|
|
|
|
if test -z "$disturl"; then
|
|
|
|
disturl=$d
|
|
|
|
fi
|
|
|
|
if test "$disturl" != "$d"; then
|
|
|
|
echo "Error: packages have different disturl: $d vs $disturl"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
rpms=("${rpms[@]}" "$rpm")
|
|
|
|
done
|
|
|
|
popd
|
|
|
|
mkdir rsasigned
|
|
|
|
pushd rsasigned
|
|
|
|
cpio -idm <%_sourcedir/@NAME@.cpio.rsasign.sig
|
|
|
|
cat >cert.crt <<EOF
|
|
|
|
@CERT@
|
|
|
|
EOF
|
|
|
|
if test "$(wc -l <cert.crt)" -gt 1; then
|
|
|
|
openssl x509 -inform PEM -in cert.crt -outform DER -out cert.x509
|
|
|
|
cert=cert.x509
|
|
|
|
else
|
|
|
|
echo "warning: No buildservice project certificate found, add"
|
|
|
|
echo "warning: # needssslcertforbuild to the specfile"
|
2013-02-06 13:25:06 +01:00
|
|
|
echo "warning: Using /usr/lib/rpm/pesign/pesign-cert.x509 as fallback"
|
|
|
|
cert=/usr/lib/rpm/pesign/pesign-cert.x509
|
2013-02-05 11:41:47 +01:00
|
|
|
fi
|
2013-02-05 14:35:22 +01:00
|
|
|
mkdir nss-db
|
|
|
|
nss_db=$PWD/nss-db
|
|
|
|
echo foofoofoo > "$nss_db/passwd"
|
|
|
|
certutil -N -d "$nss_db" -f "$nss_db/passwd"
|
|
|
|
certutil -A -d "$nss_db" -n cert -t CT,CT,CT -i "$cert"
|
|
|
|
|
2014-04-27 09:52:13 +02:00
|
|
|
sigs=($(find -type f -name '*.sig' -printf '%%P\n'))
|
2013-02-05 11:41:47 +01:00
|
|
|
for sig in "${sigs[@]}"; do
|
|
|
|
f=%buildroot/${sig%.sig}
|
2014-04-27 09:52:13 +02:00
|
|
|
case "/$sig" in
|
2013-02-05 11:41:47 +01:00
|
|
|
*.ko.sig)
|
2013-02-06 13:25:06 +01:00
|
|
|
/usr/lib/rpm/pesign/kernel-sign-file -s "$sig" sha256 "$cert" "$f"
|
2013-02-05 11:41:47 +01:00
|
|
|
;;
|
2014-04-27 09:52:13 +02:00
|
|
|
/boot/* | *.efi.sig)
|
2013-02-05 14:35:22 +01:00
|
|
|
infile=${sig%.sig}
|
|
|
|
cpio -i --to-stdout ${infile#./} <%_sourcedir/@NAME@.cpio.rsasign > ${infile}.sattrs
|
|
|
|
test -s ${infile}.sattrs || exit 1
|
2013-03-28 04:57:10 +01:00
|
|
|
ohash=$(pesign -n "$nss_db" -h -P -i "$f")
|
2013-02-05 14:35:22 +01:00
|
|
|
pesign -n "$nss_db" -c cert -i "$f" -o "$f.tmp" -d sha256 -I "${infile}.sattrs" -R "$sig"
|
|
|
|
rm -f "${infile}.sattrs"
|
|
|
|
mv "$f.tmp" "$f"
|
2013-02-12 17:04:58 +01:00
|
|
|
nhash=$(pesign -n "$nss_db" -h -i "$f")
|
|
|
|
if test "$ohash" != "$nhash" ; then
|
|
|
|
echo "hash mismatch error: $ohash $nhash"
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-04-27 09:52:13 +02:00
|
|
|
# Regenerate the HMAC if it exists
|
|
|
|
hmac="${f%%/*}/.${f##*/}.hmac"
|
|
|
|
if test -e "$hmac"; then
|
|
|
|
/usr/lib/rpm/pesign/gen-hmac -r %buildroot "/${sig%.sig}"
|
|
|
|
fi
|
2013-02-05 14:35:22 +01:00
|
|
|
;;
|
2013-02-05 11:41:47 +01:00
|
|
|
*)
|
|
|
|
echo "Warning: unhandled signature: $sig" >&2
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
popd
|
2013-02-06 13:25:06 +01:00
|
|
|
/usr/lib/rpm/pesign/pesign-gen-repackage-spec --directory=%buildroot "${rpms[@]}"
|
2013-02-05 11:41:47 +01:00
|
|
|
rpmbuild --define "%%buildroot %buildroot" --define "%%disturl $disturl" \
|
|
|
|
--define "%%_builddir $PWD" \
|
|
|
|
--define "%_suse_insert_debug_package %%{nil}" -bb repackage.spec
|
|
|
|
|
|
|
|
# This is needed by the kernel packages. Ideally, we should not run _any_ brp
|
|
|
|
# checks, because the RPMs passed them once already
|
|
|
|
export NO_BRP_STALE_LINK_ERROR=yes
|
|
|
|
|
|
|
|
# Make sure that our rpmbuild does not complain about unpackaged files
|
|
|
|
rm -rf %buildroot
|
|
|
|
mkdir %buildroot
|
|
|
|
|