Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Before importing an OpenPGP certificate, lint it #2052

Merged
merged 1 commit into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions include/rpm/rpmpgp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,32 @@ pgpArmor pgpParsePkts(const char *armor, uint8_t ** pkt, size_t * pktlen);
*/
int pgpPubKeyCertLen(const uint8_t *pkts, size_t pktslen, size_t *certlen);

/** \ingroup rpmpgp
* Lints the certificate.
*
* There are four cases:
*
* The packets do not describe a certificate: returns an error and
* sets *explanation to NULL.
*
* The packets describe a certificate and the certificate is
* completely unusable: returns an error and sets *explanation to a
* human readable explanation.
*
* The packets describe a certificate and some components are not
* usable: returns success, and sets *explanation to a human readable
* explanation.
*
* The packets describe a certificate and there are no lints: returns
* success, and sets *explanation to NULL.
*
* @param pkts OpenPGP pointer to a buffer with certificates
* @param pktslen length of the buffer with certificates
* @param[out] explanation An optional lint to display to the user.
* @return RPMRC_OK on success
*/
rpmRC pgpPubKeyLint(const uint8_t *pkts, size_t pktslen, char **explanation);

/** \ingroup rpmpgp
* Wrap a OpenPGP packets in ascii armor for transport.
* @param atype type of armor
Expand Down
15 changes: 15 additions & 0 deletions lib/rpmts.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ rpmRC rpmtsImportPubkey(const rpmts ts, const unsigned char * pkt, size_t pktlen
{
Header h = NULL;
rpmRC rc = RPMRC_FAIL; /* assume failure */
char *lints = NULL;
rpmPubkey pubkey = NULL;
rpmPubkey *subkeys = NULL;
int subkeysCount = 0;
Expand All @@ -615,6 +616,20 @@ rpmRC rpmtsImportPubkey(const rpmts ts, const unsigned char * pkt, size_t pktlen
if (txn == NULL)
return rc;

krc = pgpPubKeyLint(pkt, pktlen, &lints);
if (lints) {
if (krc != RPMRC_OK) {
rpmlog(RPMLOG_ERR, "%s\n", lints);
} else {
rpmlog(RPMLOG_WARNING, "%s\n", lints);
}
free(lints);
}
if (krc != RPMRC_OK) {
rc = krc;
goto exit;
}

/* XXX keyring wont load if sigcheck disabled, force it temporarily */
rpmtsSetVSFlags(ts, (oflags & ~RPMVSF_MASK_NOSIGNATURES));
keyring = rpmtsGetKeyring(ts, 1);
Expand Down
6 changes: 6 additions & 0 deletions rpmio/rpmpgp_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1345,3 +1345,9 @@ char * pgpArmorWrap(int atype, const unsigned char * s, size_t ns)
free(buf);
return val;
}

rpmRC pgpPubKeyLint(const uint8_t *pkts, size_t pktslen, char **explanation)
{
*explanation = NULL;
return RPMRC_OK;
}