Commit Graph

1729 Commits

Author SHA1 Message Date
Panu Matilainen b204a9037b Kick out 21 year old commented-out debugging fprintf()'s 2022-05-06 10:14:09 +03:00
Panu Matilainen 66fa46c006 Axe our internal and buggy glob() and fnmatch() copies
glibc 2.2 (or thereabouts) changed glob() and fnmatch() to not return
dangling symlinks as matches, which gravely affects rpmbuild in particular.
Because of this, rpm has carried a bundled copies of glibc 2.1 functions
for close to 22 years now (commit bed2a465fe).
glibc 2.27 in 2018 thankfully finally reverted that particular braindamage,
I think we've carried the compatibility babbage long enough to excuse
ourselves with a little shorter grace period in this case.
Nukes away, add a blurb about the version requirement on glibc
based systems.

This still leaves our internal glob_pattern_p() intact as unlike glob()
itself, that's not portable.

No functional changes as such.
2022-05-04 09:17:35 +03:00
Neal H. Walfield db36ea85aa Add a Sequoia-based OpenPGP backend
This change adds support for using Sequoia as an alternative to the
internal OpenPGP backend.  To use this backend, it is necessary to
have the rpm-sequoia library installed.

https://gitlab.com/sequoia-pgp/rpm-sequoia

Fixes #1978.
2022-04-29 14:36:44 +03:00
Panu Matilainen c1121a5c69 Remove stillborn rpmlog facility definitions
While we're purging obsolete APIs:
I fail to see how any of these would ever be of any relevance within
rpm. RPMLOG_UUCP? Nope. RPMLOG_NEWS? RPMLOG_KERN? Nope...
Unsurprisingly none of this stuff has ever been used.

This frees up the top 28 bits of the log code for things that we may
actually want to use.
2022-04-29 10:20:12 +03:00
Demi Marie Obenour 7f830132fe Fix OpenPGP key ID parsing regression
This fixes a regression in 598a771d8b,
which caused RPM to parse key flags from a hashed key ID subpacket.  As
a result, RPM would wrongly reject a signature that had both key ID and
key usage flags subpackets in the hashed section.
2022-04-22 10:43:52 +03:00
Neal H. Walfield c3e988287d Move digest functionality to the internal OpenPGP implementation
rpmio/digest.h contains definitions that are only used by the interal
OpenPGP parser, and are not required by the future Sequoia backend.
Move those definitions into rpmio/rpmpgp_internal.h.

Fixes #2006.
2022-04-13 10:25:04 +03:00
Panu Matilainen 547acb6696 Rename the internal rpmpgp.h header to rpmpgpval.h for clarity
Commit d8bb57eeab reintroduced
rpmio/rpmpgp.h which is quite confusing when we have a public header by
the same name elsewhere, and doubly more confusing to those of use who
are used to having the public header by the same name in this very
location prior to commit 650ba79f22.

No functional changes.
2022-04-13 10:25:04 +03:00
Demi Marie Obenour 2b48aa7c69 Avoid clobbering existing saved time
The public key parser needs to set PGPDIG_SAVED_TIME, so that future
iterations in pgpDigParams() do not clobber the key’s creation time.

Fixes #2004.
2022-04-13 09:19:43 +03:00
Neal H. Walfield d8bb57eeab Move the internal OpenPGP implementation to its own file.
Split the internal OpenPGP implementation into the bits that are
needed by a new OpenPGP backend like Sequoia, and the bits that are
not needed by another OpenPGP backend.

Move most of the functionality in rpmio/rpmpgp.c into
rpmio/rpmpgp_internal.c.

Leave pgpValStr, and pgpIdentItem, which are used for printing and
needn't be reimplemented by other backends, and pgpReadPkts, which is
just a thin wrapper around pgpParsePkts, and which uses an internal
rpm function that a new backend shouldn't have to worry about
emulating or even calling.

Move the symbol tables, which are used by pgpValStr, pgpIdentItem, and
the internal OpenPGP implementation to rpmio/rpmpgp.h.  These are
common to all implementations.

Fixes #2000.
2022-04-12 09:48:53 +03:00
Panu Matilainen eaf359f35c Merge Lua posix extension into librpmio
Once upon a time there may have been a point to having the extension in a
separate convenience library, but nowdays with Lua being mandatory there's
not a whole lot of point in complicating the build with all this fubar.
As a nice little bonus, we can now hide luaopen_posix() symbol.
2022-04-08 14:11:44 +03:00
Panu Matilainen ab01b5eacf Remove most of rpmsq signal machinery, no longer needed 2022-04-08 12:00:11 +03:00
Panu Matilainen 8cbf22013f And another one bites the dust, pgpHexStr() isn't needed anymore 2022-04-08 12:00:11 +03:00
Panu Matilainen 87c4eee816 Axe pgpDig and related APIs
These haven't been used by rpm in years but have been left to linger,
perhaps for too long. Bye now.
2022-04-08 12:00:11 +03:00
Panu Matilainen ae7ef1a433 Remove deprecated rpmKeyring APIs
These have been on their way out for more than ten years now, since
commit 9e58316b0f. Time to let go.
2022-04-08 12:00:11 +03:00
Panu Matilainen 4f34fa9623 Only print rpmio descriptor statistics when io debugging is enabled
The stats aren't particularly interesting except for development
and debugging purposes. Rather than change all the debug fprintf()'s
in rpmio to rpmlog(), just change the stats to only get printed
when --rpmiodebug is active like the rest of the io debug code.

Fixes: #1987
2022-04-06 12:09:17 +03:00
Panu Matilainen 10804d32d9 Use rpmuncompress to handle %{uncompress:...}
This means that finally there's just one place that when adding support
for new compress formats, there's in theory there's just one place to
update. Reality is a little more complicated, but hey...

Adjust tests a bit, and rather test functionality than command output
because those reflect command paths which we can't easily adjust now.
2022-04-04 10:04:25 +03:00
Neal H. Walfield b113a9d729 Make pgpDigParams opaque
- Add accessor functions pgpDigParamsSignID, pgpDigParamsUserID,
    pgpDigParamsVersion, and pgpDigParamsTime.

  - Move the definition of `pgpDigParams_s` from `rpmio/digest.h` to
    `rpmio/rpmpgp.c`.

  - Change code to use the accessor functions.

  - Fixes #1979.
2022-03-31 15:48:18 +03:00
Demi Marie Obenour 8948ec79f6 Avoid unneded MPI reparsing
Modify pgpPrtSig() to ignore the MPIs of a signature if its `tag`
parameter is 0.  The only caller that sets `tag` to 0 is
pgpPrtParamSubkeys() (via parseSubkeySig()), which does not actually
check any cryptographic signatures.  The subkey binding signature has
been checked earlier in pgpPrtParams().
2022-03-31 09:52:50 +03:00
Demi Marie Obenour a9cca032a2 Ignore subkeys that cannot be used for signing
This ensures that a signature is only accepted if the subkey that made
it is actually allowed to sign.  Test 265 verifies that RPM ignores
subkeys that cannot sign.

A subkey is considered to be capable of signing if, and only if, its
subkey binding signature has a hashed key flags subpacket that contains
the flag 0x02.  RFC4880 requires that the subkey binding signature be
v4, which this requirement enforces implicitly.  RFC4880 also requires
that primary key binding signatures be present and checked.  This is not
yet implemented, but may be implemented later.

Fixes #1911.
2022-03-31 09:52:50 +03:00
Demi Marie Obenour 598a771d8b Parse key usage flags
RPM needs to know if a subkey can be used for signing.  Signatures made
by a subkey that cannot be used for signing are invalid.  Add a
key_flags member to pgpDigParams_s to store this information, and a
PGPDIG_SIG_HAS_KEY_FLAGS flag to indicate that it is valid.  The key
usage flags are reset for every signature.  Key usage flags in the
unhashed section are ignored.  If there is more than one key usage flags
subpacket in the hashed section, the signature is rejected.
2022-03-31 09:52:50 +03:00
Demi Marie Obenour 55849d2d6e Add a hashed flag to pgpPrtSubtype()
This is needed for key usage flags parsing, as key usage flags outside
of the hashed region must be ignored.  For now, just use it to
unconditionally ignore unhashed creation time subpackets.
2022-03-31 09:52:50 +03:00
Demi Marie Obenour 0a91d1f62d Avoid double frees if EVP_PKEY_assign_RSA fails
Previously, the bignums would be left as dangling and double-freed.
2022-03-31 09:44:48 +03:00
Demi Marie Obenour 1ddaeddffa Fix return value checks in OpenSSL code
According to `man 3ssl` the only successful return value for
EVP_PKEY_verify_init() is 1, and EVP_PKEY_CTX_set_rsa_padding() and
EVP_PKEY_CTX_set_signature_md() can both return 0 or a negative number
on failure or any positive number on success.  BN_bn2binpad() returns -1
on error, but 0 (an empty key or signature) is also not valid.
Therefore use != 1 to check the return value of EVP_PKEY_verify_init(),
<= 0 to check the return values of the other three functions mentioned
above.  Also delete a bunch of cruft.
2022-03-31 09:44:48 +03:00
Demi Marie Obenour 31c41707d7 Reject OpenPGP data at or over 64KiB
Such data is probably an attempt to exploit RPM, not do anything useful.
This avoids a whole class of silly integer overflow problems.
Signatures in packages are already limited to less than 64MiB by the
maximum size of the signature header, and this is already a sufficient
limitation.
2022-03-21 13:55:24 +02:00
Demi Marie Obenour 7e7266c9af Require creation time to be unique and hashed
According to RFC 4880 §5.2.3.4 the signature creation time MUST be a
hashed subpacket.  Enforce this requirement in RPM.  Also set the saved
flags to PGPDIG_SAVED_TIME | PGPDIG_SAVED_ID |
PGPDIG_SAVED_CREATION_TIME for v3 signatures, and do not overwrite an
already saved key ID with one taken from a v3 signature.
2022-03-18 13:00:29 +02:00
Demi Marie Obenour 10ac962bf2 Fix memory leak in pgpPrtParams()
Found by leak sanitizer on a fuzzed test case.
2022-03-18 12:49:08 +02:00
Panu Matilainen 962ba7a4c1 Drop misleading hardcoded NSS-3 string from import public keys
The crypto backend used during importing has little relevance to
anything, plus we discarded the NSS backend two years ago so it doesn't
have an even theoretical chance of being right...
2022-03-14 11:20:41 +02:00
Panu Matilainen 650ba79f22 Eliminate the strange include pre-build install machinery
Introduced back in 2007 in 5831404601 the
point was to fake up a sane public header structure with minimal
internal disruption, TEMPORARILY. I think 15 years is temporary enough.

The machinery has worked rather well for what it is, but having the
headers appear in multiple locations is weird and confusing to people,
plus this "physical" separation makes it far more clearer what is
a public header and what isn't.
2022-03-10 08:40:07 +02:00
Panu Matilainen 3d97c19c6e Remove leading directories from doxygen notation
These don't represent the exported include structure so they're
probably more harmful than anything else.
2022-03-10 08:40:07 +02:00
Panu Matilainen 2f0f3be64d Use proper addressing for our public headers everywhere 2022-03-10 08:40:07 +02:00
Panu Matilainen f9290999e9 Detach rpm signal queue enablement from database open
The rpm signal queue (rpmsq) was necessary to support clean shutdown
of Berkeley Database on signals, but our current backends do not
need such handholding. A library silently hogging your signals on
function call is antisocial behavior, stop doing that since we no
longer have to.

Since the rpmsq is no longer active in transactions, use sigaction()
instead of rpmsqSetAction() to manipulate SIGPIPE. While at it,
eliminate the use of deprecated signal() which in particular should
not be mixed with sigaction() use.

This is quite a dramatic behavior change to a long-standing behavior
so while everybody hated the signal hogging, this may still cause some
fallout in strange places.

This also makes a whole lot of rpmsq code redundant and unused, leaving
it in place for the time being as a backup if we need to revert
short term, to be flushed in the next soname bump.
2022-03-07 09:34:45 +02:00
Panu Matilainen d44be2cbc1 Rename pgpHexStr() to rpmhex(), but preserve ABI for now
Fixup internal callers to use rpmhex(), deprecate pgpHexStr().
pgpHexStr() should be dropped at next soname bump, whenever that
happens.
2022-02-25 11:08:25 +01:00
Panu Matilainen dcfa7323a0 Move pgpHexStr() out of rpmpgp.h, it has nothing to do with PGP 2022-02-25 11:08:25 +01:00
Panu Matilainen 01d6605d93 Detach rpm's hash algorithm values from PGP hash algorith values
At this point this is quite literally merely a symbolic change,
as values from PGP hash algo are assumed equal to RPM hash algos,
but it's a necessary first step to supporting hashes not included
in RFC-4880.

Fixes: #1899
2022-02-25 11:08:25 +01:00
Panu Matilainen ca822ed6d2 Split off rpmDigest*() APIs from rpmpgp.h to a new rpmcrypto.h header
These APIs never belonged to rpmpgp.h anyway, it was only used for
being the least-worst fit within rpm. As if it was so hard to just
add a new header...
2022-02-25 11:08:25 +01:00
Demi Marie Obenour e32332b8a9 Bail out if a key ID cannot be obtained
If a key ID cannot be obtained, the key is useless.  This also ensures
that pgpPrtKey only needs to handle input that getKeyID has already
validated.
2022-02-09 16:38:50 +01:00
Panu Matilainen 6aec7c673f Add rreallocn() to librpmio public API
rreallocn() is like realloc() but with multiplication protection.
Inspired by glibc's reallocarray() but I dislike that name.

While at it, add xmallocn() as a shortcut to rreallocn(NULL, ...) case.

Based on initial patch by Demi Marie Obenour.
2022-02-09 15:04:55 +01:00
Demi Marie Obenour 1f03aba8b2 Check that the CRC length is correct
Also fix a memory leak in an error path.
2022-02-07 15:55:26 +02:00
Demi Marie Obenour 714e606558 Fix bounds checks in public key parsing
If a public key was too short for the curve ID, the code would
previously perform out-of-bounds pointer arithmetic, which is undefined
behavior in C.  Check that the packet is long enough to contain the
curve ID before bumping `se` past the curve ID.

Furthermore, if a public key is too short to even contain the fixed-size
header, an out-of-bounds pointer would be created, which is also
undefined behavior.  Fix this by returning early if the buffer is too
short.

Finally, return early if the public key algorithm or curve ID is
invalid, rather than relying in processMpis() to fail.  While
processMpis() will error out, bailing out explicitly is much clearer.
2022-01-25 09:38:32 +01:00
Aleš Matěj c624966e13 Add an option for zstd long distance matching compression
The behavior is supposed to match the --long[=#] option of zstd binary.
2022-01-21 14:57:00 +01:00
Aleš Matěj 1fdf660ba5 Replace hardcoded min/max values for zstd compression levels 2022-01-21 14:57:00 +01:00
Michal Domonkos b6dffb6dc5 Fix memory leak in pgpPrtParams()
Make sure selfsig is freed in case we break out of the loop in this
block.

Note that the tests added with the binding validation commit bd36c5d do
not cover this code path so valgrind won't show this.
2022-01-10 13:20:56 +02:00
Panu Matilainen 298bb60a9f Add optional readline history support in rpmlua interactive mode
We don't want readline dependency in librpmio so need to do this the
hard way: add an optional callback through which rpmlua can supply
it's own readline-aware callback function.
2021-12-20 12:19:07 +02:00
Panu Matilainen 523da38e4f Eliminate rpm.next_file() from the permanent Lua API
This screams for a closure, use one. This is not supposed to change
any functionality except, except only make the rpm.next_file() function
available in the context of scriptlets which is the only context it is
meaningful.
2021-12-15 16:57:58 +02:00
Michal Domonkos 7fd7a60ea2 Separate build warnings from error summary
Confusingly, the "RPM build errors" section also includes messages
logged as warnings.  That gives the false impression that they somehow
contributed to the actual build failure and therefore were turned into
errors.

This appears to be a historical artifact; when a message passes through
the logging system and is of the priority RPMLOG_WARNING or higher, we
save it in a global buffer (ctx->recs), which is then simply dumped with
rpmlogPrint() in the error summary.  This was probably good enough when
the summary was introduced (commit f2efc72, year 2000), as there were
almost no warnings generated by RPM at that time, however as they became
more abundant, the summary code was never revisited.

There are 3 ways to fix this discrepancy:

 1) Change the summary's title to "RPM build problems"
 2) Remove the summary altogether
 3) Don't show warnings in it

Options #1 and #2 would be too disruptive.  The error summary needs to
stay as is, for the following reasons:

 - While it usually just repeats the last error, not all errors
   terminate a build right away, so those can get drown in the output
   that follows after.  Examples: "File not found" in rpmInstall(), or
   macro expansion errors (note: we may have these terminate a build in
   the future).

 - It makes it immediately obvious that something went wrong when
   examining build logs, and the title "RPM build errors" undoubtedly
   has become the de-facto text string to search for.

That leaves us with option #3.  To further lessen the disruption, do
keep a summary of warnings, but put them under their own heading, and
only show it on build failures.  That way, we restrict all the extra
verbosity to error time (as it is now) and don't pollute the output of
otherwise good builds.  There may be packages with long-standing
warnings that are not feasible to fix for any reason, and having an
indented block of text resembling "RPM build errors" at the end of every
build would do no good.

Effectively, this commit is just cosmetic - it splits the error summary
into two, without any functional or API changes (apart from two function
additions).

Fixes: #793
2021-12-15 11:53:54 +02:00
Panu Matilainen cd6317ba61 Auto-print returned values from Lua macros
Avoids having to manually "print()" everything, at the cost of requiring
a "return" which is not really less to type but more natural for
programming, and other benefits likely to follow.
2021-12-13 10:56:14 +02:00
Panu Matilainen 0df9abd174 Fixup one missed adjustment to INITSTATE() callers
Guess this is rebase considered harmful: this should've been in
commit de9cc32b98 but in that fork,
rpmluaCallStringFunction() didn't yet exist so it couldn't be
adjusted there, but merging the PR broke the build.
2021-11-26 14:00:47 +02:00
Michael Schroeder b71495c967 Simplify opt,arg setup in lua macros
No need to do select() trickery.
2021-11-26 13:48:47 +02:00
Michael Schroeder 43e89bf74b Reinstantiate print buffer after poping it in lua interactive mode
We pop it to print its contents, but we forgot to push an empty
print buffer afterwards. This makes a difference as a newline
is not automatically added in print statements if a buffer is used.
2021-11-26 13:48:47 +02:00
Michael Schroeder 12c7fe7daa Fix indentation of rpmluaReadline and _rpmluaInteractive
No functual changes
2021-11-26 13:48:47 +02:00