summaryrefslogtreecommitdiff
path: root/rpmio/rpmpgp.c
AgeCommit message (Collapse)AuthorFilesLines
2012-03-22Oops, "magic eight" is necessary here afterallPanu Matilainen1-2/+2
- Fix regression from commit 807b402d95702f3f91e9e2bfbd2b5ca8c9964ed9, the array gets passed as a pointer (how else would it work at all), so despite having seemingly correct type, sizeof(keyid) depends on the pointer size. This happens to be 8 on x86_64 and friends but breaks pgp fingerprint calculation on eg i386. - Also return the explicit size from pgpExtractPubkeyFingerprint(), this has been "broken" for much longer but then all callers should really care about is -1 for error.
2011-11-10Doh, somehow managed to miss the warnings from these missing includes :(Panu Matilainen1-0/+1
- Should've been in commit 70f063cb773bedb7d336429d9bc8ed1d4e5d18f4
2011-11-09Make base64 encoding/decoding part of rpmio public APIPanu Matilainen1-5/+5
- Base64 is present in headers and all, it's only reasonable that our API users have access to this functionality without having to link to other libraries. Even if we didn't want to carry the implementation forever in our codebase, we should provide a wrapping for this (much like the other crypto stuff) for the reason stated above. - A bigger issue is that our dirty little (badly hidden) secret was using non-namespaced function names, clashing with at least beecrypt. And we couldn't have made these internal-only symbols even on platforms that support it, because they are used all over the place outside rpmio. So... rename the b64 functions to rpmLikeNamingStyle and make 'em public. No functional changes, just trivial renaming despite touching numerous places.
2011-11-09Add an alternative API for parsing PGP packetsPanu Matilainen1-6/+27
- pgpPrtParams() returns a pointer to an allocated pgpDigParams on success, eliminating the need for callers to worry about freeing "target buffer" on failure and bypassing the now rather useless pgpDig middleman. Also allows specifying the expected packet type so if we expect a key we'll error out if we get a signature instead. - pgpPrtPkts() is basically just a wrapper to pgpPrtParams() - Further pre-requisites for separating key and signature management. - Yes, pgpPrtParams() is a stupid name for this. However all the saner ones are already taken for other purposes (for which the names are just as bad/misleading, sigh)
2011-11-09Allocate signature and pubkey dynamically within pgpDig on PGP parsePanu Matilainen1-23/+35
- This way we can parse the whole thing into a private storage first and only if its actually successful we return anything through the pgpDig. Previously we would return partial garbage on failure and/or consecutive calls unless manually "cleaned" as we were parsing directly into the pgpDig. - Dynamic allocation is a pre-requirement separating management of keys and signatures: while they walk hand in hand much of the time, they come from different sources and have different lifetimes and should be managed separately. - Dynamic allocation of these is also a pre-requirement for handling more than one public key, ie mainly subkeys.
2011-11-09Use pgpDigGetParams() in pgpVerifySig() compat wrapper tooPanu Matilainen1-1/+2
- The fewer places that "know" about pgpDig allocation internals the better...
2011-11-08Tolerate NULL key in pgpVerifySignature()Panu Matilainen1-3/+3
2011-11-07Eliminate unused params member from pgpDigParamsPanu Matilainen1-3/+0
- Rpm has never used this for anything, amounting to helluva lot unnecessary free()'s over the years.
2011-11-07Add ad API for retrieving algorithm values from digest parameter containersPanu Matilainen1-0/+16
- Mildly annoying but necessary in order to make pgpDigParams properly opaque some day (and also allow sane access to this data)
2011-11-07Add an API for comparing two digest parameter containersPanu Matilainen1-0/+23
- Lift the digest parameter comparison from librpmsign to rpmpgp.c where it really belongs.
2011-11-07And finally, make pgpDig struct fully opaquePanu Matilainen1-0/+8
- As long as this was exposed and relied on, we couldn't really make any changes to how this stuff is stored. Now we have a chance...
2011-11-07Add a dumb API to retrieve pubkey / signature params from pgpDigPanu Matilainen1-0/+16
2011-11-07Process all keys and signatures we findPanu Matilainen1-37/+32
- We still can't store more than one signature / key at a time, but since we can easily *process* them without trashing already stored values, lets do so to avoid returning errors from legal packets. Also pay attention to only store data matching our expected type, ie dont store signature data into pubkey parameters and vice versa. - This mostly affects pubkey packets which can have more than one key present and which (can) also carry certification signature which we currently do not handle properly at all.
2011-11-07Make pgpPrtPubkeyParams() return an int like all the others do tooPanu Matilainen1-7/+7
- No functional changes, just making the interfaces consistent
2011-11-07Add another pgpVerify variant which takes key and sig as separate argsPanu Matilainen1-13/+20
- 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-07Clean up pgpPrtPkts() and friends a bitPanu Matilainen1-29/+20
- Use decodePkt() for added initial sanity check + grabbing the "main" tag instead of duplicating the tag decoding here. - Call decodePkt() from the main parse loop instead of pgpPrtPkt(), and return simple ok/error codes from pgpPrtPkt() and do the length calculation in the main loop. - Besides making the code simpler and more obvious this fixes some fishy cases where we previously would've returned 0 for success despite there being an error.
2011-11-04Bury all NSS specifics into a separate sourcePanu Matilainen1-401/+2
- Not everybody needs/wants the certified monster that NSS is (along with all its quirks), this leaves room for alternative compile-time selectable crypto backends. Besides that, we get a clean functionality separation for the PGP parser and the cryptography parts. - The whole crypto abstraction works inspired + somewhat based on Michael Schroeder's similar patch in Suse, kudos. - TODO: port beecrypt support from Suse to the new interface.
2011-11-04Implement PGP key & sig algorithm specific part OO-stylePanu Matilainen1-133/+136
- Collect the crypto algorithm specific bits into new struct with function pointers for the necessary set/verify/free methods, adjust callers to operate on these. This will allow nice and clean switching for different underlying crypto implementations with differing supported algorithms etc with minimal internals exposure. - pgpSignatureNew() and pgpPubkeyNew() never fail to avoid having to check for NULL's over and over, they just return a "null object" object for which all operations return failure instead. - This shreds out some of the output --prtpkts used to give. Wouldn't be hard to preserve but the stderr fprintf() spew is not very useful nor library-like behavior.
2011-11-04Lift RSA/DSA specific signature verification to helper functionsPanu Matilainen1-57/+80
- Use function pointers to call appropriate helper, cleaning up pgpVerifySig() a bit. Supposedly no functional changes, just further isolation of NSS specifics. - Pass down pubkey and signature as separate pointers, we'll want to get rid of pgpDig eventually as it only obfuscates things.
2011-11-04Lift RSA/DSA key MPI calculations to helper functionsPanu Matilainen1-44/+66
- Same as commit 8473a5b6ce2050a8e899b0be4a012f5724eb0b6d, only for keys - Use function pointers to call appropriate helper etc, cleaning up pgpPrtPubkeyParams() considerably. Supposedly no functional changes, just further isolating NSS specifics behind generic interfaces.
2011-11-04Lift RSA/DSA signature MPI calculations to helper functionsPanu Matilainen1-47/+58
- Use function pointers to call appropriate helper, cleaning up pgpPrtSigParams() considerably. Supposedly no functional changes. - Also serves as first step towards isolating NSS-specific bits and pieces behind more generic interfaces to enable using alternative crypto "engines" later on.
2011-11-04Remove now redundant NULL digparam checks within the PGP parserPanu Matilainen1-64/+52
- Since the only entry to these is pgpPrtPkts() and that ensures the internals are never called with non-NULL digp... Cleans up and simplifies the internals.
2011-11-04Arrange temporary storage for parsing if called with NULL digPanu Matilainen1-4/+12
- The only known caller with NULL dig is in the rather useless wrapping of prtPrtPkts() in the python bindings, but since in theory some other callers could use this just for validating a PGP packet .. preserve the behavior since it's easy. The actual benefit here is that this frees the parser internals of having to check for NULL pointers everywhere.
2011-11-04Added sanity checks on pgpPrtPkts() entryPanu Matilainen1-2/+5
- Error out cleanly on NULL pkts pointer (caller error but not worth dying for) - Error out early if packet is clearly not valid
2011-11-04Eliminate bunch of unused/useless debug cruft from pgp parserPanu Matilainen1-16/+6
2011-11-04Split digest parameter freeing into a separate helper functionPanu Matilainen1-23/+21
- The data is all the same except for rsa/dsa specific bits, to me this calls for a function. We might want to export pgpCleanDigParams() or such later on but for now keep it static. No functional changes.
2011-11-04Store the rsa/dsa parameters in pgpDigParamers struct directlyPanu Matilainen1-55/+53
- Avoids having to pass around pgpDig pointers in addition to pgpDigParamrs pointers. The type (key vs sig) is determined early on in pgpPrtPkts() and doesn't change, and the rsa/dsa data is associated with that always. No functional changes, just makes the whole thing just a little bit cleaner.
2011-11-01Verify PGP signature packet sizes and number of MPIs match expectationsPanu Matilainen1-9/+17
- Similar to commit 807b402d95702f3f91e9e2bfbd2b5ca8c9964ed9 but for signature packets: packet must be larger than the "intro" structure, and verify the calculated sizes match our expectations.
2011-11-01Eliminate buggy pgpPrtComment()Panu Matilainen1-29/+0
- Removes another source of stupid bugs: for rpm's purposes we're not interested in PGP comment tag contents, and the implementation here was unsafe as it assumes there always is a terminating \0 somewhere in the packet which might not be true for a malformed packet.
2011-11-01Verify PGP key packet sizes and number of MPIs match expectations, part IIPanu Matilainen1-28/+32
- Same as commit 807b402d95702f3f91e9e2bfbd2b5ca8c9964ed9 but for retrieving the actual key data instead of its fingerprint. - Only look inside keys whose pubkey algo we actually support: DSA and RSA. Anything else is better left untouched and treated as an error to avoid nasty surprises.
2011-11-01Verify PGP key packet sizes and number of MPIs match expectationsPanu Matilainen1-29/+34
- A key packet must be larger than the "intro" structure to have room for the trailing MPIs, ie in order to be valid. This also ensures we can safely access the pubkey algorithm data. - Verify the number of trailing MPI's and their total size matches the expectations and packet size exactly before bothering with digest calculations. - Also use sizeof(keyid) instead of "magic eight" and memcpy() instead of memmove(), the argument keyid and memory returned from rpmDigestFinal() cannot overlap.
2011-10-26Verify MPI size is within packet boundary in pgpMpiItem()Panu Matilainen1-9/+20
- Malformed data can claim the MPI size to be "arbitrarily" large, pass packet end pointer to pgpMpiItem() and validate we have enough bytes in the packet to contain the MPI before copying.
2011-10-26Remove support for V3 public keysPanu Matilainen1-40/+3
- V3 keys have been long since deprecated and extinct for all practical purposes for more than a decade by now (for example, Red Hat Linux 6.0 from 1999 was the last RHL to use a V3 key for signing). RFC-4880 says V3 keys MUST NOT be generated (they have a number of weaknesses), but implementations MAY accept them. We choose not to accept them anymore, eliminating a code path that would essentially only get triggered by malformed packages. The said code path also contained a few buffer overflows and other bugs, so its more than just "good riddance." - Worth nothing is that only support for V3 *keys* is removed, V3 signatures are still supported along with V4 ones.
2011-10-26We dont deal with secret keys, leave them alonePanu Matilainen1-108/+0
- As we only do OpenPGP signature verification and never signing / encrypting content ourselves, we have no need to know anything about secret keys. One less place to worry about, tripping up on bad data that we dont even try to use would be pretty dumb.
2011-10-25Centralize PGP packet decoding and sanity checking into helper functionPanu Matilainen1-46/+56
- Stricter sanity checking on both old and new packet types - whereas new format packets were mostly covered by pgpLen() changes already, old format has similar case where malformed packet could cause us to read beyond packet (buffer) end. - Collect the necessary packet data into a struct that's nicer to pass around (taking advantage of this mostly left for next steps)
2011-10-25Verify there are sufficient number of bytes to calculate packet lengthPanu Matilainen1-19/+34
- The number of bytes used to store a PGP packet body length is not known until we decode the first byte, pass remaining packet length to pgpLen() and verify there are sufficient bytes for the used encoding before reading them. - Clarify the function description while at it.
2011-10-25Avoid redundant calculations on pubkey fingerprint retrievalPanu Matilainen1-21/+26
- In pgpPrtPkt() we just calculated the packet body and length, avoid redoing it for the fingerprint by splitting the actual fingerprint calculation out of pgpPubkeyFingerprint() into a helper function and calling that instead.
2011-10-25pgpPubkeyFingerprint() can fail, propagate errorsPanu Matilainen1-5/+9
- Rpm itself doesn't even use pgpExtractPubkeyFingerprint() anymore but there appear to be other users so leaving it alone for now, just behave sanely on errors.
2011-10-24Eliminate useless pgpIsPkt() helper functionPanu Matilainen1-61/+0
- While I can imagine uses for such a function, our only caller is using it in a bogus way: decodePkts() is trying to avoid looking into binary-only data by calling it, but then pgpIsPkt() returns "not pgp tag" for various things that *are* pgp tags, making the whole thing just moot. If such checks are actually needed, we'd be better of checking for printable characters or such.
2011-10-24Eliminate broken pgpLen() from the APIPanu Matilainen1-0/+21
- pgpLen() only works for new format packets, and even for those its unsafe and cannot be fixed without breaking the API. Start by taking it behind the barn for further, err, operations. Rpm has no users outside rpmpgp.c now and anybody else using it will be better off not doing so.
2011-10-24Valid PGP packets are always at least two bytes longPanu Matilainen1-2/+2
- Old format tags encode the number of body length bytes in the packet header, new format encodes it in the first body length byte. In both cases there must be at least two bytes worth of data for it to be a valid header. Sanity check before accessing.
2011-09-30Sanity check OpenPGP packet lengths in pgpPrtSubType()Panu Matilainen1-3/+8
- Sub-packet prefix length + packet length can't very well be larger than the remaining packet length. In addition to sanity checking, return an error code and have callers actually check for it. - Fixes (yet another) segfault on malformed package (RhBug:742499)
2011-09-01Source formatting cosmetics: function blocks start on the next linePanu Matilainen1-1/+2
2011-08-02pgpVerifySig() check of NULL hash is the wrong way aroundPanu Matilainen1-1/+1
- NULL hash is pretty much a can't happen-case here but lets be sane if it happens afterall - NULL hash would be an error and we dont want to process the rest if that happened.
2011-07-14Sanity check signatures even if we dont have a keyPanu Matilainen1-1/+10
- Fixes a regression originating all the way back from commit c7fc09d585ff3831924f72f61d990aa791f2c3f2 (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-13Fix memleak on keys with more than one user idPanu Matilainen1-3/+3
- This is not "correct", we should permit more than one user id. Leaking memory is still worse than not leaking, corrent behavior or not.
2011-07-13Fix crash on PGP packets/armors with more than one key (RhBug:667582)Panu Matilainen1-4/+8
- While OpenPGP permits arbitrary number of keys per packet/armor, we can't handle more than one, error out early. The poor user wont get much of a clue as to what went wrong, but thats still better than crashing and burning. - Return NULL from pgpPrtPubkeyParams() on errors and pass it onwards from pgpPrtKey() which propagates it up to callers. Besides the crash, this also fixes the error path from pgpNewPublicKey() failures.
2011-03-03Eliminate unused variable + calculations in pgpPubkeyFingerprint()Panu Matilainen1-3/+0
2010-09-21Adjust pgpMpiSet() dest type to match actual usePanu Matilainen1-2/+2
2010-06-29Tell rpm about SHA-224 existence (RhBug:608599)Jiri Kastner1-0/+1
- Fixes "Unknown hash algorithm" message but this is cosmetic only as NSS doesn't currently support SHA-224.