Delphi如何使用最新版本的OpenSSL
程序员文章站
2022-07-13 18:03:08
...
Delphi如何使用最新版本的OpenSSL
无论是D6还是D10,要让自带的Indy方便的使用最新版的OpenSSL及其函数,需要客制化文件其头文件的常量定义IdSSLOpenSSLHeaders.pas
步骤:
1、官网下载最新版的OpenSSL
2、修改Indy中的关于OpenSSL的动态库名或静态库名:
D6版Indy8.0.25,见行次:2632~2634
implementation
//......
const
SSL_DLL_name = 'ssleay32.dll'; {Do not localize}
SSLCLIB_DLL_name = 'libeay32.dll'; {Do not localize}
D10版Indy10.6.2,见行次:19555~19591
implementation
//......
{$IFDEF STATICLOAD_OPENSSL}
const
SSL_LIB_name = 'libssl.a'; {Do not Localize}
SSLCLIB_LIB_name = 'libcrypto.a'; {Do not Localize}
{$ELSE}
{$IFDEF UNIX}
const
{This is a workaround for some Linux distributions and a few other things
where the symbolic link libbsl.so and libcrypto.so do not exist}
SSL_DLL_name = 'libssl'; {Do not localize}
SSLCLIB_DLL_name = 'libcrypto'; {Do not localize}
SSLDLLVers : array [0..10] of string = (
'.10',
'.1.0.2','.1.0.1',
'.44', // MacOS LibreSSL forked from which OpenSSL version? Sometimes found ...
'.43', // MacOS LibreSSL forked from which OpenSSL version? Sometimes found ...
'.35', // MacOS LibreSSL forked from OpenSSL version 1.0.1, almost always found
//
'.1.0.0','.0.9.9','.0.9.8','.0.9.7','.0.9.6'
);
SSLDLLVersChar : array [0..26] of string = ('','a','b','c','d','e','f','g','h','i',
'j','k','l','m','n','o','p','q','r',
's','t','u','v','w','x','y','z');
{$ENDIF}
{$IFDEF WINDOWS}
const
SSL_DLL_name = 'ssleay32.dll'; {Do not localize}
//The following is a workaround for an alternative name for
//one of the OpenSSL .DLL's. If you compile the .DLL's using
//mingw32, the SSL .dll might be named 'libssl32.dll' instead of
//ssleay32.dll like you would expect.
SSL_DLL_name_alt = 'libssl32.dll'; {Do not localize}
SSLCLIB_DLL_name = 'libeay32.dll'; {Do not localize}
{$ENDIF}
{$ENDIF}
比如Windows下,修改Indy10.6.2(D10)的头文件IdSSLOpenSSLHeaders.pas,如上改为:
{$IFDEF WINDOWS}
const
//SSL_DLL_name = 'ssleay32.dll'; {Do not localize}//:屏蔽的
SSL_DLL_name = 'libssl-1_1.dll'; {Do not localize}//:改的
//SSL_DLL_name_alt = 'libssl32.dll'; {Do not localize}//:屏蔽的
SSLCLIB_DLL_name = 'libcrypto-1_1'; {Do not localize}//:改的
{$ENDIF}
{$ENDIF}
再如Windows下,修改D6的头文件IdSSLOpenSSLHeaders.pas,如上改为:
{$IFDEF WINDOWS}
const
//SSL_DLL_name = 'ssleay32.dll'; {Do not localize}//:屏蔽的
SSL_DLL_name = 'libssl-1_1.dll'; {Do not localize}//:改的
//SSL_DLL_name_alt = 'libssl32.dll'; {Do not localize}//:屏蔽的
SSLCLIB_DLL_name = 'libcrypto-1_1'; {Do not localize}//:改的
{$ENDIF}
{$ENDIF}
var
hIdSSL: Integer = 0;
hIdSSLLib: Integer = 0;
hIdCrypto: Integer = 0; //:加的
3、按照最新的OpenSSL函数的调用说明,可能依赖调用对应的函数:
比如,可能依赖调用这些函数:
SSL_CTX_new、TLS_client_method、OPENSSL_init_ssl等等
4、对Indy8.0.25以下版本(对应D6及其以下),其它函数本质类似IdSsl***、ssl_***,其前加了前缀Indy_,可进行更名:
比如,D6,第2541行次:
IdSslSetFd: function(s: PSSL; fd: Integer): Integer cdecl = nil;
可改为:
Indy_IdSslSetFd: function(s: PSSL; fd: Integer): Integer cdecl = nil;
推荐阅读
-
教你如何保持UC浏览器版本始终最新并删除臃肿的文件
-
详解如何使用Docker快速部署ELK环境(最新5.5.1版本)
-
详解如何在 Linux 中安装最新的 Python 3.6 版本
-
如何使用php脚本给html中引用的js和css路径打上版本号
-
如何下载最新的Windows 11 22000.100版本 附最新win11系统下载地址
-
最新版本的Chrome浏览器如何设置网页编码?设置网页编码的两种方法介绍
-
如何在jupyter中使用不同版本的python
-
Rxpermissions最新版本的使用
-
Delphi如何使用最新版本的OpenSSL
-
使用最新版本的androidjunitrunner运行测试用例报:xxx/R.txt (系统找不到指定的文件。)的解决方法