diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:49:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:49:59 +0000 |
commit | 01997497f915e8f79871f3f2acb55ac465051d24 (patch) | |
tree | 1ce1afd7246e1014199e15cbf854bf7924458e5d /debian/signing_templates/sign-file-attach | |
parent | Adding upstream version 6.1.76. (diff) | |
download | linux-01997497f915e8f79871f3f2acb55ac465051d24.tar.xz linux-01997497f915e8f79871f3f2acb55ac465051d24.zip |
Adding debian version 6.1.76-1.debian/6.1.76-1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/signing_templates/sign-file-attach')
-rwxr-xr-x | debian/signing_templates/sign-file-attach | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/debian/signing_templates/sign-file-attach b/debian/signing_templates/sign-file-attach new file mode 100755 index 000000000..6a8a18cac --- /dev/null +++ b/debian/signing_templates/sign-file-attach @@ -0,0 +1,56 @@ +#!/usr/bin/python3 + +import argparse +import pathlib +import shutil +import struct +import sys + + +module_magic = b'~Module signature appended~\n' +# Only relevant fields are id_type and sig_len +module_signature = struct.Struct('!2xB2x3xL') +module_signature_PKEY_ID_PKCS7 = 2 + + +def sign_file_attach(sig_base: pathlib.Path, module_base: pathlib.Path, output_base: pathlib.Path) -> None: + for line in sys.stdin: + path, _, file = line.strip().rpartition('/') + name, _, _ = file.partition('.') + + sig = sig_base / path / f'{name}.ko.sig' + module = module_base / path / f'{name}.ko' + output = output_base / path / f'{name}.ko' + output.parent.mkdir(parents=True, exist_ok=True) + + with sig.open('rb') as f_sig, module.open('rb') as f_module, output.open('wb') as f_output: + shutil.copyfileobj(f_module, f_output) + shutil.copyfileobj(f_sig, f_output) + len_sig = f_sig.tell() + f_output.write(module_signature.pack( + module_signature_PKEY_ID_PKCS7, + len_sig, + )) + f_output.write(module_magic) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument( + 'sig_base', + metavar='SIGNATURE', + type=pathlib.Path, + ) + parser.add_argument( + 'module_base', + metavar='MODULE', + type=pathlib.Path, + ) + parser.add_argument( + 'output_base', + metavar='OUTPUT', + type=pathlib.Path, + ) + args = parser.parse_args() + + sign_file_attach(**vars(args)) |