Delphi如何使用最新版本的OpenSSL

无论是D6还是D10,要让自带的Indy方便的使用最新版的OpenSSL及其函数,需要客制化文件其头文件的常量定义IdSSLOpenSSLHeaders.pas

1、官网下载最新版的OpenSSL

2、修改Indy中的关于OpenSSL的版本描述:

IdSSLOpenSSLHeaders.pas

OPENSSL_OPENSSL_VERSION_NUMBER = $00904100;
OPENSSL_OPENSSL_VERSION_TEXT = 'OpenSSL 0.9.4 09 Aug 1999';  {Do not localize}

3、修改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}
  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;
http://www.sql.ru/forum/770962/libeay-pas-iz-delphi7-v-delphi2010 http://www.delphifaq.ru/indy-protocols-source-part4/idsslopenssl.html http://blog.csdn.net/hunter_lee/article/details/46698153
idHttp带json然后post到某个url已经比较普遍,但是如果是https的post就会不太一样,常用的post会报错或不成功,这时需要用到IdSSLIOHandlerSocketOpenSSL控件,和两个关键dll(libeay32.dll,ssleay32.dll)放到exe同级目录或system32(64位exe放systemWOW64)。 请注意:Delphi XE和Delphi2007及以下版本用到的两个dll虽同名但是不一样的! 本程序是XE10下开发,应该适用XE及以上版本!
rename C:\Windows\System32\ssleay32.dll ssleay32.dll.old rename C:\Windows\System32\libeay32.dll libeay32.dll.old 5. 将新版本OpenSSL文件复制到C:\Windows\System32目录中。 6. 运行以下命令以确保新版本OpenSSL已正确安装: openssl version 7. 如果命令输出新版本OpenSSL信息,则升级已成功完成。 请注意,升级OpenSSL可能会影响您的系统和应用程序的稳定性和兼容性。在升级之前,请确保备份您的系统和数据,并测试您的应用程序以确保它们仍然正常工作。 Iphone App创建与审核步骤一:如何在developer.apple.com网站中设置你的IOS开发所需的Certificates, Identifiers & Profiles