OpenSSL | Load Additional Functions

By Default Indy defines the most common openssl functions needed to encrypt the communications, but sometimes you need more functions for encrypt, signing... you can use the method IdOpenSSLSetLoadFuncsCallback to assign a callback for loading  additional OpenSSL functions dynamically.

 

IdOpenSSLSetLoadFuncsCallback


delegate void TIdLoadSSLFuncsCallback(TIdLibHandle hIdSSL, TIdLibHandle hIdCrypto, TStringList FailedLoadList);

This is a procedure type that serves as a callback, it takes three parameters:

 


The purpose of this callback is to allow the user to perform custom processing when OpenSSL functions are being loaded, such as logging failed function loads or handling errors.

 

 

IdOpenSSLSetUnLoadFuncsCallback

 


delegate void TIdUnLoadSSLFuncsCallback();

It serves as a callback for unloading SSL functions.This is useful for performing cleanup when OpenSSL libraries are being unloaded.

 

 

How to load custom function

Find below a simple example of how to load the function EVP_PKEY_CTX_set_rsa_padding using the callbacks.

 


// Note: Direct function pointer loading is not applicable in .NET/C#.
// Use P/Invoke or the managed OpenSSL wrapper instead.
// The following is a conceptual equivalent:

IntPtr EVP_PKEY_CTX_set_rsa_padding = IntPtr.Zero;

void DoOpenSSLLoadFuncsCallback(TIdLibHandle hIdSSL, TIdLibHandle hIdCrypto, TStringList FailedLoadList)
{
  EVP_PKEY_CTX_set_rsa_padding = LoadLibFunction(hIdCrypto, "EVP_PKEY_CTX_set_rsa_padding");
}

void DoOpenSSLUnLoadFuncsCallback()
{
  EVP_PKEY_CTX_set_rsa_padding = IntPtr.Zero;
}

IdOpenSSLSetLoadFuncsCallback(DoOpenSSLLoadFuncsCallback);
IdOpenSSLSetUnLoadFuncsCallback(DoOpenSSLUnLoadFuncsCallback);