Skip to content

Commit

Permalink
Add rpmkeys --export
Browse files Browse the repository at this point in the history
Just writes the keys out to stdout in an ASCII armored format.

Resolves: rpm-software-management#3366
  • Loading branch information
ffesti authored and pmatilai committed Oct 16, 2024
1 parent b02d648 commit d376e45
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/man/rpmkeys.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ The general forms of rpm digital signature commands are

**rpmkeys** **\--list** \[*KEYFINGERPRINT \...*\]

**rpmkeys** **\--export** \[*KEYFINGERPRINT \...*\]

**rpmkeys** **\--import** *PUBKEY \...*

**rpmkeys** **\--delete** *KEYHASH \...*
Expand Down Expand Up @@ -53,6 +55,10 @@ querying. Here\'s information about the Red Hat GPG/DSA key:
Finally, public keys can be erased after importing just like packages.
Here\'s how to remove the Red Hat GPG/DSA key:

**rpmkeys** **\--export**

Write the keys in an armor wrapped text format to standard out.

**rpmkeys** **\--delete db42a60e**

Or alternatively:
Expand Down
147 changes: 147 additions & 0 deletions tests/rpmdb.at
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,117 @@ b6542f92f30650c36b6f41bcb3a771bfeb04e625 Alice <[email protected]> public key
],
[])

RPMTEST_CHECK([
runroot rpmkeys --export
],
[0],
[-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBFjmORgBCAC7TMEk6wnjSs8Dr4yqSScWdU2pjcqrkTxuzdWvowcIUPZI0w/g
HkRqGd4apjvY2V15kjL10gk3QhFP3pZ/9p7zh8o8NHX7aGdSGDK7NOq1eFaErPRY
91LW9RiZ0lbOjXEzIL0KHxUiTQEmdXJT43DJMFPyW9fkCWg0OltiX618FUdWWfI8
eySdLur1utnqBvdEbCUvWK2RX3vQZQdvEBODnNk2pxqTyV0w6VPQ96W++lF/5Aas
7rUv3HIyIXxIggc8FRrnH+y9XvvHDonhTIlGnYZN4ubm9i4y3gOkrZlGTrEw7elQ
1QeMyG2QQEb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VDNPO4DhJdkEX5MPF6nuC03lJI
SWwylag9pWowzEee85erULWZWy3OQR+042+pSJ68e79VY2uXHuq7iRiwJ3k9GU2c
CieyDGAe3RB9sUUIn4i1U4p6na3700ZiG/sAgAk9T+s+c/IX+HAvV3DSLxsjnwOY
Fz+p5F6okRH/pMB2Y6XDsejcoQFKiXjBhdGR9c6vRod1L0aXNoIJxek1Ir8vaB81
3cgCJ4+NvdZlvQAGBzEyyUI4iVR9yxyFNB4P+Rt7qKnI+w0u5CROmBvXL7OXHQru
BlgjNTm30U4AGjWmvl24U6a1o8/m
=Qf3c
-----END PGP PUBLIC KEY BLOCK-----
],
[])

RPMTEST_CHECK([
runroot rpmkeys --list 771b18d3d7baa28734333c424344591e1964c5fc
],
Expand All @@ -184,6 +295,42 @@ runroot rpmkeys --list 4344591e1964c5fc
],
[])

RPMTEST_CHECK([
runroot rpmkeys --export 4344591e1964c5fc
],
[0],
[-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBFjmORgBCAC7TMEk6wnjSs8Dr4yqSScWdU2pjcqrkTxuzdWvowcIUPZI0w/g
HkRqGd4apjvY2V15kjL10gk3QhFP3pZ/9p7zh8o8NHX7aGdSGDK7NOq1eFaErPRY
91LW9RiZ0lbOjXEzIL0KHxUiTQEmdXJT43DJMFPyW9fkCWg0OltiX618FUdWWfI8
eySdLur1utnqBvdEbCUvWK2RX3vQZQdvEBODnNk2pxqTyV0w6VPQ96W++lF/5Aas
7rUv3HIyIXxIggc8FRrnH+y9XvvHDonhTIlGnYZN4ubm9i4y3gOkrZlGTrEw7elQ
1QeMyG2QQEbze8YjpTm4iLABCBrRfPRaQpwrABEBAAG0IXJwbS5vcmcgUlNBIHRl
c3RrZXkgPHJzYUBycG0ub3JnPokBNwQTAQgAIQUCWOY5GAIbAwULCQgHAgYVCAkK
CwIEFgIDAQIeAQIXgAAKCRBDRFkeGWTF/MxxCACnjqFL+MmPh9W9JQKT2DcLbBzf
Cqo6wcEBoCOcwgRSk8dSikhARo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UBLIC KEY BLOCK-----
],
[])


RPMTEST_CHECK([
runroot rpmkeys --list XXX
Expand Down
18 changes: 17 additions & 1 deletion tools/rpmkeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum modes {
MODE_IMPORTKEY = (1 << 1),
MODE_DELKEY = (1 << 2),
MODE_LISTKEY = (1 << 3),
MODE_EXPORTKEY = (1 << 4),
};

static int mode = 0;
Expand All @@ -24,6 +25,8 @@ static struct poptOption keyOptsTable[] = {
N_("verify package signature(s)"), NULL },
{ "import", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_IMPORTKEY,
N_("import an armored public key"), NULL },
{ "export", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_EXPORTKEY,
N_("export an public key"), NULL },
{ "test", '\0', POPT_ARG_NONE, &test, 0,
N_("don't import, but tell if it would work or not"), NULL },
{ "delete", '\0', (POPT_ARG_VAL|POPT_ARGFLAG_OR), &mode, MODE_DELKEY,
Expand Down Expand Up @@ -123,6 +126,14 @@ static int deleteKey(rpmPubkey key, void * data)
return 0;
}

static int exportKey(rpmPubkey key, void * data)
{
char * armored = rpmPubkeyArmorWrap(key);
rpmlog(RPMLOG_NOTICE, "%s", armored);
free(armored);
return 0;
}

int main(int argc, char *argv[])
{
int ec = EXIT_FAILURE;
Expand All @@ -139,7 +150,7 @@ int main(int argc, char *argv[])

args = (ARGV_const_t) poptGetArgs(optCon);

if (mode != MODE_LISTKEY && args == NULL)
if (args == NULL && mode != MODE_LISTKEY && mode != MODE_EXPORTKEY)
argerror(_("no arguments given"));

ts = rpmtsCreate();
Expand All @@ -154,6 +165,11 @@ int main(int argc, char *argv[])
rpmtsSetFlags(ts, (rpmtsFlags(ts)|RPMTRANS_FLAG_TEST));
ec = rpmcliImportPubkeys(ts, args);
break;
case MODE_EXPORTKEY:
{
ec = matchingKeys(ts, args, exportKey);
break;
}
case MODE_DELKEY:
{
rpmtxn txn = rpmtxnBegin(ts, RPMTXN_WRITE);
Expand Down

0 comments on commit d376e45

Please sign in to comment.