@@ -16,13 +16,32 @@ from contextlib import contextmanager
from oeqa.utils.ftools import write_file
+def detach_sign_worker(args):
+ import bb.data
+ import oe.gpg_sign
+
+ gpg_bin, gpg_path, tmpdir, path, serialize = args
+ d = bb.data.init()
+ d.setVar('GPG_BIN', gpg_bin)
+ d.setVar('GPG_PATH', gpg_path)
+ d.setVar('TMPDIR', tmpdir)
+ if serialize is not None:
+ d.setVar('GPG_SIGN_SERIALIZE', serialize)
+ try:
+ signer = oe.gpg_sign.get_signer(d, 'local')
+ signer.detach_sign(path, 'testuser', None, 'test123', armor=False)
+ except Exception as e:
+ return '%s: %s' % (path, repr(e))
+ return None
+
+
class Signing(OESelftestTestCase):
gpg_dir = ""
pub_key_path = ""
secret_key_path = ""
- def setup_gpg(self):
+ def setup_gpg(self, agent_conf="auto-expand-secmem\n"):
bitbake('gnupg-native -c addto_recipe_sysroot')
self.gpg_dir = tempfile.mkdtemp(prefix="oeqa-signing-")
@@ -34,7 +53,7 @@ class Signing(OESelftestTestCase):
nsysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "gnupg-native")
with open(os.path.join(self.gpg_dir, "gpg-agent.conf"), "w") as f:
- f.write("auto-expand-secmem\n")
+ f.write(agent_conf)
runCmd('gpg --batch --homedir %s --import %s %s' % (self.gpg_dir, self.pub_key_path, self.secret_key_path), native_sysroot=nsysroot)
return nsysroot
@@ -176,6 +195,81 @@ class Signing(OESelftestTestCase):
# gpg: Good signature from "testuser (nocomment) <testuser@email.com>"
self.assertIn('gpg: Good signature from', ret.output, 'Package signed incorrectly.')
+ def test_signing_parallel_existing_agent(self):
+ """
+ Summary: Test parallel signing with an already running gpg-agent
+ Expected: All signatures are created even though the running
+ gpg-agent was started without auto-expand-secmem
+ Product: oe-core
+ """
+ import multiprocessing
+
+ # No auto-expand-secmem; disable-scdaemon makes the failure reproducible.
+ # (Test written with AI assistance: Kiro)
+ nsysroot = self.setup_gpg(agent_conf="disable-scdaemon\n")
+ gpg_bindir = os.path.join(nsysroot, 'usr', 'bin')
+ self.add_command_to_tearDown('%s/gpgconf --homedir %s --kill gpg-agent' % (gpg_bindir, self.gpg_dir))
+ ret = runCmd('gpg-connect-agent --homedir %s --no-autostart "GETINFO pid" /bye' % self.gpg_dir, native_sysroot=nsysroot)
+ self.assertRegex(ret.output, r'(?m)^D \d+$', 'No gpg-agent running after key import')
+
+ datadir = tempfile.mkdtemp(prefix="oeqa-signing-data-")
+ self.track_for_cleanup(datadir)
+ files = []
+ for i in range(64):
+ path = os.path.join(datadir, 'file%d' % i)
+ with open(path, 'wb') as f:
+ f.write(os.urandom(4096))
+ files.append(path)
+
+ gpg_bin = os.path.join(gpg_bindir, 'gpg')
+ tmpdir = get_bb_var('TMPDIR')
+ with multiprocessing.get_context('fork').Pool(32) as pool:
+ errors = pool.map(detach_sign_worker, [(gpg_bin, self.gpg_dir, tmpdir, f, None) for f in files])
+ errors = [e for e in errors if e]
+ self.assertEqual(errors, [], '%d of %d parallel signatures failed' % (len(errors), len(files)))
+
+ for f in files:
+ runCmd('gpg --homedir %s --verify %s.sig %s' % (self.gpg_dir, f, f), native_sysroot=nsysroot)
+
+ def test_signing_serialize_option(self):
+ """
+ Summary: Test that GPG_SIGN_SERIALIZE controls the signing lock
+ Expected: With "0" signing completes while the lock is held; by
+ default signing waits until the lock is released
+ Product: oe-core
+ """
+ import multiprocessing
+
+ nsysroot = self.setup_gpg()
+ gpg_bindir = os.path.join(nsysroot, 'usr', 'bin')
+ self.add_command_to_tearDown('%s/gpgconf --homedir %s --kill gpg-agent' % (gpg_bindir, self.gpg_dir))
+ gpg_bin = os.path.join(gpg_bindir, 'gpg')
+
+ tmpdir = tempfile.mkdtemp(prefix="oeqa-signing-tmpdir-")
+ self.track_for_cleanup(tmpdir)
+ args = {}
+ for serialize in ("0", None):
+ path = os.path.join(tmpdir, 'file-%s' % serialize)
+ with open(path, 'wb') as f:
+ f.write(os.urandom(4096))
+ args[serialize] = ((gpg_bin, self.gpg_dir, tmpdir, path, serialize),)
+
+ # Fork the workers before taking the lock so they don't inherit it
+ with multiprocessing.get_context('fork').Pool(2) as pool:
+ lock = bb.utils.lockfile(os.path.join(tmpdir, 'gpg-sign.lock'))
+ try:
+ optout = pool.apply_async(detach_sign_worker, args["0"])
+ optout.wait(timeout=60)
+ self.assertTrue(optout.ready(), 'Signing with GPG_SIGN_SERIALIZE = "0" waited for the lock')
+ self.assertIsNone(optout.get(), 'Signing with GPG_SIGN_SERIALIZE = "0" failed')
+ default = pool.apply_async(detach_sign_worker, args[None])
+ default.wait(timeout=10)
+ self.assertFalse(default.ready(), 'Default signing did not wait for the lock')
+ finally:
+ bb.utils.unlockfile(lock)
+ default.wait(timeout=60)
+ self.assertTrue(default.ready(), 'Default signing did not finish after the lock was released')
+ self.assertIsNone(default.get(), 'Default signing failed after the lock was released')
class LockedSignatures(OESelftestTestCase):
The existing tests enable auto-expand-secmem, so they can't catch gpg-agent running out of secure memory. Sign 64 files in parallel against an agent started without it; 44 failed before the previous commit. Also check that signing waits for a held lock by default but not with GPG_SIGN_SERIALIZE = "0". [YOCTO #16480] AI-Generated: Uses Kiro (claude-opus-5.5) Signed-off-by: Adarsh Jagadish Kamini <adarsh.jagadish.kamini@est.tech> --- meta/lib/oeqa/selftest/cases/signing.py | 98 ++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-)