blob: 51c24b38b26da5d8f25d818d3ef4ce57c05a2e7b [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05007# Class for generating signed IPK packages.
8#
9# Configuration variables used by this class:
10# IPK_GPG_PASSPHRASE_FILE
11# Path to a file containing the passphrase of the signing key.
12# IPK_GPG_NAME
13# Name of the key to sign with.
14# IPK_GPG_BACKEND
15# Optional variable for specifying the backend to use for signing.
16# Currently the only available option is 'local', i.e. local signing
17# on the build host.
18# IPK_GPG_SIGNATURE_TYPE
19# Optional variable for specifying the type of gpg signatures, can be:
20# 1. Ascii armored (ASC), default if not set
21# 2. Binary (BIN)
22# GPG_BIN
23# Optional variable for specifying the gpg binary/wrapper to use for
24# signing.
25# GPG_PATH
26# Optional variable for specifying the gnupg "home" directory:
27#
28
29inherit sanity
30
31IPK_SIGN_PACKAGES = '1'
32IPK_GPG_BACKEND ?= 'local'
33IPK_GPG_SIGNATURE_TYPE ?= 'ASC'
34
35python () {
36 # Check configuration
37 for var in ('IPK_GPG_NAME', 'IPK_GPG_PASSPHRASE_FILE'):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038 if not d.getVar(var):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050039 raise_sanity_error("You need to define %s in the config" % var, d)
40
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041 sigtype = d.getVar("IPK_GPG_SIGNATURE_TYPE")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050042 if sigtype.upper() != "ASC" and sigtype.upper() != "BIN":
43 raise_sanity_error("Bad value for IPK_GPG_SIGNATURE_TYPE (%s), use either ASC or BIN" % sigtype)
44}
45
46def sign_ipk(d, ipk_to_sign):
47 from oe.gpg_sign import get_signer
48
49 bb.debug(1, 'Signing ipk: %s' % ipk_to_sign)
50
Brad Bishop6e60e8b2018-02-01 10:27:11 -050051 signer = get_signer(d, d.getVar('IPK_GPG_BACKEND'))
52 sig_type = d.getVar('IPK_GPG_SIGNATURE_TYPE')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050053 is_ascii_sig = (sig_type.upper() != "BIN")
54
55 signer.detach_sign(ipk_to_sign,
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056 d.getVar('IPK_GPG_NAME'),
57 d.getVar('IPK_GPG_PASSPHRASE_FILE'),
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050058 armor=is_ascii_sig)