Providing UPKI support in OpenSSL - HOW?
Several days ago we had a discussion covering the outcome of the polls to add support to bring support of UPKI to OpenSSL. There is a strong support in communities and in TAC/BAC.
According to the purpose of ACs, TAC's responsibility is to provide the "HOW" approach for the features added to the roadmap by BAC.
This thread represents a starting point for discussing the approaches. We have a deadline November 27 to get the ideas of the preferred approaches. This thread doesn't intend to provide the final design of the UPKI implementation.
UPKI integration to OpenSSL, approaches
This document outlines several approaches to integrate UPKI with OpenSSL from a distribution perspective. Two of them imply using UPKI API for certificate validation, and the last implies OpenSSL working with the UPKI files.
Using UPKI API
OpenSSL (and other libraries) can use either UPKI C-FFI interface (upki.h provides native API to verify the set of certificates represented as DER bytes) or a standard OpenSSL callback provided by upki-openssl.h. The 1st approach seems to play relatively well with recent improvements of caching the certificates in libssl. The 2nd approach also can be integrated with OpenSSL native verification procedure.
The problems with UPKI API are:
Not all platforms/architectures have Rust support, so this approach will not be universal and will require some dealing with the UPKI database from the OpenSSL code. See Levitte's code
Upstream doesn’t like linking to external libraries, so probably we will have to deal with the dlopen/dlclose interface.
The open question is: should we use UPKI verification as one more callback after application ones or as a default one?
Build time configuration parameters for both approaches: enable-upki
Run-time configuration parameters: use UPKI for verification at all (boolean, on by default), UPKI config path (string, filename), UPKI library path (string, filename), UPKI callback name (for compatible/extended implementations)
This implementation (any approach) can be done relatively fast, I think.
Working with UPKI database from OpenSSL directly
This approach implies that we use UPKI as a command-line tool to deliver the database to the machine (the local one, host in case of containers, etc). This approach is chosen by several components: rustls integration, the openssl integration (via the FFI interface), and the Go integration all imply reading from the cached data directory. There's no long running daemon component, the database is updated via cron/systemd timer.
To work with the UPKI files directly, we will need a long-term strategy for handling updates to the file format (e.g. forward/backward compatibility in case of containers reading old/new versions of the UPKI database).
https://c2sp.org/[email protected] documents the file format, concurrency updates obligation, and the procedure of revocation verification.
This implementation resolves the Rust dependency but
will need more development work
would duplicate both UPKI code and the code necessary for other libraries
would require to duplicate the UPKI functionality
@Simo Sorce I'm considering potential future improvements in UPKI here — let's say UPKI becomes the simplest method to enforce certificate transparency for CAs that should provide it on Linux; if OpenSSL directly reads the database file format, it won't get these improvements even as they would become available automatically through method 1.
Or, let's say UPKI adds OneCRL revocation checking support for intermediates (that's probably a more realistic short-term scenario). If OpenSSL works with the UPKI database directly, it needs to write new code to also support this.
I don't think the lack of Rust support is a big deal; platforms that do not have a Rust compiler can still implement the 'read the database directly' approach pretty easily behind the same API — and even if they don't, they won't be worse off than they are today.
Any access of a database is outside of the OpenSSL bailiwick. Any database access requires linking to complex libraries that aren't designed around security and aren't widely tested in the same security scope. Rust (and go) are a nightmare for most systems that aren't mainstream which goes back to the "everything is a vax" plague of open source for decades. To me this seems like a whole lot of code, extra dependencies and abstraction to almost but not quite fix a problem.
@Tim Hogard This isn't a real database — it's not SQLite or anything like that. The format is actually quite simple, just a few structs in a few files that can be mmap()'d or read.
I think the format is simple enough that the people maintaining systems that don't support Rust could easily re-implement the same interface in a language of their choice. I don't think old systems that don't support Rust should hold back an improvement that could finally deliver working revocation across most of the Linux ecosystem.
Personally, I'm in favor of just implementing the DB parsing: the format spec looks comprehensible, and having several independent implementations is traditionally beneficial for open standards and mechanisms.
@Eugene Syromiatnikov I have mixing feelings there. We have to duplicate some work, and also the format is not formalized.
@Dmitry Belyavsky the benefit here is that the people who implement and review it will hold the relevant knowledge (unless it's some vibe-coded garbage and LGTM^WTLDR reviews, of course) and will be able to maintain it long-term.
the format is not formalized
What do you mean by that? The structures are described using TLS-style notation.
@beldmit, we do have to duplicate some work if we want it as an integral feature in OpenSSL, anyway... unless we want to support Rust modules in libcrypto / libssl (I don't see that happening soon).
@Eugene Syromiatnikov Current specification is local for UPKI community. Yes, it's great. However, I would like to see an IETF spec in some future :)
@richard Isn't it just a case of runtime (dlopen) linking to a module written in Rust. As far as we're concerned its just a C like interface. The fact its written in Rust is irrelevant to us (except that it might not be available on all platforms)
@matt, yes, if a dlopen solution is what we're going for. My reading of @eugenes' question was something more integrated into libcrypto.
But, we've done the runtime thingy before, see zip compression.
@eugenes But, presumably, we don't get the benefit of OneCRL support via this route once it is added (assuming that https://github.com/rustls/upki/issues/229 happens)
@Matt Caswell Yeah, probably not without writing additional code in OpenSSL, i.e., requiring users of OpenSSL to upgrade to a new release; and with many consumers jumping from LTS to LTS, that could mean a significant delay.
https://github.com/rustls/upki/blob/main/FAQ.md is a nice document to consider
My thoughts on @beldmit's post above:
Not all platforms/architectures have Rust support, so this approach will not be universal and will require some dealing with the UPKI database from the OpenSSL code. See Levitte's code
I do not see this as a blocker. If its available we use it. If its not available we don't. Platforms that don't have it are no worse off than they are today. Platforms that do (which is the vast majority) do. For those that don't have it, it would be fairly simple to implement without Rust if the desire for it is strong enough: e.g. see https://radicle.network/nodes/projects.levitte.org/rad%3Az4DxU5ejZnfp7rDdHCd3ZH3MHasyR
Upstream doesn’t like linking to external libraries, so probably we will have to deal with the dlopen/dlclose interface.
I don't see a huge problem here. You can either put it behind an off-by-default Configure option (which presumably all distros would turn on). Or you just deal with dlopen/dlclose: which from my understanding is just a couple of functions for UPKI.
My preference is just to use the UPKI API. We immediately get the benefit of improvements that are made to the service (e.g. addition of OneCRL support).
I don't see a great benefit from and only problems with implementing direct file access ourselves.
@matt, this would be a huge step away from OpenSSL's well known NIH habits! I'm not against it, believe you me, but it should be noted in the history books!
Seriousity: medium
@richard I don't really see it that way. There is plenty of precedent for us linking external libraries this way, e.g. enable-zlib, enable-zstd, enable-brotli, enable-jitter
@Matt Caswell And also some rejecting the same approach
@beldmit Probably. We're not always consistent!! I do think we seek to avoid new by default dependencies. But there are ways to avoid that here and still achieve the goal of using the existing UPKI API.
Item removed
Do we want to have a poll as a part of this discussion?
I would strongly consider avoiding dlopen(), we've seen deadlocks when doing this in some cass if the library we dlopen() is itself linked to openssl and an application has multiple threads trying to initialize openssl at the same time ... Unless we have a vision to allow to load different libraries, we should just have it linked at build time like any other regular library
Simo is referring to this issue: https://bugzilla.redhat.com/show_bug.cgi?id=2524692#c18
This could possibly be avoided on the OpenSSL end by wrapping the contents of OPENSSL_init_crypto in a while (true) loop that releases the lock between attempts, but it is correct that this could cause problems. On the other hand, this already causes problems regardless of whether OpenSSL dlopen()s a UPKI loadable module in configurations where OpenSSL does dlopen() for other reasons (e.g., FIPS provider, PKCS#11 provider, etc.).
I am not sure what "would require to duplicate the UPKI functionality" means exactly here.
But we'll just need code that can read the database, we do not need to write code that deals with updating it as that is done by the UPKI system timer/daemon (whatever will it be).
What other libraries do is not really OpenSSL's concern, what matters is whether there are resources to maintain the database reader side, or whether it is ok to offer upki functionality only on systems that have access to a rust compiler and use the upki project provided C-FFI library.