openssl.pas 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  1. unit OpenSSL;
  2. {==============================================================================|
  3. | Project : Ararat Synapse | 003.004.001 |
  4. |==============================================================================|
  5. | Content: SSL support by OpenSSL |
  6. |==============================================================================|
  7. | Copyright (c)1999-2005, Lukas Gebauer |
  8. | All rights reserved. |
  9. | |
  10. | Redistribution and use in source and binary forms, with or without |
  11. | modification, are permitted provided that the following conditions are met: |
  12. | |
  13. | Redistributions of source code must retain the above copyright notice, this |
  14. | list of conditions and the following disclaimer. |
  15. | |
  16. | Redistributions in binary form must reproduce the above copyright notice, |
  17. | this list of conditions and the following disclaimer in the documentation |
  18. | and/or other materials provided with the distribution. |
  19. | |
  20. | Neither the name of Lukas Gebauer nor the names of its contributors may |
  21. | be used to endorse or promote products derived from this software without |
  22. | specific prior written permission. |
  23. | |
  24. | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
  25. | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
  26. | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
  27. | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
  28. | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
  29. | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
  30. | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
  31. | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  32. | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
  33. | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
  34. | DAMAGE. |
  35. |==============================================================================|
  36. | The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
  37. | Portions created by Lukas Gebauer are Copyright (c)2002-2005. |
  38. | All Rights Reserved. |
  39. |==============================================================================|
  40. | Contributor(s): |
  41. |==============================================================================|
  42. | FreePascal basic cleanup (original worked too): Ales Katona |
  43. | WARNING: due to reliance on some units, I have removed the ThreadLocks init |
  44. | if need be, it should be re-added, or handled by the |
  45. | OS threading init somehow |
  46. |==============================================================================|
  47. | History: see HISTORY.HTM from distribution package |
  48. | (Found at URL: http://www.ararat.cz/synapse/) |
  49. |==============================================================================}
  50. {
  51. Special thanks to Gregor Ibic <[email protected]>
  52. (Intelicom d.o.o., http://www.intelicom.si)
  53. for good inspiration about begin with SSL programming.
  54. }
  55. {$MODE DELPHI}{$H+}
  56. {:@abstract(OpenSSL support)
  57. This unit is Pascal interface to OpenSSL library (used by @link(ssl_openssl) unit).
  58. OpenSSL is loaded dynamicly on-demand. If this library is not found in system,
  59. requested OpenSSL function just return errorcode.
  60. }
  61. interface
  62. uses
  63. DynLibs;
  64. var
  65. {$IFDEF WINDOWS}
  66. DLLSSLName: string = 'ssleay32.dll';
  67. DLLSSLName2: string = 'libssl32.dll';
  68. DLLUtilName: string = 'libeay32.dll';
  69. {$ELSE}
  70. DLLSSLName: string = 'libssl';
  71. DLLUtilName: string = 'libcrypto';
  72. { ADD NEW ONES WHEN THEY APPEAR!
  73. Always make .so/dylib first, then versions, in descending order!
  74. Add "." .before the version, first is always just "" }
  75. DLLVersions: array[1..10] of string = ('', '.0.9.9'{futureproof :D}, '.0.9.8',
  76. '.0.9.7', '.0.9.6', '.0.9.5', '.0.9.4',
  77. '.0.9.3', '.0.9.2', '.0.9.1');
  78. {$ENDIF}
  79. type
  80. SslPtr = Pointer;
  81. PSslPtr = ^SslPtr;
  82. PSSL_CTX = SslPtr;
  83. PSSL = SslPtr;
  84. PSSL_METHOD = SslPtr;
  85. PX509 = SslPtr;
  86. PX509_NAME = SslPtr;
  87. PEVP_MD = SslPtr;
  88. PInteger = ^Integer;
  89. PBIO_METHOD = SslPtr;
  90. PBIO = SslPtr;
  91. EVP_PKEY = SslPtr;
  92. PRSA = SslPtr;
  93. PASN1_UTCTIME = SslPtr;
  94. PASN1_INTEGER = SslPtr;
  95. PPasswdCb = SslPtr;
  96. PFunction = procedure;
  97. DES_cblock = array[0..7] of Byte;
  98. PDES_cblock = ^DES_cblock;
  99. des_ks_struct = packed record
  100. ks: DES_cblock;
  101. weak_key: Integer;
  102. end;
  103. des_key_schedule = array[1..16] of des_ks_struct;
  104. const
  105. EVP_MAX_MD_SIZE = 16 + 20;
  106. SSL_ERROR_NONE = 0;
  107. SSL_ERROR_SSL = 1;
  108. SSL_ERROR_WANT_READ = 2;
  109. SSL_ERROR_WANT_WRITE = 3;
  110. SSL_ERROR_WANT_X509_LOOKUP = 4;
  111. SSL_ERROR_SYSCALL = 5; //look at error stack/return value/errno
  112. SSL_ERROR_ZERO_RETURN = 6;
  113. SSL_ERROR_WANT_CONNECT = 7;
  114. SSL_ERROR_WANT_ACCEPT = 8;
  115. SSL_OP_NO_SSLv2 = $01000000;
  116. SSL_OP_NO_SSLv3 = $02000000;
  117. SSL_OP_NO_TLSv1 = $04000000;
  118. SSL_OP_ALL = $000FFFFF;
  119. SSL_VERIFY_NONE = $00;
  120. SSL_VERIFY_PEER = $01;
  121. OPENSSL_DES_DECRYPT = 0;
  122. OPENSSL_DES_ENCRYPT = 1;
  123. X509_V_OK = 0;
  124. X509_V_ILLEGAL = 1;
  125. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT = 2;
  126. X509_V_ERR_UNABLE_TO_GET_CRL = 3;
  127. X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE = 4;
  128. X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE = 5;
  129. X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY = 6;
  130. X509_V_ERR_CERT_SIGNATURE_FAILURE = 7;
  131. X509_V_ERR_CRL_SIGNATURE_FAILURE = 8;
  132. X509_V_ERR_CERT_NOT_YET_VALID = 9;
  133. X509_V_ERR_CERT_HAS_EXPIRED = 10;
  134. X509_V_ERR_CRL_NOT_YET_VALID = 11;
  135. X509_V_ERR_CRL_HAS_EXPIRED = 12;
  136. X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD = 13;
  137. X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD = 14;
  138. X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD = 15;
  139. X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD = 16;
  140. X509_V_ERR_OUT_OF_MEM = 17;
  141. X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT = 18;
  142. X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN = 19;
  143. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY = 20;
  144. X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE = 21;
  145. X509_V_ERR_CERT_CHAIN_TOO_LONG = 22;
  146. X509_V_ERR_CERT_REVOKED = 23;
  147. X509_V_ERR_INVALID_CA = 24;
  148. X509_V_ERR_PATH_LENGTH_EXCEEDED = 25;
  149. X509_V_ERR_INVALID_PURPOSE = 26;
  150. X509_V_ERR_CERT_UNTRUSTED = 27;
  151. X509_V_ERR_CERT_REJECTED = 28;
  152. //These are 'informational' when looking for issuer cert
  153. X509_V_ERR_SUBJECT_ISSUER_MISMATCH = 29;
  154. X509_V_ERR_AKID_SKID_MISMATCH = 30;
  155. X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH = 31;
  156. X509_V_ERR_KEYUSAGE_NO_CERTSIGN = 32;
  157. X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER = 33;
  158. X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION = 34;
  159. //The application is not happy
  160. X509_V_ERR_APPLICATION_VERIFICATION = 50;
  161. SSL_FILETYPE_ASN1 = 2;
  162. SSL_FILETYPE_PEM = 1;
  163. EVP_PKEY_RSA = 6;
  164. var
  165. SSLLibHandle: TLibHandle = 0;
  166. SSLUtilHandle: TLibHandle = 0;
  167. SSLLibFile: string = '';
  168. SSLUtilFile: string = '';
  169. // libssl.dll
  170. function SslGetError(s: PSSL; ret_code: Integer):Integer;
  171. function SslLibraryInit:Integer;
  172. procedure SslLoadErrorStrings;
  173. // function SslCtxSetCipherList(arg0: PSSL_CTX; str: PChar):Integer;
  174. function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String):Integer;
  175. function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
  176. procedure SslCtxFree(arg0: PSSL_CTX);
  177. function SslSetFd(s: PSSL; fd: Integer):Integer;
  178. function SslMethodV2:PSSL_METHOD;
  179. function SslMethodV3:PSSL_METHOD;
  180. function SslMethodTLSV1:PSSL_METHOD;
  181. function SslMethodV23:PSSL_METHOD;
  182. function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):Integer;
  183. function SslCtxUsePrivateKeyASN1(pk: integer; ctx: PSSL_CTX; d: String; len: integer):Integer;
  184. // function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer;
  185. function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
  186. function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):Integer;
  187. function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: integer; d: String):Integer;
  188. function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
  189. // function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: PChar):Integer;
  190. function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):Integer;
  191. function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer;
  192. procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
  193. procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
  194. // function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):Integer;
  195. function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: String; const CApath: String):Integer;
  196. function SslNew(ctx: PSSL_CTX):PSSL;
  197. procedure SslFree(ssl: PSSL);
  198. function SslAccept(ssl: PSSL):Integer;
  199. function SslConnect(ssl: PSSL):Integer;
  200. function SslShutdown(ssl: PSSL):Integer;
  201. function SslRead(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  202. function SslPeek(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  203. function SslWrite(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  204. function SslPending(ssl: PSSL):Integer;
  205. function SslGetVersion(ssl: PSSL):String;
  206. function SslGetPeerCertificate(ssl: PSSL):PX509;
  207. procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction);
  208. function SSLGetCurrentCipher(s: PSSL):SslPtr;
  209. function SSLCipherGetName(c: SslPtr): String;
  210. function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer;
  211. function SSLGetVerifyResult(ssl: PSSL):Integer;
  212. // libeay.dll
  213. function X509New: PX509;
  214. procedure X509Free(x: PX509);
  215. function X509NameOneline(a: PX509_NAME; var buf: String; size: Integer):String;
  216. function X509GetSubjectName(a: PX509):PX509_NAME;
  217. function X509GetIssuerName(a: PX509):PX509_NAME;
  218. function X509NameHash(x: PX509_NAME):Cardinal;
  219. // function SslX509Digest(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer;
  220. function X509Digest(data: PX509; _type: PEVP_MD; md: String; var len: Integer):Integer;
  221. function X509print(b: PBIO; a: PX509): integer;
  222. function X509SetVersion(x: PX509; version: integer): integer;
  223. function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer;
  224. function X509SetIssuerName(x: PX509; name: PX509_NAME): integer;
  225. function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: integer;
  226. bytes: string; len, loc, _set: integer): integer;
  227. function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer;
  228. function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME;
  229. function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer;
  230. function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer;
  231. function X509GetSerialNumber(x: PX509): PASN1_INTEGER;
  232. function EvpPkeyNew: EVP_PKEY;
  233. procedure EvpPkeyFree(pk: EVP_PKEY);
  234. function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer;
  235. function EvpGetDigestByName(Name: String): PEVP_MD;
  236. procedure EVPcleanup;
  237. // function ErrErrorString(e: integer; buf: PChar): PChar;
  238. function SSLeayversion(t: integer): string;
  239. procedure ErrErrorString(e: integer; var buf: string; len: integer);
  240. function ErrGetError: integer;
  241. procedure ErrClearError;
  242. procedure ErrFreeStrings;
  243. procedure ErrRemoveState(pid: integer);
  244. procedure OPENSSLaddallalgorithms;
  245. procedure CRYPTOcleanupAllExData;
  246. procedure RandScreen;
  247. function BioNew(b: PBIO_METHOD): PBIO;
  248. procedure BioFreeAll(b: PBIO);
  249. function BioSMem: PBIO_METHOD;
  250. function BioCtrlPending(b: PBIO): integer;
  251. function BioRead(b: PBIO; var Buf: String; Len: integer): integer;
  252. function BioWrite(b: PBIO; Buf: String; Len: integer): integer;
  253. function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
  254. function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): integer;
  255. procedure PKCS12free(p12: SslPtr);
  256. function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA;
  257. function Asn1UtctimeNew: PASN1_UTCTIME;
  258. procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
  259. function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
  260. function i2dX509bio(b: PBIO; x: PX509): integer;
  261. function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer;
  262. // 3DES functions
  263. procedure DESsetoddparity(Key: des_cblock);
  264. function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer;
  265. procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer);
  266. function IsSSLloaded: Boolean;
  267. function InitSSLInterface: Boolean;
  268. function DestroySSLInterface: Boolean;
  269. implementation
  270. type
  271. // libssl.dll
  272. TSslGetError = function(s: PSSL; ret_code: Integer):Integer; cdecl;
  273. TSslLibraryInit = function:Integer; cdecl;
  274. TSslLoadErrorStrings = procedure; cdecl;
  275. TSslCtxSetCipherList = function(arg0: PSSL_CTX; str: PChar):Integer; cdecl;
  276. TSslCtxNew = function(meth: PSSL_METHOD):PSSL_CTX; cdecl;
  277. TSslCtxFree = procedure(arg0: PSSL_CTX); cdecl;
  278. TSslSetFd = function(s: PSSL; fd: Integer):Integer; cdecl;
  279. TSslMethodV2 = function:PSSL_METHOD; cdecl;
  280. TSslMethodV3 = function:PSSL_METHOD; cdecl;
  281. TSslMethodTLSV1 = function:PSSL_METHOD; cdecl;
  282. TSslMethodV23 = function:PSSL_METHOD; cdecl;
  283. TSslCtxUsePrivateKey = function(ctx: PSSL_CTX; pkey: sslptr):Integer; cdecl;
  284. TSslCtxUsePrivateKeyASN1 = function(pk: integer; ctx: PSSL_CTX; d: sslptr; len: integer):Integer; cdecl;
  285. TSslCtxUsePrivateKeyFile = function(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer; cdecl;
  286. TSslCtxUseCertificate = function(ctx: PSSL_CTX; x: SslPtr):Integer; cdecl;
  287. TSslCtxUseCertificateASN1 = function(ctx: PSSL_CTX; len: Integer; d: SslPtr):Integer; cdecl;
  288. TSslCtxUseCertificateFile = function(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer; cdecl;
  289. TSslCtxUseCertificateChainFile = function(ctx: PSSL_CTX; const _file: PChar):Integer; cdecl;
  290. TSslCtxCheckPrivateKeyFile = function(ctx: PSSL_CTX):Integer; cdecl;
  291. TSslCtxSetDefaultPasswdCb = procedure(ctx: PSSL_CTX; cb: SslPtr); cdecl;
  292. TSslCtxSetDefaultPasswdCbUserdata = procedure(ctx: PSSL_CTX; u: SslPtr); cdecl;
  293. TSslCtxLoadVerifyLocations = function(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):Integer; cdecl;
  294. TSslNew = function(ctx: PSSL_CTX):PSSL; cdecl;
  295. TSslFree = procedure(ssl: PSSL); cdecl;
  296. TSslAccept = function(ssl: PSSL):Integer; cdecl;
  297. TSslConnect = function(ssl: PSSL):Integer; cdecl;
  298. TSslShutdown = function(ssl: PSSL):Integer; cdecl;
  299. TSslRead = function(ssl: PSSL; buf: PChar; num: Integer):Integer; cdecl;
  300. TSslPeek = function(ssl: PSSL; buf: PChar; num: Integer):Integer; cdecl;
  301. TSslWrite = function(ssl: PSSL; const buf: PChar; num: Integer):Integer; cdecl;
  302. TSslPending = function(ssl: PSSL):Integer; cdecl;
  303. TSslGetVersion = function(ssl: PSSL):PChar; cdecl;
  304. TSslGetPeerCertificate = function(ssl: PSSL):PX509; cdecl;
  305. TSslCtxSetVerify = procedure(ctx: PSSL_CTX; mode: Integer; arg2: SslPtr); cdecl;
  306. TSSLGetCurrentCipher = function(s: PSSL):SslPtr; cdecl;
  307. TSSLCipherGetName = function(c: Sslptr):PChar; cdecl;
  308. TSSLCipherGetBits = function(c: SslPtr; alg_bits: PInteger):Integer; cdecl;
  309. TSSLGetVerifyResult = function(ssl: PSSL):Integer; cdecl;
  310. // libeay.dll
  311. TX509New = function: PX509; cdecl;
  312. TX509Free = procedure(x: PX509); cdecl;
  313. TX509NameOneline = function(a: PX509_NAME; buf: PChar; size: Integer):PChar; cdecl;
  314. TX509GetSubjectName = function(a: PX509):PX509_NAME; cdecl;
  315. TX509GetIssuerName = function(a: PX509):PX509_NAME; cdecl;
  316. TX509NameHash = function(x: PX509_NAME):Cardinal; cdecl;
  317. TX509Digest = function(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer; cdecl;
  318. TX509print = function(b: PBIO; a: PX509): integer; cdecl;
  319. TX509SetVersion = function(x: PX509; version: integer): integer; cdecl;
  320. TX509SetPubkey = function(x: PX509; pkey: EVP_PKEY): integer; cdecl;
  321. TX509SetIssuerName = function(x: PX509; name: PX509_NAME): integer; cdecl;
  322. TX509NameAddEntryByTxt = function(name: PX509_NAME; field: PChar; _type: integer;
  323. bytes: PChar; len, loc, _set: integer): integer; cdecl;
  324. TX509Sign = function(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer; cdecl;
  325. TX509GmtimeAdj = function(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME; cdecl;
  326. TX509SetNotBefore = function(x: PX509; tm: PASN1_UTCTIME): integer; cdecl;
  327. TX509SetNotAfter = function(x: PX509; tm: PASN1_UTCTIME): integer; cdecl;
  328. TX509GetSerialNumber = function(x: PX509): PASN1_INTEGER; cdecl;
  329. TEvpPkeyNew = function: EVP_PKEY; cdecl;
  330. TEvpPkeyFree = procedure(pk: EVP_PKEY); cdecl;
  331. TEvpPkeyAssign = function(pkey: EVP_PKEY; _type: integer; key: Prsa): integer; cdecl;
  332. TEvpGetDigestByName = function(Name: PChar): PEVP_MD; cdecl;
  333. TEVPcleanup = procedure; cdecl;
  334. TSSLeayversion = function(t: integer): PChar; cdecl;
  335. TErrErrorString = procedure(e: integer; buf: PChar; len: integer); cdecl;
  336. TErrGetError = function: integer; cdecl;
  337. TErrClearError = procedure; cdecl;
  338. TErrFreeStrings = procedure; cdecl;
  339. TErrRemoveState = procedure(pid: integer); cdecl;
  340. TOPENSSLaddallalgorithms = procedure; cdecl;
  341. TCRYPTOcleanupAllExData = procedure; cdecl;
  342. TRandScreen = procedure; cdecl;
  343. TBioNew = function(b: PBIO_METHOD): PBIO; cdecl;
  344. TBioFreeAll = procedure(b: PBIO); cdecl;
  345. TBioSMem = function: PBIO_METHOD; cdecl;
  346. TBioCtrlPending = function(b: PBIO): integer; cdecl;
  347. TBioRead = function(b: PBIO; Buf: PChar; Len: integer): integer; cdecl;
  348. TBioWrite = function(b: PBIO; Buf: PChar; Len: integer): integer; cdecl;
  349. Td2iPKCS12bio = function(b:PBIO; Pkcs12: SslPtr): SslPtr; cdecl;
  350. TPKCS12parse = function(p12: SslPtr; pass: PChar; var pkey, cert, ca: SslPtr): integer; cdecl;
  351. TPKCS12free = procedure(p12: SslPtr); cdecl;
  352. TRsaGenerateKey = function(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA; cdecl;
  353. TAsn1UtctimeNew = function: PASN1_UTCTIME; cdecl;
  354. TAsn1UtctimeFree = procedure(a: PASN1_UTCTIME); cdecl;
  355. TAsn1IntegerSet = function(a: PASN1_INTEGER; v: integer): integer; cdecl;
  356. Ti2dX509bio = function(b: PBIO; x: PX509): integer; cdecl;
  357. Ti2dPrivateKeyBio= function(b: PBIO; pkey: EVP_PKEY): integer; cdecl;
  358. // 3DES functions
  359. TDESsetoddparity = procedure(Key: des_cblock); cdecl;
  360. TDESsetkeychecked = function(key: des_cblock; schedule: des_key_schedule): Integer; cdecl;
  361. TDESecbencrypt = procedure(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer); cdecl;
  362. //thread lock functions
  363. TCRYPTOnumlocks = function: integer; cdecl;
  364. TCRYPTOSetLockingCallback = procedure(cb: Sslptr); cdecl;
  365. var
  366. // libssl.dll
  367. _SslGetError: TSslGetError = nil;
  368. _SslLibraryInit: TSslLibraryInit = nil;
  369. _SslLoadErrorStrings: TSslLoadErrorStrings = nil;
  370. _SslCtxSetCipherList: TSslCtxSetCipherList = nil;
  371. _SslCtxNew: TSslCtxNew = nil;
  372. _SslCtxFree: TSslCtxFree = nil;
  373. _SslSetFd: TSslSetFd = nil;
  374. _SslMethodV2: TSslMethodV2 = nil;
  375. _SslMethodV3: TSslMethodV3 = nil;
  376. _SslMethodTLSV1: TSslMethodTLSV1 = nil;
  377. _SslMethodV23: TSslMethodV23 = nil;
  378. _SslCtxUsePrivateKey: TSslCtxUsePrivateKey = nil;
  379. _SslCtxUsePrivateKeyASN1: TSslCtxUsePrivateKeyASN1 = nil;
  380. _SslCtxUsePrivateKeyFile: TSslCtxUsePrivateKeyFile = nil;
  381. _SslCtxUseCertificate: TSslCtxUseCertificate = nil;
  382. _SslCtxUseCertificateASN1: TSslCtxUseCertificateASN1 = nil;
  383. _SslCtxUseCertificateFile: TSslCtxUseCertificateFile = nil;
  384. _SslCtxUseCertificateChainFile: TSslCtxUseCertificateChainFile = nil;
  385. _SslCtxCheckPrivateKeyFile: TSslCtxCheckPrivateKeyFile = nil;
  386. _SslCtxSetDefaultPasswdCb: TSslCtxSetDefaultPasswdCb = nil;
  387. _SslCtxSetDefaultPasswdCbUserdata: TSslCtxSetDefaultPasswdCbUserdata = nil;
  388. _SslCtxLoadVerifyLocations: TSslCtxLoadVerifyLocations = nil;
  389. _SslNew: TSslNew = nil;
  390. _SslFree: TSslFree = nil;
  391. _SslAccept: TSslAccept = nil;
  392. _SslConnect: TSslConnect = nil;
  393. _SslShutdown: TSslShutdown = nil;
  394. _SslRead: TSslRead = nil;
  395. _SslPeek: TSslPeek = nil;
  396. _SslWrite: TSslWrite = nil;
  397. _SslPending: TSslPending = nil;
  398. _SslGetVersion: TSslGetVersion = nil;
  399. _SslGetPeerCertificate: TSslGetPeerCertificate = nil;
  400. _SslCtxSetVerify: TSslCtxSetVerify = nil;
  401. _SSLGetCurrentCipher: TSSLGetCurrentCipher = nil;
  402. _SSLCipherGetName: TSSLCipherGetName = nil;
  403. _SSLCipherGetBits: TSSLCipherGetBits = nil;
  404. _SSLGetVerifyResult: TSSLGetVerifyResult = nil;
  405. // libeay.dll
  406. _X509New: TX509New = nil;
  407. _X509Free: TX509Free = nil;
  408. _X509NameOneline: TX509NameOneline = nil;
  409. _X509GetSubjectName: TX509GetSubjectName = nil;
  410. _X509GetIssuerName: TX509GetIssuerName = nil;
  411. _X509NameHash: TX509NameHash = nil;
  412. _X509Digest: TX509Digest = nil;
  413. _X509print: TX509print = nil;
  414. _X509SetVersion: TX509SetVersion = nil;
  415. _X509SetPubkey: TX509SetPubkey = nil;
  416. _X509SetIssuerName: TX509SetIssuerName = nil;
  417. _X509NameAddEntryByTxt: TX509NameAddEntryByTxt = nil;
  418. _X509Sign: TX509Sign = nil;
  419. _X509GmtimeAdj: TX509GmtimeAdj = nil;
  420. _X509SetNotBefore: TX509SetNotBefore = nil;
  421. _X509SetNotAfter: TX509SetNotAfter = nil;
  422. _X509GetSerialNumber: TX509GetSerialNumber = nil;
  423. _EvpPkeyNew: TEvpPkeyNew = nil;
  424. _EvpPkeyFree: TEvpPkeyFree = nil;
  425. _EvpPkeyAssign: TEvpPkeyAssign = nil;
  426. _EvpGetDigestByName: TEvpGetDigestByName = nil;
  427. _EVPcleanup: TEVPcleanup = nil;
  428. _SSLeayversion: TSSLeayversion = nil;
  429. _ErrErrorString: TErrErrorString = nil;
  430. _ErrGetError: TErrGetError = nil;
  431. _ErrClearError: TErrClearError = nil;
  432. _ErrFreeStrings: TErrFreeStrings = nil;
  433. _ErrRemoveState: TErrRemoveState = nil;
  434. _OPENSSLaddallalgorithms: TOPENSSLaddallalgorithms = nil;
  435. _CRYPTOcleanupAllExData: TCRYPTOcleanupAllExData = nil;
  436. _RandScreen: TRandScreen = nil;
  437. _BioNew: TBioNew = nil;
  438. _BioFreeAll: TBioFreeAll = nil;
  439. _BioSMem: TBioSMem = nil;
  440. _BioCtrlPending: TBioCtrlPending = nil;
  441. _BioRead: TBioRead = nil;
  442. _BioWrite: TBioWrite = nil;
  443. _d2iPKCS12bio: Td2iPKCS12bio = nil;
  444. _PKCS12parse: TPKCS12parse = nil;
  445. _PKCS12free: TPKCS12free = nil;
  446. _RsaGenerateKey: TRsaGenerateKey = nil;
  447. _Asn1UtctimeNew: TAsn1UtctimeNew = nil;
  448. _Asn1UtctimeFree: TAsn1UtctimeFree = nil;
  449. _Asn1IntegerSet: TAsn1IntegerSet = nil;
  450. _i2dX509bio: Ti2dX509bio = nil;
  451. _i2dPrivateKeyBio: Ti2dPrivateKeyBio = nil;
  452. // 3DES functions
  453. _DESsetoddparity: TDESsetoddparity = nil;
  454. _DESsetkeychecked: TDESsetkeychecked = nil;
  455. _DESecbencrypt: TDESecbencrypt = nil;
  456. //thread lock functions
  457. _CRYPTOnumlocks: TCRYPTOnumlocks = nil;
  458. _CRYPTOSetLockingCallback: TCRYPTOSetLockingCallback = nil;
  459. var
  460. SSLloaded: boolean = false;
  461. // libssl.dll
  462. function SslGetError(s: PSSL; ret_code: Integer):Integer;
  463. begin
  464. if InitSSLInterface and Assigned(_SslGetError) then
  465. Result := _SslGetError(s, ret_code)
  466. else
  467. Result := SSL_ERROR_SSL;
  468. end;
  469. function SslLibraryInit:Integer;
  470. begin
  471. if InitSSLInterface and Assigned(_SslLibraryInit) then
  472. Result := _SslLibraryInit
  473. else
  474. Result := 1;
  475. end;
  476. procedure SslLoadErrorStrings;
  477. begin
  478. if InitSSLInterface and Assigned(_SslLoadErrorStrings) then
  479. _SslLoadErrorStrings;
  480. end;
  481. function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String):Integer;
  482. begin
  483. if InitSSLInterface and Assigned(_SslCtxSetCipherList) then
  484. Result := _SslCtxSetCipherList(arg0, PChar(str))
  485. else
  486. Result := 0;
  487. end;
  488. function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
  489. begin
  490. if InitSSLInterface and Assigned(_SslCtxNew) then
  491. Result := _SslCtxNew(meth)
  492. else
  493. Result := nil;
  494. end;
  495. procedure SslCtxFree(arg0: PSSL_CTX);
  496. begin
  497. if InitSSLInterface and Assigned(_SslCtxFree) then
  498. _SslCtxFree(arg0);
  499. end;
  500. function SslSetFd(s: PSSL; fd: Integer):Integer;
  501. begin
  502. if InitSSLInterface and Assigned(_SslSetFd) then
  503. Result := _SslSetFd(s, fd)
  504. else
  505. Result := 0;
  506. end;
  507. function SslMethodV2:PSSL_METHOD;
  508. begin
  509. if InitSSLInterface and Assigned(_SslMethodV2) then
  510. Result := _SslMethodV2
  511. else
  512. Result := nil;
  513. end;
  514. function SslMethodV3:PSSL_METHOD;
  515. begin
  516. if InitSSLInterface and Assigned(_SslMethodV3) then
  517. Result := _SslMethodV3
  518. else
  519. Result := nil;
  520. end;
  521. function SslMethodTLSV1:PSSL_METHOD;
  522. begin
  523. if InitSSLInterface and Assigned(_SslMethodTLSV1) then
  524. Result := _SslMethodTLSV1
  525. else
  526. Result := nil;
  527. end;
  528. function SslMethodV23:PSSL_METHOD;
  529. begin
  530. if InitSSLInterface and Assigned(_SslMethodV23) then
  531. Result := _SslMethodV23
  532. else
  533. Result := nil;
  534. end;
  535. function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):Integer;
  536. begin
  537. if InitSSLInterface and Assigned(_SslCtxUsePrivateKey) then
  538. Result := _SslCtxUsePrivateKey(ctx, pkey)
  539. else
  540. Result := 0;
  541. end;
  542. function SslCtxUsePrivateKeyASN1(pk: integer; ctx: PSSL_CTX; d: String; len: integer):Integer;
  543. begin
  544. if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyASN1) then
  545. Result := _SslCtxUsePrivateKeyASN1(pk, ctx, Sslptr(d), len)
  546. else
  547. Result := 0;
  548. end;
  549. function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
  550. begin
  551. if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyFile) then
  552. Result := _SslCtxUsePrivateKeyFile(ctx, PChar(_file), _type)
  553. else
  554. Result := 0;
  555. end;
  556. function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):Integer;
  557. begin
  558. if InitSSLInterface and Assigned(_SslCtxUseCertificate) then
  559. Result := _SslCtxUseCertificate(ctx, x)
  560. else
  561. Result := 0;
  562. end;
  563. function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: integer; d: String):Integer;
  564. begin
  565. if InitSSLInterface and Assigned(_SslCtxUseCertificateASN1) then
  566. Result := _SslCtxUseCertificateASN1(ctx, len, SslPtr(d))
  567. else
  568. Result := 0;
  569. end;
  570. function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
  571. begin
  572. if InitSSLInterface and Assigned(_SslCtxUseCertificateFile) then
  573. Result := _SslCtxUseCertificateFile(ctx, PChar(_file), _type)
  574. else
  575. Result := 0;
  576. end;
  577. function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):Integer;
  578. begin
  579. if InitSSLInterface and Assigned(_SslCtxUseCertificateChainFile) then
  580. Result := _SslCtxUseCertificateChainFile(ctx, PChar(_file))
  581. else
  582. Result := 0;
  583. end;
  584. function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer;
  585. begin
  586. if InitSSLInterface and Assigned(_SslCtxCheckPrivateKeyFile) then
  587. Result := _SslCtxCheckPrivateKeyFile(ctx)
  588. else
  589. Result := 0;
  590. end;
  591. procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
  592. begin
  593. if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCb) then
  594. _SslCtxSetDefaultPasswdCb(ctx, cb);
  595. end;
  596. procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
  597. begin
  598. if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCbUserdata) then
  599. _SslCtxSetDefaultPasswdCbUserdata(ctx, u);
  600. end;
  601. function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: String; const CApath: String):Integer;
  602. begin
  603. if InitSSLInterface and Assigned(_SslCtxLoadVerifyLocations) then
  604. Result := _SslCtxLoadVerifyLocations(ctx, SslPtr(CAfile), SslPtr(CApath))
  605. else
  606. Result := 0;
  607. end;
  608. function SslNew(ctx: PSSL_CTX):PSSL;
  609. begin
  610. if InitSSLInterface and Assigned(_SslNew) then
  611. Result := _SslNew(ctx)
  612. else
  613. Result := nil;
  614. end;
  615. procedure SslFree(ssl: PSSL);
  616. begin
  617. if InitSSLInterface and Assigned(_SslFree) then
  618. _SslFree(ssl);
  619. end;
  620. function SslAccept(ssl: PSSL):Integer;
  621. begin
  622. if InitSSLInterface and Assigned(_SslAccept) then
  623. Result := _SslAccept(ssl)
  624. else
  625. Result := -1;
  626. end;
  627. function SslConnect(ssl: PSSL):Integer;
  628. begin
  629. if InitSSLInterface and Assigned(_SslConnect) then
  630. Result := _SslConnect(ssl)
  631. else
  632. Result := -1;
  633. end;
  634. function SslShutdown(ssl: PSSL):Integer;
  635. begin
  636. if InitSSLInterface and Assigned(_SslShutdown) then
  637. Result := _SslShutdown(ssl)
  638. else
  639. Result := -1;
  640. end;
  641. function SslRead(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  642. begin
  643. if InitSSLInterface and Assigned(_SslRead) then
  644. Result := _SslRead(ssl, PChar(buf), num)
  645. else
  646. Result := -1;
  647. end;
  648. function SslPeek(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  649. begin
  650. if InitSSLInterface and Assigned(_SslPeek) then
  651. Result := _SslPeek(ssl, PChar(buf), num)
  652. else
  653. Result := -1;
  654. end;
  655. function SslWrite(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  656. begin
  657. if InitSSLInterface and Assigned(_SslWrite) then
  658. Result := _SslWrite(ssl, PChar(buf), num)
  659. else
  660. Result := -1;
  661. end;
  662. function SslPending(ssl: PSSL):Integer;
  663. begin
  664. if InitSSLInterface and Assigned(_SslPending) then
  665. Result := _SslPending(ssl)
  666. else
  667. Result := 0;
  668. end;
  669. //function SslGetVersion(ssl: PSSL):PChar;
  670. function SslGetVersion(ssl: PSSL):String;
  671. begin
  672. if InitSSLInterface and Assigned(_SslGetVersion) then
  673. Result := _SslGetVersion(ssl)
  674. else
  675. Result := '';
  676. end;
  677. function SslGetPeerCertificate(ssl: PSSL):PX509;
  678. begin
  679. if InitSSLInterface and Assigned(_SslGetPeerCertificate) then
  680. Result := _SslGetPeerCertificate(ssl)
  681. else
  682. Result := nil;
  683. end;
  684. procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction);
  685. begin
  686. if InitSSLInterface and Assigned(_SslCtxSetVerify) then
  687. _SslCtxSetVerify(ctx, mode, @arg2);
  688. end;
  689. function SSLGetCurrentCipher(s: PSSL):SslPtr;
  690. begin
  691. if InitSSLInterface and Assigned(_SSLGetCurrentCipher) then
  692. {$IFDEF CIL}
  693. {$ELSE}
  694. Result := _SSLGetCurrentCipher(s)
  695. {$ENDIF}
  696. else
  697. Result := nil;
  698. end;
  699. function SSLCipherGetName(c: SslPtr):String;
  700. begin
  701. if InitSSLInterface and Assigned(_SSLCipherGetName) then
  702. Result := _SSLCipherGetName(c)
  703. else
  704. Result := '';
  705. end;
  706. function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer;
  707. begin
  708. if InitSSLInterface and Assigned(_SSLCipherGetBits) then
  709. Result := _SSLCipherGetBits(c, @alg_bits)
  710. else
  711. Result := 0;
  712. end;
  713. function SSLGetVerifyResult(ssl: PSSL):Integer;
  714. begin
  715. if InitSSLInterface and Assigned(_SSLGetVerifyResult) then
  716. Result := _SSLGetVerifyResult(ssl)
  717. else
  718. Result := X509_V_ERR_APPLICATION_VERIFICATION;
  719. end;
  720. // libeay.dll
  721. function X509New: PX509;
  722. begin
  723. if InitSSLInterface and Assigned(_X509New) then
  724. Result := _X509New
  725. else
  726. Result := nil;
  727. end;
  728. procedure X509Free(x: PX509);
  729. begin
  730. if InitSSLInterface and Assigned(_X509Free) then
  731. _X509Free(x);
  732. end;
  733. function X509NameOneline(a: PX509_NAME; var buf: String; size: Integer):String;
  734. begin
  735. if InitSSLInterface and Assigned(_X509NameOneline) then
  736. Result := _X509NameOneline(a, PChar(buf),size)
  737. else
  738. Result := '';
  739. end;
  740. function X509GetSubjectName(a: PX509):PX509_NAME;
  741. begin
  742. if InitSSLInterface and Assigned(_X509GetSubjectName) then
  743. Result := _X509GetSubjectName(a)
  744. else
  745. Result := nil;
  746. end;
  747. function X509GetIssuerName(a: PX509):PX509_NAME;
  748. begin
  749. if InitSSLInterface and Assigned(_X509GetIssuerName) then
  750. Result := _X509GetIssuerName(a)
  751. else
  752. Result := nil;
  753. end;
  754. function X509NameHash(x: PX509_NAME):Cardinal;
  755. begin
  756. if InitSSLInterface and Assigned(_X509NameHash) then
  757. Result := _X509NameHash(x)
  758. else
  759. Result := 0;
  760. end;
  761. function X509Digest(data: PX509; _type: PEVP_MD; md: String; var len: Integer):Integer;
  762. begin
  763. if InitSSLInterface and Assigned(_X509Digest) then
  764. Result := _X509Digest(data, _type, PChar(md), @len)
  765. else
  766. Result := 0;
  767. end;
  768. function EvpPkeyNew: EVP_PKEY;
  769. begin
  770. if InitSSLInterface and Assigned(_EvpPkeyNew) then
  771. Result := _EvpPkeyNew
  772. else
  773. Result := nil;
  774. end;
  775. procedure EvpPkeyFree(pk: EVP_PKEY);
  776. begin
  777. if InitSSLInterface and Assigned(_EvpPkeyFree) then
  778. _EvpPkeyFree(pk);
  779. end;
  780. function SSLeayversion(t: integer): string;
  781. begin
  782. if InitSSLInterface and Assigned(_SSLeayversion) then
  783. Result := PChar(_SSLeayversion(t))
  784. else
  785. Result := '';
  786. end;
  787. procedure ErrErrorString(e: integer; var buf: string; len: integer);
  788. begin
  789. if InitSSLInterface and Assigned(_ErrErrorString) then
  790. _ErrErrorString(e, Pointer(buf), len);
  791. buf := PChar(Buf);
  792. end;
  793. function ErrGetError: integer;
  794. begin
  795. if InitSSLInterface and Assigned(_ErrGetError) then
  796. Result := _ErrGetError
  797. else
  798. Result := SSL_ERROR_SSL;
  799. end;
  800. procedure ErrClearError;
  801. begin
  802. if InitSSLInterface and Assigned(_ErrClearError) then
  803. _ErrClearError;
  804. end;
  805. procedure ErrFreeStrings;
  806. begin
  807. if InitSSLInterface and Assigned(_ErrFreeStrings) then
  808. _ErrFreeStrings;
  809. end;
  810. procedure ErrRemoveState(pid: integer);
  811. begin
  812. if InitSSLInterface and Assigned(_ErrRemoveState) then
  813. _ErrRemoveState(pid);
  814. end;
  815. procedure OPENSSLaddallalgorithms;
  816. begin
  817. if InitSSLInterface and Assigned(_OPENSSLaddallalgorithms) then
  818. _OPENSSLaddallalgorithms;
  819. end;
  820. procedure EVPcleanup;
  821. begin
  822. if InitSSLInterface and Assigned(_EVPcleanup) then
  823. _EVPcleanup;
  824. end;
  825. procedure CRYPTOcleanupAllExData;
  826. begin
  827. if InitSSLInterface and Assigned(_CRYPTOcleanupAllExData) then
  828. _CRYPTOcleanupAllExData;
  829. end;
  830. procedure RandScreen;
  831. begin
  832. if InitSSLInterface and Assigned(_RandScreen) then
  833. _RandScreen;
  834. end;
  835. function BioNew(b: PBIO_METHOD): PBIO;
  836. begin
  837. if InitSSLInterface and Assigned(_BioNew) then
  838. Result := _BioNew(b)
  839. else
  840. Result := nil;
  841. end;
  842. procedure BioFreeAll(b: PBIO);
  843. begin
  844. if InitSSLInterface and Assigned(_BioFreeAll) then
  845. _BioFreeAll(b);
  846. end;
  847. function BioSMem: PBIO_METHOD;
  848. begin
  849. if InitSSLInterface and Assigned(_BioSMem) then
  850. Result := _BioSMem
  851. else
  852. Result := nil;
  853. end;
  854. function BioCtrlPending(b: PBIO): integer;
  855. begin
  856. if InitSSLInterface and Assigned(_BioCtrlPending) then
  857. Result := _BioCtrlPending(b)
  858. else
  859. Result := 0;
  860. end;
  861. function BioRead(b: PBIO; var Buf: String; Len: integer): integer;
  862. begin
  863. if InitSSLInterface and Assigned(_BioRead) then
  864. Result := _BioRead(b, PChar(Buf), Len)
  865. else
  866. Result := -2;
  867. end;
  868. //function BioWrite(b: PBIO; Buf: PChar; Len: integer): integer;
  869. function BioWrite(b: PBIO; Buf: String; Len: integer): integer;
  870. begin
  871. if InitSSLInterface and Assigned(_BioWrite) then
  872. Result := _BioWrite(b, PChar(Buf), Len)
  873. else
  874. Result := -2;
  875. end;
  876. function X509print(b: PBIO; a: PX509): integer;
  877. begin
  878. if InitSSLInterface and Assigned(_X509print) then
  879. Result := _X509print(b, a)
  880. else
  881. Result := 0;
  882. end;
  883. function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
  884. begin
  885. if InitSSLInterface and Assigned(_d2iPKCS12bio) then
  886. Result := _d2iPKCS12bio(b, Pkcs12)
  887. else
  888. Result := nil;
  889. end;
  890. function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): integer;
  891. begin
  892. if InitSSLInterface and Assigned(_PKCS12parse) then
  893. Result := _PKCS12parse(p12, SslPtr(pass), pkey, cert, ca)
  894. else
  895. Result := 0;
  896. end;
  897. procedure PKCS12free(p12: SslPtr);
  898. begin
  899. if InitSSLInterface and Assigned(_PKCS12free) then
  900. _PKCS12free(p12);
  901. end;
  902. function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA;
  903. begin
  904. if InitSSLInterface and Assigned(_RsaGenerateKey) then
  905. Result := _RsaGenerateKey(bits, e, callback, cb_arg)
  906. else
  907. Result := nil;
  908. end;
  909. function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer;
  910. begin
  911. if InitSSLInterface and Assigned(_EvpPkeyAssign) then
  912. Result := _EvpPkeyAssign(pkey, _type, key)
  913. else
  914. Result := 0;
  915. end;
  916. function X509SetVersion(x: PX509; version: integer): integer;
  917. begin
  918. if InitSSLInterface and Assigned(_X509SetVersion) then
  919. Result := _X509SetVersion(x, version)
  920. else
  921. Result := 0;
  922. end;
  923. function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer;
  924. begin
  925. if InitSSLInterface and Assigned(_X509SetPubkey) then
  926. Result := _X509SetPubkey(x, pkey)
  927. else
  928. Result := 0;
  929. end;
  930. function X509SetIssuerName(x: PX509; name: PX509_NAME): integer;
  931. begin
  932. if InitSSLInterface and Assigned(_X509SetIssuerName) then
  933. Result := _X509SetIssuerName(x, name)
  934. else
  935. Result := 0;
  936. end;
  937. function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: integer;
  938. bytes: string; len, loc, _set: integer): integer;
  939. begin
  940. if InitSSLInterface and Assigned(_X509NameAddEntryByTxt) then
  941. Result := _X509NameAddEntryByTxt(name, PChar(field), _type, PChar(Bytes), len, loc, _set)
  942. else
  943. Result := 0;
  944. end;
  945. function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer;
  946. begin
  947. if InitSSLInterface and Assigned(_X509Sign) then
  948. Result := _X509Sign(x, pkey, md)
  949. else
  950. Result := 0;
  951. end;
  952. function Asn1UtctimeNew: PASN1_UTCTIME;
  953. begin
  954. if InitSSLInterface and Assigned(_Asn1UtctimeNew) then
  955. Result := _Asn1UtctimeNew
  956. else
  957. Result := nil;
  958. end;
  959. procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
  960. begin
  961. if InitSSLInterface and Assigned(_Asn1UtctimeFree) then
  962. _Asn1UtctimeFree(a);
  963. end;
  964. function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME;
  965. begin
  966. if InitSSLInterface and Assigned(_X509GmtimeAdj) then
  967. Result := _X509GmtimeAdj(s, adj)
  968. else
  969. Result := nil;
  970. end;
  971. function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer;
  972. begin
  973. if InitSSLInterface and Assigned(_X509SetNotBefore) then
  974. Result := _X509SetNotBefore(x, tm)
  975. else
  976. Result := 0;
  977. end;
  978. function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer;
  979. begin
  980. if InitSSLInterface and Assigned(_X509SetNotAfter) then
  981. Result := _X509SetNotAfter(x, tm)
  982. else
  983. Result := 0;
  984. end;
  985. function i2dX509bio(b: PBIO; x: PX509): integer;
  986. begin
  987. if InitSSLInterface and Assigned(_i2dX509bio) then
  988. Result := _i2dX509bio(b, x)
  989. else
  990. Result := 0;
  991. end;
  992. function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer;
  993. begin
  994. if InitSSLInterface and Assigned(_i2dPrivateKeyBio) then
  995. Result := _i2dPrivateKeyBio(b, pkey)
  996. else
  997. Result := 0;
  998. end;
  999. function EvpGetDigestByName(Name: String): PEVP_MD;
  1000. begin
  1001. if InitSSLInterface and Assigned(_EvpGetDigestByName) then
  1002. Result := _EvpGetDigestByName(PChar(Name))
  1003. else
  1004. Result := nil;
  1005. end;
  1006. function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
  1007. begin
  1008. if InitSSLInterface and Assigned(_Asn1IntegerSet) then
  1009. Result := _Asn1IntegerSet(a, v)
  1010. else
  1011. Result := 0;
  1012. end;
  1013. function X509GetSerialNumber(x: PX509): PASN1_INTEGER;
  1014. begin
  1015. if InitSSLInterface and Assigned(_X509GetSerialNumber) then
  1016. Result := _X509GetSerialNumber(x)
  1017. else
  1018. Result := nil;
  1019. end;
  1020. // 3DES functions
  1021. procedure DESsetoddparity(Key: des_cblock);
  1022. begin
  1023. if InitSSLInterface and Assigned(_DESsetoddparity) then
  1024. _DESsetoddparity(Key);
  1025. end;
  1026. function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer;
  1027. begin
  1028. if InitSSLInterface and Assigned(_DESsetkeychecked) then
  1029. Result := _DESsetkeychecked(key, schedule)
  1030. else
  1031. Result := -1;
  1032. end;
  1033. procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer);
  1034. begin
  1035. if InitSSLInterface and Assigned(_DESecbencrypt) then
  1036. _DESecbencrypt(Input, output, ks, enc);
  1037. end;
  1038. {$IFNDEF WINDOWS}
  1039. { Try to load all library versions until you find or run out }
  1040. function LoadLibHack(const Value: String): HModule;
  1041. var
  1042. i: Integer;
  1043. begin
  1044. Result := NilHandle;
  1045. for i := Low(DLLVersions) to High(DLLVersions) do begin
  1046. {$IFDEF DARWIN}
  1047. Result := LoadLibrary(Value + DLLVersions[i] + '.dylib');
  1048. {$ELSE}
  1049. Result := LoadLibrary(Value + '.so' + DLLVersions[i]);
  1050. {$ENDIF}
  1051. if Result <> NilHandle then
  1052. Break;
  1053. end;
  1054. end;
  1055. {$ENDIF}
  1056. function LoadLib(const Value: String): HModule;
  1057. begin
  1058. {$IFDEF WINDOWS}
  1059. Result := LoadLibrary(Value);
  1060. {$ELSE}
  1061. Result := LoadLibHack(Value);
  1062. {$ENDIF}
  1063. end;
  1064. function GetProcAddr(module: HModule; const ProcName: string): SslPtr;
  1065. begin
  1066. Result := GetProcAddress(module, PChar(ProcName));
  1067. end;
  1068. function InitSSLInterface: Boolean;
  1069. begin
  1070. if not IsSSLloaded then
  1071. begin
  1072. SSLLibHandle := LoadLib(DLLSSLName);
  1073. SSLUtilHandle := LoadLib(DLLUtilName);
  1074. {$IFNDEF UNIX}
  1075. if (SSLLibHandle = 0) then
  1076. SSLLibHandle := LoadLib(DLLSSLName2);
  1077. {$ENDIF}
  1078. if (SSLLibHandle <> 0) and (SSLUtilHandle <> 0) then
  1079. begin
  1080. _SslGetError := GetProcAddr(SSLLibHandle, 'SSL_get_error');
  1081. _SslLibraryInit := GetProcAddr(SSLLibHandle, 'SSL_library_init');
  1082. _SslLoadErrorStrings := GetProcAddr(SSLLibHandle, 'SSL_load_error_strings');
  1083. _SslCtxSetCipherList := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_cipher_list');
  1084. _SslCtxNew := GetProcAddr(SSLLibHandle, 'SSL_CTX_new');
  1085. _SslCtxFree := GetProcAddr(SSLLibHandle, 'SSL_CTX_free');
  1086. _SslSetFd := GetProcAddr(SSLLibHandle, 'SSL_set_fd');
  1087. _SslMethodV2 := GetProcAddr(SSLLibHandle, 'SSLv2_method');
  1088. _SslMethodV3 := GetProcAddr(SSLLibHandle, 'SSLv3_method');
  1089. _SslMethodTLSV1 := GetProcAddr(SSLLibHandle, 'TLSv1_method');
  1090. _SslMethodV23 := GetProcAddr(SSLLibHandle, 'SSLv23_method');
  1091. _SslCtxUsePrivateKey := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey');
  1092. _SslCtxUsePrivateKeyASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey_ASN1');
  1093. //use SSL_CTX_use_RSAPrivateKey_file instead SSL_CTX_use_PrivateKey_file,
  1094. //because SSL_CTX_use_PrivateKey_file not support DER format. :-O
  1095. _SslCtxUsePrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_RSAPrivateKey_file');
  1096. _SslCtxUseCertificate := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate');
  1097. _SslCtxUseCertificateASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_ASN1');
  1098. _SslCtxUseCertificateFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_file');
  1099. _SslCtxUseCertificateChainFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_chain_file');
  1100. _SslCtxCheckPrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_check_private_key');
  1101. _SslCtxSetDefaultPasswdCb := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb');
  1102. _SslCtxSetDefaultPasswdCbUserdata := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb_userdata');
  1103. _SslCtxLoadVerifyLocations := GetProcAddr(SSLLibHandle, 'SSL_CTX_load_verify_locations');
  1104. _SslNew := GetProcAddr(SSLLibHandle, 'SSL_new');
  1105. _SslFree := GetProcAddr(SSLLibHandle, 'SSL_free');
  1106. _SslAccept := GetProcAddr(SSLLibHandle, 'SSL_accept');
  1107. _SslConnect := GetProcAddr(SSLLibHandle, 'SSL_connect');
  1108. _SslShutdown := GetProcAddr(SSLLibHandle, 'SSL_shutdown');
  1109. _SslRead := GetProcAddr(SSLLibHandle, 'SSL_read');
  1110. _SslPeek := GetProcAddr(SSLLibHandle, 'SSL_peek');
  1111. _SslWrite := GetProcAddr(SSLLibHandle, 'SSL_write');
  1112. _SslPending := GetProcAddr(SSLLibHandle, 'SSL_pending');
  1113. _SslGetPeerCertificate := GetProcAddr(SSLLibHandle, 'SSL_get_peer_certificate');
  1114. _SslGetVersion := GetProcAddr(SSLLibHandle, 'SSL_get_version');
  1115. _SslCtxSetVerify := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_verify');
  1116. _SslGetCurrentCipher := GetProcAddr(SSLLibHandle, 'SSL_get_current_cipher');
  1117. _SslCipherGetName := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_name');
  1118. _SslCipherGetBits := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_bits');
  1119. _SslGetVerifyResult := GetProcAddr(SSLLibHandle, 'SSL_get_verify_result');
  1120. _X509New := GetProcAddr(SSLUtilHandle, 'X509_new');
  1121. _X509Free := GetProcAddr(SSLUtilHandle, 'X509_free');
  1122. _X509NameOneline := GetProcAddr(SSLUtilHandle, 'X509_NAME_oneline');
  1123. _X509GetSubjectName := GetProcAddr(SSLUtilHandle, 'X509_get_subject_name');
  1124. _X509GetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_get_issuer_name');
  1125. _X509NameHash := GetProcAddr(SSLUtilHandle, 'X509_NAME_hash');
  1126. _X509Digest := GetProcAddr(SSLUtilHandle, 'X509_digest');
  1127. _X509print := GetProcAddr(SSLUtilHandle, 'X509_print');
  1128. _X509SetVersion := GetProcAddr(SSLUtilHandle, 'X509_set_version');
  1129. _X509SetPubkey := GetProcAddr(SSLUtilHandle, 'X509_set_pubkey');
  1130. _X509SetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_set_issuer_name');
  1131. _X509NameAddEntryByTxt := GetProcAddr(SSLUtilHandle, 'X509_NAME_add_entry_by_txt');
  1132. _X509Sign := GetProcAddr(SSLUtilHandle, 'X509_sign');
  1133. _X509GmtimeAdj := GetProcAddr(SSLUtilHandle, 'X509_gmtime_adj');
  1134. _X509SetNotBefore := GetProcAddr(SSLUtilHandle, 'X509_set_notBefore');
  1135. _X509SetNotAfter := GetProcAddr(SSLUtilHandle, 'X509_set_notAfter');
  1136. _X509GetSerialNumber := GetProcAddr(SSLUtilHandle, 'X509_get_serialNumber');
  1137. _EvpPkeyNew := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_new');
  1138. _EvpPkeyFree := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_free');
  1139. _EvpPkeyAssign := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_assign');
  1140. _EVPCleanup := GetProcAddr(SSLUtilHandle, 'EVP_cleanup');
  1141. _EvpGetDigestByName := GetProcAddr(SSLUtilHandle, 'EVP_get_digestbyname');
  1142. _SSLeayversion := GetProcAddr(SSLUtilHandle, 'SSLeay_version');
  1143. _ErrErrorString := GetProcAddr(SSLUtilHandle, 'ERR_error_string_n');
  1144. _ErrGetError := GetProcAddr(SSLUtilHandle, 'ERR_get_error');
  1145. _ErrClearError := GetProcAddr(SSLUtilHandle, 'ERR_clear_error');
  1146. _ErrFreeStrings := GetProcAddr(SSLUtilHandle, 'ERR_free_strings');
  1147. _ErrRemoveState := GetProcAddr(SSLUtilHandle, 'ERR_remove_state');
  1148. _OPENSSLaddallalgorithms := GetProcAddr(SSLUtilHandle, 'OPENSSL_add_all_algorithms_noconf');
  1149. _CRYPTOcleanupAllExData := GetProcAddr(SSLUtilHandle, 'CRYPTO_cleanup_all_ex_data');
  1150. _RandScreen := GetProcAddr(SSLUtilHandle, 'RAND_screen');
  1151. _BioNew := GetProcAddr(SSLUtilHandle, 'BIO_new');
  1152. _BioFreeAll := GetProcAddr(SSLUtilHandle, 'BIO_free_all');
  1153. _BioSMem := GetProcAddr(SSLUtilHandle, 'BIO_s_mem');
  1154. _BioCtrlPending := GetProcAddr(SSLUtilHandle, 'BIO_ctrl_pending');
  1155. _BioRead := GetProcAddr(SSLUtilHandle, 'BIO_read');
  1156. _BioWrite := GetProcAddr(SSLUtilHandle, 'BIO_write');
  1157. _d2iPKCS12bio := GetProcAddr(SSLUtilHandle, 'd2i_PKCS12_bio');
  1158. _PKCS12parse := GetProcAddr(SSLUtilHandle, 'PKCS12_parse');
  1159. _PKCS12free := GetProcAddr(SSLUtilHandle, 'PKCS12_free');
  1160. _RsaGenerateKey := GetProcAddr(SSLUtilHandle, 'RSA_generate_key');
  1161. _Asn1UtctimeNew := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_new');
  1162. _Asn1UtctimeFree := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_free');
  1163. _Asn1IntegerSet := GetProcAddr(SSLUtilHandle, 'ASN1_INTEGER_set');
  1164. _i2dX509bio := GetProcAddr(SSLUtilHandle, 'i2d_X509_bio');
  1165. _i2dPrivateKeyBio := GetProcAddr(SSLUtilHandle, 'i2d_PrivateKey_bio');
  1166. // 3DES functions
  1167. _DESsetoddparity := GetProcAddr(SSLUtilHandle, 'DES_set_odd_parity');
  1168. _DESsetkeychecked := GetProcAddr(SSLUtilHandle, 'DES_set_key_checked');
  1169. _DESecbencrypt := GetProcAddr(SSLUtilHandle, 'DES_ecb_encrypt');
  1170. //
  1171. _CRYPTOnumlocks := GetProcAddr(SSLUtilHandle, 'CRYPTO_num_locks');
  1172. _CRYPTOsetlockingcallback := GetProcAddr(SSLUtilHandle, 'CRYPTO_set_locking_callback');
  1173. //init library
  1174. if assigned(_SslLibraryInit) then
  1175. _SslLibraryInit;
  1176. if assigned(_SslLoadErrorStrings) then
  1177. _SslLoadErrorStrings;
  1178. if assigned(_OPENSSLaddallalgorithms) then
  1179. _OPENSSLaddallalgorithms;
  1180. if assigned(_RandScreen) then
  1181. _RandScreen;
  1182. Result := True;
  1183. SSLloaded := True;
  1184. end
  1185. else
  1186. begin
  1187. //load failed!
  1188. if SSLLibHandle <> 0 then
  1189. begin
  1190. FreeLibrary(SSLLibHandle);
  1191. SSLLibHandle := 0;
  1192. end;
  1193. if SSLUtilHandle <> 0 then
  1194. begin
  1195. FreeLibrary(SSLUtilHandle);
  1196. SSLLibHandle := 0;
  1197. end;
  1198. Result := False;
  1199. end;
  1200. end
  1201. else
  1202. //loaded before...
  1203. Result := true;
  1204. end;
  1205. function DestroySSLInterface: Boolean;
  1206. begin
  1207. if IsSSLLoaded then
  1208. begin
  1209. //deinit library
  1210. EVPCleanup;
  1211. CRYPTOcleanupAllExData;
  1212. ErrRemoveState(0);
  1213. end;
  1214. SSLloaded := false;
  1215. if SSLLibHandle <> 0 then
  1216. begin
  1217. FreeLibrary(SSLLibHandle);
  1218. SSLLibHandle := 0;
  1219. end;
  1220. if SSLUtilHandle <> 0 then
  1221. begin
  1222. FreeLibrary(SSLUtilHandle);
  1223. SSLLibHandle := 0;
  1224. end;
  1225. _SslGetError := nil;
  1226. _SslLibraryInit := nil;
  1227. _SslLoadErrorStrings := nil;
  1228. _SslCtxSetCipherList := nil;
  1229. _SslCtxNew := nil;
  1230. _SslCtxFree := nil;
  1231. _SslSetFd := nil;
  1232. _SslMethodV2 := nil;
  1233. _SslMethodV3 := nil;
  1234. _SslMethodTLSV1 := nil;
  1235. _SslMethodV23 := nil;
  1236. _SslCtxUsePrivateKey := nil;
  1237. _SslCtxUsePrivateKeyASN1 := nil;
  1238. _SslCtxUsePrivateKeyFile := nil;
  1239. _SslCtxUseCertificate := nil;
  1240. _SslCtxUseCertificateASN1 := nil;
  1241. _SslCtxUseCertificateFile := nil;
  1242. _SslCtxUseCertificateChainFile := nil;
  1243. _SslCtxCheckPrivateKeyFile := nil;
  1244. _SslCtxSetDefaultPasswdCb := nil;
  1245. _SslCtxSetDefaultPasswdCbUserdata := nil;
  1246. _SslCtxLoadVerifyLocations := nil;
  1247. _SslNew := nil;
  1248. _SslFree := nil;
  1249. _SslAccept := nil;
  1250. _SslConnect := nil;
  1251. _SslShutdown := nil;
  1252. _SslRead := nil;
  1253. _SslPeek := nil;
  1254. _SslWrite := nil;
  1255. _SslPending := nil;
  1256. _SslGetPeerCertificate := nil;
  1257. _SslGetVersion := nil;
  1258. _SslCtxSetVerify := nil;
  1259. _SslGetCurrentCipher := nil;
  1260. _SslCipherGetName := nil;
  1261. _SslCipherGetBits := nil;
  1262. _SslGetVerifyResult := nil;
  1263. _X509New := nil;
  1264. _X509Free := nil;
  1265. _X509NameOneline := nil;
  1266. _X509GetSubjectName := nil;
  1267. _X509GetIssuerName := nil;
  1268. _X509NameHash := nil;
  1269. _X509Digest := nil;
  1270. _X509print := nil;
  1271. _X509SetVersion := nil;
  1272. _X509SetPubkey := nil;
  1273. _X509SetIssuerName := nil;
  1274. _X509NameAddEntryByTxt := nil;
  1275. _X509Sign := nil;
  1276. _X509GmtimeAdj := nil;
  1277. _X509SetNotBefore := nil;
  1278. _X509SetNotAfter := nil;
  1279. _X509GetSerialNumber := nil;
  1280. _EvpPkeyNew := nil;
  1281. _EvpPkeyFree := nil;
  1282. _EvpPkeyAssign := nil;
  1283. _EVPCleanup := nil;
  1284. _EvpGetDigestByName := nil;
  1285. _SSLeayversion := nil;
  1286. _ErrErrorString := nil;
  1287. _ErrGetError := nil;
  1288. _ErrClearError := nil;
  1289. _ErrFreeStrings := nil;
  1290. _ErrRemoveState := nil;
  1291. _OPENSSLaddallalgorithms := nil;
  1292. _CRYPTOcleanupAllExData := nil;
  1293. _RandScreen := nil;
  1294. _BioNew := nil;
  1295. _BioFreeAll := nil;
  1296. _BioSMem := nil;
  1297. _BioCtrlPending := nil;
  1298. _BioRead := nil;
  1299. _BioWrite := nil;
  1300. _d2iPKCS12bio := nil;
  1301. _PKCS12parse := nil;
  1302. _PKCS12free := nil;
  1303. _RsaGenerateKey := nil;
  1304. _Asn1UtctimeNew := nil;
  1305. _Asn1UtctimeFree := nil;
  1306. _Asn1IntegerSet := nil;
  1307. _i2dX509bio := nil;
  1308. _i2dPrivateKeyBio := nil;
  1309. // 3DES functions
  1310. _DESsetoddparity := nil;
  1311. _DESsetkeychecked := nil;
  1312. _DESecbencrypt := nil;
  1313. //
  1314. _CRYPTOnumlocks := nil;
  1315. _CRYPTOsetlockingcallback := nil;
  1316. Result := True;
  1317. end;
  1318. function IsSSLloaded: Boolean;
  1319. begin
  1320. Result := SSLLoaded;
  1321. end;
  1322. finalization
  1323. DestroySSLInterface;
  1324. end.