the_Foundation [main]

TlsRequest: Querying name of the SSL library

=> 8b08a406c82dd118053bb08eb87e1291ae1f70d7

diff --git a/CHANGES.md b/CHANGES.md
index c061234..0943ac7 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -3,6 +3,7 @@
 ## 1.6 - Unreleased
 * Block: Added a method to encode contents in Base64.
 * TlsRequest: Avoid possible crash when reusing TLS sessions.
+* TlsRequest: Added a method to query the SSL library name (OpenSSL/LibreSSL).
 
 ## 1.5 - 2022-11-25
 * RegExp: PCRE2 can be used as an alternative to the older PCRE.
diff --git a/include/the_Foundation/tlsrequest.h b/include/the_Foundation/tlsrequest.h
index d0e4d06..9880db0 100644
--- a/include/the_Foundation/tlsrequest.h
+++ b/include/the_Foundation/tlsrequest.h
@@ -148,5 +148,6 @@ typedef iBool (*iTlsRequestVerifyFunc)(iTlsRequest *, const iTlsCertificate *, i
 void        setCACertificates_TlsRequest(const iString *caFile, const iString *caPath);
 void        setCiphers_TlsRequest       (const char *cipherList);
 void        setVerifyFunc_TlsRequest    (iTlsRequestVerifyFunc verifyFunc);
+const char *libraryName_TlsRequest      (void); /* "OpenSSL" or "LibreSSL", for example */
 
 iEndPublic
diff --git a/src/tlsrequest.c b/src/tlsrequest.c
index 745a34f..a5e897f 100644
--- a/src/tlsrequest.c
+++ b/src/tlsrequest.c
@@ -124,6 +124,7 @@ static void reuse_CachedSession(const iCachedSession *d, SSL *ssl) {
 }
 
 struct Impl_Context {
+    iString               libraryName;
     SSL_CTX *             ctx;
     X509_STORE *          certStore;
     iTlsRequestVerifyFunc userVerifyFunc;
@@ -230,6 +231,12 @@ static int verifyCallback_Context_(int preverifyOk, X509_STORE_CTX *storeCtx) {
 }
 
 void init_Context(iContext *d) {
+    init_String(&d->libraryName);
+#if defined (LIBRESSL_VERSION_TEXT)
+    setCStr_String(&d->libraryName, "LibreSSL");
+#else
+    setCStr_String(&d->libraryName, "OpenSSL");
+#endif
     d->tssKeyCurrentRequest = 0;
     tss_create(&d->tssKeyCurrentRequest, NULL);
 #if OPENSSL_API_COMPAT >= 0x10100000L
@@ -263,6 +270,7 @@ void deinit_Context(iContext *d) {
     deinit_Mutex(&d->cacheMutex);
     SSL_CTX_free(d->ctx);
     tss_delete(d->tssKeyCurrentRequest);
+    deinit_String(&d->libraryName);
 }
 
 iBool isValid_Context(iContext *d) {
@@ -826,6 +834,11 @@ void setCiphers_TlsRequest(const char *cipherList) {
     SSL_CTX_set_cipher_list(context_->ctx, cipherList);
 }
 
+const char *libraryName_TlsRequest(void) {
+    initContext_();
+    return cstr_String(&context_->libraryName);
+}
+
 void init_TlsRequest(iTlsRequest *d) {
     initContext_();
     init_Mutex(&d->mtx);
Proxy Information
Original URL
gemini://git.skyjake.fi/the_Foundation/main/cdiff/8b08a406c82dd118053bb08eb87e1291ae1f70d7
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
30.222979 milliseconds
Gemini-to-HTML Time
0.285866 milliseconds

This content has been proxied by September (ba2dc).