Commit Graph

351 Commits

Author SHA1 Message Date
Panu Matilainen 8849e0ecf7 Eliminate now unused rpmNewSignature() and rpmFreeSignature()
These have been exposed in the ABI all along but in public headers
maybe never, or at least so long ago it just doesn't matter.
2016-10-24 11:36:14 +03:00
Panu Matilainen 58711eb636 Eliminate last uses of rpmNewSignature() and rpmFreeSignature()
These are nothing but wrappers for headerNew() and headerFree(),
lets call things by their own names shall we?
2016-10-24 11:34:50 +03:00
Panu Matilainen 0cc5ee83f1 Bury the last remains of non-header signatures into lead
Header signatures were the new hot almost exactly twenty years ago, we
haven't supported anything else in a very, very, very, very very long time.
Drop the useless argument to rpmReadSignature() and bury the last remaining
related constant into rpmlead.c which is the only place that "needs" it.
No functional changes.
2016-10-24 08:41:32 +03:00
Panu Matilainen 441a0998fc Require exact match on header vs region sizes when reading package files
In rpm V4 packages both the signature and mail header consist of one
contiguous immutable region when read from package files and any
disparities in index or data size means malformed package.

Once the signature header is merged into the main header this is
no longer true of course and installation adds further tags, so for
headers from other sources (such as rpmdb), tags outside the immutable
region (known as "dribbles" in rpm lore) must be allowed, and eg
headerCheck() cannot require exact match.
2016-10-21 17:50:32 +03:00
Panu Matilainen d26dff0632 Eliminate unnecessary entry argument to headerVerifyRegion()
No data is passed to or from via it, and even within headerVerifyRegion()
only the info member is ever used. Pfft.
2016-10-21 13:58:06 +03:00
Panu Matilainen 870aede417 The data returned in headerVerifyInfo() iv is only used for error reporting
Use a scope local variable to make this clear(er).
2016-10-21 13:40:02 +03:00
Florian Festi 673bd8a066 Compare Checksums case insensitive
Resolves: trac #905
2016-04-07 09:51:25 +02:00
fin@linux.vnet.ibm.com ca6389b617 Export generateSignature
This patch exports generateSignature under the new name rpmGenerateSignature
so that includeFileSignatures can call it.

[lkardos@redhat.com: fixed indentation]
Signed-off-by: Lubos Kardos <lkardos@redhat.com>
2015-08-12 13:33:47 +02:00
Panu Matilainen ff8547a0cf Start consolidating our tribal knowledge on signature tag data
- New internal API to "parse" signature tags, performing various
  sanity checks, classifying the type (digest, actual signature etc)
  and gathering other relevant info.
- Unused as of this commit...
2014-10-24 10:26:08 +03:00
Panu Matilainen 81885737d1 Unify our internal digest verification functions
- There's nothing md5/sha1-specific in either of these functions,
  the only real difference is whether we're dealing with ascii or
  binary digest.
- Always operate in ascii mode: we need to convert the digest to ascii
  for the return message string anyway, so this only makes things much
  simpler, and this way we wont crash and burn even if the digest tag
  were of mismatching type as rpmtdFormat() can convert anything into
  a string.
2014-10-16 12:49:51 +03:00
Lubos Kardos 0ab486b8e1 Fixed double dealocation of ei pointer (RhBug:1133885) 2014-08-26 15:00:07 +02:00
Lubos Kardos 17ad1fb27b Removed now unused internal helper functions.
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2014-05-21 10:46:26 +03:00
Panu Matilainen 85a5b00430 Use headerVerifyRegion() for signature headers too. Die copy-slop, die!
- This isn't supposed to change any behavior, so if something changes
  its likely a bug...
2014-02-03 12:02:07 +02:00
Panu Matilainen 7c703e1269 Drop signature header region trailer tag quirk
- AFAICT rpm never actually created signature headers with HEADER_IMAGE
  as region trailer tag, except when trying to sign V3 packages with
  old rpm 4.x versions (newer ones refuse to do so). This region trailer
  quirk doesn't actually make such packages work any better, they just
  fail in a different way (such as RhBug:517818)
2014-02-03 11:59:38 +02:00
Panu Matilainen 9c4bf14e29 Move newlines from error message strings to rpmlog() calls
- While the newlines are needed in rpm cli usage, other users
  might have other needs
2014-02-01 17:24:37 +02:00
Florian Festi 116a6f7105 Move RPMSIGTAG_SIZE vs PMSIGTAG_LONGSIZE detection to rpmGenDigest()
Fixes problem with rpmSign() only using RPMSIGTAG_SIZE
Fixes rh#1012595 for now as we are only moving to PMSIGTAG_LONGSIZE when needed
2013-09-30 16:08:57 +02:00
Panu Matilainen 5f857c0c09 Clarify the zero-padding "buffer" use in rpmWriteSignature()
- This is not a buffer where anything gets written to, its only
  used as a source for writing zero-padding into signature headers.
  Rename to "zeros" and make it const which it is.
2013-02-19 18:13:23 +02:00
Panu Matilainen cbd6ef58bb Handle partial reads and errors in package IO (RhBug:802839, RhBug:580974)
- There are no guarantees Fread() will return all of the requested size:
  it can return partial data eg on signals and pipe descriptors. Introduce
  a helper function to handle this centrally for all package read IO,
  effectively reintroducing timedRead() but without the caveats:
  timedRead() did not work on compressed streams, did not handle
  eg EINTR correctly and while really being an internal helper,
  was exported in the API.
2012-10-30 11:36:56 +02:00
Panu Matilainen 6fc6b45bf9 Validate negated offsets too in headerVerifyInfo()
- Undo the ancient broken fix for RhBug:71996 from commit
  9e06e3b8ca76ae55eaf2c4e37ba9cac729789014: instead of disabling
  the check, pass in the correct upper range which is entirely
  different from everything else for the region trailer tag.
- Fixes CVE-2012-0815
2012-04-03 15:47:44 +03:00
Panu Matilainen f239982519 Differentiate between non-existent and invalid region tag
- Non-existent region tag is very different from existing but invalid
  one - the former is not an error but the latter one is, and needs
  to be handled as such. Previously an invalid region tag would cause
  us to treat it like rpm v3 package on entry, skipping all the region
  sanity checks and then crashing and burning later on when the immutable
  tag is fetched.
- Refer to REGION_TAG_TYPE instead of RPM_BIN_TYPE wrt the expected
  type of region tag for consistency and clarity, they are the same
  exact thing though.
- Should unify these damn copy-slop check one of these days, sigh...
  For now, settling for the easily backportable approach.
- Fixes the other half of CVE-2012-0060
2012-04-03 15:46:42 +03:00
Panu Matilainen e83aa4f638 Update internal callers to use headerImport() instead of headerLoad()
- Pass size where possible, this is a bit redundant in places since
  its already checked in various places but wont hurt anyway.
2011-11-30 11:00:40 +02:00
Panu Matilainen 4537c8c8bc Log an error on attempt to sign V3 packages (RhBug:517818 & others)
- We haven't been able to sign V3 packages in the last decade or so,
  might as well spit out an error on it instead of silently failing.
2011-11-24 11:16:19 +02:00
Panu Matilainen bbf2f63676 Switch to using rpmKeyringVerifySig() internally
- Change rpmVerifySignature() to take just the signature parameters
  instead of the whole dig (this is an internal API so we're free
  to mess with it) from which it only needed the signature params.
- The internal low-level verifySignature() is thus reduced to
  to a call to rpmKeyringVerifySig() and spitting some silly
  strings to msg.
- With this, keyring can now use and reuse the its internally stored
  pgp key parameters instead of having to parse the same PGP packets
  over and over. As a result, signature checking is faster now. Not
  dramatically so but measurably nevertheless.
2011-11-09 13:12:01 +02:00
Panu Matilainen 9e9761caa8 Don't make assumptions about how pgpDig allocates things
- Only call pgpDigGetParams() on the public key once we've at least
  tried to fetch it via rpmKeyringLookup(). This way we dont assume
  things about how pgpDig internal allocation is done - currently
  it does return what's essentially a static pointer into pgpDig,
  but this is not a reasonable assumption for an opaque type.
  No functional changes.
2011-11-09 09:23:26 +02:00
Panu Matilainen cde47f5945 Use pgpDigParamsAlgo() throughout the codebase
- Tedious but straightforward conversion to use the API instead
  of going to the struct directly.
- Remove digest.h includes where no longer necessary
2011-11-07 14:47:03 +02:00
Panu Matilainen 0afd3343f0 Eliminate direct pgpDig accesses from lowlevel signature code 2011-11-07 12:54:30 +02:00
Panu Matilainen dc3f313b66 Add another pgpVerify variant which takes key and sig as separate args
- pgpVerifySig() is now just a dumb wrapper around pgpVerifySignature()
  which does the real work.
- Update the sole caller to use the new interface instead, deprecate
  the old dig interface.
- First steps towards getting rig of pgpDig which always was a
  strange creature and now is nothing but a nuisance and obfuscation.
  Yes keys and signatures walk hand in hand much of the time, but
  they come from different sources and want to be handled as
  separate data really.
2011-11-07 08:05:34 +02:00
Panu Matilainen 85b90e4176 Add a couple of missing includes, masked by NSS headers 2011-11-04 16:28:13 +02:00
Panu Matilainen bfcc5bf3b9 Verify the entire region trailer, not just its offset, is within data area
- Offset being within the data area doesn't help if the actual data doesn't
  fit. Since the trailer size is well known, we can just as easily
  make the check accurate to prevent reading beyond end of data in case
  the offset is subtly wrong.
- In headerLoad(), region offset of zero doesn't need sanity checking,
  only validate if its something else and do so accurately there too.
2011-10-20 10:52:58 +03:00
Panu Matilainen a2e5918027 Eliminate redundant NULL-checks in lower level sigchecking functions
- sigtd->data and dig checking (where needed) is done at
  rpmVerifySignature() level, dont bother double-checking
- Hash context is dup'ed, which CAN fail, so while we dont need
  to check the argument for non-null, the dup result needs to
  be checked for digests. For actual signatures the dup happens
  elsewhere, we dont need to check the argument for non-null here.
2011-10-06 12:56:13 +03:00
Panu Matilainen 9718ede792 Sanitize rpmVerifySignature() a bit
- Hash context is required for everything, require non-NULL ctx
  in rpmVerifySignature() already
- pgpDig is only relevant for true signature, digest checking doesn't
  need it - dont require dummy dig to be passed for digests.
- Treat unknown signatures as a case of bad parameters: we're the
  only caller of rpmVerifySignature() so it'd be us screwing up if
  we ask for unknown signature to be verified.
- Treat bad parameters as a hard failure instead of "not found",
  bad parameters mean we cannot verify the signature which really
  equals FAIL.
2011-10-06 12:49:18 +03:00
Panu Matilainen c07efb9fec Sanity check signatures even if we dont have a key
- Fixes a regression originating all the way back from commit
  c7fc09d585 (ie rpm >= 4.8.0)
  where a package with a bogus signature can slip through undetected
  if we dont have a key for it.
- This additional sanity check on the signature prevents is enough
  to prevent the fuzzed package in RhBug:721225 from crashing us
  by stopping the bad package at the front door. That we don't have
  proper tag data validation is another, much wider issue...
2011-07-14 14:05:32 +03:00
Panu Matilainen e7b55f61a9 Eliminate dead NULL-assignments at scope-end in librpm, part II
- Remove NULL-assignments of local variables at the end of scope
  in package+signature manipulation code
2011-05-28 22:24:37 +03:00
Panu Matilainen 44ce440509 Remove redundant strlen()'s on sha1 digest verification
- string comparison notices different length anyway, avoid going
  through the same data twice
2011-04-28 15:24:09 +03:00
Jindrich Novy 3ab3a931b4 Avoid timedRead() usage
- it is to be removed in the next soname bump
2011-03-23 11:25:06 +01:00
Panu Matilainen 65358a072f Replace remaing rpmSigTag uses with rpmTagVal
- Some of these might actually be "correct" but about one case from
  librpmbuild cascades down here ... just not worth the trouble to
  keep the as rpmSigTags.
2010-10-22 13:23:09 +03:00
Panu Matilainen 7d29077921 And now sighdrPut() can be buried back into signature.c 2010-09-29 16:15:04 +03:00
Panu Matilainen bf5da95131 Clean up makeHDRDigest() a bit
- No need to separately free this stuff (at least anymore), it
  gets done on exit anyway.
2010-09-29 13:10:49 +03:00
Panu Matilainen 23a9d64ea4 Lift the signature generation in all its g(l)ory to rpmgensig.c
- signature.c is now entirely free of all actual signing activities,
  which requires stuff that like gpg that nothing else needs.
2010-09-29 11:27:26 +03:00
Panu Matilainen 9c254cd225 Move sighdrPut() to inline function in signature.h
- Avoids having to expose this in the ABI in the next steps
2010-09-29 11:21:07 +03:00
Panu Matilainen 8422a94ca9 Split signature and digest generation to separate functions
- Similar in spirit to commit 825691afb2,
  these have fairly little in common really.
- Change the function names to force breakage on users (these are exported
  in ABI but not in public headers so "users" are internal uses in
  practise): the automatically generated bits in signature header are
  not signatures, but digests (even size is a checksum of sorts) ...
  and fix the couple of internal uses.
2010-09-29 10:55:38 +03:00
Panu Matilainen 825691afb2 Split internal header signature and digest generation to separate functions
- These have fairly little in common in reality: one is always
  automatically created on package generation, the other is optional
  extra step requiring passphrases and all sorts of other things.
- The switch-cases are now fairly hysterical but leaving them for
  later spring-clean to keep changes minimal for this step.
- No functional changes (supposedly ;)
2010-09-29 10:48:19 +03:00
Panu Matilainen cc5959a57d Whoops, wrong enum type used for pubkey algorithm
- dumb thinko/typo from commit 0e143cfe9f
2010-09-28 22:13:25 +03:00
Panu Matilainen e293130613 Decide header sigtag based on what was actually written
- makeGPGSignature() figures the signature type by parsing the
  created signature, use that instead of the rather bogus tag
  based on %_signature macro value passed from the cli level.
2010-09-28 14:55:29 +03:00
Panu Matilainen 1b347d4261 Put the rpmLookupSignature() and rpmGetPassPhrase() out of their misery 2010-09-03 15:12:17 +03:00
Panu Matilainen 0e143cfe9f Add some sanity checks for generated signatures (related to RhBug:608599)
- GPG supports all sorts of algorithms NSS doesn't, do some basic tests
  to verify the generated signature is something we can actually use.
2010-06-29 10:47:18 +03:00
Panu Matilainen dd58384ede Move <errno.h> include out of system.h to the places that need it 2010-01-05 15:25:31 +02:00
Panu Matilainen 2c6120755c Unconditionally include <sys/wait.h> where needed
- no point conditionalizing what we cant live without
2010-01-05 12:35:54 +02:00
Panu Matilainen 9f43fee26b Move getpass() portability tweaks out of system.h
- only signature.c needs, no need to pollute system.h
2009-12-23 12:41:38 +02:00
Panu Matilainen 2b41860984 Fix signature password checking result on abnormal conditions (RhBug:496754)
- Execve() failure wasn't returning an error code, causing rpm to
  think the password was ok when we couldn't even try verifying
- Stricter return code checking from the password checking child:
  the password can only be ok if the child exits with WIFEXITED() *and*
  WIFEXITCODE() of 0. Also WIFEXITCODE() should only be called if
  WIFEXITED() returns true.
2009-11-25 16:42:43 +02:00