diff --git a/rpm_head_signing/extract_rpm_with_filesigs.py b/rpm_head_signing/extract_rpm_with_filesigs.py index b6349dd..9c973ea 100755 --- a/rpm_head_signing/extract_rpm_with_filesigs.py +++ b/rpm_head_signing/extract_rpm_with_filesigs.py @@ -55,11 +55,15 @@ def _extract_rpm(rpm_path, output_path): RPMSIGTAG_RSAHEADER = 268 +class NonImaSignedPackage(ValueError): + pass + + # Koji doesn't support type 8 (string array) for returning def _get_header_type_8(raw_hdr, tag): entry = raw_hdr.index.get(RPMSIGTAG_FILESIGNATURES) if entry is None: - raise Exception("No file signatures found") + raise NonImaSignedPackage("No file signatures found") (dtype, offset, count) = entry[1:] # This is basically RawHeader._getitem, but then for only type 8 il = len(raw_hdr.index) @@ -84,10 +88,6 @@ def _get_header_type_8(raw_hdr, tag): def _extract_filesigs(rpm_path): sighdr = rip_rpm_sighdr(rpm_path) sighdr = RawHeader(sighdr) - filesigs = _get_header_type_8(sighdr, RPMSIGTAG_FILESIGNATURES) - - if not filesigs: - return None rpm_hdr = get_rpm_header(rpm_path) fileflags = rpm_hdr[rpm.RPMTAG_FILEFLAGS] @@ -95,6 +95,15 @@ def _extract_filesigs(rpm_path): dirnames = rpm_hdr[rpm.RPMTAG_DIRNAMES] basenames = rpm_hdr[rpm.RPMTAG_BASENAMES] + if len(basenames) == 0: + logging.debug("Empty RPM encountered") + return {} + + filesigs = _get_header_type_8(sighdr, RPMSIGTAG_FILESIGNATURES) + + if not filesigs: + return None + if len(basenames) != len(filesigs): raise Exception( "Invalid number of file signatures (%d) for basenames (%d)"