History log of /openbsd-current/usr.sbin/rpki-client/mft.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.117 11-Jun-2024 tb

rpki-client: fix incorrect use of ASN1_tag2str()

This goes back to the initial import in mft.c and was then copied to rsc.c.
ASN1_tag2str() doesn't take a nid but rather an ASN.1 tag. Use nid2str()
instead.

ok claudio (who helped me use nid2str() correctly)


# 1.116 24-May-2024 tb

Update references to new and not quite so new RFCs

Four warnings now contain "RFC 9582" rather than "RFC 6482bis".
Also update some references to I-Ds.

ok claudio


# 1.115 20-May-2024 claudio

Instead of tracking certificates by SKI track them by an internal identifier.

The certificate SKI is not strictly unique so using it as a unique id is
problematic. It is also not really needed to do that since in theory we
already know the path (but this got lost in the privsep communication).
So add a cert id and pass this id back and forth between main process and
the parser. With this id we can lookup the authentication chain in the
parser and this even works with multiple paths to the same resource.
Since we no longer lookup by SKI the valid_aki_ski function is replaced
by find_issuer() which does the lookup by certid.

The loop protection is now extended to allow each TAL to reach each file
once but still triggers if a file is reaccessed by the tree of a TAL.

In filemode the lookup now uses an AIA uri based lookup tree. Again this
replaces the SKI based lookups from before.

Done together with tb@
OK tb@ job@


# 1.114 15-May-2024 tb

rpki-client: plug leak of the crl path

also, drop an unnecessary NULL check and make freeing have the same order
as the struct field so auditing for leaks is easier.

ok claudio


# 1.113 20-Apr-2024 job

Display distinct errors for various problematic CRL/MFT situationships

RFC 6487 section 8 specifies only a single CRL is issued at a time, so
error when multiple .crl files are listed in a Manifest's FileList.

The CRLDP extension identifies the location of the CRL, so the CRL's
filename must match the CA's CRLDP's 'rsync://' entry, error if that
isn't the case. (RFC 6486 section 4.8.6)

with & OK tb@


Revision tags: OPENBSD_7_5_BASE
# 1.112 22-Feb-2024 job

Add support for RPKI Signed Prefix Lists

Signed Prefix List are a CMS protected content type for use with the
RPKI to carry the complete list of prefixes which an Autonomous System
may originate to all or any of its routing peers. The validation of a
Signed Prefix List confirms that the holder of the listed ASN produced
the object, and that this list is a current, accurate and complete
description of address prefixes that may be announced into the routing
system originated by this AS.

https://datatracker.ietf.org/doc/html/draft-ietf-sidrops-rpki-prefixlist

with and OK claudio@ tb@


# 1.111 21-Feb-2024 tb

rpki-client: remove the remaining struct parse

With the exception of mft.c where there is an additional boolean, this
struct carries a file name and a result. This means functions having
struct parse in the signature can't be shared between files, which has
been annoying. Simply pass file name and necessary info directly as a
function parameter and add a small dance to handle the boolean in mft.c.

ok job


# 1.110 16-Feb-2024 tb

Rename fn into file to avoid clash in upcoming diff

ok job


# 1.109 16-Feb-2024 tb

Use _asn1 suffix for some aspa/mft/roa/rsc/tak

This would otherwie clash with an upcoming replacement of struct parse.

ok job


# 1.108 15-Feb-2024 tb

Ensure that the FileAndHashes list in a mft has no duplicates

ok job


# 1.107 13-Feb-2024 job

Add explicit ASN1_ITEM_EXP prototypes

In LibreSSL *_it are variables, in other implementations they might
be a function. This helps squash compiler warnings in -portable.

Related: https://github.com/openbsd/src/commit/65af98848fc7a42e34d470d10fc1db8e23f9db93

OK tb@


# 1.106 05-Feb-2024 job

Check whether all data in eContent has been consumed

It is possible that a given ASN.1 template generated d2i_*() function
didn't consume all data, so there is a potential for malleability.
The econtent is a sequence (which means it could be the concatenation
of several DER "blobs"). d2i_*() would only deserialize the first one
and not notice blobs following it.

OK tb@


# 1.105 04-Feb-2024 job

Use x509_get_time() to get the Manifest thisUpdate / nextUpdate

From the moment d2i_Manifest() was introduced, it was automatically
checked whether the thisUpdate/nextUpdate are ASN1_GENERALIZEDTIME.

Unfortunately, an additional check is needed, because OpenSSL doesn't
require RFC 5280 conformance for GeneralizedTime DER encoding.

OK tb@


# 1.104 03-Feb-2024 job

Refactor handling of stale manifests

No need to hoist a staleness indicator through the whole process and
count it explicitly.

OK tb@


# 1.103 02-Feb-2024 job

Remove old comment

OK tb@


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.116 24-May-2024 tb

Update references to new and not quite so new RFCs

Four warnings now contain "RFC 9582" rather than "RFC 6482bis".
Also update some references to I-Ds.

ok claudio


# 1.115 20-May-2024 claudio

Instead of tracking certificates by SKI track them by an internal identifier.

The certificate SKI is not strictly unique so using it as a unique id is
problematic. It is also not really needed to do that since in theory we
already know the path (but this got lost in the privsep communication).
So add a cert id and pass this id back and forth between main process and
the parser. With this id we can lookup the authentication chain in the
parser and this even works with multiple paths to the same resource.
Since we no longer lookup by SKI the valid_aki_ski function is replaced
by find_issuer() which does the lookup by certid.

The loop protection is now extended to allow each TAL to reach each file
once but still triggers if a file is reaccessed by the tree of a TAL.

In filemode the lookup now uses an AIA uri based lookup tree. Again this
replaces the SKI based lookups from before.

Done together with tb@
OK tb@ job@


# 1.114 15-May-2024 tb

rpki-client: plug leak of the crl path

also, drop an unnecessary NULL check and make freeing have the same order
as the struct field so auditing for leaks is easier.

ok claudio


# 1.113 20-Apr-2024 job

Display distinct errors for various problematic CRL/MFT situationships

RFC 6487 section 8 specifies only a single CRL is issued at a time, so
error when multiple .crl files are listed in a Manifest's FileList.

The CRLDP extension identifies the location of the CRL, so the CRL's
filename must match the CA's CRLDP's 'rsync://' entry, error if that
isn't the case. (RFC 6486 section 4.8.6)

with & OK tb@


Revision tags: OPENBSD_7_5_BASE
# 1.112 22-Feb-2024 job

Add support for RPKI Signed Prefix Lists

Signed Prefix List are a CMS protected content type for use with the
RPKI to carry the complete list of prefixes which an Autonomous System
may originate to all or any of its routing peers. The validation of a
Signed Prefix List confirms that the holder of the listed ASN produced
the object, and that this list is a current, accurate and complete
description of address prefixes that may be announced into the routing
system originated by this AS.

https://datatracker.ietf.org/doc/html/draft-ietf-sidrops-rpki-prefixlist

with and OK claudio@ tb@


# 1.111 21-Feb-2024 tb

rpki-client: remove the remaining struct parse

With the exception of mft.c where there is an additional boolean, this
struct carries a file name and a result. This means functions having
struct parse in the signature can't be shared between files, which has
been annoying. Simply pass file name and necessary info directly as a
function parameter and add a small dance to handle the boolean in mft.c.

ok job


# 1.110 16-Feb-2024 tb

Rename fn into file to avoid clash in upcoming diff

ok job


# 1.109 16-Feb-2024 tb

Use _asn1 suffix for some aspa/mft/roa/rsc/tak

This would otherwie clash with an upcoming replacement of struct parse.

ok job


# 1.108 15-Feb-2024 tb

Ensure that the FileAndHashes list in a mft has no duplicates

ok job


# 1.107 13-Feb-2024 job

Add explicit ASN1_ITEM_EXP prototypes

In LibreSSL *_it are variables, in other implementations they might
be a function. This helps squash compiler warnings in -portable.

Related: https://github.com/openbsd/src/commit/65af98848fc7a42e34d470d10fc1db8e23f9db93

OK tb@


# 1.106 05-Feb-2024 job

Check whether all data in eContent has been consumed

It is possible that a given ASN.1 template generated d2i_*() function
didn't consume all data, so there is a potential for malleability.
The econtent is a sequence (which means it could be the concatenation
of several DER "blobs"). d2i_*() would only deserialize the first one
and not notice blobs following it.

OK tb@


# 1.105 04-Feb-2024 job

Use x509_get_time() to get the Manifest thisUpdate / nextUpdate

From the moment d2i_Manifest() was introduced, it was automatically
checked whether the thisUpdate/nextUpdate are ASN1_GENERALIZEDTIME.

Unfortunately, an additional check is needed, because OpenSSL doesn't
require RFC 5280 conformance for GeneralizedTime DER encoding.

OK tb@


# 1.104 03-Feb-2024 job

Refactor handling of stale manifests

No need to hoist a staleness indicator through the whole process and
count it explicitly.

OK tb@


# 1.103 02-Feb-2024 job

Remove old comment

OK tb@


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.115 20-May-2024 claudio

Instead of tracking certificates by SKI track them by an internal identifier.

The certificate SKI is not strictly unique so using it as a unique id is
problematic. It is also not really needed to do that since in theory we
already know the path (but this got lost in the privsep communication).
So add a cert id and pass this id back and forth between main process and
the parser. With this id we can lookup the authentication chain in the
parser and this even works with multiple paths to the same resource.
Since we no longer lookup by SKI the valid_aki_ski function is replaced
by find_issuer() which does the lookup by certid.

The loop protection is now extended to allow each TAL to reach each file
once but still triggers if a file is reaccessed by the tree of a TAL.

In filemode the lookup now uses an AIA uri based lookup tree. Again this
replaces the SKI based lookups from before.

Done together with tb@
OK tb@ job@


# 1.114 15-May-2024 tb

rpki-client: plug leak of the crl path

also, drop an unnecessary NULL check and make freeing have the same order
as the struct field so auditing for leaks is easier.

ok claudio


# 1.113 20-Apr-2024 job

Display distinct errors for various problematic CRL/MFT situationships

RFC 6487 section 8 specifies only a single CRL is issued at a time, so
error when multiple .crl files are listed in a Manifest's FileList.

The CRLDP extension identifies the location of the CRL, so the CRL's
filename must match the CA's CRLDP's 'rsync://' entry, error if that
isn't the case. (RFC 6486 section 4.8.6)

with & OK tb@


Revision tags: OPENBSD_7_5_BASE
# 1.112 22-Feb-2024 job

Add support for RPKI Signed Prefix Lists

Signed Prefix List are a CMS protected content type for use with the
RPKI to carry the complete list of prefixes which an Autonomous System
may originate to all or any of its routing peers. The validation of a
Signed Prefix List confirms that the holder of the listed ASN produced
the object, and that this list is a current, accurate and complete
description of address prefixes that may be announced into the routing
system originated by this AS.

https://datatracker.ietf.org/doc/html/draft-ietf-sidrops-rpki-prefixlist

with and OK claudio@ tb@


# 1.111 21-Feb-2024 tb

rpki-client: remove the remaining struct parse

With the exception of mft.c where there is an additional boolean, this
struct carries a file name and a result. This means functions having
struct parse in the signature can't be shared between files, which has
been annoying. Simply pass file name and necessary info directly as a
function parameter and add a small dance to handle the boolean in mft.c.

ok job


# 1.110 16-Feb-2024 tb

Rename fn into file to avoid clash in upcoming diff

ok job


# 1.109 16-Feb-2024 tb

Use _asn1 suffix for some aspa/mft/roa/rsc/tak

This would otherwie clash with an upcoming replacement of struct parse.

ok job


# 1.108 15-Feb-2024 tb

Ensure that the FileAndHashes list in a mft has no duplicates

ok job


# 1.107 13-Feb-2024 job

Add explicit ASN1_ITEM_EXP prototypes

In LibreSSL *_it are variables, in other implementations they might
be a function. This helps squash compiler warnings in -portable.

Related: https://github.com/openbsd/src/commit/65af98848fc7a42e34d470d10fc1db8e23f9db93

OK tb@


# 1.106 05-Feb-2024 job

Check whether all data in eContent has been consumed

It is possible that a given ASN.1 template generated d2i_*() function
didn't consume all data, so there is a potential for malleability.
The econtent is a sequence (which means it could be the concatenation
of several DER "blobs"). d2i_*() would only deserialize the first one
and not notice blobs following it.

OK tb@


# 1.105 04-Feb-2024 job

Use x509_get_time() to get the Manifest thisUpdate / nextUpdate

From the moment d2i_Manifest() was introduced, it was automatically
checked whether the thisUpdate/nextUpdate are ASN1_GENERALIZEDTIME.

Unfortunately, an additional check is needed, because OpenSSL doesn't
require RFC 5280 conformance for GeneralizedTime DER encoding.

OK tb@


# 1.104 03-Feb-2024 job

Refactor handling of stale manifests

No need to hoist a staleness indicator through the whole process and
count it explicitly.

OK tb@


# 1.103 02-Feb-2024 job

Remove old comment

OK tb@


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.114 15-May-2024 tb

rpki-client: plug leak of the crl path

also, drop an unnecessary NULL check and make freeing have the same order
as the struct field so auditing for leaks is easier.

ok claudio


# 1.113 20-Apr-2024 job

Display distinct errors for various problematic CRL/MFT situationships

RFC 6487 section 8 specifies only a single CRL is issued at a time, so
error when multiple .crl files are listed in a Manifest's FileList.

The CRLDP extension identifies the location of the CRL, so the CRL's
filename must match the CA's CRLDP's 'rsync://' entry, error if that
isn't the case. (RFC 6486 section 4.8.6)

with & OK tb@


Revision tags: OPENBSD_7_5_BASE
# 1.112 22-Feb-2024 job

Add support for RPKI Signed Prefix Lists

Signed Prefix List are a CMS protected content type for use with the
RPKI to carry the complete list of prefixes which an Autonomous System
may originate to all or any of its routing peers. The validation of a
Signed Prefix List confirms that the holder of the listed ASN produced
the object, and that this list is a current, accurate and complete
description of address prefixes that may be announced into the routing
system originated by this AS.

https://datatracker.ietf.org/doc/html/draft-ietf-sidrops-rpki-prefixlist

with and OK claudio@ tb@


# 1.111 21-Feb-2024 tb

rpki-client: remove the remaining struct parse

With the exception of mft.c where there is an additional boolean, this
struct carries a file name and a result. This means functions having
struct parse in the signature can't be shared between files, which has
been annoying. Simply pass file name and necessary info directly as a
function parameter and add a small dance to handle the boolean in mft.c.

ok job


# 1.110 16-Feb-2024 tb

Rename fn into file to avoid clash in upcoming diff

ok job


# 1.109 16-Feb-2024 tb

Use _asn1 suffix for some aspa/mft/roa/rsc/tak

This would otherwie clash with an upcoming replacement of struct parse.

ok job


# 1.108 15-Feb-2024 tb

Ensure that the FileAndHashes list in a mft has no duplicates

ok job


# 1.107 13-Feb-2024 job

Add explicit ASN1_ITEM_EXP prototypes

In LibreSSL *_it are variables, in other implementations they might
be a function. This helps squash compiler warnings in -portable.

Related: https://github.com/openbsd/src/commit/65af98848fc7a42e34d470d10fc1db8e23f9db93

OK tb@


# 1.106 05-Feb-2024 job

Check whether all data in eContent has been consumed

It is possible that a given ASN.1 template generated d2i_*() function
didn't consume all data, so there is a potential for malleability.
The econtent is a sequence (which means it could be the concatenation
of several DER "blobs"). d2i_*() would only deserialize the first one
and not notice blobs following it.

OK tb@


# 1.105 04-Feb-2024 job

Use x509_get_time() to get the Manifest thisUpdate / nextUpdate

From the moment d2i_Manifest() was introduced, it was automatically
checked whether the thisUpdate/nextUpdate are ASN1_GENERALIZEDTIME.

Unfortunately, an additional check is needed, because OpenSSL doesn't
require RFC 5280 conformance for GeneralizedTime DER encoding.

OK tb@


# 1.104 03-Feb-2024 job

Refactor handling of stale manifests

No need to hoist a staleness indicator through the whole process and
count it explicitly.

OK tb@


# 1.103 02-Feb-2024 job

Remove old comment

OK tb@


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.113 20-Apr-2024 job

Display distinct errors for various problematic CRL/MFT situationships

RFC 6487 section 8 specifies only a single CRL is issued at a time, so
error when multiple .crl files are listed in a Manifest's FileList.

The CRLDP extension identifies the location of the CRL, so the CRL's
filename must match the CA's CRLDP's 'rsync://' entry, error if that
isn't the case. (RFC 6486 section 4.8.6)

with & OK tb@


Revision tags: OPENBSD_7_5_BASE
# 1.112 22-Feb-2024 job

Add support for RPKI Signed Prefix Lists

Signed Prefix List are a CMS protected content type for use with the
RPKI to carry the complete list of prefixes which an Autonomous System
may originate to all or any of its routing peers. The validation of a
Signed Prefix List confirms that the holder of the listed ASN produced
the object, and that this list is a current, accurate and complete
description of address prefixes that may be announced into the routing
system originated by this AS.

https://datatracker.ietf.org/doc/html/draft-ietf-sidrops-rpki-prefixlist

with and OK claudio@ tb@


# 1.111 21-Feb-2024 tb

rpki-client: remove the remaining struct parse

With the exception of mft.c where there is an additional boolean, this
struct carries a file name and a result. This means functions having
struct parse in the signature can't be shared between files, which has
been annoying. Simply pass file name and necessary info directly as a
function parameter and add a small dance to handle the boolean in mft.c.

ok job


# 1.110 16-Feb-2024 tb

Rename fn into file to avoid clash in upcoming diff

ok job


# 1.109 16-Feb-2024 tb

Use _asn1 suffix for some aspa/mft/roa/rsc/tak

This would otherwie clash with an upcoming replacement of struct parse.

ok job


# 1.108 15-Feb-2024 tb

Ensure that the FileAndHashes list in a mft has no duplicates

ok job


# 1.107 13-Feb-2024 job

Add explicit ASN1_ITEM_EXP prototypes

In LibreSSL *_it are variables, in other implementations they might
be a function. This helps squash compiler warnings in -portable.

Related: https://github.com/openbsd/src/commit/65af98848fc7a42e34d470d10fc1db8e23f9db93

OK tb@


# 1.106 05-Feb-2024 job

Check whether all data in eContent has been consumed

It is possible that a given ASN.1 template generated d2i_*() function
didn't consume all data, so there is a potential for malleability.
The econtent is a sequence (which means it could be the concatenation
of several DER "blobs"). d2i_*() would only deserialize the first one
and not notice blobs following it.

OK tb@


# 1.105 04-Feb-2024 job

Use x509_get_time() to get the Manifest thisUpdate / nextUpdate

From the moment d2i_Manifest() was introduced, it was automatically
checked whether the thisUpdate/nextUpdate are ASN1_GENERALIZEDTIME.

Unfortunately, an additional check is needed, because OpenSSL doesn't
require RFC 5280 conformance for GeneralizedTime DER encoding.

OK tb@


# 1.104 03-Feb-2024 job

Refactor handling of stale manifests

No need to hoist a staleness indicator through the whole process and
count it explicitly.

OK tb@


# 1.103 02-Feb-2024 job

Remove old comment

OK tb@


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.112 22-Feb-2024 job

Add support for RPKI Signed Prefix Lists

Signed Prefix List are a CMS protected content type for use with the
RPKI to carry the complete list of prefixes which an Autonomous System
may originate to all or any of its routing peers. The validation of a
Signed Prefix List confirms that the holder of the listed ASN produced
the object, and that this list is a current, accurate and complete
description of address prefixes that may be announced into the routing
system originated by this AS.

https://datatracker.ietf.org/doc/html/draft-ietf-sidrops-rpki-prefixlist

with and OK claudio@ tb@


# 1.111 21-Feb-2024 tb

rpki-client: remove the remaining struct parse

With the exception of mft.c where there is an additional boolean, this
struct carries a file name and a result. This means functions having
struct parse in the signature can't be shared between files, which has
been annoying. Simply pass file name and necessary info directly as a
function parameter and add a small dance to handle the boolean in mft.c.

ok job


# 1.110 16-Feb-2024 tb

Rename fn into file to avoid clash in upcoming diff

ok job


# 1.109 16-Feb-2024 tb

Use _asn1 suffix for some aspa/mft/roa/rsc/tak

This would otherwie clash with an upcoming replacement of struct parse.

ok job


# 1.108 15-Feb-2024 tb

Ensure that the FileAndHashes list in a mft has no duplicates

ok job


# 1.107 13-Feb-2024 job

Add explicit ASN1_ITEM_EXP prototypes

In LibreSSL *_it are variables, in other implementations they might
be a function. This helps squash compiler warnings in -portable.

Related: https://github.com/openbsd/src/commit/65af98848fc7a42e34d470d10fc1db8e23f9db93

OK tb@


# 1.106 05-Feb-2024 job

Check whether all data in eContent has been consumed

It is possible that a given ASN.1 template generated d2i_*() function
didn't consume all data, so there is a potential for malleability.
The econtent is a sequence (which means it could be the concatenation
of several DER "blobs"). d2i_*() would only deserialize the first one
and not notice blobs following it.

OK tb@


# 1.105 04-Feb-2024 job

Use x509_get_time() to get the Manifest thisUpdate / nextUpdate

From the moment d2i_Manifest() was introduced, it was automatically
checked whether the thisUpdate/nextUpdate are ASN1_GENERALIZEDTIME.

Unfortunately, an additional check is needed, because OpenSSL doesn't
require RFC 5280 conformance for GeneralizedTime DER encoding.

OK tb@


# 1.104 03-Feb-2024 job

Refactor handling of stale manifests

No need to hoist a staleness indicator through the whole process and
count it explicitly.

OK tb@


# 1.103 02-Feb-2024 job

Remove old comment

OK tb@


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.110 16-Feb-2024 tb

Rename fn into file to avoid clash in upcoming diff

ok job


# 1.109 16-Feb-2024 tb

Use _asn1 suffix for some aspa/mft/roa/rsc/tak

This would otherwie clash with an upcoming replacement of struct parse.

ok job


# 1.108 15-Feb-2024 tb

Ensure that the FileAndHashes list in a mft has no duplicates

ok job


# 1.107 13-Feb-2024 job

Add explicit ASN1_ITEM_EXP prototypes

In LibreSSL *_it are variables, in other implementations they might
be a function. This helps squash compiler warnings in -portable.

Related: https://github.com/openbsd/src/commit/65af98848fc7a42e34d470d10fc1db8e23f9db93

OK tb@


# 1.106 05-Feb-2024 job

Check whether all data in eContent has been consumed

It is possible that a given ASN.1 template generated d2i_*() function
didn't consume all data, so there is a potential for malleability.
The econtent is a sequence (which means it could be the concatenation
of several DER "blobs"). d2i_*() would only deserialize the first one
and not notice blobs following it.

OK tb@


# 1.105 04-Feb-2024 job

Use x509_get_time() to get the Manifest thisUpdate / nextUpdate

From the moment d2i_Manifest() was introduced, it was automatically
checked whether the thisUpdate/nextUpdate are ASN1_GENERALIZEDTIME.

Unfortunately, an additional check is needed, because OpenSSL doesn't
require RFC 5280 conformance for GeneralizedTime DER encoding.

OK tb@


# 1.104 03-Feb-2024 job

Refactor handling of stale manifests

No need to hoist a staleness indicator through the whole process and
count it explicitly.

OK tb@


# 1.103 02-Feb-2024 job

Remove old comment

OK tb@


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.107 13-Feb-2024 job

Add explicit ASN1_ITEM_EXP prototypes

In LibreSSL *_it are variables, in other implementations they might
be a function. This helps squash compiler warnings in -portable.

Related: https://github.com/openbsd/src/commit/65af98848fc7a42e34d470d10fc1db8e23f9db93

OK tb@


# 1.106 05-Feb-2024 job

Check whether all data in eContent has been consumed

It is possible that a given ASN.1 template generated d2i_*() function
didn't consume all data, so there is a potential for malleability.
The econtent is a sequence (which means it could be the concatenation
of several DER "blobs"). d2i_*() would only deserialize the first one
and not notice blobs following it.

OK tb@


# 1.105 04-Feb-2024 job

Use x509_get_time() to get the Manifest thisUpdate / nextUpdate

From the moment d2i_Manifest() was introduced, it was automatically
checked whether the thisUpdate/nextUpdate are ASN1_GENERALIZEDTIME.

Unfortunately, an additional check is needed, because OpenSSL doesn't
require RFC 5280 conformance for GeneralizedTime DER encoding.

OK tb@


# 1.104 03-Feb-2024 job

Refactor handling of stale manifests

No need to hoist a staleness indicator through the whole process and
count it explicitly.

OK tb@


# 1.103 02-Feb-2024 job

Remove old comment

OK tb@


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.106 05-Feb-2024 job

Check whether all data in eContent has been consumed

It is possible that a given ASN.1 template generated d2i_*() function
didn't consume all data, so there is a potential for malleability.
The econtent is a sequence (which means it could be the concatenation
of several DER "blobs"). d2i_*() would only deserialize the first one
and not notice blobs following it.

OK tb@


# 1.105 04-Feb-2024 job

Use x509_get_time() to get the Manifest thisUpdate / nextUpdate

From the moment d2i_Manifest() was introduced, it was automatically
checked whether the thisUpdate/nextUpdate are ASN1_GENERALIZEDTIME.

Unfortunately, an additional check is needed, because OpenSSL doesn't
require RFC 5280 conformance for GeneralizedTime DER encoding.

OK tb@


# 1.104 03-Feb-2024 job

Refactor handling of stale manifests

No need to hoist a staleness indicator through the whole process and
count it explicitly.

OK tb@


# 1.103 02-Feb-2024 job

Remove old comment

OK tb@


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.105 04-Feb-2024 job

Use x509_get_time() to get the Manifest thisUpdate / nextUpdate

From the moment d2i_Manifest() was introduced, it was automatically
checked whether the thisUpdate/nextUpdate are ASN1_GENERALIZEDTIME.

Unfortunately, an additional check is needed, because OpenSSL doesn't
require RFC 5280 conformance for GeneralizedTime DER encoding.

OK tb@


# 1.104 03-Feb-2024 job

Refactor handling of stale manifests

No need to hoist a staleness indicator through the whole process and
count it explicitly.

OK tb@


# 1.103 02-Feb-2024 job

Remove old comment

OK tb@


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.102 31-Jan-2024 tb

Introduce and use mft_compare_issued()

Newly issued manifests should not only have a higher manifestNumber,
their issuance time should also be later. Add corresponding checks
and warnings when comparing a newly fetched manifest to a manifest
from the cache.

ok job (who noticed that such a check was missing)


# 1.101 31-Jan-2024 tb

Rename mft_compare() to mft_compare_seqnum()

This makes it clearer what exactly this function compares. Also drop some
NULL checks that made the semantics of this function tricky.

ok job


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.100 11-Dec-2023 job

Log a warning when a manifest replay is detected

OK tb@ claudio@


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.99 13-Oct-2023 job

Allow imposing constraints on RPKI trust anchors

The ability to constrain a RPKI Trust Anchor's effective signing
authority to a limited set of Internet Number Resources allows
Relying Parties to enjoy the potential benefits of assuming trust,
within a bounded scope.

Some examples: ARIN does not support inter-RIR IPv6 transfers, so
it wouldn't make any sense to see a ROA subordinate to ARIN's trust
anchor covering RIPE-managed IPv6 space. Conversely, it wouldn't
make sense to observe a ROA covering ARIN-managed IPv6 space under
APNIC's, LACNIC's, or RIPE's trust anchor - even if a derived trust
arc (a cryptographically valid certificate path) existed. Along these
same lines, AFRINIC doesn't support inter-RIR transfers of any kind,
and none of the RIRs have authority over private resources like
10.0.0.0/8 and 2001:db8::/32.

For more background see:
https://datatracker.ietf.org/doc/draft-snijders-constraining-rpki-trust-anchors/
https://mailman.nanog.org/pipermail/nanog/2023-September/223354.html

With and OK tb@, OK claudio@


Revision tags: OPENBSD_7_4_BASE
# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.98 25-Sep-2023 tb

Pass the talid to various parse functions

This will be needed by an upcoming feature where we will need to know
what trust anchor a given cert chains to. This doesn't change anything
except the size of the diff.

ok claudio job


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.97 03-Sep-2023 job

Shuffle the order in which Manifest entries are processed

Previously work items were enqueued in the order the CA intended them
to appear on a Manifest. However, there is no obvious benefit to letting
third parties decide the order in which things are processed.

Instead, randomize: ordering has no meaning anyway, and the number of
concurrent repository synchronization operations is limited & timeboxed.
As they say, a fox is not taken twice in the same snare

OK tb@


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.96 29-Jun-2023 tb

Retire log.c

Convert all cryptowarnx() and cryptoerrx() to appropriate versions of
warn() and err{,x}(). Neither users nor developers benefit from them.
If we need better errors, we need to do some thinking. libcrypto won't
do that for us.

suggested by claudio
ok job


# 1.95 20-Jun-2023 job

Add compliance checks for the version, KU, and EKU of TAK/MFT/GBR EE certs

OK tb@


# 1.94 07-Jun-2023 job

In anticipation of a bump of the ASPA eContent profile version, update
valid_econtent_version() to allow for non-zero versions.

OK tb@


# 1.93 22-May-2023 tb

Convert generalizedtime_to_tm() to ASN1_TIME_to_tm()

Second step of moving away from ASN1_time_parse(). Being an OpenSSL API,
ASN1_TIME_to_tm() supports a variety of things. In this specific case we
don't really want it to parse anything but a GeneralizedTime expressed in
Zulu time. Unfortunately, OpenSSL make this annoying. So punt on this and
only do checks for the correct type and length. LibreSSL only accepts Zulu
time, so there is no change of behavior.

ok claudio job


# 1.92 22-May-2023 tb

Avoid use of LibreSSL-specific ASN1_time_tm_cmp() API

We convert these struct tm into time_t in the next few lines, so we can
simply use > instead.

ok claudio job


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.91 26-Apr-2023 claudio

Improve accounting by tracking things by repo and tal.
This fixes some wrong accounting for repositories that are referenced
from more than one TAL. It changes the ometric lable output a little bit
since there are repository metrics that no longer include the 'name' label.
OK tb@


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.90 24-Apr-2023 claudio

If the two mfts in mft_compare() are the same do not prefer the
first (DIR_VALID) but perfer the 2nd (DIR_TEMP) since this allows
rpki-client to move the equal files from .rrdp back into the valid
repo tree and so there are less unaccounted files for.
Problem noticed by and OK job@


Revision tags: OPENBSD_7_3_BASE
# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.89 13-Mar-2023 job

Check that the CMS signing-time is not after the MFT's nextUpdate

Issuing manifests whose validity window is entirely in the past, as
observed from the purported CMS signing-time would be a form of backdating.

OK tb@


# 1.88 13-Mar-2023 tb

Revert accidental change from explicit to implicit tagging in r1.86.

ok job


# 1.87 13-Mar-2023 job

Rename some data fields to closer match their provenance

OK tb@


# 1.86 12-Mar-2023 job

Refactor expiration calculation

Unify common code paths which find the exact expiry moment into a new
helper function. Additionally, the new helper offers more accuracy by
checking more applicable CRLs whether their 'nextupdate' is 'sooner'.

tb@ noted: The helper adds a multiplier of log(#crls), but that's
certainly acceptable as it is still very cheap.

OK tb@


# 1.85 12-Mar-2023 tb

Initialize the local signtime variable in the individual *_parse()
functions

ok job


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.84 09-Mar-2023 tb

Unwrap a few lines and zap a tab


# 1.83 09-Mar-2023 job

Show CMS signing-time signed attribute in filemode

OK tb@


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.82 01-Dec-2022 claudio

Adjust comment for rtype_from_mftfile(). It is important that RTYPE_INVALID
is not an error. It marks file as not handled by rpki-client and they will
be ignored after checking that the provided hash matches.
New file types should only be added once the needed code in parse_entity() is
available.
OK tb@ job@


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.81 30-Nov-2022 job

Remove unused ctype.h include

OK tb@


# 1.80 29-Nov-2022 job

Only include stdarg.h, if we call any of va_{start,end}()

OK tb@


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.79 26-Nov-2022 job

Add support for authenticating geofeed data CSV files in filemode

RFC 9092 describes a scheme in which an authenticator is appended to a
geofeed (RFC 8805) file. It is a digest of the main body of the file
signed by the private key of the relevant RPKI certificate for a covering
address range. The authenticator is a detached CMS signature.

with and OK tb@


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.78 07-Nov-2022 job

Simplify use of strrchr()

with and OK tb@


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.77 04-Nov-2022 job

Check the SIA signedObject in ROA/MFT/ASPA/TAK/GBR EE certificates

Unfortunately we can't yet error out when accessMethods other than
signedObject are encountered in the SubjectInformationAccess extension
because there is pollution in the ecosystem.

OK tb@


# 1.76 02-Nov-2022 job

Add support for draft-ietf-sidrops-signed-tal-12

Add support validation of Signed Objects containing Trust Anchor Keys
(TAKs - aka 'Signed TALs'). Signed TALs provide a mechanism for RIRs
to distribute and sign the next Trust Anchor with the current Trust
Anchor. This might be an improvement over visiting RIR websites and
copy+pasting TAL data by hand.

OK tb@


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.75 13-Oct-2022 job

All of ROA, MFT, ASPA, and RSC define their respective 'version' field
in ASN.1 as following: "version [0] INTEGER DEFAULT 0,". Each object
profile preamble contains "DEFINITIONS EXPLICIT TAGS ::=".

We didn't bump into any issue yet, because all Signed Objects are at
version 0, which means the field is entirely omitted (including the tag,
be it implicit or explicit). (From X.690 section 11.5: "The encoding of
a set value or a sequence value shall not include an encoding for any
component value which is equal to its default value.")

OK tb@


Revision tags: OPENBSD_7_2_BASE
# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.74 30-Aug-2022 job

Add support for ASPA objects (draft-ietf-sidrops-aspa-profile-10)

ASPA objects are published in the RPKI and can be used to detect and
mitigate BGP route leaks. Validated ASPA Payloads are visible through
filemode (-f) and the JSON output format (-j).

With feedback from tb@

OK claudio@ tb@


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.73 18-Aug-2022 job

Remove dangling ASPA references until we land real support

OK tb@


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.72 10-Jun-2022 tb

Unify error messages on d2i failure for econtent


# 1.71 10-Jun-2022 tb

Dedup econtent version checks

Since the ASN.1 template conversions, we have three copies of mostly dead
code that validates that the econtent version is at its default value 0.
Until a new standard bumps this version and we decide to support that,
we're better off with only one copy of this code.

ok claudio


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.70 01-Jun-2022 tb

Fix off-by-one in MAX_MANIFEST_ENTRIES check

ok claudio job


# 1.69 31-May-2022 tb

I made non-trivial contributions to these files.


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.68 23-May-2022 tb

Improve #ifdefs for STACK_OF() helpers.

Discussed with claudio


# 1.67 19-May-2022 tb

Adjust or remove some stale comments


# 1.66 19-May-2022 tb

Rewrite mft.c and roa.c with ASN.1 templates

The ASN.1 templates are a rather direct translation of the ASN.1 in the
relevant RFCs and they allow deserializing the Manifest and ROA eContent
in a single step instead of numerous opaque d2i_ASN1_SEQUENCE_ANY() calls.
Once the eContent is deserialized, we can walk the structs, validate it
as before and populate the internal data structures.

Positive feedback job
ok claudio


# 1.65 15-May-2022 deraadt

whitespace spotted during read-thru


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.64 11-May-2022 job

Verify MFT and GBR objects only carry RFC 3779 extensions set to 'inherit'

OK claudio@ tb@


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.63 10-May-2022 tb

Validate RSC filenames

Factor out POSIX portable filename check into a new valid_filename() and
rename the previous valid_filename() to valid_mft_filename(). Fixes and
supersedes imcomplete checks in the RSC code. Avoids truncation via
strndup() in case of embedded NULs.

input/ok claudio


# 1.62 10-May-2022 job

Improve control flow readability by removing 'else if' stanzas

OK tb@ claudio@


# 1.61 09-May-2022 job

Add preliminary support for decoding RSC objects in filemode

This implements decoding support for draft-ietf-sidrops-rpki-rsc-06

There are three major outstanding issues:

* The wire image might still change to conform to the more widely deployed
3779 API in libressl/openssl. IETF discussion ongoing.
* Whether the resources listed in the ResourceBlock are contained within
the EE's RFC 3779 extension is not hooked up yet.
* There is a fair bit of duplicity between rsc.c and cert.c, look for XXX

OK tb@


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.60 20-Apr-2022 job

Add Concatenated JSON output in filemode (rpki-client -j -f *)

The schema is still work in progress.

OK claudio@


# 1.59 19-Apr-2022 tb

Avoid leaking crldp in mft_parse() if one of the crlfile checks fails.

ok claudio


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.58 19-Apr-2022 claudio

Adjust on how CRL and MFT files are verified.

Verify the CRL referenced from the mft against the mft's fileAndHash info.
If the CRL matches then load it and use it to validate this mft. If the
mft validated OK add the now also valid CRL to the auth store for later use.

Before the newest CRL was always selected but that has negative consequences
because it is common practice to revoke the previous MFT's EE cert and with
that the cache is turned useless as soon as a new CRL is used. Also there
was a possibility that the CRL used for validation of the MFT was not the
one later used.

Both RFC6486 and draft-ietf-sidrops-6486bis are unclear about this part
of the validation process. We opted in favor of the chached MFT.

With and OK tb@


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.57 11-Apr-2022 claudio

Sort RTYPE in case alphabetically and mention ASPA in the comment.
No functional change.


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_7_1_BASE
# 1.56 08-Apr-2022 claudio

All times in the x509 are UTC so use timegm() and not mktime().
The latter will apply the timezone offset and so the further west
the more probable you are to have problems with valid_from times.
Fix from tb@
OK job@, benno@ and me


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.55 01-Apr-2022 claudio

Change x509_get_aki(), x509_get_ski(), x509_get_aia(), and x509_get_crl()
to work more like x509_get_expire(). They will return an error if the
extension extraction failed but not if it was not present. The callers
must now do that check but most did already.
With this cert_parse_inner() no longer cares about TA vs non-TA certs.
Feedback and OK tb@


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.54 31-Mar-2022 job

Sync & permit ASPA objects to appear on Manifests

OK tb@ claudio@


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.53 10-Feb-2022 claudio

Fix serial number printing in crl_print() for large serials.
Create a common x509_convert_seqnum() function to convert the various
ASN1_INTEGERs into hexnumbers and use this for mft and crl handling.
With and OK tb@, also OK job@


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.52 28-Jan-2022 claudio

Properly handle .mft files as intended by the RFC. Instead of always
selecting the newest file this opens both the new (from rrdp or rsync)
and old (valid) MFT. It then compares the manifest number and based on
that the 'newer' MFT is selected.
The MFT file and hash check is also changed to always try both locations
and selecting whatever matches up with the hash. The selction is passed
back to the the main process and used later on to open exactly the same
file as was checked against the hash.
The MFT parsing code has been split up into multiple steps so that the
files can be parsed, compared and then fully validated.
In most cases this makes no difference but it prevents replay attacks
using old but still valid files.
With and OK tb@


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.51 24-Jan-2022 claudio

Adjust code to handle unsupported file types a bit more graceful.
The file still needs to match its hash to make the MFT valid but then
there will only be a warning printed. Parsing of other files from that
MFT are not influenced.
OK tb@


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.50 22-Jan-2022 tb

Change valid_filename() ot return an enum rtype and rename it to
rtype_from_mftfile(). Move both rtype_from functions to mft.c.

ok beck claudio


# 1.49 21-Jan-2022 tb

Add function to determine the file type from the file name extension

rpki-client uses the same idiom to determine the file type in too many
places. Use one function that determines the appropriate RTYPE from the
file name. Add that type to struct mftfile and use this new member to
simplify queue_add_from_mft*().

input/ok claudio


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.48 18-Jan-2022 claudio

Revert all the files that should have not been committed in last commit.


# 1.47 18-Jan-2022 claudio

Kill extra newline


# 1.46 18-Jan-2022 claudio

Cleanup the scattered OBJ_txt2obj() calls and move them into
x509_init_oid() to initalize all necessary OID objects at start.
OK tb@


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.45 13-Jan-2022 claudio

Alter valid_filehash() to take a file descriptor instead of a path.
This is needed so that callers can allow a file to be in multiple
locations. Also move mft_check() from mft.c to parser.c.
OK tb@


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.44 11-Jan-2022 claudio

Change the way the parser accesses files. It now builds the file path
based on information from the repository, a local path and the filename.
This simplifies some code both in the main process and the parser.
For this to work repositories are passed to the parser before any other
entity of this repository is passed. Struct entity is extended to include
the repoid and the path along the file(name).
Input and OK tb@ & job@


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.43 06-Jan-2022 claudio

Cleanup mft file handling, especially the stale mft bits.
Move staleness check up into mft_parse_econtent() to simplify code.
Remove the big FIXME bits since they are no longer needed. The parent
process will only process MFTs that are not stale.
Cleanup a few other bits mainly unneccessary else if cascades and
use valid_filename() to check if the filename embedded in the mft
fileandhash is sensible.
OK tb@


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

branches: 1.38.4;
Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

branches: 1.32.2;
Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.42 28-Oct-2021 job

Limit how many FileAndHash entries a single manifest may contain

OK claudio@


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.41 26-Oct-2021 claudio

Change CMS and CRL d2i functions from their BIO version to passing the
der buffer instead. The file are loaded early in the entity processing
loop.
OK tb@


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.40 24-Oct-2021 job

Restrict the characterset for filenames on Manifests

feedback from benno@

OK claudio@


# 1.39 23-Oct-2021 claudio

Finnally move away from blocking reads in rpki-client. The code was a
mish mash of poll, non-blocking writes and blocking reads. Using the
introduced ibuf size header in io_buf_new()/io_buf_close() the read
side can be changed to pull in a full ibuf and only start the un-marshal
once all data has been read.
OK benno@


Revision tags: OPENBSD_7_0_BASE
# 1.38 09-Sep-2021 claudio

Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.38 09-Sep-2021 claudio

Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.38 09-Sep-2021 claudio

Rework how various OIDs are compared in the code.

Instead of converting the ASN1_OBJECT into a string and comparing the
strings, convert the string into an ASN1_OBJECT once and then compare
these objects with OBJ_cmp().

Makes the code a bit easier to read and removes some repetitive conversions.
With input and OK tb@


# 1.37 08-Sep-2021 claudio

The number of elements being processed is known upfront. So allocate the
storage needed outside of the loop. This reduces the number of recallocarray
calls.
OK tb@


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.36 13-Jul-2021 job

Add more checks for eContent 'version' fields.

Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.35 14-Jun-2021 job

Fix ROA & MFT version check handling

This check was incomplete: to correctly verify the ASN1 INTEGER holding
the version component, first the context specific explicit tag would need
to be checked.

However, the X.690 spec (section 11.5) states that if the one should not
encode a component if it is the default value. There are no RFCs specifying
new versions of ROA or MFT, so checking the content of the version component
should be skipped entirely.

Thus if the version component is present, something is wrong.


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.34 11-May-2021 claudio

Before calling ASN1_time_parse() initialize the struct tm. While
recent libressl version initalise the struct tm properly older
versions did not and so -portable runs into problem on systems
with older libressl versions installed.
Problem found by job@
OK tb@


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.33 09-May-2021 tb

Garbage collect sz in mft_parse_filehash() which has been unused
since mft.c r1.20.


Revision tags: OPENBSD_6_9_BASE
# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.32 29-Mar-2021 tb

Inline x509_get_extensions() and remove it

Since aia, aki and ski are all represented by char *, this is an
error-prone interface - as found by job. The function doesn't do
much anyway.

ok claudio


# 1.31 28-Mar-2021 job

Add some restrictions to manifest object profile

OK tb@, feedback from claudio@


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.30 27-Mar-2021 job

Send arguments in alphabetical order

OK tb@


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.29 05-Mar-2021 claudio

Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.28 04-Mar-2021 claudio

Use the same way to error out in out of memory situation.
Just use 'err(1, NULL);' there is no need to include the type of function
that failed since it is still impossible to locate the right call.
Just use a debugger in that case.
OK tb@ deraadt@


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.27 19-Feb-2021 tb

Convert reallocarray + memset to recallocarray.

ok claudio


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.26 16-Feb-2021 job

get Authority Information Access (AIA) from CA & EE certs

In the context of the RPKI, the AIA extension identifies the publication
point of the certificate of the issuer of the certificate in which the
extension appears. A single reference to the publication point of the
immediate superior certificate MUST be present, except for a
"self-signed" certificate.

Thanks tb@ for review

OK claudio@


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.25 04-Feb-2021 claudio

Eventhough most openssl includes include everything try to be a bit more
explicit about what is used where. Seems to be the least worst solution.


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.24 29-Jan-2021 claudio

A while ago rpki-client was changed to validate the sha256 hashes of
files referenced in MFT files during the validation of the MFT file.
An MFT is only valid if all files are present and their hashes are valid.
Because of this there is no longer the need to check the hash when
these files are parsed later on. Remove these checks for CRT, ROA and CRL
files. Use the presence of the pkey when parsing cert files to decide
if it is a root cert or not.
OK tb@


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.23 08-Jan-2021 claudio

Start using the ibuf API (ibuf_dynamic, ibuf_add, ibuf_close) for writing
data between processes. This completely decouples the write side.
rpki-client can't really use the imsg framework but it can use the ibuf
bits wich imsg is built on.
OK benno@ job@


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.22 21-Dec-2020 claudio

Now that a NULL string is marshalled as NULL again we can drop some
extra has_xyz integers to indicate if the following buffer is present
or not. At the same time sprinkle some asserts for strings which must
be not NULL.
OK tb@


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.21 18-Dec-2020 claudio

Use asprintf with %.*s to construct the path based on the mft file
location and the filename of the referenced file. Use the same method
both in main.c and mft.c which is a fair bit simpler than using calloc
and strlcpy/strlcat to build the string by hand.
OK tb@


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.20 09-Dec-2020 claudio

All files provided in a manifest needs to be checked against the provided
hash even if rpki-client ignores this file later on.
OK job@


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

branches: 1.16.4;
Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

branches: 1.14.4;
Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.19 06-Nov-2020 tb

Treat stale manifests as such, not as 'failed to parse'

There is currently dead code in mft_parse() that handles stale
manifests by setting the stale flag and removing all files they
reference. This code was made unreachable in a refactor that
fixed a logic error that made mft_parse() succeed despite its
error handling. check_validity() returns three possible values.
Report failures and stale mfts back immediately via rc. Success
needs to reset rc to -1, so subsequent errors are reported as
such.

This is mostly cosmetic and only changes the rpki-client output
in that the comment at the top of the config now actually shows
stale manifests. This makes regress pass again.

ok claudio job


# 1.18 05-Nov-2020 tb

typo


# 1.17 05-Nov-2020 tb

Fix checks for manifest validity interval

The check_validity() function used the X509_cmp_time() functions with
GeneralizedTime. This doesn't work with current dates since LibreSSL
enforces conformance with RFC 5280 in X509_cmp_time(), which requires
that dates before 2050 are represented with UTCTime. The functions
would return an error, but missing error checking led to failing to
detect expired or not yet valid manifests. Fix this by converting the
dates into struct tm and using ASN1_time_tm_cmp() instead.

With input from claudio, jsing

ok benno claudio jsing


Revision tags: OPENBSD_6_8_BASE
# 1.16 12-Sep-2020 claudio

Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.16 12-Sep-2020 claudio

Include openssl/x509.h in extern.h since it uses a few of the typedefs from
there in structs and prototypes. Remove the openssl/ssl.h and other strange
openssl includes in the .c files that don't use openssl specific functions.
OK beck@ and tb@


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.15 30-Jun-2020 job

Remove -f (force) option.

The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@


Revision tags: OPENBSD_6_7_BASE
# 1.14 11-Apr-2020 deraadt

Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.14 11-Apr-2020 deraadt

Avoid using libc SHA256File(), just perform the operation inline to
make things easier for -portable
ok claudio


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.13 01-Apr-2020 claudio

Split the mft file and hash check from the mft parsing. This makes it easier
to check all files in a mft before failing and also the check is now done
after the embedded cert was checked.
This refactor was triggered because of a bug in mft_parse_econtent().
check_validity() altered rc but later failure code assumed that goto out
is good enough to return an error (rc == -1) but since rc was 1 success
was returned. This bug is now also fixed.
Bug report and OK job@


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.12 30-Mar-2020 claudio

Delay failure in mft parsing until all elements of FileAndHash have been
checked. This way all corrupted or missing files should show up in a
single run. This should help operators to get a better idea what and how
much is broken.
OK benno@


# 1.11 30-Mar-2020 claudio

Check the hash and with it the presence of a file referenced in a MFT early
on. In case the file hash does not match or the file does not exist the full
MFT is considered invalid and dropped. With this partial ROA updates based
on a corrupt data set will produce less likely inconsistencies in the VRP
output.
With and OK job@


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.10 29-Nov-2019 benno

The code is more what you'd call 'guidelines' than actual rules.
s/EXIT_FAILURE/1/
ok claudio@


# 1.9 28-Nov-2019 benno

enable more warning flags and fix a few issues noticed.
ok claudio@ deraadt@


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.8 23-Oct-2019 claudio

Rewrite the time validity check for mfts. Using ASN1_GENERALIZEDTIME_print
and strptime to convert the timestamp does not correctly account for the
timezone. Instead use X509_cmp_time which later on should be replaced with
ASN1_time_tm_cmp since the ASN1_STRING_cmp() check at the end will fail
around 2049.

Problem with timezone reported by Alexandre Hamada (hamada at registro.br).
He also tested this diff.
OK tb@


Revision tags: OPENBSD_6_6_BASE
# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.7 13-Aug-2019 claudio

Show the most common warnings only if verbose is set. Most of these warnings
were shown because of an inconsistent rpki database and is no real problem.
OK florian@


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.6 20-Jun-2019 claudio

Those changes should not have been in last commit. Revert them for now.


# 1.5 20-Jun-2019 claudio

Don't use assert to validate user input. assert() is not for that, instead
check and error out like it is done one other parsing issues.
Agreed by deraadt@
Fixes another afl "crash" found by jsg@


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.4 19-Jun-2019 deraadt

use $OpenBSD$ headers


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.3 19-Jun-2019 deraadt

indentation adjustments, in particular near warn statements
ok claudio


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision


# 1.2 17-Jun-2019 deraadt

Don't do -portable in base. It is better done outside the tree.
Imagine if we did it throughout the tree, how many copies of strlcpy
would we have, and how much time would all the configure shell scripts
and includes take? It would be ludicrous.


# 1.1 17-Jun-2019 job

branches: 1.1.1;
Initial revision