summaryrefslogtreecommitdiffstats
path: root/openpgp/src/parse.rs
AgeCommit message (Collapse)Author
2024-01-22openpgp: Add Parse::from_buffered_reader.Justus Winter
- Add a buffered-reader-based function to trait Parse. This allows us to manipulate the buffered reader stack before and after parsing, e.g. to parse several armored objects in one stream. The CertParser also does this, but uses internal interfaces for that.
2024-01-22openpgp: Rename every from_buffered_reader to from_cookie_reader.Justus Winter
- This is an internal interface that uses our reader stack's cookie. We need this to traverse the buffered reader stack. We did not, however, expose it as an external interface, because we didn't want to bake in the cookie type into the API. - Having a public API that operates on buffered readers is convenient: the current Parser::from_reader operates on io::Readers, and will most likely construct a buffered_reader::Generic from it. This will eagerly buffer some data, making this interface unsuitable if you want to read in one artifact (e.g. an MPI) without consuming more data. - Renaming the internal functions gives us a chance to add a more general buffered reader interface.
2024-01-22openpgp: Simplify Parse implementations by using the macro.Justus Winter
2023-11-14openpgp: Improve tracing.Justus Winter
2023-09-12openpgp: Fix building without compression support.Justus Winter
2023-08-21openpgp: Shortcut parse_finish for non-document signatures.Justus Winter
2023-07-07openpgp: Improve test.Justus Winter
2023-07-07openpgp: Add test vectors for the Camellia ciphers.Justus Winter
- Generated using GnuPG 2.2.40. - Fixes #1037.
2023-07-07openpgp: Explicitly and selectively enable hashing.Justus Winter
- When we opt out of automatic hashing, it is useful to selectively opt in to hashing on a per-one-pass-signature basis. Add PacketParser::start_hashing to do this. - This is somewhat similar to PacketParser::decrypt in that they are invoked while the packet is in the packet parser, and they communicate intent to act upon that packet. - Fixes #1034.
2023-07-07openpgp: Add a way to disable automatic hashing.Justus Winter
- When encountering a one-pass-signature packet, the packet parser will, by default, start hashing later packets using the hash algorithm specified in the packet. In some cases, this is not needed, and hashing will incur a non-trivial overhead. - See #1034.
2023-07-07openpgp: Reuse computed value.Justus Winter
2023-07-05openpgp: Don't put the packet body in the map unless we're bufferingJustus Winter
- Previously, Sequoia would buffer packet bodies when mapping is enabled in the parser, even if the packet parser is not configured to buffer the bodies. This adds considerable overhead. - With this change, Sequoia no longer includes the packet bodies in the maps unless the parser is configured to buffer any unread content. - This makes parsing packets faster if you don't rely on the packet body in the map, but changes the default behavior. If you need the old behavior, please do adjust your code to buffer unread content.
2023-07-05openpgp: Fix body length computation.Justus Winter
- Fixes c7adc7a5b3929956c1960493dfc1c7c5c624af9b.
2023-07-04openpgp: Avoid extra copy.Justus Winter
2023-07-03openpgp: Deprecate SubpacketTag::PreferredAEADAlgorithms.Justus Winter
- This is replaced by a more expressive subpacket type in the crypto refresh. - See #1017.
2023-06-20openpgp: Accept slightly malformed MPIs when reading secrets.Justus Winter
- Apparently, some OpenPGP implementations create malformed secret keys that have MPIs with leading zeros. Not accepting those seems not helpful. - Fixes #1024.
2023-06-14openpgp: Deprecate `Packet::MDC` variant.Wiktor Kwapisiewicz
- Crypto refresh changes MDC to not be a standalone packet but an implementation detail of the SEIPDv1 packet. - Adjust use-sites to allow for deprecations. - See https://gitlab.com/sequoia-pgp/sequoia/-/issues/860
2023-06-06buffered_reader: Introduce `into_boxed` and deprecate `as_boxed`.Wiktor Kwapisiewicz
- According to the Rust API Guidelines, a conversion function taking self should be called `into_*` if the self is not Copy, so this function should be named `into_boxed`. - Deprecate old function not to break the API. - Update all references in the code. - Fixes https://gitlab.com/sequoia-pgp/sequoia/-/issues/781
2023-05-12openpgp: Fix crash in the packet parser.Justus Winter
- The packet parser hashes packet bodies to provide a robust equality relation even when packet bodies are streamed. To hash all bytes on the fly everywhere, we do that when it is consumed in PacketParser::consume. - This function assumes that if BufferedReader::data and friends returned n bytes, future calls to these interfaces will succeed if up to n bytes are requested, and no data was consumed in the meantime. - However, armor::Reader::data_helper did not provide that guarantee, making PacketParser::consume panic with the message "It is an error to consume more than data returns", which doesn't quite correctly name the problem at hand. - Fix this crash by fixing armor::Reader::data_helper in the same way the previous commit fixes buffered_reader::Generic::data_helper. - Fixes #957.
2023-05-11buffered-reader: Fix returning partial reads ending in errors.Justus Winter
- Make sure that we return the data we already have in our buffer, even though we encountered an IO error while filling it. - Notably, the packet parser assumes that data once read can be requested through the buffered reader protocol again and again. Unfortunately, that was not the case, leading to a panic. - As the generic reader is used to implement the buffered reader protocol on top of io::Read, this problem affects among other things the compression container. Demonstrate this using test. - Fixes #1005.
2023-04-26Revert "openpgp: Improve error message, avoid stuttering."Justus Winter
This reverts commit d57bd33cf9bddda77dff8e6508ebb1e4902f9294.
2023-04-18openpgp: Avoid leaking secrets in error messages.Justus Winter
2023-04-07openpgp: Don't unwrap.Justus Winter
2023-04-07openpgp: Refactor OnePassSig::parse in preparation for v6.Justus Winter
2023-04-07openpgp: Improve error message, avoid stuttering.Justus Winter
2023-03-23openpgp: Re-export buffered_reader.Justus Winter
- We use this in our API, and re-exporting it here makes it easy to use the correct version of the crate in downstream code without having to explicitly depend on it.
2023-03-14openpgp: Avoid leaking secrets when parsing secret key material.Justus Winter
2023-03-14openpgp: Avoid a heap allocation during MPI parsing.Justus Winter
- Not only was the heap allocation superfluous, it also leaked secrets into the heap.
2023-03-06openpgp: Eagerly erase type in the PacketHeaderParser.Justus Winter
- The PacketHeaderParser returns erased BufferedReaders anyway, so we might as well do it early. This avoids any accidental specialization and hence code duplication.
2023-02-01openpgp: Avoid creating a Buffered reader when parsing packets.Neal H. Walfield
- For each packet type, add a private function `from_buffered_reader`. - Implement `Parse::from_reader` and `Parse::from_bytes` in terms of `from_buffered_reader`. For `Parse::from_bytes`, this means that we can wrap the input in a `buffered_reader::Memory`, which is much faster than a `buffered_reader::Generic`, which we use now. - Note: `PacketParserBuilder` and by extension `Cert` already implement this optimimzation.
2023-01-19openpgp: Improve tracing.Justus Winter
2023-01-06openpgp: Fix PacketParser to return the packet preceding any junk.Neal H. Walfield
- If the `PacketParser` encounters junk (i.e., corruption) and is able to find a valid packet within `RECOVERY_THRESHOLD` bytes of the end of the last valid packet, it recovers by converting the junk to an `Unknown` packet, and continuing to parse. - Extend this recovery mechanism to junk at the end of the file. If the `PacketParser` encounters up to `RECOVERY_THRESHOLD` bytes of junk at the end of the file, convert that data into an `Unknown` packet instead of immediately returning an error. - By returning an `Unknown` packet instead of an error, we also return the last buffered packet, which was otherwise lost. - When converting `RECOVERY_THRESHOLD` bytes of junk into an `Unknown` packet, queue an error (in `PacketParserState`) so that the next call to `PacketParser::next` will not continue trying to parse the input, but return an unrecoverable error. - Fixes #967.
2023-01-06openpgp: Reduce debug output.Neal H. Walfield
- When tracing the execution of a `PacketParser`, don't emit the `BufferedReader`, as this can result in a huge amount of unreadable output.
2023-01-06openpgp: Make PacketParser::plausible_cert more generic.Neal H. Walfield
- Make `PacketParser::plausible_cert` generic over the cookie so that it is usable with generic `BufferedReader`s.
2022-12-21openpgp: Adjust test suite to filter out unsupported AEAD algorithms.Wiktor Kwapisiewicz
2022-12-12openpgp: Make hash_update_text more idomatic.Neal H. Walfield
- Make `hash_update_text` a method on `HashingMode<Digest>`, `HashingMode<Digest>::update`.
2022-12-11openpgp: Move HashingMode.Neal H. Walfield
- `HashingMode` is mostly used by `HashedReader`. - Move the `HashingMode` declaration and implementation from `parse.rs` to `parse/hashed_reader.rs`.
2022-11-18openpgp: Improve tests with marker packets.Justus Winter
2022-11-18openpgp: Ignore marker packets when validating cert streams.Justus Winter
- While we correctly ignored marker packets in the CertParser, we did not ignore them in the CertValidator. This made sq inspect complain about marker packets in certrings.
2022-11-11openpgp: Add support for verifying v3 signatures.Neal H. Walfield
- RFC 4880 explicitly allows the use of v3 signatures, but adds: > Implementations SHOULD accept V3 signatures. Implementations > SHOULD generate V4 signatures. - In practice, rpm-based distributions are generating v3 signatures, and it will be awhile before we can actually stop supporting them. https://bugzilla.redhat.com/show_bug.cgi?id=2141686#c20 - Add support for parsing, verifying, and serializing v3 signatures (but not v3 certificates, and not generating v3 signatures!).
2022-06-09openpgp: Rename PacketParser::{set_,}encrypted to processed.Wiktor Kwapisiewicz
- Convert `encrypted` to `processed`. - Since `set_encrypted` is internal API it was directly renamed without forwarder stub. - `encrypted()` is public API thus the old function is converted to a forwarder of the negation of `processed()`. - `unprocessed()` marked as deprecated. - Update docs and NEWS file. - Fixes #845.
2022-05-12openpgp: Rename `iv_size` to `nonce_size` leaving `iv_size`.Wiktor Kwapisiewicz
- Rename `iv_size` to `nonce_size`. - Introduce `iv_size` that forwards to `nonce_size` for compatibility reasons. - Change all calls to `iv_size` to `nonce_size`.
2022-05-03openpgp: Make the stern warning sterner, add reference.Justus Winter
2022-05-03openpgp: Don't include decrypted block in error message.Justus Winter
- Even though the documentation warns that this function returns rich errors that must not be returned to the user, and the mid-level streaming decryption's API prevents leaking rich errors, including decrypted data in the error message seems dicey.
2022-05-03openpgp: Rename function.Justus Winter
2022-04-28openpgp: Rework handing of unknown compression algorithms.Justus Winter
- Currently, if we don't understand a compression algorithm, parsing a compressed data packet fails and it is turned into an Unknown packet. This is rather unfortunate, and deviates from what we do for the encryption containers. - Encryption containers are either not decrypted, in which case they have a Body::Unprocessed, decrypted with Body::Processed, or decrypted and parsed Body::Structured. - Likewise, if we don't understand a compression algorithm, we should simply return a compressed data packet with an unprocessed body. This change does exactly that. - Fixes #830.
2022-04-28openpgp: Fix comment.Justus Winter
2022-04-28openpgp: Don't mark unknown packets as encrypted.Justus Winter
- This goes back a long way, to e304deb0fc7a92801cf3ba58aafeb14ce2301aed where the flag was called `decrypted`, and every packet but SEIP had decrypted set to `true`. At some point, we inverted the flag, but for some reason decided to mark Unknown packets as encrypted, which makes no sense, and changing it doesn't seem to break documented (i.e. tested) behavior.
2022-03-28openpgp: Explicit SEIP packet version in the message parser.Justus Winter
- In order to deal with version 2 SEIP packets, we first need to be explicit about the packet version in the message parser. - Rename the token and grammar rules, pass in a version to MessageParser::push.
2022-03-28openpgp: Clarify that message::Token is not covered by SemVer.Justus Winter
- Do this using a deprecation so that anyone using it will get a compiler warning. - Revert this change once message::Token is private. - See #836.