1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00
Commit Graph

234 Commits

Author SHA1 Message Date
claudio
1aea4e0e02 Limit the size of the base64 blob inside the RRDP XML to be less than
MAX_FILE_SIZE after base64 decoding it. This way hostile RRDP servers
do less damage.
OK beck@ tb@
2021-10-28 11:57:00 +00:00
beck
61c641a85a Don't exit in certain cases on failures to parse x509 objects.
In most cases we already warn and continue if someone sends us malformed
x509 objects. This makes this consistent behaviour in all places
so that if someone passes in bogus X509, We end up failing their entry
and continuing rather than exiting.

We still exit on memory/system failures so that a future run of rpki
client can simply do better when the machine is perhaps less hammered
on

ok job@ claudio@
2021-10-28 09:02:19 +00:00
beck
1c69962622 Add limits on size of certain untrusted inputs
ok job@
2021-10-27 21:56:58 +00:00
claudio
2cfd2d3bd9 Move load_file() to encoding.c so that regress can use the function. 2021-10-26 16:59:19 +00:00
claudio
41edc6705a Refactor the tal parsing code to use the same load_file() and buffer
passing as done for the other parsers.
OK job@ tb@
2021-10-26 16:12:54 +00:00
claudio
803d3b9acd Also move the cert parser code away from using BIO.
OK beck@
2021-10-26 13:31:05 +00:00
claudio
cabf3a3b92 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@
2021-10-26 10:52:49 +00:00
claudio
714f4e3f5f Move the various print functions from the regress tests into print.c.
OK tb@
2021-10-24 17:53:07 +00:00
job
dbcbf67572 Restrict the characterset for filenames on Manifests
feedback from benno@

OK claudio@
2021-10-24 12:06:16 +00:00
claudio
25f7afeed8 Rename io_buf_new to io_new_buffer and io_buf_close to io_close_buffer.
With this the write functions are all of the form io_xyz_buffer.
Remove some prototypes of functions I forgot to remove in previous commit.
OK benno@
2021-10-23 20:01:16 +00:00
claudio
7eb79a4a63 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@
2021-10-23 16:06:04 +00:00
claudio
2defcb5299 First step of cleanup in the io land. Introduce io_buf_new() and
io_buf_close(). These function will inject a size of the the buffer
at the beginning of the buffer and will allow the read size to be
switched to proper async IO.
OK benno@
2021-10-22 11:13:06 +00:00
job
17304ed1d4 Emit SKI in the JSON output and improve flow in x509_get_pubkey()
OK claudio@
2021-10-12 15:16:45 +00:00
job
6b83d8e365 Add support for BGPsec Router Certificates (RFC 8209)
BGPsec router keys are extracted from RPKI certificates and
emitted via the JSON output in base64 encoded form.

OK tb@ claudio@
2021-10-11 16:50:03 +00:00
job
dc8afe7e46 Make style consistent and remove an unused code path
OK tb@
2021-10-10 21:57:43 +00:00
claudio
7fd566d895 Add x509_get_expire() to extract the not-after time from a certificate
as a epoch time_t. Store the expire time for certs, crls will follow after.
OK tb@
2021-10-07 08:30:39 +00:00
job
fdfddccf0d Add rudimentary support for BGPsec router certificates
OK claudio@
2021-10-05 11:20:46 +00:00
claudio
d2e465bb28 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@
2021-09-09 14:15:49 +00:00
claudio
6f704872d7 Add http_proxy support to rpki-client's http handler.
OK tb@
2021-09-01 08:09:41 +00:00
job
59470c3fe1 Add more checks for eContent 'version' fields.
Input from deraadt@, tb@, claudio@

OK deraadt@ claudio@ tb@
2021-07-13 18:39:39 +00:00
job
a66158d7f8 Add an 'expires' column to CSV & JSON output
The 'expires' value contains a reasonable earliest moment a VRP would expire,
in light of the currently available set of CAs and CRLs. The 'expires' value
can be used to avoid route selection based on stale data when generating VRP
sets, when faced with loss of communication between consumer and valdiator,
or validator and CA repository.

OK claudio@
2021-05-06 17:03:57 +00:00
benno
0bef1a86f2 move the RPKI_VERSION define into its own version.h file, helps portable.
ok claudio@
2021-04-14 18:05:47 +00:00
claudio
8ecbadc116 Initial commit of RRDP (The RPKI Repository Delta Protocol - RFC8182) support
in rpki-client. For now it is off by default.

All XML processing is done in its own process with minimal pledge rights.
It uses the already present https process to fetch the xml files and uses
the master porcess to handle the file IO into the repositories.
RRDP data is stored in the cache under ./rrdp/ and the first directory
is the SHA256 hash of the notify URI.

Fetching snapshots and deltas works to bring the cache up to date.
If something goes wrong rpki-client will fall back to rsync.

RRDP was implemented by Nils Fisher and integrated into rpki-client by myself.
"Time to get it in" deraadt@
2021-04-01 16:04:48 +00:00
claudio
155f32c368 Do a better job at cleaning up. Remove empty directories, scan not only the
known repositories but also clean up no longer known repositories.
With this rpki-client keeps its cache nice and shiny.
With and OK job@
2021-04-01 06:53:49 +00:00
claudio
087c464339 Move base64 and hex encoding functions into their own place.
OK tb@
2021-04-01 06:43:23 +00:00
claudio
1a998f47f2 Introduce hex_encode() to transform the aki/ski values to a string.
OK tb@
2021-03-29 12:41:34 +00:00
tb
1f25fa5db5 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
2021-03-29 06:50:44 +00:00
job
ab5c69fdbf Add some restrictions to manifest object profile
OK tb@, feedback from claudio@
2021-03-28 16:22:17 +00:00
claudio
09b708f572 Adjust HTTP client code a bit. Add support for 304 Not Modified responses,
remove handling of 206 Partial Content (the client does not use range
headers). Report the Last-Modified timestamp back to the requestor and
switch OK to a enum value for (FAIL, OK and NOT MODIFIED).
OK tb@
2021-03-25 12:18:45 +00:00
claudio
c4f4bcd576 Add an -V option to show the version of rpki-client. For the base version
it will show just OpenBSD while -portable will show the portable version.
OK sthen@, tb@, kn@
2021-03-19 13:56:10 +00:00
claudio
8a3c435df6 Since the entity queues are per repo there is no need to store the repo id
anymore.
OK job@ tb@
2021-03-18 14:03:42 +00:00
claudio
8c2eb28888 Factor out the URI check we do in various places into valid_uri().
RRDP will add a bunch more checks so this makes even more sense.
With and OK tb@
2021-03-05 17:15:19 +00:00
claudio
67d45509f5 Factor out the SHA256 hash checks into valid_filehash() so that it can
be used by the RRDP code as well.
OK tb@
2021-03-05 16:00:00 +00:00
claudio
542b31bb4e Remove space at end of line 2021-03-05 12:33:19 +00:00
claudio
1ef5b48a83 Implement a https client as a sub-process for rpki-client. This code will
be used to fetch TA certs and later on for RRDP. Kind of unreached for now
since the default TAL files don't include https URI.
The http client is fully asynchronous and can handle multiple downloads at
the same time. This code was based on the http client in ftp(1).
OK tb@, job@
2021-03-04 13:01:41 +00:00
claudio
809b75d378 There is no longer the need to mkpathat(), the main process runs now from
the cachedir.
2021-03-02 09:23:59 +00:00
claudio
b015ea5655 Open both the cachedir and outputdir early and use fchdir(2) to
switch between the two.
OK deraadt@ job@
2021-03-02 09:08:59 +00:00
claudio
e57cd5ae85 Rename mkpath() to mkpathat() since it uses mkdirat() internally. 2021-02-22 09:46:05 +00:00
claudio
a0dad60592 Move the mkpath() call from the rsync path to the main process. This allows
to drop cpath from the rsync proc pledge (down to "stdio proc exec").
This will also make work easier with the upcoming http fetcher.
OK tb@
2021-02-19 08:14:49 +00:00
claudio
356f9aec6f Use X509_get_ext_d2i() also for x509_get_aki() and x509_get_ski().
Now x509_get_extensions() is no longer required to loop over all
extensions and the code becomes a lot simpler.
While there cleanup x509_get_crl(), as explained by tb@ X509_get_ext_d2i()
allocates memory so one needs to free the pointer at the end.
For x509_crl_get_aki() use X509_CRL_get_ext_d2i() and more or less
copy the rest over from x509_get_aki().
Warn if extensions are missing or present when not expected and also
check the the extensions are marked non-critical as required.
OK job@ tb@
2021-02-18 16:23:17 +00:00
claudio
402543e655 Rework the repository handling. Split the handling of trust anchors into
ta_lookup() while regular repositories (to fetch .mft files) are handled
by repo_lookup(). Also the cache directory layout changed; moving the
trust anchors to ./ta/{tal basename}/ the other repositories end up in
./rsync/
OK tb@
2021-02-16 08:52:00 +00:00
job
ebd5581623 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@
2021-02-16 07:58:30 +00:00
claudio
84c20e473c Extract the 1.3.6.1.5.5.7.48.5 (caRepository) SIA from the certificate.
Make sure that the caRepository matches the start of the URI of rpkiManifest.
The MFT must be a file inside the caRepository.
OK tb@
2021-02-08 09:22:53 +00:00
claudio
82d296570e The uri parameter of struct entity is actually a local file path.
Rename field to reduce confusion about what is what.
OK tb@
2021-02-04 14:32:01 +00:00
claudio
eae583789f Shuffle code around, move all the bits of proc_parser into parser.c.
OK tb@
2021-02-04 08:10:24 +00:00
claudio
61aab7a055 Add a mkpath() helper function to rpki-client to recursively create
directories.
OK deraadt@
2021-02-02 18:33:11 +00:00
claudio
fc5c0efe76 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@
2021-01-29 10:13:16 +00:00
claudio
08db11772c 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@
2021-01-08 08:09:07 +00:00
claudio
4be5941a58 Validate ghostbuster records (RFC 6493) but for now do nothing with the
provided vcard payload. This change verifies the certificate of the .gbr
file and makes sure it is valid (like we do for e.g. .roa files).
OK job@
2020-12-09 11:29:04 +00:00
claudio
26b5971f17 Remove the last users of io_*_write functions that call io_simple_write()
internally. This is a step in direction of more async aware io in rpki-client.
Now everything uses a buffer which is then written.
OK tb@
2020-12-02 15:31:15 +00:00
claudio
0102fb1b97 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@
2020-09-12 15:46:48 +00:00
claudio
cfc09c7b83 Move the proc_rsync and with that the rsync processing into rsync.c
main.c is too crowded
OK deraadt@
2020-09-12 10:02:01 +00:00
claudio
3d81c3df19 One tiny step towards adding RRDP support in rpki-client.
Extract the notify URL from the cert if it is available and pass it back to
the parent process. The parent process can then use this info to load the
repo via RRDP instead of rsync.
OK benno@ (some long time ago)
2020-07-28 07:35:04 +00:00
job
91da860ac5 Remove -f (force) option.
The -f option existed for some initial debugging work.

Thanks Weerd for review

OK claudio@
2020-06-30 12:52:44 +00:00
claudio
74f3d1527d Stop using rsync --delete when syncing up with the CA repos. Instead
use the files referenced in the manifests to build up a list of files
to keep and remove anything that is not in the list after doing the
full computation.
OK job@ benno@
2020-06-24 14:39:21 +00:00
deraadt
b0404f1fdb Place elapsed, user, and system time for processing in the comment headers.
ok job benno claudio
2020-04-30 13:46:39 +00:00
deraadt
0ee5ab88e4 Print statistics as comments at the top of the files which can take
comments.
ok claudio job
2020-04-28 13:41:35 +00:00
claudio
630e12ade6 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@
2020-04-01 14:15:49 +00:00
jca
bfe2257568 Narrow the visibility of some functions and variables local to output.c
Also make the outputs table const.
Based on a suggestion from claudio@, ok deraadt@ claudio@
2020-03-10 14:22:26 +00:00
jca
70ba94e50d Ensure that we properly flush, close and rename temporary output files
Makes sure we don't feed an incomplete/garbage file to consumers.
Input and ok claudio@ deraadt@
2020-03-09 23:50:01 +00:00
benno
2e60d9e89d generate 3 different outputs for BIRD:
- bird v1 with IPv4 routes
- bird v1 with IPv6 routes
- bird v2
when using command line option -B.
BIRD v2 output from Robert Scheck, robert AT fedoraproject DOT org
time_t cast hint from jca@, and tested by job@
ok deraadt@ claudio@
2020-03-06 17:36:42 +00:00
claudio
5b613a61b6 Don't hardcode the cache directory for rpki-client. If started as root
rpki-client will use the defaults for cache and output directory. If not
started as root users need to provide both directories as arguments.
While there switch from absolute path names to relative ones. For this
the parser and rsync process do a chdir(2) to the cache directory on startup.
OK benno@
2019-12-06 09:27:12 +00:00
deraadt
1f9a8b9481 split output management code into seperate file. iterate over output
methods using a table.  detect output truncation (for instance filesystem
full) and don't overwrite previous output
ok claudio
2019-12-04 12:40:17 +00:00
deraadt
747ff6ba73 output_createtmp() remembers the true name, so output_finish() does not
need to replay it.
2019-12-02 02:11:13 +00:00
deraadt
ed26e04b57 Tweak rpki-client to create all 4 output file formats from a single
compute, based upon flags.  OpenBGPD compatible format by default if
no options, to integrate with bgpd.conf and bgpctl reload.  Adapt
mtree and stuff.  This will receive further refactoring...
ok benno job
2019-11-30 02:31:12 +00:00
claudio
e669621f7c Use the AKI embedded in the CRL to store the crls. This way the AKI from
the cert can be used to load the correct CRL. This simplifies the code
even further.
OK benno@, beck@ agrees that this is the right way to do it
2019-11-29 04:40:04 +00:00
deraadt
43dfc6a83c If run as root, priv-drop to _rpki-client.
If no output file is specified, output to the bgpd/bgpd.conf-compatible
/var/db/rpki-client/roa file.
ok claudio and benno
2019-11-29 04:04:08 +00:00
claudio
a079bbf85d Convert the auths array into an RB tree indexed by SKI. For fast lookups
the parent auth struct is stored as a pointer so walking up the certificate
chain remains simple. Doing this replaces a few slow lookups and speeds up
rpki-client by a factor of 2.
OK benno@
2019-11-28 20:36:17 +00:00
deraadt
4cefd9474e Output to a temporary file, which gets renamed on success. This will
work much better with bgpd.conf include automation.
ok claudio benno
2019-11-28 20:23:09 +00:00
benno
51b3988bb8 To verify a manifest, a roa, or a certificate, we check its signature
against the CA one layer above it. This check just needs to use the
certificate revocation list published by that CA.

Instead of loading all CRLs we find into the trust store, we create a
STACK_OF(X509_CRL), push the onto it and use it with
X509_STORE_CTX_set0_crls(ctx, crls);

The x509_get_crl() function to retrieve a crl path from an X509 object
is written by claudio@.
ok claudio@
2019-11-28 03:22:59 +00:00
benno
4f1d433364 whitespace 2019-11-27 17:14:20 +00:00
benno
730721603a Only store ta certs in the trust store and build chains of the
intermediate certificates for use in X509_STORE_CTX_init(). To do that
save the X509 cert in struct cert.
claudio sees > 2x speed increase.

ok claudio@ and feedback from jsing@ and beck@.
2019-11-27 17:08:12 +00:00
benno
cbcd0d1ab6 knf, make types grepable. ok claudio@ 2019-11-27 04:32:09 +00:00
claudio
6a48a44272 Refactor tal code a bit. Move the file reader back into tal.c so that the
regress test is able to use it.
OK deraadt@
2019-11-04 09:35:43 +00:00
claudio
397f8a58d6 Handle the TAL files in the master process and pass them as buffer to the
parser process. This way the parser never needs to read outside of the
cache directory which makes the unveil simpler. Additionally rsync_uri_parse
no longer needs to know about .tal files so there is now no chance to sneak
in a .tal file later on.
OK deraadt@
2019-10-31 08:36:43 +00:00
claudio
5a1f8137e2 Add an output format for bird and one doing CSV. Also update the manpage
to include all the changes.
2019-10-16 17:43:29 +00:00
claudio
a382efa298 Rewrite the output handling of rpki-client and add an option to dump the
data in JSON format. To make the JSON output the same as the output of the
RIPE rpki-validator the basename of the TAL had to be added and passed around
in rpki-client. Additinally the VRPs are now stored in an RB tree in the
main process instead of keeping them per ROA object. This changes the sort
order to be in network order and no longer just lexographical.
Agreed by job@ deraadt@
2019-10-08 10:04:36 +00:00
claudio
2d3101137f Change the arguments to rpki-client a bit. Instead of listing all TAL files
as arguments rpki-client will now load the TAL installed in /etc/rpki by
default. For debug reasons an option -t tal is added to pass in TAL files
by hand. The argument is now instead the filename of the output file.
Now `rpki-client roa.conf` will do what you need which is a lot nicer.
Agreed by deraadt@ job@ to be a step in the right direction.
2019-08-20 16:01:52 +00:00
claudio
8825d98844 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@
2019-08-13 13:27:26 +00:00
deraadt
23c49d5288 use $OpenBSD$ headers 2019-06-19 16:30:36 +00:00
claudio
22bf19692e Instead of the strange ASN.1 encoding of IP addresses with a size in bytes
and a count of how many bits of the last byte are unused switch to a much
more normal prefixlen in bits encoding for internal use. This makes the
code easier to understand. Also switch to inet_ntop() for converting a
struct ip_addr into a string.
OK job@
2019-06-19 15:47:34 +00:00
deraadt
80272c4992 indentation adjustments, in particular near warn statements
ok claudio
2019-06-19 04:21:43 +00:00
deraadt
e1e433b451 This portable code knocking out pledge or unveil is better done
as a C stub, rather than #define.
Anyways, this "-portable by default" approach is not the OpenBSD way.
2019-06-17 15:02:39 +00:00
job
9a7e9e7f88 ../../../logmessage 2019-06-17 14:31:30 +00:00