-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to determine RPM signing state
This adds a function that can tell whether a package is header-only signable, header-only signed, IMA signed and signed. Signed-off-by: Patrick Uiterwijk <[email protected]>
- Loading branch information
1 parent
0fc7d80
commit 50b9a40
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
parse_ima_signature, | ||
get_rpm_ima_signature_info, | ||
) | ||
from .determine import determine_rpm_status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import rpm | ||
from koji import ( | ||
find_rpm_sighdr, | ||
rpm_hdr_size, | ||
RawHeader, | ||
get_header_fields, | ||
) | ||
|
||
from .extract_header import RPMTAG_PAYLOADDIGEST | ||
from .extract_rpm_with_filesigs import RPMSIGTAG_FILESIGNATURES | ||
|
||
|
||
class DetermineResult(object): | ||
is_head_only_signable = None | ||
is_head_only_signed = None | ||
is_signed = None | ||
is_ima_signed = None | ||
|
||
|
||
def determine_rpm_status(rpm_path): | ||
(sig_start, sig_size) = find_rpm_sighdr(rpm_path) | ||
hdr_start = sig_start + sig_size | ||
hdr_size = rpm_hdr_size(rpm_path, hdr_start) | ||
|
||
with open(rpm_path, "rb") as f: | ||
f.seek(sig_start) | ||
sighdr = f.read(sig_size) | ||
sighdr = RawHeader(sighdr) | ||
f.seek(hdr_start) | ||
hdr = f.read(hdr_size) | ||
hdr = RawHeader(hdr) | ||
|
||
fields = get_header_fields( | ||
rpm_path, | ||
( | ||
"name", | ||
"basenames", | ||
"siggpg", | ||
"sigpgp", | ||
"rsaheader", | ||
"dsaheader", | ||
), | ||
) | ||
|
||
filesignatures = sighdr.index.get(RPMSIGTAG_FILESIGNATURES) | ||
payloaddigest = hdr.index.get(RPMTAG_PAYLOADDIGEST) | ||
|
||
result = DetermineResult() | ||
result.is_head_only_signable = payloaddigest is not None | ||
result.is_head_only_signed = ( | ||
(fields["rsaheader"] is not None or fields["dsaheader"] is not None) | ||
and fields["siggpg"] is None | ||
and fields["sigpgp"] is None | ||
) | ||
result.is_signed = ( | ||
fields["rsaheader"] is not None | ||
or fields["dsaheader"] is not None | ||
or fields["siggpg"] is not None | ||
or fields["sigpgp"] is not None | ||
) | ||
result.is_ima_signed = filesignatures is not None | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters