import os import infra.basetest class TestLibGpgme(infra.basetest.BRTest): config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ """ BR2_PACKAGE_LIBGPGME=y BR2_TARGET_ROOTFS_CPIO=y # BR2_TARGET_ROOTFS_TAR is not set """ def test_run(self): cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") self.emulator.boot(arch="armv5", kernel="builtin", options=["-initrd", cpio_file]) self.emulator.login() # We check the binary program can execute. self.assertRunOk("gpgme-tool --version") # Some common data for all the tests. plain_data = "Hello Buildroot!" gpg_userid = "br-test@buildroot" plain_file = "reference-plain.txt" enc_file = "encrypted.dat" dec_file = "decrypted.txt" # We did not create a gpg key yet. We should not be able to # list our key. gpgme_listkey = f"echo LISTKEYS | gpgme-tool | grep '{gpg_userid}'" _, exit_code = self.emulator.run(gpgme_listkey) self.assertNotEqual(exit_code, 0) # We now create our gpg key. cmd = "gpg --batch --passphrase ''" cmd += f" --quick-generate-key {gpg_userid} default default" self.assertRunOk(cmd) # We should now see our key in the list. self.assertRunOk(gpgme_listkey) # We generate a plain text data file. cmd = f"echo '{plain_data}' > {plain_file}" self.assertRunOk(cmd) # We encrypt the plain text file using gpgme-tool commands. gpgme_enc_cmds = [ "RESET", f"INPUT FILE={plain_file}", f"OUTPUT FILE={enc_file}", f"RECIPIENT {gpg_userid}", "ENCRYPT", "BYE" ] cmd = "gpgme-tool <