(file_path, key_path, signature_path=None)
| 207 | |
| 208 | |
| 209 | def sign_file(file_path, key_path, signature_path=None): |
| 210 | if signature_path is None: |
| 211 | signature_path = file_path + ".sig" |
| 212 | cmd = [ |
| 213 | "openssl", "pkeyutl", "-sign", |
| 214 | "-inkey", key_path, |
| 215 | "-rawin", "-in", file_path, |
| 216 | "-out", signature_path, |
| 217 | ] |
| 218 | proc = subprocess.run(cmd, capture_output=True, text=True) |
| 219 | if proc.returncode != 0: |
| 220 | stderr = proc.stderr.strip() |
| 221 | stdout = proc.stdout.strip() |
| 222 | raise SigningError(f"Signing {file_path} with {key_path} failed (exitcode: {proc.returncode} stdout: {stdout!s} stderr: {stderr!s}") |
| 223 | logger.info(f"Signed {file_path}, signature {signature_path}") |
| 224 | return signature_path |
| 225 | |
| 226 | |
| 227 | def verify_file(file_path, signature_path, pub_key_path): |
no test coverage detected