summaryrefslogtreecommitdiff
path: root/lib/libtls/tls.c
AgeCommit message (Collapse)Author
2024-04-08Remove spaces before tabsTheo Buehler
2024-03-27Add TLS_ERROR_INVALID_ARGUMENT error code to libtlsjoshua
This is an initial pass, defining the error code and using it for "too long"/length-related errors. ok beck jsing
2024-03-26Add TLS_ERROR_INVALID_CONTEXT error code to libtlsjoshua
ok jsing@ beck@
2024-03-26Add error code support to libtlsjoshua
This adds tls_config_error_code() and tls_error_code(), which will become public API at a later date. Additional error codes will be added in follow-up commits. ok jsing@ beck@
2024-03-26Use errno_value instead of num for readabilityjoshua
ok jsing@
2024-03-26Use errno_value instead of num for readabilityjoshua
ok beck@ jsing@
2023-07-02Remove the ability to do tls 1.0 and 1.1 from libtls.Bob Beck
With this change any requests from configurations to request versions of tls before tls 1.2 will use tls 1.2. This prepares us to deprecate tls 1.0 and tls 1.1 support from libssl. ok tb@
2023-06-18libtls: switch ECDSA_METHOD usage to EC_KEY_METHODOmar Polo
smtpd and the bits it needs in libtls are the only consumer left of ECDSA_METHOD, which is long deprecated. This paves the way for the removal in libcrypto. The diff is from gilles' work on OpenSMTPD-portable, libretls had a similar diff. ok tb@, jsing@
2023-05-25Forcibly update the EVP_PKEY's internal keyOmar Polo
To aid privilege separation, libtls maintains application-specific data on the key inside the EVP_PKEY abstraction because the EVP API doesn't provide a way to do that on the EVP_PKEY itself. OpenSSL 3 changed behavior of EVP_PKEY_get1_RSA() and related functions. These now return a struct from some cache. Thus, modifying the RSA will no longer modify the EVP_PKEY like it did previously, which was clearly implied to be the case in the older documentation. This is a subtle breaking change that affects several applications. While this is documented, no real solution is provided. The transition plan from one OpenSSL major version to the next one tends to involve many #ifdef in the ecosystem, and the only suggestion provided by the new documentation is to switch to a completely unrelated, new API. Instead, forcibly reset the internal key on EVP_PKEY after modification, this way the change is picked up also by OpenSSL 3. Fixes issue 1171 in OpenSMTPD-portable ok tb@, jsing@
2023-05-14add missing #include <string.h>; ok tb@Omar Polo
2022-02-08Plug a long standing leak in libtls CRL handlingTheo Buehler
X509_STORE_add_crl() does not take ownership of the CRL, it bumps its refcount. So nulling out the CRL from the stack will leak it. Issue reported by KS Sreeram, thanks! ok jsing
2022-01-25Introduce a signer interface intented to make TLS privsep simplerEric Faurot
to implement. Add a tls_config_set_sign_cb() function that allows to register a callback for the signing operation on a tls_config. When used, the context installs fake pivate keys internally, and the callback receives the hash of the public key. Add a tls_signer_*() set of functions to manage tls_signer objects. A tls_signer is an opaque structure on which keys are added. It is used to compute signatures with private keys identified by their associated public key hash. Discussed with and ok jsing@ tb@
2021-10-21Switch from X509_VERIFY_PARAM_set_flags() to X509_STORE_set_flags().Theo Buehler
This reduces the number of reacharounds into libcrypto internals. ok jsing
2021-10-21Use *printf %d instead of %iTheo Buehler
ok jsing
2021-10-02Use SSL_CTX_get0_param() rather than reaching into the SSL_CTX.Joel Sing
2021-02-01Use "EC/RSA key setup failure" to align error with othersTheo Buehler
ok eric jsing
2021-01-26Move private key setup to a helper function with proper errorEric Faurot
checking. Only install the hash on the key if fake key is used, and do it for EC keys too. ok tb@ jsing@
2021-01-21return -1 on error for consistencyEric Faurot
ok tb@
2021-01-21Allow setting a keypair on a tls context without specifying the privateEric Faurot
key, and fake it internally with the certificate public key instead. It makes it easier for privsep engines like relayd that don't have to use bogus keys anymore. ok beck@ tb@ jsing@
2020-05-24Clear SSL_MODE_AUTO_RETRY in libtls, since we handle WANT_POLLIN correctly.Joel Sing
2020-01-20Add support for TLSv1.3 as a protocol to libtls.Joel Sing
This makes tls_config_parse_protocols() recognise and handle "tlsv1.3". If TLSv1.3 is enabled libtls will also request libssl to enable it. ok beck@ tb@
2019-04-01Add a mutex to guard reference counting for tls_config.Joel Sing
This makes libtls more friendly for multithreaded use - otherwise we can end up with incorrect refcounts and end up freeing when we should not be (or not freeing when we should be). ok beck@
2018-11-29expose the default cert file as a function, not a define. it's reallyTed Unangst
an internal detail of the library, so the string should live inside it, not in the application code. ok jsing
2018-11-06Define TLS_CA_CERT_FILE rather than having every application create theirJoel Sing
own define for /etc/ssl/cert.pem. ok beck@ bluhm@ tb@
2018-04-07Switch to OPENSSL_init_ssl() and prevent an openssl configuration file fromJoel Sing
being loaded behind our back, at a later point. ok beck@
2018-03-19Automatically handle library initialisation for libtls.Joel Sing
Now that we have tls_init() under pthread_once(), automatically initialise libtls from the entry point functions (tls_config(), tls_client() and tls_server()) - this makes an explicit tls_init() call no longer a requirement. ok bcook@ beck@ inoguchi@
2018-03-08un-revert tls_init pthread_once change, now that stub is added so that ↵Bob Beck
builds work
2018-03-07backout. diff was not tested comprehensively, resulting in a broken tree.Theo de Raadt
2018-03-07Make tls_init() concurrently callable using pthread_once().Bob Beck
ok jsing@ This brings pthread_once usage into libressl, which will need to get dealt with correctly in portable. This sets us up to autoinit libtls, and we will also be using pthread_once to deal with autoinit stuff in libssl and libcrypto
2018-02-10Move the keypair pubkey hash handling code to during config.Joel Sing
The keypair pubkey hash was being generated and set in the keypair when the TLS context was being configured. This code should not be messing around with the keypair contents, since it is part of the config (and not the context). Instead, generate the pubkey hash and store it in the keypair when the certificate is configured. This means that we are guaranteed to have the pubkey hash and as a side benefit, we identify bad certificate content when it is provided, instead of during the context configuration. ok beck@
2018-02-08Have tls_keypair_pubkey_hash() call tls_keypair_load_cert() instead ofJoel Sing
rolling its own certificate loading. This also means we get better error reporting on failure.
2018-02-08Move tls_keypair_pubkey_hash() to the keypair file.Joel Sing
2018-02-08Avoid a memory leak that results when the same tls_config is reused.Joel Sing
Reported by and fix from Nate Bessette <openbsd at nate dot sh> - thanks.
2017-09-20Keep track of which keypair is in use by a TLS context.Joel Sing
This fixes a bug where by a TLS server with SNI would always only return the OCSP staple for the default keypair, rather than returning the OCSP staple associated with the keypair that was selected via SNI. Issue reported by William Graeber and confirmed by Andreas Bartelt. Fix tested by William Graeber and Andreas Bartelt - thanks!
2017-08-28Fix unchecked return nitBob Beck
ok bcook@ jsing@
2017-08-09Don't use tls_cert_hash for the hashing used by the engine offloading magicClaudio Jeker
for the TLS privsep code. Instead use X509_pubkey_digest() because only the key should be used as identifier. Relayd is rewriting certificates and then the hash would change. Rename the hash is struct tls_keypair to pubkey_hash to make clear what this hash is about. With input and OK jsing@
2017-07-06Add support for providing CRLs to libtls - once a CRL is provided weJoel Sing
enable CRL checking for the full certificate chain. Based on a diff from Jack Burton <jack at saosce dot com dot au>, thanks! Discussed with beck@
2017-06-22Use the tls_password_cb() callback with all PEM_read_bio_*() calls, so thatJoel Sing
we can prevent libcrypto from going behind our back and trying to read passwords from standard input (which we may not be permitted to do). Found by jsg@ with httpd and password protected keys.
2017-06-22Fix incorrect indentation.Joel Sing
2017-06-22Plug a memory leak in tls_keypair_cert_hash(), introduced in r1.60.Joel Sing
2017-06-22Remove dead code that has remained hiding since ressl.c r1.14!Joel Sing
2017-05-07Return an error if tls_handshake() is called on a TLS context that hasJoel Sing
already completed a TLS handshake.
2017-05-06Perform reference counting for tls_config. This allows tls_config_free() toJoel Sing
be called as soon as it has been passed to the final tls_configure() call, simplifying lifetime tracking for the application. Requested some time ago by tedu@. ok beck@
2017-04-05Add tls_peer_cert_chain_pem - To retreive the peer certificate and chainBob Beck
as PEM format. This allows for it to be used or examined with tools external to libtls bump minor ok jsing@
2017-04-05Internal changes to allow for relayd engine privsep. sends the hash of theBob Beck
public key as an identifier to RSA, and adds an function for relayd to use to disable private key checking when doing engine privsep. ok jsing@
2017-01-26Use a flag to track when we need to call SSL_shutdown(). This avoids anJoel Sing
issue where by calling tls_close() on a TLS context that has not attempted a handshake, results in an unexpected failure. Reported by Vinay Sajip. ok beck@
2017-01-22Disable session cache and tickets by default.Claudio Jeker
OK beck@ jsing@
2017-01-13whitespaceTheo de Raadt
2017-01-03If certificate verification has been disabled, do not attempt to load aJoel Sing
CA chain or specify CA paths. This prevents attempts to access the file system, which may fail due to pledge. ok bluhm@
2017-01-03Revert previous - the original code was correct since X509_verify_cert()Joel Sing
should not have changed the X509_STORE_CTX error value on success and it was initialised to X509_V_OK by X509_STORE_CTX_init(). Other software also depends on this behaviour. Previously X509_verify_cert() was mishandling the X509_STORE_CTX error value when validating alternate chains. This has been fixed and further changes now explicitly ensure that the error value will be set to X509_V_OK if X509_verify_cert() returns success.