]> git.ipfire.org Git - thirdparty/FORT-validator.git/log
thirdparty/FORT-validator.git
2 years agoEnsure X509 extensions are hashed & cached, before deciding a cert is CA or EE 88/head
Job Snijders [Sat, 21 Jan 2023 11:43:02 +0000 (11:43 +0000)] 
Ensure X509 extensions are hashed & cached, before deciding a cert is CA or EE

If X509_check_ca() fails to cache X509v3 extension values, the return
value may be incorrect, leading to erroneously assuming a given certificate
is a CA or EE cert (while in reality it is the other, or neither).

This failure mode can arise because X509_check_ca() doesn't verify
whether libcrypto's (void)x509v3_cache_extensions(x) flipped the EXFLAG_INVALID
flag in x->ex_flags. Unfortunately, X509_check_ca() doesn't have a return code
to indicate an error, so this can't be fixed in libcrypto - the API is broken.

The workaround is to call X509_check_purpose(3) with a purpose argument of -1,
before calling X509_check_ca(), this ensures the X509v3 extensions are cached.
Since X509_check_purpose() does have a return code to indicate errors, we can
use that to supplement X509_check_ca()'s shortcomings.

OpenBSD's rpki-client also uses the above approach.

2 years agoRemove traces of the master branch from the doc
Alberto Leiva Popper [Wed, 28 Dec 2022 23:15:37 +0000 (17:15 -0600)] 
Remove traces of the master branch from the doc

The "master" branch was renamed to "main" a short while ago.

2 years agoCompile backtrace out if unavailable on system
Alberto Leiva Popper [Wed, 28 Dec 2022 22:12:45 +0000 (16:12 -0600)] 
Compile backtrace out if unavailable on system

backtrace() is a glibc-only feature. Some systems, such as Alpine,
do not support glibc.

It seems one solution is to rely on community ports, but I imagine it'd
be best to offload such a decision to the user. Not the safest.

Instead, if backtrace() is not available, just delete stack traces from
the binary. It's going to be a pain to debug, but that's the world we
live in, I guess.

Turns libexec into an optional dependency. Fixes #87.

Also, the commit contains a review and update of the documentation's
Alpine dependency list. There was a lot of fat in there.

2 years agoProtocolary updates for release 1.5.4
Alberto Leiva Popper [Tue, 13 Dec 2022 20:47:37 +0000 (14:47 -0600)] 
Protocolary updates for release 1.5.4

2 years agoMerge branch 'imgbot'
Alberto Leiva Popper [Tue, 13 Dec 2022 18:49:45 +0000 (12:49 -0600)] 
Merge branch 'imgbot'

2 years agoCertificate: Remove subject name uniqueness validation
Alberto Leiva Popper [Tue, 22 Nov 2022 18:14:34 +0000 (12:14 -0600)] 
Certificate: Remove subject name uniqueness validation

RFC 6487:

> An issuer SHOULD use a different subject name if the subject's key
> pair has changed (i.e., when the CA issues a certificate as part of
> re-keying the subject.)

Fort's implementation was problematic. The code was comparing the
certificate's subject name and public key to siblings that had
potentially not been validated yet. It seems to me this would make it
possible for attackers to crash FORT (by posting invalid objects) or to
invalidate legitimate objects (by publishing siblings that contained
conflicting subject names and public keys, without having to worry about
the rest of the fields).

This would be somewhat difficult o fix. I asked on the mailing list and
Discord ("RPKI Community"), and it seems the concensus is "don't
validate it." Subject Names don't really matter that much, because
RPKI's primary concern is resource ownership, not identity. Furthermore,
I'm not convinced that chopping off branches off the tree because of a
clumsy key rollover is a good idea.

https://mailarchive.ietf.org/arch/msg/sidrops/mXWbCwh6RO8pAtt7N30Q9m6jUws/

Manually cherry-picked from 0a6a80b558e12304ba0e68c021848e292bfe3ce6.

Hopefully f1xes #86.

2 years ago[ImgBot] Optimize images
ImgBotApp [Fri, 4 Nov 2022 18:11:35 +0000 (18:11 +0000)] 
[ImgBot] Optimize images

*Total -- 140.66kb -> 97.46kb (30.71%)

/docs/img/warn.svg -- 3.87kb -> 1.90kb (50.81%)
/docs/img/design.svg -- 30.10kb -> 19.69kb (34.57%)
/docs/img/chain.svg -- 47.84kb -> 32.16kb (32.77%)
/docs/img/tree.svg -- 38.56kb -> 26.89kb (30.27%)
/docs/img/GitHub-Mark-Light-120px-plus.png -- 3.95kb -> 2.93kb (25.72%)
/docs/img/logo_validador_og.png -- 12.58kb -> 10.44kb (17.02%)
/docs/img/logo_validador_fort.svg -- 3.77kb -> 3.44kb (8.71%)

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
2 years agoAdd project status to the README
Alberto Leiva Popper [Mon, 24 Oct 2022 20:20:12 +0000 (15:20 -0500)] 
Add project status to the README

2 years agoUpdate the project's status in the website
Alberto Leiva Popper [Mon, 24 Oct 2022 20:17:12 +0000 (15:17 -0500)] 
Update the project's status in the website

3 years agoRefactors resulting from the issue #83 review
Alberto Leiva Popper [Mon, 6 Jun 2022 22:16:12 +0000 (17:16 -0500)] 
Refactors resulting from the issue #83 review

Mostly quality of life improvements.

On the other hand, it looks like the notfatal hash table API was being
used incorrectly. HASH_ADD_KEYPTR can OOM, but `errno` wasn't being
catched.

Fixing this is nontrivial, however, because strange `reqs_error`
functions are in the way, and that's a spaggetti I decided to avoid.
Instead, I converted HASH_ADD_KEYPTR usage to the fatal hash table API.
That's the future according to #40, anyway.

I don't think this has anything to do with #83, though.

3 years agoEmploy proper API to iterate through hash table entries
Alberto Leiva Popper [Mon, 16 May 2022 22:20:56 +0000 (17:20 -0500)] 
Employ proper API to iterate through hash table entries

Found this quirk while eyeballing #83. I don't think it's going to
fix the problem, but it's definitely an improvement.

3 years agoHTTP: Shut up file delete error message
Alberto Leiva Popper [Wed, 19 Jan 2022 02:27:30 +0000 (20:27 -0600)] 
HTTP: Shut up file delete error message

For #67.

When the file didn't need to be downloaded, because the IMS header did
its job, nothing needs to be deleted. So Fort shouldn't be complaining.

Like the previous commit, this is not a great solution, because IMS is
not the only trigger of file deletes, and the error message might be
helpful in other cases. Then again, I don't really agree with this eager
repository cleaning technique; it complicates debugging.

The proper solution is a WIP in the rrdp-refactor branch.

3 years agoHTTP: Result code 304 quick fix
Alberto Leiva Popper [Sun, 16 Jan 2022 22:24:14 +0000 (16:24 -0600)] 
HTTP: Result code 304 quick fix

Dirty version of the equivalent patch from the rrdp-refactor branch.

304 is neither an error nor a redirect. It needs to be handled as a
skip.

3 years agolog: Print libcrypto stack properly
Alberto Leiva Popper [Sun, 16 Jan 2022 20:36:13 +0000 (14:36 -0600)] 
log: Print libcrypto stack properly

3 years agoDocker: Update for 1.5.3
Alberto Leiva Popper [Sat, 4 Dec 2021 03:21:53 +0000 (21:21 -0600)] 
Docker: Update for 1.5.3

3 years agoLogging: Upgrade HTTP and rsync requests to INFO
Alberto Leiva Popper [Tue, 16 Nov 2021 19:27:18 +0000 (13:27 -0600)] 
Logging: Upgrade HTTP and rsync requests to INFO

Maybe f1xes #62. Needs feedback.

3 years agoLog: Remove ##__VA_ARGS__ and -Wlogical-op
Alberto Leiva Popper [Tue, 9 Nov 2021 19:08:54 +0000 (13:08 -0600)] 
Log: Remove ##__VA_ARGS__ and -Wlogical-op

Improves portability. F1xes #64.

3 years agoProtocolary updates for release 1.5.3 1.5.3
Alberto Leiva Popper [Tue, 9 Nov 2021 02:10:05 +0000 (20:10 -0600)] 
Protocolary updates for release 1.5.3

3 years agoMerge branch 'master' into ncsc
Alberto Leiva Popper [Tue, 9 Nov 2021 02:04:14 +0000 (20:04 -0600)] 
Merge branch 'master' into ncsc

3 years agoRRDP: Fix underutilization of the filename stack
Alberto Leiva Popper [Mon, 8 Nov 2021 22:06:18 +0000 (16:06 -0600)] 
RRDP: Fix underutilization of the filename stack

Lots of error messages were referring to the wrong file, and several of
them printed the correct file manually as what I can only describe as a
quick workaround.

It's not perfect; not all the RRDP code has been patched. That'll have
to wait until the deep RRDP refactor.

3 years agoHTTP: Warn if a download exceeds 50% of the file size limit
Alberto Leiva Popper [Mon, 8 Nov 2021 21:58:43 +0000 (15:58 -0600)] 
HTTP: Warn if a download exceeds 50% of the file size limit

Requested by Ties de Kock:

> Since some RPs now includes an upper limit on object size (some use
> 2MB if I recall correctly) I would appreciate a warning if an object
> goes over "a large fraction" of this limit (and a sample of the
> warning in the changelog and metrics if possible) - so people know
> what they need to alert on. In this situation operators can monitor
> for "natural growth" of an object and intervene, while the case that
> this check prevents (maliciously large objects) is still covered.
>
> The largest object I could find in the wild is 1.2MB (APNIC AS0 ROA).
> The RIPE NCC's largest object is smaller at the moment (but the CRL
> grows quickly if we do member CA keyrolls - since it adds all object
> on it).
>
> In summary:
>
> - I would recommend a warning (and preferably a metric) when an object
>   of 50% of the object size limit is encountered.
> - I would like it if the hard limit is "safe" - especially CRLs can
>   grow in some cases.

The metric will be added later, as part of #50. The warning is eg.

File size exceeds 50% of the configured limit (10/20 bytes).

50% is hardcoded at the moment.

Notice that this is an HTTP-only patch. rsync does not warn.

3 years agoLog: Improve some messages
Alberto Leiva Popper [Mon, 8 Nov 2021 18:48:15 +0000 (12:48 -0600)] 
Log: Improve some messages

3 years agoRRDP: Add DEBUG_RRDP
Alberto Leiva Popper [Mon, 8 Nov 2021 18:23:00 +0000 (12:23 -0600)] 
RRDP: Add DEBUG_RRDP

I had a lot of trouble debugging N.

The problem was that RRDP files are not cached, so it wasn't possible
to debug the snapshot parser in offline mode.

So I added DEBUG_RRDP. It forces RRDP file caching. Not meant to be
enabled in production.

3 years agoConfig: Remove unused code
Alberto Leiva Popper [Fri, 29 Oct 2021 18:12:06 +0000 (13:12 -0500)] 
Config: Remove unused code

3 years agorsync: Remove $HTTP_MAX_FILE_SIZE
Alberto Leiva Popper [Fri, 29 Oct 2021 17:00:42 +0000 (12:00 -0500)] 
rsync: Remove $HTTP_MAX_FILE_SIZE

RRDP snapshots are the only large files RPs neet to get, so the RRDP
limit tends to need to be much larger than the rsync limit.

Therefore, allowing them to be defined in terms of the other doesn't
make much sense.

3 years agoRRDP: Patch uninitialized string
Alberto Leiva Popper [Thu, 28 Oct 2021 23:09:14 +0000 (18:09 -0500)] 
RRDP: Patch uninitialized string

Detected by valgrind.

3 years agoManifest: Improve validation of FileAndHash.file names, version 2
Alberto Leiva Popper [Thu, 28 Oct 2021 21:33:28 +0000 (16:33 -0500)] 
Manifest: Improve validation of FileAndHash.file names, version 2

Now following the rules defined in 6486bis, section 4.2.2

3 years agoManifest: Improve validation of FileAndHash.file names
Alberto Leiva Popper [Thu, 28 Oct 2021 19:59:58 +0000 (14:59 -0500)] 
Manifest: Improve validation of FileAndHash.file names

The following are now rejected:

- slashes
- '.' as full name
- '..' as full name
- Non-printable ASCII

3 years agoCore: Relocate basic data types
Alberto Leiva Popper [Thu, 28 Oct 2021 01:53:21 +0000 (20:53 -0500)] 
Core: Relocate basic data types

Helps the code review. Some structs and functions (such as
struct delta_router_key and router_key_print()) were bleeding into
mostly unrelated modules, and there were a couple of data types (struct
v4_address and struct v6_address) that were only used once, and induced
needless copying.

3 years agoDocumentation: update FreeBSD build instructions 63/head
Philip Paeps [Wed, 27 Oct 2021 07:41:28 +0000 (15:41 +0800)] 
Documentation: update FreeBSD build instructions

While binary packages are available, some people like to build from
source.  Update the instructions for building from a port, a release
tarball or a Git checkout.

3 years agoDocumentation: note FreeBSD packages exist
Philip Paeps [Wed, 27 Oct 2021 07:41:28 +0000 (15:41 +0800)] 
Documentation: note FreeBSD packages exist

A port of FORT validator was committed to the FreeBSD ports tree and
binary packages are now available.  Add instructions for using FreeBSD
packages.

3 years agoMerge branch 'master' into ncsc
Alberto Leiva Popper [Tue, 26 Oct 2021 23:25:36 +0000 (18:25 -0500)] 
Merge branch 'master' into ncsc

3 years agoTest & patch the previous commit
Alberto Leiva Popper [Tue, 26 Oct 2021 23:01:51 +0000 (18:01 -0500)] 
Test & patch the previous commit

Also adds a bunch of database stringify functions for debugging.

Could use some more testing, but I want to merge first.

3 years agoGeneral review
Alberto Leiva Popper [Tue, 28 Sep 2021 21:52:10 +0000 (16:52 -0500)] 
General review

- Increase default remote object file size limit, because RRDP snapshot
  files can be very large. (Current: ~148 MB, double on key rollover)
- Treat HTTP redirects as errors.
    - Before: Redirects were treated as successes, but Fort didn't
      bother to follow the redirect. As a result, the code was either
      not finding the file, or finding an empty file.
    - Now: Redirects are treated as errors. (Not sure if I'm meant to do
      something here; curl doesn't do it automatically, and RFCs are
      silent. In particular, I'm not in the mood to have to deal with
      redirect loops and whatnot.)
- Remove ROA database clone operation in the SLURM code.
  According to the code, it was working on a clone "so that updates can
  be reverted" (on error, I presume.) But it was never reverting them.
- Refactor SLURM cleanup code.
  I don't remember this one very well. Starting from the clone removal,
  I got distracted with some inconsistent cleanups. Patched a buggy
  cleanup somewhere.

There's still more I want to do to the SLURM code; it looks somewhat
slow.

Dirty; needs testing.

3 years agoDocumentation: Update links to the latest binaries
Alberto Leiva Popper [Thu, 21 Oct 2021 02:32:29 +0000 (21:32 -0500)] 
Documentation: Update links to the latest binaries

3 years agoProtocolary updates for release 1.5.2 1.5.2
Alberto Leiva Popper [Tue, 19 Oct 2021 19:47:01 +0000 (14:47 -0500)] 
Protocolary updates for release 1.5.2

3 years agoReorganize imports in common and address modules
Alberto Leiva Popper [Tue, 19 Oct 2021 17:01:12 +0000 (12:01 -0500)] 
Reorganize imports in common and address modules

Was throwing a compilation warning in FreeBSD.

3 years agoCherry-pick 5afab1693bd5983fd3d6cf5aac63770807d74d90
Alberto Leiva Popper [Tue, 19 Oct 2021 03:02:58 +0000 (22:02 -0500)] 
Cherry-pick 5afab1693bd5983fd3d6cf5aac63770807d74d90

Best include this in the upcoming release.

3 years agoCertificate: Remove a bunch of unreachable code
Alberto Leiva Popper [Mon, 18 Oct 2021 21:34:33 +0000 (16:34 -0500)] 
Certificate: Remove a bunch of unreachable code

Also patches a bad cleanup that happened when certificate extension
errors were found.

Fixes #61.

3 years agoTemporary #58 solution
Alberto Leiva Popper [Wed, 13 Oct 2021 05:18:07 +0000 (00:18 -0500)] 
Temporary #58 solution

Completely axes the whole ordeal.

Is not a long-term solution, but will lead to stable behavior until
the other branch has been thoroughly tested.

3 years agoCertificate stack: Remove bogus x509stack_cancel()
Alberto Leiva Popper [Mon, 11 Oct 2021 21:22:08 +0000 (16:22 -0500)] 
Certificate stack: Remove bogus x509stack_cancel()

It seems the #58 and #59 problem is a stray defer separator pop.

The comment above x509stack_cancel() clearly states that the function
should only be called shortly after a x509stack_push(), but there's one
in certificate_traverse() that isn't.

Removing this x509stack_cancel() seems to prevent the crash. I'm still
investigating the original intent of this code.

Tentatively f1xes #58 and #59.

3 years agoRRDP: Patch deltas foreach
Alberto Leiva Popper [Wed, 29 Sep 2021 00:01:00 +0000 (19:01 -0500)] 
RRDP: Patch deltas foreach

The foreach was looping past the array limits.

Likely fixes #57.

3 years agoHTTP: Apply retries only on transient errors
Alberto Leiva Popper [Fri, 24 Sep 2021 00:02:12 +0000 (19:02 -0500)] 
HTTP: Apply retries only on transient errors

File too big -> Do not retry
Timeout -> Retry
HTTP 408, 429, 5xx -> Retry
Else -> Do not retry

Most of this logic was copied from curl.

3 years agorsync: Add --max-size to default rsync arguments
Alberto Leiva Popper [Mon, 20 Sep 2021 18:49:35 +0000 (13:49 -0500)] 
rsync: Add --max-size to default rsync arguments

Applies the patch from the previous commit to the rsync code.

Also adds documentation.

3 years agoHTTP: Add --http.max-file-size
Alberto Leiva Popper [Mon, 20 Sep 2021 17:43:26 +0000 (12:43 -0500)] 
HTTP: Add --http.max-file-size

Prevents repositories from stagnating Fort with absurdly large files.

Thanks to Koen van Hove for reporting this.

3 years agoHTTP: Patch CURLOPT_LOW_SPEED_LIMIT and CURLOPT_LOW_SPEED_TIME
Alberto Leiva Popper [Fri, 17 Sep 2021 18:35:59 +0000 (13:35 -0500)] 
HTTP: Patch CURLOPT_LOW_SPEED_LIMIT and CURLOPT_LOW_SPEED_TIME

Likely due to some misunderstanding, Fort was managing both of these
variables using one command-line argument (--http.idle-timeout). This
unnecessarily limited the configurability of minimum transfer speeds for
HTTP connections.

--http.idle-timeout is now deprecated, and has been replaced by
--http.low-speed-limit and --http.low-speed-time, which correlate
verbatim to the corresponding curl arguments (CURLOPT_LOW_SPEED_LIMIT
and CURLOPT_LOW_SPEED_TIME).

Thanks to Koen van Hove for reporting this.

3 years agoCertificates: Fuse meta and level stacks
Alberto Leiva Popper [Wed, 8 Sep 2021 17:40:26 +0000 (12:40 -0500)] 
Certificates: Fuse meta and level stacks

These stacks always had the same size, and their corresponding elements
always referred to the same certificate.

This was pending work from #55, which I think is now properly solved.

Also refactors x509stack_push(); was messy. Patched an unlikely memory
leak in the chaos.

3 years agoStartup: Print version number better
Alberto Leiva Popper [Mon, 6 Sep 2021 16:05:00 +0000 (11:05 -0500)] 
Startup: Print version number better

Version number is now inferred by git during the autogen.sh step.

It's a more automated version of the previous commit.

3 years agoStartup: Print version number
Alberto Leiva Popper [Sat, 4 Sep 2021 05:33:54 +0000 (00:33 -0500)] 
Startup: Print version number

Just to make sure ongoing debugs are running the right version.

Needs to be more automated.

3 years agoRRDP Notification: Optimize delta parse
Alberto Leiva Popper [Sat, 4 Sep 2021 04:58:01 +0000 (23:58 -0500)] 
RRDP Notification: Optimize delta parse

It was allocating the deltas array twice, for seemingly no reason.
Also, the array slots were pointers, and the two arrays pointed to
different instances of the same objects. For seemingly no reason.

Now there's only one array, and it stores the objects directly.

Also adds relevant unit tests.

3 years agoCertificate stack: Revert levels stack when x509stack_push() fails
Alberto Leiva Popper [Tue, 31 Aug 2021 23:28:15 +0000 (18:28 -0500)] 
Certificate stack: Revert levels stack when x509stack_push() fails

Likely fixes #55.

3 years agoMake FORT compile on OpenBSD 54/head
Job Snijders [Mon, 30 Aug 2021 17:07:15 +0000 (17:07 +0000)] 
Make FORT compile on OpenBSD

3 years agoRTR Server: Prevent crash when server.address is NULL
Alberto Leiva Popper [Mon, 9 Aug 2021 15:03:09 +0000 (10:03 -0500)] 
RTR Server: Prevent crash when server.address is NULL

Fixes #51.

3 years agoProtocolary updates for release 1.5.1 v1.5.1
Alberto Leiva Popper [Fri, 6 Aug 2021 20:55:00 +0000 (15:55 -0500)] 
Protocolary updates for release 1.5.1

3 years agoConfig: Improve --init-tals
Alberto Leiva Popper [Thu, 29 Jul 2021 22:56:15 +0000 (17:56 -0500)] 
Config: Improve --init-tals

1. Update the TAL URLs. (The old ones were very obsolete.)
2. Add --init-as0-tals. (Used to download the ASN0 TALs.)
3. Deprecate and zero-op --init-locations. (Didn't make sense.
   If the user needs a different URL, they can do wget instead.)
4. Deprecate setup_fort.sh. (Seems to be redundant. --init-tals
   already takes care of downloading TALs.)

3 years agoRTR Server: Clean up clients array after every poll
Alberto Leiva Popper [Thu, 29 Jul 2021 20:55:20 +0000 (15:55 -0500)] 
RTR Server: Clean up clients array after every poll

This was a pending optimization from commit
23478fdff80e8ceeaeeaffc71880f950b3c71104.

In truth, this data structure should technically be a linked list.
But I'm not sure if sacrificing cache locality for faster removal is
worth the tradeoff.

3 years agoTODOs: Reprioritize
Alberto Leiva Popper [Thu, 29 Jul 2021 20:53:43 +0000 (15:53 -0500)] 
TODOs: Reprioritize

There were a lot of FIXMEs that were minor nice-to-haves at best.

3 years agoRTR Server: poll before writing
Alberto Leiva Popper [Wed, 14 Jul 2021 15:25:43 +0000 (10:25 -0500)] 
RTR Server: poll before writing

Problem:

write() was sometimes failing with EAGAIN when Fort tried to send PDUs
to clients.

Diagnosis:

Obviously, it's because RTR client sockets now ship with O_NONBLOCK
enabled. Fort wants O_NONBLOCK for reading, but not for writing.

This bug was introduced in the previous commit.

Solution:

Make sure the socket is writable (via poll()) before calling write().

4 years agoRTR Server: thread-pool.server.max now refers to RTR requests
Alberto Leiva Popper [Wed, 7 Jul 2021 19:42:39 +0000 (14:42 -0500)] 
RTR Server: thread-pool.server.max now refers to RTR requests

Apparently, there was a huge misunderstanding when the thread pool was
implemented.

The intended model was

> When the RTR server receives a request, it borrows a thread from the
> thread pool, and tasks it with the request.

Which is logical and a typical thread pool use case. However, what was
actually implemented was

> When the RTR server opens a connection, it borrows a thread from the
> thread pool, and tasks it with the whole connection.

So `thread-pool.server.max` was a hard limit for simultaneous RTR
clients (routers), but now it's just a limit to simultaneous RTR
requests. (Surplus requests will queue.) This is much less taxing to the
CPU when there are hundreds of clients.

Thanks to Mark Tinka for basically spelling this out to me.

-----------------------

Actually, this commit is an almost entire rewrite of the RTR server
core. Here's a (possibly incomplete) list of other problems I had to fix
in the process:

== Problem 1 ==

sockaddr2str() was returning a pointer to invalid memory on success.

This was due to a naive attempt of a bugfix from
1ff403a0c7f61d443cbc4e2e512b8d0324547856.

== Problem 2 ==

Changed the delta expiration conditional.

Was "keep track of the clients, expire deltas when all clients outgrow
them." I see two problems with that:

1. It'll lead to bad performance if a client misbehaves by not
   maintaining the connection. (ie. the server will have to fall back to
   too many cache resets.)
2. It might keep the deltas forever if a client bugs out without killing
   the connection.

New conditional is "keep deltas for server.deltas.lifetime iterations."
"server.deltas.lifetime" is a new configuration argument.

== Problem 3 ==

Serials weren't being compared according to RFC 1982 serial arithmetic.
This was going to cause mayhem when the integer wrapped.

(Though Fort always starts at 1, and serials are 32-bit unsigned
integers, so this wasn't going to be a problem for a very long time.)

== Problem 4 ==

The thread pool had an awkward termination bug. When threads were
suspended, they were meant to be ended through a pthread signal, but
when they were running, they were supposed to be terminated through
pthread_cancel(). (Because, since each client was assigned a thread,
they would spend most of their time sleeping.) These termination methods
don't play well with each other.

Apparently, threads waiting on a signal cannot be canceled, because of
this strange quirk from man 3 pthread_cond_wait:

> a side effect of acting upon a cancellation request while in a
> condition wait is that the mutex is (in effect) re-acquired before
> calling the first cancellation cleanup handler.

(So the first thread dies with the mutex locked, and no other threads
can be canceled because no one can ever lock the mutex again.)

And of course, you can't stop a server thread through a signal, because
they aren't listening to it; they're sleeping in wait for a request.

I still don't really know how would I fix this, but luckily, the problem
no longer exists since working threads are mapped to single requests,
and therefore no longer sleep. (For long periods of time, anyway.)
So always using the signal works fine.

4 years agoRTR Server: Clear O_NONBLOCK on client sockets
Alberto Leiva Popper [Mon, 5 Jul 2021 15:15:45 +0000 (10:15 -0500)] 
RTR Server: Clear O_NONBLOCK on client sockets

It seems that client sockets inherit the O_NONBLOCK flag from the server
socket on some implementations of `accept()`.

We definitely don't want O_NONBLOCK on client sockets, so clear it
explicitely every time.

4 years agoVRPS: Clean up validation core
Alberto Leiva Popper [Fri, 2 Jul 2021 23:58:19 +0000 (18:58 -0500)] 
VRPS: Clean up validation core

It was pretty messy; I had to rewrite a good chunk of it.

== Problem 1 ==

It was discarding meaningful validation results when miscellaneous
errors prevented the deltas array from being built.

Deltas are optional; as long as Fort has the snapshot of the latest
tree, it doesn't technically need deltas. They speed up synchronization,
but in the worst case scenario, the RTR server can keep pushing Cache
Resets.

Severity: Warning. Memory allocation failures are the only eventuality
that might prevent the deltas array from being built.

== Problem 2 ==

The database was always keeping one serial's worth of obsolete deltas.

Cleaned up, saves a potentially large amount of memory.

Severity: Fine. Not a memory leak.

== Problem 3 ==

The code computed deltas even whene there were no routers listening.
Routers are the only delta consumers, so there was no need to waste all
that time.

Severity: Fine; performance quirk.

== Problem 4 ==

I found an RTR client implementation (Cloudflare's rpki-rtr-client) that
hangs when the first serial is zero. Fort's first serial is now 1.

Severity: Warning. This is rpki-rtr-client's fault, but any client
implementations are prone to the same bug. The new solution is more
future-proof.

== Problem 5 ==

It seems it wasn't cleaning the deltas array when all routers were known
to have bogus serials. This was the code:

/* Its the first element or reached end, nothing to purge */
if (group == state.deltas.array ||
   (group - state.deltas.array) == state.deltas.len)
return 0;

If you reached the end of the deltas array, and the minimum router
serial is larger than all the array serials, then all deltas are
useless; you're supposed to purge all of them.

Severity: Fine. It was pretty hard to trigger, and not a memory leak.

4 years agoinit: Remove SIGPIPE SIG_IGN override during RTR server startup
Alberto Leiva Popper [Fri, 2 Jul 2021 23:56:34 +0000 (18:56 -0500)] 
init: Remove SIGPIPE SIG_IGN override during RTR server startup

Because it's now redundant.

As discovered in #49, SIGPIPE is total bullshit in all circumstances, no
exceptions, so there's now a global SIGPIPE SIG_IGN override, rendering
this one useless.

I guess we now know why #49 never triggered on server mode.

4 years agoMain: Add a result code sanitizer
Alberto Leiva Popper [Thu, 24 Jun 2021 19:09:31 +0000 (14:09 -0500)] 
Main: Add a result code sanitizer

Improves the exit status code.

4 years agoGlobal: Further #49 cleanup
Alberto Leiva Popper [Thu, 24 Jun 2021 17:44:55 +0000 (12:44 -0500)] 
Global: Further #49 cleanup

4 years agoTAL: Remove leftover #49 debug messages
Alberto Leiva Popper [Thu, 24 Jun 2021 14:46:04 +0000 (09:46 -0500)] 
TAL: Remove leftover #49 debug messages

4 years agoGlobal: Ignore SIGPIPE
Alberto Leiva Popper [Mon, 21 Jun 2021 21:14:50 +0000 (16:14 -0500)] 
Global: Ignore SIGPIPE

I think I finally found #49. The signal is not SIGSYS; it's SIGPIPE.
That's why dorpauli was getting no core dumps.

Apparently, this is a typical newbie trap for libcurl users.
CURLOPT_NOSIGNAL is incapable of supressing all SIGPIPEs, because some
of them are OS-generated.

I can't believe how dumb SIGPIPE has turned out to be. I/O functions
should return EPIPE; not interrupt the whole program to a handler that
defaults to "die silently."

What the hell, POSIX.

4 years agohttp: Force curl_easy_setopt() to use longs more
Alberto Leiva Popper [Tue, 15 Jun 2021 18:28:58 +0000 (13:28 -0500)] 
http: Force curl_easy_setopt() to use longs more

This is not likely to be useful.

4 years agohttp: Eliminate the custom writefunction
Alberto Leiva Popper [Tue, 15 Jun 2021 17:40:39 +0000 (12:40 -0500)] 
http: Eliminate the custom writefunction

The writefunction was incorrect. It's supposed to return an unsigned
value, but yielded -EINVAL on error.

The default writefunction is `fwrite(3)`, which is perfect for Fort's
purposes.

4 years agoLog: Add handlers for all common signals
Alberto Leiva Popper [Sat, 12 Jun 2021 00:10:09 +0000 (19:10 -0500)] 
Log: Add handlers for all common signals

These should be safe. They just print the signal number, the stack
trace, then restore the original behavior.

The only problem is I can't do the same with SIGKILL nor SIGSTOP,
but I suppose if SIGKILL were the problem, the kernel would have left
something in the logs. And SIGSTOP would have left the process alive.

Intended for #49.

4 years agoLog: Remove illegal operations from segfault handler
Alberto Leiva Popper [Fri, 11 Jun 2021 23:07:31 +0000 (18:07 -0500)] 
Log: Remove illegal operations from segfault handler

Signal handlers are not technically allowed to call backtrace_symbols(),
fprintf(), syslog() nor free().

4 years agoLog: Revert ad841d5024bea7f7d9243a0aae5fdecc40afcd3b
Alberto Leiva Popper [Fri, 11 Jun 2021 19:59:29 +0000 (14:59 -0500)] 
Log: Revert ad841d5024bea7f7d9243a0aae5fdecc40afcd3b

ad841d50 was a mistake. It was never agreed in #40 that Fort should
shotgun blast its own face on the first ENOMEM, and even if it was, the
idea is preposterous. Memory allocation failures are neither programming
errors nor an excuse to leave all the routers hanging.

While there's some truth to the notion that a Fort memory leak (which
has been exhausting memory over time) could be temporarily amended by
killing Fort (and letting the OS clean it up), the argument completely
misses the reality that memory allocation failures could happen
regardless of the existence of a memory leak.

A memory leak is a valid reason to throw away the results of a current
validation run (as long as the admin is warned), but an existing
validation result and the RTR server must remain afloat.

Also includes a pr_enomem() caller review.

4 years agoThread pool: Convert threads to joinable
Alberto Leiva Popper [Mon, 7 Jun 2021 19:22:17 +0000 (14:22 -0500)] 
Thread pool: Convert threads to joinable

Hypothesis: Something (which I haven't spotted yet) was causing the
main thread to skip its wait before the pool threads finished their
tasks. Maybe something to do with the ready signal again?

So the main thread returned early, which means pool threads were
silently suppressed by the OS. That explains the early terminations and
nonexistent stack traces.

If I keep finding crippling errors like this, I will definitely have to
purge the thread pool. It's turned out to be a fucking bug colony at
this point. I'm sick of it.

Way I see it, the root of the problem was the thread pool's control
code, which was too complicated for its own good. A surprisingly large
part of why it was overcomplicated was because it reinvented thread
joining.

So I simplified the control code by removing the detach property. Now
that the main thread joins the proper way, the validation code will not
be interrupted anymore.

This might well be the solution for #49. However, it bothers me that I
still don't have a reasonable explanation as to why the main thread
seemed to be skipping wait.

Argh!

4 years agoScatter more specific debugging messages near the bug
Alberto Leiva Popper [Fri, 4 Jun 2021 05:37:21 +0000 (00:37 -0500)] 
Scatter more specific debugging messages near the bug

Iterates from the previous commit.

4 years agoScatter lots of debugging messages near the bug
Alberto Leiva Popper [Fri, 28 May 2021 00:51:23 +0000 (19:51 -0500)] 
Scatter lots of debugging messages near the bug

Wasted too much time looking for the stack trace, and still got
nothing. It's time for some old-fashioned college style debugging.

4 years agoCode review
Alberto Leiva Popper [Thu, 27 May 2021 22:04:36 +0000 (17:04 -0500)] 
Code review

1. (error) Fix the --work-offline flag.
   It has been unused since commit
   85478ff30ebc029abb0ded48de5b557f52a758e0.
2. (performance) Remove redundant fopen() and fclose() during
   valid_file_or_dir().
   If stat() is used instead of fstat(), there's no need to open and
   close the file.
   (Technically, it's no longer validating readabilty, but since the
   validator downloads the files, read permission errors should be
   extremely rare, and can be catched later.)
3. (fine) Remove return value from thread_pool_task_cb.
   This wasn't a problem, but the return value was meaningless, and
   no callers were using it.

4 years agoCode review
Alberto Leiva Popper [Wed, 26 May 2021 01:17:09 +0000 (20:17 -0500)] 
Code review

- Main validation loop: Remove some confusing, seemingly needless
  wrapper functions.
- Libcurl: Catch lots of status codes properly
- Libcurl: Send proper data types to curl_easy_setopt()
  (Argument types were not matching documented requirements.)
- RTR server: Reduce argument lists.

4 years agoUnit tests: Update
Alberto Leiva Popper [Mon, 24 May 2021 18:30:01 +0000 (13:30 -0500)] 
Unit tests: Update

4 years agoPatch previous commit
Alberto Leiva Popper [Mon, 24 May 2021 17:49:22 +0000 (12:49 -0500)] 
Patch previous commit

That merge didn't go smoothly.

4 years agoMerge branch 'issue49'
Alberto Leiva Popper [Mon, 24 May 2021 17:41:21 +0000 (12:41 -0500)] 
Merge branch 'issue49'

4 years agoThread pool: Code review
Alberto Leiva Popper [Wed, 28 Apr 2021 01:47:03 +0000 (20:47 -0500)] 
Thread pool: Code review

Gets rid of some inconsistencies, but no bugs as far as I can tell.

4 years agoLogging: More refactors
Alberto Leiva Popper [Fri, 21 May 2021 18:30:32 +0000 (13:30 -0500)] 
Logging: More refactors

1. Merges the log and debug modules. I think their separation was the
   reason why they forgot to add stack traces to syslog when they added
   syslog to the project.
   Not risking that mistake again.
2. Removes as many obstacles as possible from stack trace printing on
   critical errors.
3. Add mutexes to logging. This should prevent messages from mixing on
   top of each other when there are threads.

4 years agoLogging: Code review
Alberto Leiva Popper [Thu, 20 May 2021 18:26:21 +0000 (13:26 -0500)] 
Logging: Code review

Two bugfixes:

1. (warning) The libcrypto error stack trace was always showing empty.
   This was because of a bad counter.
2. (critical) Normal stack traces were only being printed in the
   standard streams, never on syslog.
   This is probably the reason why we don't have a proper error message
   on #49. It's probably a segmentation fault.

Also a whole bunch of cleanup. The logging module had a bit of a
duplicate code problem.

4 years agoDocumentation: Show multiple server address config in JSON example
Alberto Leiva Popper [Fri, 14 May 2021 23:58:52 +0000 (18:58 -0500)] 
Documentation: Show multiple server address config in JSON example

Feedback came from private mails.

4 years agoThread pool: Print more debug information
Alberto Leiva Popper [Thu, 22 Apr 2021 20:32:56 +0000 (15:32 -0500)] 
Thread pool: Print more debug information

Might help us catch #49.

4 years agoThread pool: Patch previous commit
Alberto Leiva Popper [Wed, 7 Apr 2021 21:41:43 +0000 (16:41 -0500)] 
Thread pool: Patch previous commit

I accidentally removed a lock operation in the previous commit,
so lots of undefined behavior was being triggered.

Also, restores (but improves) the thread ready signal. It's hard to
explain:

- Before: Workers send ready signal to parent,
  but parent might not be listening yet;
  Therefore parent timeouts on wait.
- Previous: Workers do not send ready signal to parent.
  Therefore, parent might signal work when no workers are ready yet;
  Therefore nobody works.
- Now: Workers send ready signal to parent,
  parent listens lazily (ie. late), but only if workers aren't ready
  yet.
  Therefore, correct behavior.

4 years agoThread pool: remove thread ready signal
Alberto Leiva Popper [Wed, 7 Apr 2021 20:11:44 +0000 (15:11 -0500)] 
Thread pool: remove thread ready signal

It seems the workers were sending the "ready" signal before the
parent thread started to wait for it. This lead to timeouts.

The parent thread doesn't really need to wait for the worker
threads to carry on with its own work, so I've decided to remove
the check.

Progress on #49.

4 years agoDocumentation: Update status
Alberto Leiva Popper [Tue, 6 Apr 2021 17:54:20 +0000 (12:54 -0500)] 
Documentation: Update status

Also elaborates on some command line flag documentation that has
changed since the last release.

4 years agoDocumentation: Fix formatting of usage.html
Alberto Leiva Popper [Tue, 23 Feb 2021 23:31:39 +0000 (17:31 -0600)] 
Documentation: Fix formatting of usage.html

Some '<' and '>' symbols where disrupting Jekyll's parser.

4 years agoMerge branch 'reschke-master'
Alberto Leiva Popper [Tue, 23 Feb 2021 22:47:35 +0000 (16:47 -0600)] 
Merge branch 'reschke-master'

4 years agoImprove NID retrieval/registration
Alberto Leiva Popper [Tue, 23 Feb 2021 17:42:38 +0000 (11:42 -0600)] 
Improve NID retrieval/registration

Curiously, old code used to assume the RPKI objects would never
be added to Libre/OpenSSL. New code handles the objects already
existing.

Attempts to fix #48; untested still.

4 years agoMerge branch 'master' into master 47/head
Julian Reschke [Fri, 19 Feb 2021 09:36:57 +0000 (10:36 +0100)] 
Merge branch 'master' into master

4 years agoUpdate docs, set 'router-keys' as name for output.bgpsec in json format
pcarana [Thu, 18 Feb 2021 04:41:33 +0000 (22:41 -0600)] 
Update docs, set 'router-keys' as name for output.bgpsec in json format

4 years agoAdd argument to set the desired output format
pcarana [Thu, 18 Feb 2021 02:08:30 +0000 (20:08 -0600)] 
Add argument to set the desired output format

4 years agosupport ROA export in JSON formatwq
reschke [Wed, 10 Feb 2021 18:01:44 +0000 (19:01 +0100)] 
support ROA export in JSON formatwq

4 years agoFix rsync and thread pool bugs. 1.5.0 v1.5.0
pcarana [Wed, 27 Jan 2021 15:32:18 +0000 (09:32 -0600)] 
Fix rsync and thread pool bugs.

+Mistakenly (of course, it was a bug) the returned value from rsync execution was being confused with the returned value from execvp call. The main problem was when rsync returned a code 12 (Error in rsync protocol data stream); in that case, the caller confused that error with ENOMEM (also with value 12), which led to terminate execution.
+The thread pool wait function wasn't considering pending taks at the queue; also the poll function was holding and releasing the mutex more than it was needed, and the thread attributes are now globally initialized (thanks @ydahhrk for the code review).
+Increment the number of threads at the internal pool to 10.

4 years agoFix vCard broken unit test
pcarana [Mon, 18 Jan 2021 22:33:02 +0000 (16:33 -0600)] 
Fix vCard broken unit test

4 years agoFix vCard properties basic validation
pcarana [Wed, 13 Jan 2021 16:47:24 +0000 (10:47 -0600)] 
Fix vCard properties basic validation

4 years agoUpdate license year
pcarana [Thu, 7 Jan 2021 22:53:15 +0000 (16:53 -0600)] 
Update license year

4 years agoAdd 'Quick Start' paragraph and some usage examples of --init-tals
pcarana [Tue, 15 Dec 2020 23:00:51 +0000 (17:00 -0600)] 
Add 'Quick Start' paragraph and some usage examples of --init-tals

4 years agoUpdate default value of thread-pool.validation.max to 5
pcarana [Tue, 15 Dec 2020 00:37:17 +0000 (18:37 -0600)] 
Update default value of thread-pool.validation.max to 5