TLS server API: mutual TLS, encrypted private keys, cipher-list control#194
Closed
freitasjca wants to merge 1 commit into
Closed
TLS server API: mutual TLS, encrypted private keys, cipher-list control#194freitasjca wants to merge 1 commit into
freitasjca wants to merge 1 commit into
Conversation
Owner
|
Thanks for the feedback, I implemented the relevant functions in a way that I think is more appropriate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLS server API: mutual TLS (client-cert verification), encrypted private keys, and cipher-list control
Into:
winddriver/Delphi-Cross-Socket:masterSummary
Extends the OpenSSL server-side TLS API with four commonly-needed capabilities the
library currently lacks. All are additive and mirror the shape of the existing
SetCertificate/SetPrivateKeyfamily — no existing method is renamed, removed, orre-signed.
SetCACertificateoverload chain (file → string → bytes → buffer) — load the CA used to verify client certificatesNet.CrossSslSocket.Base.pas,Net.CrossSslSocket.OpenSSL.pasSetVerifyPeer(Boolean)— require & verify a client certificate (mutual TLS)SetPrivateKeyPassword— load a password-protected private keySetCipherList— override the TLS 1.2 cipher listMotivation: the current API can present a server certificate but cannot (a) require and
verify client certificates (mTLS), (b) load an encrypted private key, or (c)
constrain the cipher suites — all standard requirements for hardened/enterprise
deployments. These were implemented while adding mTLS support to a Horse web-framework
provider built on this library.
MTLS-1 —
SetCACertificateoverload chainMirrors the existing
SetCertificate*family so the CA (used to verify client certs) canbe supplied from a file, a PEM string, raw bytes, or a buffer:
The file/string/bytes overloads funnel to the buffer overload (identical to how
SetCertificatealready works). OpenSSL implementation (Net.CrossSslSocket.OpenSSL.pas):parses the PEM with
BIO_new_mem_buf+PEM_read_bio_X509, thenSSL_CTX_add_client_CA— populates the CA-name list the server advertises in the TLShandshake (tells the client which client-certs are acceptable), and
X509_STORE_add_cert(intoSSL_CTX_get_cert_store) — adds the CA to the trust storeused to actually verify the presented client certificate.
MTLS-2 —
SetVerifyPeer(Boolean)True→SSL_VERIFY_PEER or SSL_VERIFY_FAIL_IF_NO_PEER_CERT(require + verify a client cert)False→SSL_VERIFY_NONE(the existing default — no behaviour change when unused)Must be called after
SetCACertificateso the trust store is populated first.TLSOPT-1 —
SetPrivateKeyPassword(encrypted private keys)Stores the passphrase; the OpenSSL private-key load path then reads the key with
PEM_read_bio_PrivateKey+ a password callback and installs it viaSSL_CTX_use_PrivateKey. Without this, a password-protected key file cannot be loaded.When no password is set, the existing (unencrypted) key path is unchanged.
TLSOPT-2 —
SetCipherListCalls
SSL_CTX_set_cipher_listto override the TLS 1.2 cipher list — lets operatorsrestrict to a hardened suite set.
Compatibility / risk
identical when the new methods are not called (
SetVerifyPeer(False)= current default).SetCertificatepattern, so they read naturallyagainst the existing surface.
virtual; abstractonTCrossSslSocketBaseand overridden inTCrossOpenSslSocket(the only SSLimplementation in the tree). If you would rather not add abstract methods to the base
(in case of out-of-tree TLS backends), I'm happy to change them to
virtualwith adefault
raise ENotSupportedbody instead — your call.Testing
Exercised end-to-end with a TLS/mTLS integration suite: server presenting a certificate,
requiring and verifying a client certificate against a supplied CA, loading a
password-protected private key, and negotiating a restricted cipher list — validated with
both an OpenSSL/
TCrossHttpClientmTLS client and external tooling.These additions originate from a downstream fork (
freitasjca/Delphi-Cross-Socket) usedas the transport for a Horse web-framework provider; offered upstream so the main library
gains first-class mTLS/cipher control. Can be split into an mTLS PR (MTLS-1/2) and a
key/cipher PR (TLSOPT-1/2) if preferred.