ssl_openssl_lib.pas 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335
  1. {==============================================================================|
  2. | Project : Ararat Synapse | 003.009.001 |
  3. |==============================================================================|
  4. | Content: SSL support by OpenSSL |
  5. |==============================================================================|
  6. | Copyright (c)1999-2017, Lukas Gebauer |
  7. | All rights reserved. |
  8. | |
  9. | Redistribution and use in source and binary forms, with or without |
  10. | modification, are permitted provided that the following conditions are met: |
  11. | |
  12. | Redistributions of source code must retain the above copyright notice, this |
  13. | list of conditions and the following disclaimer. |
  14. | |
  15. | Redistributions in binary form must reproduce the above copyright notice, |
  16. | this list of conditions and the following disclaimer in the documentation |
  17. | and/or other materials provided with the distribution. |
  18. | |
  19. | Neither the name of Lukas Gebauer nor the names of its contributors may |
  20. | be used to endorse or promote products derived from this software without |
  21. | specific prior written permission. |
  22. | |
  23. | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
  24. | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
  25. | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
  26. | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
  27. | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
  28. | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
  29. | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
  30. | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  31. | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
  32. | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
  33. | DAMAGE. |
  34. |==============================================================================|
  35. | The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
  36. | Portions created by Lukas Gebauer are Copyright (c)2002-2017. |
  37. | Portions created by Petr Fejfar are Copyright (c)2011-2012. |
  38. | Portions created by Pepak are Copyright (c)2018. |
  39. | All Rights Reserved. |
  40. |==============================================================================|
  41. | Contributor(s): |
  42. | Tomas Hajny (OS2 support) |
  43. | Pepak (multiversion support) |
  44. |==============================================================================|
  45. | History: see HISTORY.HTM from distribution package |
  46. | (Found at URL: http://www.ararat.cz/synapse/) |
  47. |==============================================================================}
  48. {
  49. Special thanks to Gregor Ibic <[email protected]>
  50. (Intelicom d.o.o., http://www.intelicom.si)
  51. for good inspiration about begin with SSL programming.
  52. }
  53. {$IFDEF FPC}
  54. {$MODE DELPHI}
  55. {$ENDIF}
  56. {$H+}
  57. {$IFDEF VER125}
  58. {$DEFINE BCB}
  59. {$ENDIF}
  60. {$IFDEF BCB}
  61. {$ObjExportAll On}
  62. (*$HPPEMIT 'namespace ssl_openssl_lib { using System::Shortint; }' *)
  63. {$ENDIF}
  64. //old Delphi does not have MSWINDOWS define.
  65. {$IFDEF WIN32}
  66. {$IFNDEF MSWINDOWS}
  67. {$DEFINE MSWINDOWS}
  68. {$ENDIF}
  69. {$ENDIF}
  70. {:@abstract(OpenSSL support)
  71. This unit is Pascal interface to OpenSSL library (used by @link(ssl_openssl) unit).
  72. OpenSSL is loaded dynamicly on-demand. If this library is not found in system,
  73. requested OpenSSL function just return errorcode.
  74. }
  75. unit ssl_openssl_lib;
  76. interface
  77. uses
  78. {$IFDEF CIL}
  79. System.Runtime.InteropServices,
  80. System.Text,
  81. {$ENDIF}
  82. Classes,
  83. synafpc,
  84. {$IFNDEF MSWINDOWS}
  85. {$IFDEF FPC}
  86. {$IFDEF UNIX}
  87. BaseUnix,
  88. {$ENDIF UNIX}
  89. {$ELSE}
  90. Libc,
  91. {$ENDIF}
  92. SysUtils;
  93. {$ELSE}
  94. SysUtils,
  95. Windows;
  96. {$ENDIF}
  97. {$IFDEF CIL}
  98. const
  99. {$IFDEF LINUX}
  100. DLLSSLName = 'libssl.so';
  101. DLLUtilName = 'libcrypto.so';
  102. {$ELSE}
  103. DLLSSLName = 'ssleay32.dll';
  104. DLLUtilName = 'libeay32.dll';
  105. {$ENDIF}
  106. {$ELSE}
  107. var
  108. {$IFNDEF MSWINDOWS}
  109. {$IFDEF DARWIN}
  110. DLLSSLName: string = 'libssl.dylib';
  111. DLLUtilName: string = 'libcrypto.dylib';
  112. {$ELSE}
  113. {$IFDEF OS2}
  114. {$IFDEF OS2GCC}
  115. DLLSSLName: string = 'kssl.dll';
  116. DLLUtilName: string = 'kcrypto.dll';
  117. {$ELSE OS2GCC}
  118. DLLSSLName: string = 'ssl.dll';
  119. DLLUtilName: string = 'crypto.dll';
  120. {$ENDIF OS2GCC}
  121. {$ELSE OS2}
  122. DLLSSLName: string = 'libssl.so';
  123. DLLUtilName: string = 'libcrypto.so';
  124. {$ENDIF OS2}
  125. {$ENDIF}
  126. {$ELSE}
  127. DLLSSLName: string = 'ssleay32.dll';
  128. DLLSSLName2: string = 'libssl32.dll';
  129. DLLUtilName: string = 'libeay32.dll';
  130. {$ENDIF}
  131. {$IFDEF MSWINDOWS}
  132. const
  133. LibCount = 5;
  134. SSLLibNames: array[0..LibCount-1] of string = (
  135. // OpenSSL v3.0
  136. {$IFDEF WIN64}
  137. 'libssl-3-x64.dll',
  138. {$ELSE}
  139. 'libssl-3.dll',
  140. {$ENDIF}
  141. // OpenSSL v1.1.x
  142. {$IFDEF WIN64}
  143. 'libssl-1_1-x64.dll',
  144. {$ELSE}
  145. 'libssl-1_1.dll',
  146. {$ENDIF}
  147. // OpenSSL v1.0.2 distinct names for x64 and x86
  148. {$IFDEF WIN64}
  149. 'ssleay32-x64.dll',
  150. {$ELSE}
  151. 'ssleay32-x86.dll',
  152. {$ENDIF}
  153. // OpenSSL v1.0.2
  154. 'ssleay32.dll',
  155. // OpenSSL (ancient)
  156. 'libssl32.dll'
  157. );
  158. CryptoLibNames: array[0..LibCount-1] of string = (
  159. // OpenSSL v3.0
  160. {$IFDEF WIN64}
  161. 'libcrypto-3-x64.dll',
  162. {$ELSE}
  163. 'libcrypto-3.dll',
  164. {$ENDIF}
  165. // OpenSSL v1.1.x
  166. {$IFDEF WIN64}
  167. 'libcrypto-1_1-x64.dll',
  168. {$ELSE}
  169. 'libcrypto-1_1.dll',
  170. {$ENDIF}
  171. // OpenSSL v1.0.2 distinct names for x64 and x86
  172. {$IFDEF WIN64}
  173. 'libeay32-x64.dll',
  174. {$ELSE}
  175. 'libeay32-x86.dll',
  176. {$ENDIF}
  177. // OpenSSL v1.0.2
  178. 'libeay32.dll',
  179. // OpenSSL (ancient)
  180. 'libeay32.dll'
  181. );
  182. {$ENDIF}
  183. {$ENDIF}
  184. type
  185. {$IFDEF CIL}
  186. SslPtr = IntPtr;
  187. {$ELSE}
  188. SslPtr = Pointer;
  189. {$ENDIF}
  190. PSslPtr = ^SslPtr;
  191. PSSL_CTX = SslPtr;
  192. PSSL = SslPtr;
  193. PSSL_METHOD = SslPtr;
  194. PX509 = SslPtr;
  195. PX509_NAME = SslPtr;
  196. PEVP_MD = SslPtr;
  197. PInteger = ^Integer;
  198. PBIO_METHOD = SslPtr;
  199. PBIO = SslPtr;
  200. EVP_PKEY = SslPtr;
  201. PRSA = SslPtr;
  202. PASN1_UTCTIME = SslPtr;
  203. PASN1_INTEGER = SslPtr;
  204. PPasswdCb = SslPtr;
  205. PFunction = procedure;
  206. PSTACK = SslPtr; {pf}
  207. TSkPopFreeFunc = procedure(p:SslPtr); cdecl; {pf}
  208. TX509Free = procedure(x: PX509); cdecl; {pf}
  209. DES_cblock = array[0..7] of Byte;
  210. PDES_cblock = ^DES_cblock;
  211. des_ks_struct = packed record
  212. ks: DES_cblock;
  213. weak_key: Integer;
  214. end;
  215. des_key_schedule = array[1..16] of des_ks_struct;
  216. const
  217. EVP_MAX_MD_SIZE = 16 + 20;
  218. SSL_ERROR_NONE = 0;
  219. SSL_ERROR_SSL = 1;
  220. SSL_ERROR_WANT_READ = 2;
  221. SSL_ERROR_WANT_WRITE = 3;
  222. SSL_ERROR_WANT_X509_LOOKUP = 4;
  223. SSL_ERROR_SYSCALL = 5; //look at error stack/return value/errno
  224. SSL_ERROR_ZERO_RETURN = 6;
  225. SSL_ERROR_WANT_CONNECT = 7;
  226. SSL_ERROR_WANT_ACCEPT = 8;
  227. SSL_OP_NO_SSLv2 = $01000000;
  228. SSL_OP_NO_SSLv3 = $02000000;
  229. SSL_OP_NO_TLSv1 = $04000000;
  230. SSL_OP_ALL = $000FFFFF;
  231. SSL_VERIFY_NONE = $00;
  232. SSL_VERIFY_PEER = $01;
  233. OPENSSL_DES_DECRYPT = 0;
  234. OPENSSL_DES_ENCRYPT = 1;
  235. X509_V_OK = 0;
  236. X509_V_ILLEGAL = 1;
  237. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT = 2;
  238. X509_V_ERR_UNABLE_TO_GET_CRL = 3;
  239. X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE = 4;
  240. X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE = 5;
  241. X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY = 6;
  242. X509_V_ERR_CERT_SIGNATURE_FAILURE = 7;
  243. X509_V_ERR_CRL_SIGNATURE_FAILURE = 8;
  244. X509_V_ERR_CERT_NOT_YET_VALID = 9;
  245. X509_V_ERR_CERT_HAS_EXPIRED = 10;
  246. X509_V_ERR_CRL_NOT_YET_VALID = 11;
  247. X509_V_ERR_CRL_HAS_EXPIRED = 12;
  248. X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD = 13;
  249. X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD = 14;
  250. X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD = 15;
  251. X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD = 16;
  252. X509_V_ERR_OUT_OF_MEM = 17;
  253. X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT = 18;
  254. X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN = 19;
  255. X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY = 20;
  256. X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE = 21;
  257. X509_V_ERR_CERT_CHAIN_TOO_LONG = 22;
  258. X509_V_ERR_CERT_REVOKED = 23;
  259. X509_V_ERR_INVALID_CA = 24;
  260. X509_V_ERR_PATH_LENGTH_EXCEEDED = 25;
  261. X509_V_ERR_INVALID_PURPOSE = 26;
  262. X509_V_ERR_CERT_UNTRUSTED = 27;
  263. X509_V_ERR_CERT_REJECTED = 28;
  264. //These are 'informational' when looking for issuer cert
  265. X509_V_ERR_SUBJECT_ISSUER_MISMATCH = 29;
  266. X509_V_ERR_AKID_SKID_MISMATCH = 30;
  267. X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH = 31;
  268. X509_V_ERR_KEYUSAGE_NO_CERTSIGN = 32;
  269. X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER = 33;
  270. X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION = 34;
  271. //The application is not happy
  272. X509_V_ERR_APPLICATION_VERIFICATION = 50;
  273. SSL_FILETYPE_ASN1 = 2;
  274. SSL_FILETYPE_PEM = 1;
  275. EVP_PKEY_RSA = 6;
  276. SSL_CTRL_SET_TLSEXT_HOSTNAME = 55;
  277. TLSEXT_NAMETYPE_host_name = 0;
  278. var
  279. SSLLibHandle: TLibHandle = 0;
  280. SSLUtilHandle: TLibHandle = 0;
  281. SSLLibFile: string = '';
  282. SSLUtilFile: string = '';
  283. {$IFDEF CIL}
  284. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  285. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  286. EntryPoint = 'SSL_get_error')]
  287. function SslGetError(s: PSSL; ret_code: Integer): Integer; external;
  288. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  289. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  290. EntryPoint = 'SSL_library_init')]
  291. function SslLibraryInit: Integer; external;
  292. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  293. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  294. EntryPoint = 'SSL_load_error_strings')]
  295. procedure SslLoadErrorStrings; external;
  296. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  297. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  298. EntryPoint = 'SSL_CTX_set_cipher_list')]
  299. function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String): Integer; external;
  300. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  301. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  302. EntryPoint = 'SSL_CTX_new')]
  303. function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX; external;
  304. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  305. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  306. EntryPoint = 'SSL_CTX_free')]
  307. procedure SslCtxFree (arg0: PSSL_CTX); external;
  308. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  309. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  310. EntryPoint = 'SSL_set_fd')]
  311. function SslSetFd(s: PSSL; fd: Integer):Integer; external;
  312. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  313. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  314. EntryPoint = 'SSLv2_method')]
  315. function SslMethodV2 : PSSL_METHOD; external;
  316. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  317. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  318. EntryPoint = 'SSLv3_method')]
  319. function SslMethodV3 : PSSL_METHOD; external;
  320. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  321. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  322. EntryPoint = 'TLSv1_method')]
  323. function SslMethodTLSV1:PSSL_METHOD; external;
  324. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  325. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  326. EntryPoint = 'TLSv1_1_method')]
  327. function SslMethodTLSV11:PSSL_METHOD; external;
  328. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  329. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  330. EntryPoint = 'TLSv1_2_method')]
  331. function SslMethodTLSV12:PSSL_METHOD; external;
  332. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  333. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  334. EntryPoint = 'SSLv23_method')]
  335. function SslMethodV23 : PSSL_METHOD; external;
  336. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  337. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  338. EntryPoint = 'TLS_method')]
  339. function SslMethodTLS : PSSL_METHOD; external;
  340. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  341. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  342. EntryPoint = 'SSL_CTX_use_PrivateKey')]
  343. function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):Integer; external;
  344. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  345. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  346. EntryPoint = 'SSL_CTX_use_PrivateKey_ASN1')]
  347. function SslCtxUsePrivateKeyASN1(pk: integer; ctx: PSSL_CTX; d: String; len: integer):Integer; external;
  348. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  349. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  350. EntryPoint = 'SSL_CTX_use_RSAPrivateKey_file')]
  351. function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer; external;
  352. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  353. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  354. EntryPoint = 'SSL_CTX_use_certificate')]
  355. function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):Integer; external;
  356. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  357. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  358. EntryPoint = 'SSL_CTX_use_certificate_ASN1')]
  359. function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: integer; d: String):Integer; external;
  360. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  361. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  362. EntryPoint = 'SSL_CTX_use_certificate_file')]
  363. function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;external;
  364. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  365. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  366. EntryPoint = 'SSL_CTX_use_certificate_chain_file')]
  367. function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):Integer;external;
  368. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  369. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  370. EntryPoint = 'SSL_CTX_check_private_key')]
  371. function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer; external;
  372. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  373. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  374. EntryPoint = 'SSL_CTX_set_default_passwd_cb')]
  375. procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb); external;
  376. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  377. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  378. EntryPoint = 'SSL_CTX_set_default_passwd_cb_userdata')]
  379. procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: IntPtr); external;
  380. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  381. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  382. EntryPoint = 'SSL_CTX_load_verify_locations')]
  383. function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; CAfile: string; CApath: String):Integer; external;
  384. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  385. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  386. EntryPoint = 'SSL_CTX_ctrl')]
  387. function SslCtxCtrl(ctx: PSSL_CTX; cmd: integer; larg: integer; parg: IntPtr): integer; external;
  388. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  389. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  390. EntryPoint = 'SSL_new')]
  391. function SslNew(ctx: PSSL_CTX):PSSL; external;
  392. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  393. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  394. EntryPoint = 'SSL_free')]
  395. procedure SslFree(ssl: PSSL); external;
  396. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  397. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  398. EntryPoint = 'SSL_accept')]
  399. function SslAccept(ssl: PSSL):Integer; external;
  400. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  401. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  402. EntryPoint = 'SSL_connect')]
  403. function SslConnect(ssl: PSSL):Integer; external;
  404. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  405. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  406. EntryPoint = 'SSL_shutdown')]
  407. function SslShutdown(s: PSSL):Integer; external;
  408. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  409. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  410. EntryPoint = 'SSL_read')]
  411. function SslRead(ssl: PSSL; buf: StringBuilder; num: Integer):Integer; external;
  412. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  413. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  414. EntryPoint = 'SSL_peek')]
  415. function SslPeek(ssl: PSSL; buf: StringBuilder; num: Integer):Integer; external;
  416. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  417. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  418. EntryPoint = 'SSL_write')]
  419. function SslWrite(ssl: PSSL; buf: String; num: Integer):Integer; external;
  420. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  421. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  422. EntryPoint = 'SSL_pending')]
  423. function SslPending(ssl: PSSL):Integer; external;
  424. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  425. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  426. EntryPoint = 'SSL_get_version')]
  427. function SslGetVersion(ssl: PSSL):String; external;
  428. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  429. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  430. EntryPoint = 'SSL_get_peer_certificate')]
  431. function SslGetPeerCertificate(s: PSSL):PX509; external;
  432. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  433. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  434. EntryPoint = 'SSL_CTX_set_verify')]
  435. procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction); external;
  436. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  437. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  438. EntryPoint = 'SSL_get_current_cipher')]
  439. function SSLGetCurrentCipher(s: PSSL): SslPtr; external;
  440. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  441. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  442. EntryPoint = 'SSL_CIPHER_get_name')]
  443. function SSLCipherGetName(c: SslPtr):String; external;
  444. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  445. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  446. EntryPoint = 'SSL_CIPHER_get_bits')]
  447. function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer; external;
  448. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  449. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  450. EntryPoint = 'SSL_get_verify_result')]
  451. function SSLGetVerifyResult(ssl: PSSL):Integer;external;
  452. [DllImport(DLLSSLName, CharSet = CharSet.Ansi,
  453. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  454. EntryPoint = 'SSL_ctrl')]
  455. function SslCtrl(ssl: PSSL; cmd: integer; larg: integer; parg: IntPtr): integer; external;
  456. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  457. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  458. EntryPoint = 'X509_new')]
  459. function X509New: PX509; external;
  460. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  461. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  462. EntryPoint = 'X509_free')]
  463. procedure X509Free(x: PX509); external;
  464. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  465. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  466. EntryPoint = 'X509_NAME_oneline')]
  467. function X509NameOneline(a: PX509_NAME; buf: StringBuilder; size: Integer): String; external;
  468. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  469. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  470. EntryPoint = 'X509_get_subject_name')]
  471. function X509GetSubjectName(a: PX509):PX509_NAME; external;
  472. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  473. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  474. EntryPoint = 'X509_get_issuer_name')]
  475. function X509GetIssuerName(a: PX509):PX509_NAME; external;
  476. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  477. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  478. EntryPoint = 'X509_NAME_hash')]
  479. function X509NameHash(x: PX509_NAME):Cardinal; external;
  480. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  481. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  482. EntryPoint = 'X509_digest')]
  483. function X509Digest (data: PX509; _type: PEVP_MD; md: StringBuilder; var len: Integer):Integer; external;
  484. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  485. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  486. EntryPoint = 'X509_set_version')]
  487. function X509SetVersion(x: PX509; version: integer): integer; external;
  488. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  489. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  490. EntryPoint = 'X509_set_pubkey')]
  491. function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer; external;
  492. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  493. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  494. EntryPoint = 'X509_set_issuer_name')]
  495. function X509SetIssuerName(x: PX509; name: PX509_NAME): integer; external;
  496. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  497. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  498. EntryPoint = 'X509_NAME_add_entry_by_txt')]
  499. function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: integer;
  500. bytes: string; len, loc, _set: integer): integer; external;
  501. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  502. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  503. EntryPoint = 'X509_sign')]
  504. function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer; external;
  505. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  506. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  507. EntryPoint = 'X509_print')]
  508. function X509print(b: PBIO; a: PX509): integer; external;
  509. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  510. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  511. EntryPoint = 'X509_gmtime_adj')]
  512. function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME; external;
  513. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  514. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  515. EntryPoint = 'X509_set_notBefore')]
  516. function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer; external;
  517. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  518. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  519. EntryPoint = 'X509_set_notAfter')]
  520. function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer; external;
  521. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  522. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  523. EntryPoint = 'X509_get_serialNumber')]
  524. function X509GetSerialNumber(x: PX509): PASN1_INTEGER; external;
  525. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  526. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  527. EntryPoint = 'EVP_PKEY_new')]
  528. function EvpPkeyNew: EVP_PKEY; external;
  529. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  530. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  531. EntryPoint = 'EVP_PKEY_free')]
  532. procedure EvpPkeyFree(pk: EVP_PKEY); external;
  533. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  534. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  535. EntryPoint = 'EVP_PKEY_assign')]
  536. function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer; external;
  537. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  538. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  539. EntryPoint = 'EVP_get_digestbyname')]
  540. function EvpGetDigestByName(Name: String): PEVP_MD; external;
  541. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  542. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  543. EntryPoint = 'EVP_cleanup')]
  544. procedure EVPcleanup; external;
  545. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  546. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  547. EntryPoint = 'SSLeay_version')]
  548. function SSLeayversion(t: integer): String; external;
  549. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  550. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  551. EntryPoint = 'ERR_error_string_n')]
  552. procedure ErrErrorString(e: integer; buf: StringBuilder; len: integer); external;
  553. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  554. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  555. EntryPoint = 'ERR_get_error')]
  556. function ErrGetError: integer; external;
  557. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  558. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  559. EntryPoint = 'ERR_clear_error')]
  560. procedure ErrClearError; external;
  561. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  562. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  563. EntryPoint = 'ERR_free_strings')]
  564. procedure ErrFreeStrings; external;
  565. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  566. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  567. EntryPoint = 'ERR_remove_state')]
  568. procedure ErrRemoveState(pid: integer); external;
  569. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  570. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  571. EntryPoint = 'OPENSSL_add_all_algorithms_noconf')]
  572. procedure OPENSSLaddallalgorithms; external;
  573. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  574. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  575. EntryPoint = 'CRYPTO_cleanup_all_ex_data')]
  576. procedure CRYPTOcleanupAllExData; external;
  577. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  578. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  579. EntryPoint = 'RAND_screen')]
  580. procedure RandScreen; external;
  581. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  582. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  583. EntryPoint = 'BIO_new')]
  584. function BioNew(b: PBIO_METHOD): PBIO; external;
  585. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  586. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  587. EntryPoint = 'BIO_free_all')]
  588. procedure BioFreeAll(b: PBIO); external;
  589. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  590. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  591. EntryPoint = 'BIO_s_mem')]
  592. function BioSMem: PBIO_METHOD; external;
  593. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  594. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  595. EntryPoint = 'BIO_ctrl_pending')]
  596. function BioCtrlPending(b: PBIO): integer; external;
  597. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  598. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  599. EntryPoint = 'BIO_read')]
  600. function BioRead(b: PBIO; Buf: StringBuilder; Len: integer): integer; external;
  601. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  602. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  603. EntryPoint = 'BIO_write')]
  604. function BioWrite(b: PBIO; var Buf: String; Len: integer): integer; external;
  605. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  606. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  607. EntryPoint = 'd2i_PKCS12_bio')]
  608. function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr; external;
  609. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  610. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  611. EntryPoint = 'PKCS12_parse')]
  612. function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): integer; external;
  613. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  614. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  615. EntryPoint = 'PKCS12_free')]
  616. procedure PKCS12free(p12: SslPtr); external;
  617. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  618. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  619. EntryPoint = 'RSA_generate_key')]
  620. function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA; external;
  621. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  622. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  623. EntryPoint = 'ASN1_UTCTIME_new')]
  624. function Asn1UtctimeNew: PASN1_UTCTIME; external;
  625. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  626. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  627. EntryPoint = 'ASN1_UTCTIME_free')]
  628. procedure Asn1UtctimeFree(a: PASN1_UTCTIME); external;
  629. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  630. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  631. EntryPoint = 'ASN1_INTEGER_set')]
  632. function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer; external;
  633. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  634. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  635. EntryPoint = 'i2d_X509_bio')]
  636. function i2dX509bio(b: PBIO; x: PX509): integer; external;
  637. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  638. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  639. EntryPoint = 'i2d_PrivateKey_bio')]
  640. function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer; external;
  641. // 3DES functions
  642. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  643. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  644. EntryPoint = 'DES_set_odd_parity')]
  645. procedure DESsetoddparity(Key: des_cblock); external;
  646. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  647. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  648. EntryPoint = 'DES_set_key_checked')]
  649. function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer; external;
  650. [DllImport(DLLUtilName, CharSet = CharSet.Ansi,
  651. SetLastError = False, CallingConvention= CallingConvention.cdecl,
  652. EntryPoint = 'DES_ecb_encrypt')]
  653. procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer); external;
  654. {$ELSE}
  655. // libssl.dll
  656. function SslGetError(s: PSSL; ret_code: Integer):Integer;
  657. function SslLibraryInit:Integer;
  658. procedure SslLoadErrorStrings;
  659. // function SslCtxSetCipherList(arg0: PSSL_CTX; str: PChar):Integer;
  660. function SslCtxSetCipherList(arg0: PSSL_CTX; var str: AnsiString):Integer;
  661. function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
  662. procedure SslCtxFree(arg0: PSSL_CTX);
  663. function SslSetFd(s: PSSL; fd: Integer):Integer;
  664. function SslMethodV2:PSSL_METHOD;
  665. function SslMethodV3:PSSL_METHOD;
  666. function SslMethodTLSV1:PSSL_METHOD;
  667. function SslMethodTLSV11:PSSL_METHOD;
  668. function SslMethodTLSV12:PSSL_METHOD;
  669. function SslMethodV23:PSSL_METHOD;
  670. function SslMethodTLS:PSSL_METHOD;
  671. function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):Integer;
  672. function SslCtxUsePrivateKeyASN1(pk: integer; ctx: PSSL_CTX; d: AnsiString; len: integer):Integer;
  673. // function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer;
  674. function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: AnsiString; _type: Integer):Integer;
  675. function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):Integer;
  676. function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: integer; d: AnsiString):Integer;
  677. function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: AnsiString; _type: Integer):Integer;
  678. // function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: PChar):Integer;
  679. function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: AnsiString):Integer;
  680. function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer;
  681. procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
  682. procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
  683. // function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):Integer;
  684. function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: AnsiString; const CApath: AnsiString):Integer;
  685. function SslCtxCtrl(ctx: PSSL_CTX; cmd: integer; larg: integer; parg: SslPtr): integer;
  686. function SslNew(ctx: PSSL_CTX):PSSL;
  687. procedure SslFree(ssl: PSSL);
  688. function SslAccept(ssl: PSSL):Integer;
  689. function SslConnect(ssl: PSSL):Integer;
  690. function SslShutdown(ssl: PSSL):Integer;
  691. function SslRead(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  692. function SslPeek(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  693. function SslWrite(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  694. function SslPending(ssl: PSSL):Integer;
  695. function SslGetVersion(ssl: PSSL):AnsiString;
  696. function SslGetPeerCertificate(ssl: PSSL):PX509;
  697. procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction);
  698. function SSLGetCurrentCipher(s: PSSL):SslPtr;
  699. function SSLCipherGetName(c: SslPtr): AnsiString;
  700. function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer;
  701. function SSLGetVerifyResult(ssl: PSSL):Integer;
  702. function SSLCtrl(ssl: PSSL; cmd: integer; larg: integer; parg: SslPtr):Integer;
  703. function SslSet1Host(ssl: PSSL; hostname: PAnsiChar):Integer;
  704. procedure SslSessionFree(session: PSslPtr);
  705. function SslGet1Session(ssl: PSSL):PSslPtr;
  706. function SslSetSession(ssl: PSSL; session: PSslPtr): Integer;
  707. // libeay.dll
  708. function X509New: PX509;
  709. procedure X509Free(x: PX509);
  710. function X509NameOneline(a: PX509_NAME; var buf: AnsiString; size: Integer):AnsiString;
  711. function X509GetSubjectName(a: PX509):PX509_NAME;
  712. function X509GetIssuerName(a: PX509):PX509_NAME;
  713. function X509NameHash(x: PX509_NAME):Cardinal;
  714. // function SslX509Digest(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer;
  715. function X509Digest(data: PX509; _type: PEVP_MD; md: AnsiString; var len: Integer):Integer;
  716. function X509print(b: PBIO; a: PX509): integer;
  717. function X509SetVersion(x: PX509; version: integer): integer;
  718. function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer;
  719. function X509SetIssuerName(x: PX509; name: PX509_NAME): integer;
  720. function X509NameAddEntryByTxt(name: PX509_NAME; field: Ansistring; _type: integer;
  721. bytes: Ansistring; len, loc, _set: integer): integer;
  722. function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer;
  723. function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME;
  724. function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer;
  725. function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer;
  726. function X509GetSerialNumber(x: PX509): PASN1_INTEGER;
  727. function EvpPkeyNew: EVP_PKEY;
  728. procedure EvpPkeyFree(pk: EVP_PKEY);
  729. function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer;
  730. function EvpGetDigestByName(Name: AnsiString): PEVP_MD;
  731. procedure EVPcleanup;
  732. // function ErrErrorString(e: integer; buf: PChar): PChar;
  733. function SSLeayversion(t: integer): Ansistring;
  734. procedure ErrErrorString(e: integer; var buf: Ansistring; len: integer);
  735. function ErrGetError: integer;
  736. procedure ErrClearError;
  737. procedure ErrFreeStrings;
  738. procedure ErrRemoveState(pid: integer);
  739. procedure OPENSSLaddallalgorithms;
  740. procedure CRYPTOcleanupAllExData;
  741. procedure RandScreen;
  742. function BioNew(b: PBIO_METHOD): PBIO;
  743. procedure BioFreeAll(b: PBIO);
  744. function BioSMem: PBIO_METHOD;
  745. function BioCtrlPending(b: PBIO): integer;
  746. function BioRead(b: PBIO; var Buf: AnsiString; Len: integer): integer;
  747. function BioWrite(b: PBIO; Buf: AnsiString; Len: integer): integer;
  748. function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
  749. function PKCS12parse(p12: SslPtr; pass: Ansistring; var pkey, cert, ca: SslPtr): integer;
  750. procedure PKCS12free(p12: SslPtr);
  751. function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA;
  752. function Asn1UtctimeNew: PASN1_UTCTIME;
  753. procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
  754. function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
  755. function Asn1IntegerGet(a: PASN1_INTEGER): integer; {pf}
  756. function i2dX509bio(b: PBIO; x: PX509): integer;
  757. function d2iX509bio(b:PBIO; x:PX509): PX509; {pf}
  758. function PEMReadBioX509(b:PBIO; {var x:PX509;}x:PSslPtr; callback:PFunction; cb_arg: SslPtr): PX509; {pf}
  759. procedure SkX509PopFree(st: PSTACK; func: TSkPopFreeFunc); {pf}
  760. function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer;
  761. // 3DES functions
  762. procedure DESsetoddparity(Key: des_cblock);
  763. function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer;
  764. procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer);
  765. {$ENDIF}
  766. function IsSSLloaded: Boolean;
  767. function InitSSLInterface: Boolean;
  768. function DestroySSLInterface: Boolean;
  769. var
  770. _X509Free: TX509Free = nil; {pf}
  771. implementation
  772. uses
  773. {$IFDEF OS2}
  774. Sockets,
  775. {$ENDIF OS2}
  776. SyncObjs;
  777. {$IFNDEF CIL}
  778. type
  779. // libssl.dll
  780. TSslGetError = function(s: PSSL; ret_code: Integer):Integer; cdecl;
  781. TSslLibraryInit = function:Integer; cdecl;
  782. TSslLoadErrorStrings = procedure; cdecl;
  783. TSslCtxSetCipherList = function(arg0: PSSL_CTX; str: PAnsiChar):Integer; cdecl;
  784. TSslCtxNew = function(meth: PSSL_METHOD):PSSL_CTX; cdecl;
  785. TSslCtxFree = procedure(arg0: PSSL_CTX); cdecl;
  786. TSslSetFd = function(s: PSSL; fd: Integer):Integer; cdecl;
  787. TSslMethodV2 = function:PSSL_METHOD; cdecl;
  788. TSslMethodV3 = function:PSSL_METHOD; cdecl;
  789. TSslMethodTLSV1 = function:PSSL_METHOD; cdecl;
  790. TSslMethodTLSV11 = function:PSSL_METHOD; cdecl;
  791. TSslMethodTLSV12 = function:PSSL_METHOD; cdecl;
  792. TSslMethodV23 = function:PSSL_METHOD; cdecl;
  793. TSslMethodTLS = function:PSSL_METHOD; cdecl;
  794. TSslCtxUsePrivateKey = function(ctx: PSSL_CTX; pkey: sslptr):Integer; cdecl;
  795. TSslCtxUsePrivateKeyASN1 = function(pk: integer; ctx: PSSL_CTX; d: sslptr; len: integer):Integer; cdecl;
  796. TSslCtxUsePrivateKeyFile = function(ctx: PSSL_CTX; const _file: PAnsiChar; _type: Integer):Integer; cdecl;
  797. TSslCtxUseCertificate = function(ctx: PSSL_CTX; x: SslPtr):Integer; cdecl;
  798. TSslCtxUseCertificateASN1 = function(ctx: PSSL_CTX; len: Integer; d: SslPtr):Integer; cdecl;
  799. TSslCtxUseCertificateFile = function(ctx: PSSL_CTX; const _file: PAnsiChar; _type: Integer):Integer; cdecl;
  800. TSslCtxUseCertificateChainFile = function(ctx: PSSL_CTX; const _file: PAnsiChar):Integer; cdecl;
  801. TSslCtxCheckPrivateKeyFile = function(ctx: PSSL_CTX):Integer; cdecl;
  802. TSslCtxSetDefaultPasswdCb = procedure(ctx: PSSL_CTX; cb: SslPtr); cdecl;
  803. TSslCtxSetDefaultPasswdCbUserdata = procedure(ctx: PSSL_CTX; u: SslPtr); cdecl;
  804. TSslCtxLoadVerifyLocations = function(ctx: PSSL_CTX; const CAfile: PAnsiChar; const CApath: PAnsiChar):Integer; cdecl;
  805. TSslCtxCtrl = function(ctx: PSSL_CTX; cmd: integer; larg: integer; parg: SslPtr): integer; cdecl;
  806. TSslNew = function(ctx: PSSL_CTX):PSSL; cdecl;
  807. TSslFree = procedure(ssl: PSSL); cdecl;
  808. TSslAccept = function(ssl: PSSL):Integer; cdecl;
  809. TSslConnect = function(ssl: PSSL):Integer; cdecl;
  810. TSslShutdown = function(ssl: PSSL):Integer; cdecl;
  811. TSslRead = function(ssl: PSSL; buf: PAnsiChar; num: Integer):Integer; cdecl;
  812. TSslPeek = function(ssl: PSSL; buf: PAnsiChar; num: Integer):Integer; cdecl;
  813. TSslWrite = function(ssl: PSSL; const buf: PAnsiChar; num: Integer):Integer; cdecl;
  814. TSslPending = function(ssl: PSSL):Integer; cdecl;
  815. TSslGetVersion = function(ssl: PSSL):PAnsiChar; cdecl;
  816. TSslGetPeerCertificate = function(ssl: PSSL):PX509; cdecl;
  817. TSslCtxSetVerify = procedure(ctx: PSSL_CTX; mode: Integer; arg2: SslPtr); cdecl;
  818. TSSLGetCurrentCipher = function(s: PSSL):SslPtr; cdecl;
  819. TSSLCipherGetName = function(c: Sslptr):PAnsiChar; cdecl;
  820. TSSLCipherGetBits = function(c: SslPtr; alg_bits: PInteger):Integer; cdecl;
  821. TSSLGetVerifyResult = function(ssl: PSSL):Integer; cdecl;
  822. TSSLCtrl = function(ssl: PSSL; cmd: integer; larg: integer; parg: SslPtr):Integer; cdecl;
  823. TSslSet1Host = function(ssl: PSSL; hostname: PAnsiChar):Integer; cdecl;
  824. TSslSessionFree = procedure(session: PSslPtr); cdecl;
  825. TSslGet1Session = function(ssl: PSSL):PSslPtr; cdecl;
  826. TSslSetSession = function(ssl: PSSL; session: PSslPtr): Integer; cdecl;
  827. TSSLSetTlsextHostName = function(ssl: PSSL; buf: PAnsiChar):Integer; cdecl;
  828. // libeay.dll
  829. TX509New = function: PX509; cdecl;
  830. TX509NameOneline = function(a: PX509_NAME; buf: PAnsiChar; size: Integer):PAnsiChar; cdecl;
  831. TX509GetSubjectName = function(a: PX509):PX509_NAME; cdecl;
  832. TX509GetIssuerName = function(a: PX509):PX509_NAME; cdecl;
  833. TX509NameHash = function(x: PX509_NAME):Cardinal; cdecl;
  834. TX509Digest = function(data: PX509; _type: PEVP_MD; md: PAnsiChar; len: PInteger):Integer; cdecl;
  835. TX509print = function(b: PBIO; a: PX509): integer; cdecl;
  836. TX509SetVersion = function(x: PX509; version: integer): integer; cdecl;
  837. TX509SetPubkey = function(x: PX509; pkey: EVP_PKEY): integer; cdecl;
  838. TX509SetIssuerName = function(x: PX509; name: PX509_NAME): integer; cdecl;
  839. TX509NameAddEntryByTxt = function(name: PX509_NAME; field: PAnsiChar; _type: integer;
  840. bytes: PAnsiChar; len, loc, _set: integer): integer; cdecl;
  841. TX509Sign = function(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer; cdecl;
  842. TX509GmtimeAdj = function(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME; cdecl;
  843. TX509SetNotBefore = function(x: PX509; tm: PASN1_UTCTIME): integer; cdecl;
  844. TX509SetNotAfter = function(x: PX509; tm: PASN1_UTCTIME): integer; cdecl;
  845. TX509GetSerialNumber = function(x: PX509): PASN1_INTEGER; cdecl;
  846. TEvpPkeyNew = function: EVP_PKEY; cdecl;
  847. TEvpPkeyFree = procedure(pk: EVP_PKEY); cdecl;
  848. TEvpPkeyAssign = function(pkey: EVP_PKEY; _type: integer; key: Prsa): integer; cdecl;
  849. TEvpGetDigestByName = function(Name: PAnsiChar): PEVP_MD; cdecl;
  850. TEVPcleanup = procedure; cdecl;
  851. TSSLeayversion = function(t: integer): PAnsiChar; cdecl;
  852. TErrErrorString = procedure(e: integer; buf: PAnsiChar; len: integer); cdecl;
  853. TErrGetError = function: integer; cdecl;
  854. TErrClearError = procedure; cdecl;
  855. TErrFreeStrings = procedure; cdecl;
  856. TErrRemoveState = procedure(pid: integer); cdecl;
  857. TOPENSSLaddallalgorithms = procedure; cdecl;
  858. TCRYPTOcleanupAllExData = procedure; cdecl;
  859. TRandScreen = procedure; cdecl;
  860. TBioNew = function(b: PBIO_METHOD): PBIO; cdecl;
  861. TBioFreeAll = procedure(b: PBIO); cdecl;
  862. TBioSMem = function: PBIO_METHOD; cdecl;
  863. TBioCtrlPending = function(b: PBIO): integer; cdecl;
  864. TBioRead = function(b: PBIO; Buf: PAnsiChar; Len: integer): integer; cdecl;
  865. TBioWrite = function(b: PBIO; Buf: PAnsiChar; Len: integer): integer; cdecl;
  866. Td2iPKCS12bio = function(b:PBIO; Pkcs12: SslPtr): SslPtr; cdecl;
  867. TPKCS12parse = function(p12: SslPtr; pass: PAnsiChar; var pkey, cert, ca: SslPtr): integer; cdecl;
  868. TPKCS12free = procedure(p12: SslPtr); cdecl;
  869. TRsaGenerateKey = function(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA; cdecl;
  870. TAsn1UtctimeNew = function: PASN1_UTCTIME; cdecl;
  871. TAsn1UtctimeFree = procedure(a: PASN1_UTCTIME); cdecl;
  872. TAsn1IntegerSet = function(a: PASN1_INTEGER; v: integer): integer; cdecl;
  873. TAsn1IntegerGet = function(a: PASN1_INTEGER): integer; cdecl; {pf}
  874. Ti2dX509bio = function(b: PBIO; x: PX509): integer; cdecl;
  875. Td2iX509bio = function(b:PBIO; x:PX509): PX509; cdecl; {pf}
  876. TPEMReadBioX509 = function(b:PBIO; {var x:PX509;}x:PSslPtr; callback:PFunction; cb_arg:SslPtr): PX509; cdecl; {pf}
  877. TSkX509PopFree = procedure(st: PSTACK; func: TSkPopFreeFunc); cdecl; {pf}
  878. Ti2dPrivateKeyBio= function(b: PBIO; pkey: EVP_PKEY): integer; cdecl;
  879. // 3DES functions
  880. TDESsetoddparity = procedure(Key: des_cblock); cdecl;
  881. TDESsetkeychecked = function(key: des_cblock; schedule: des_key_schedule): Integer; cdecl;
  882. TDESecbencrypt = procedure(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer); cdecl;
  883. //thread lock functions
  884. TCRYPTOnumlocks = function: integer; cdecl;
  885. TCRYPTOSetLockingCallback = procedure(cb: Sslptr); cdecl;
  886. var
  887. // libssl.dll
  888. _SslGetError: TSslGetError = nil;
  889. _SslLibraryInit: TSslLibraryInit = nil;
  890. _SslLoadErrorStrings: TSslLoadErrorStrings = nil;
  891. _SslCtxSetCipherList: TSslCtxSetCipherList = nil;
  892. _SslCtxNew: TSslCtxNew = nil;
  893. _SslCtxFree: TSslCtxFree = nil;
  894. _SslSetFd: TSslSetFd = nil;
  895. _SslMethodV2: TSslMethodV2 = nil;
  896. _SslMethodV3: TSslMethodV3 = nil;
  897. _SslMethodTLSV1: TSslMethodTLSV1 = nil;
  898. _SslMethodTLSV11: TSslMethodTLSV11 = nil;
  899. _SslMethodTLSV12: TSslMethodTLSV12 = nil;
  900. _SslMethodV23: TSslMethodV23 = nil;
  901. _SslMethodTLS: TSslMethodTLS = nil;
  902. _SslCtxUsePrivateKey: TSslCtxUsePrivateKey = nil;
  903. _SslCtxUsePrivateKeyASN1: TSslCtxUsePrivateKeyASN1 = nil;
  904. _SslCtxUsePrivateKeyFile: TSslCtxUsePrivateKeyFile = nil;
  905. _SslCtxUseCertificate: TSslCtxUseCertificate = nil;
  906. _SslCtxUseCertificateASN1: TSslCtxUseCertificateASN1 = nil;
  907. _SslCtxUseCertificateFile: TSslCtxUseCertificateFile = nil;
  908. _SslCtxUseCertificateChainFile: TSslCtxUseCertificateChainFile = nil;
  909. _SslCtxCheckPrivateKeyFile: TSslCtxCheckPrivateKeyFile = nil;
  910. _SslCtxSetDefaultPasswdCb: TSslCtxSetDefaultPasswdCb = nil;
  911. _SslCtxSetDefaultPasswdCbUserdata: TSslCtxSetDefaultPasswdCbUserdata = nil;
  912. _SslCtxLoadVerifyLocations: TSslCtxLoadVerifyLocations = nil;
  913. _SslCtxCtrl: TSslCtxCtrl = nil;
  914. _SslNew: TSslNew = nil;
  915. _SslFree: TSslFree = nil;
  916. _SslAccept: TSslAccept = nil;
  917. _SslConnect: TSslConnect = nil;
  918. _SslShutdown: TSslShutdown = nil;
  919. _SslRead: TSslRead = nil;
  920. _SslPeek: TSslPeek = nil;
  921. _SslWrite: TSslWrite = nil;
  922. _SslPending: TSslPending = nil;
  923. _SslGetVersion: TSslGetVersion = nil;
  924. _SslGetPeerCertificate: TSslGetPeerCertificate = nil;
  925. _SslCtxSetVerify: TSslCtxSetVerify = nil;
  926. _SSLGetCurrentCipher: TSSLGetCurrentCipher = nil;
  927. _SSLCipherGetName: TSSLCipherGetName = nil;
  928. _SSLCipherGetBits: TSSLCipherGetBits = nil;
  929. _SSLGetVerifyResult: TSSLGetVerifyResult = nil;
  930. _SSLCtrl: TSSLCtrl = nil;
  931. _SslSet1Host: TSslSet1Host = nil;
  932. _SslSessionFree: TSslSessionFree = nil;
  933. _SslGet1Session: TSslGet1Session = nil;
  934. _SslSetSession: TSslSetSession = nil;
  935. // libeay.dll
  936. _X509New: TX509New = nil;
  937. _X509NameOneline: TX509NameOneline = nil;
  938. _X509GetSubjectName: TX509GetSubjectName = nil;
  939. _X509GetIssuerName: TX509GetIssuerName = nil;
  940. _X509NameHash: TX509NameHash = nil;
  941. _X509Digest: TX509Digest = nil;
  942. _X509print: TX509print = nil;
  943. _X509SetVersion: TX509SetVersion = nil;
  944. _X509SetPubkey: TX509SetPubkey = nil;
  945. _X509SetIssuerName: TX509SetIssuerName = nil;
  946. _X509NameAddEntryByTxt: TX509NameAddEntryByTxt = nil;
  947. _X509Sign: TX509Sign = nil;
  948. _X509GmtimeAdj: TX509GmtimeAdj = nil;
  949. _X509SetNotBefore: TX509SetNotBefore = nil;
  950. _X509SetNotAfter: TX509SetNotAfter = nil;
  951. _X509GetSerialNumber: TX509GetSerialNumber = nil;
  952. _EvpPkeyNew: TEvpPkeyNew = nil;
  953. _EvpPkeyFree: TEvpPkeyFree = nil;
  954. _EvpPkeyAssign: TEvpPkeyAssign = nil;
  955. _EvpGetDigestByName: TEvpGetDigestByName = nil;
  956. _EVPcleanup: TEVPcleanup = nil;
  957. _SSLeayversion: TSSLeayversion = nil;
  958. _ErrErrorString: TErrErrorString = nil;
  959. _ErrGetError: TErrGetError = nil;
  960. _ErrClearError: TErrClearError = nil;
  961. _ErrFreeStrings: TErrFreeStrings = nil;
  962. _ErrRemoveState: TErrRemoveState = nil;
  963. _OPENSSLaddallalgorithms: TOPENSSLaddallalgorithms = nil;
  964. _CRYPTOcleanupAllExData: TCRYPTOcleanupAllExData = nil;
  965. _RandScreen: TRandScreen = nil;
  966. _BioNew: TBioNew = nil;
  967. _BioFreeAll: TBioFreeAll = nil;
  968. _BioSMem: TBioSMem = nil;
  969. _BioCtrlPending: TBioCtrlPending = nil;
  970. _BioRead: TBioRead = nil;
  971. _BioWrite: TBioWrite = nil;
  972. _d2iPKCS12bio: Td2iPKCS12bio = nil;
  973. _PKCS12parse: TPKCS12parse = nil;
  974. _PKCS12free: TPKCS12free = nil;
  975. _RsaGenerateKey: TRsaGenerateKey = nil;
  976. _Asn1UtctimeNew: TAsn1UtctimeNew = nil;
  977. _Asn1UtctimeFree: TAsn1UtctimeFree = nil;
  978. _Asn1IntegerSet: TAsn1IntegerSet = nil;
  979. _Asn1IntegerGet: TAsn1IntegerGet = nil; {pf}
  980. _i2dX509bio: Ti2dX509bio = nil;
  981. _d2iX509bio: Td2iX509bio = nil; {pf}
  982. _PEMReadBioX509: TPEMReadBioX509 = nil; {pf}
  983. _SkX509PopFree: TSkX509PopFree = nil; {pf}
  984. _i2dPrivateKeyBio: Ti2dPrivateKeyBio = nil;
  985. // 3DES functions
  986. _DESsetoddparity: TDESsetoddparity = nil;
  987. _DESsetkeychecked: TDESsetkeychecked = nil;
  988. _DESecbencrypt: TDESecbencrypt = nil;
  989. //thread lock functions
  990. _CRYPTOnumlocks: TCRYPTOnumlocks = nil;
  991. _CRYPTOSetLockingCallback: TCRYPTOSetLockingCallback = nil;
  992. {$ENDIF}
  993. var
  994. SSLCS: TCriticalSection;
  995. SSLloaded: boolean = false;
  996. {$IFNDEF CIL}
  997. Locks: TList;
  998. {$ENDIF}
  999. {$IFNDEF CIL}
  1000. // libssl.dll
  1001. function SslGetError(s: PSSL; ret_code: Integer):Integer;
  1002. begin
  1003. if InitSSLInterface and Assigned(_SslGetError) then
  1004. Result := _SslGetError(s, ret_code)
  1005. else
  1006. Result := SSL_ERROR_SSL;
  1007. end;
  1008. function SslLibraryInit:Integer;
  1009. begin
  1010. if InitSSLInterface and Assigned(_SslLibraryInit) then
  1011. Result := _SslLibraryInit
  1012. else
  1013. Result := 1;
  1014. end;
  1015. procedure SslLoadErrorStrings;
  1016. begin
  1017. if InitSSLInterface and Assigned(_SslLoadErrorStrings) then
  1018. _SslLoadErrorStrings;
  1019. end;
  1020. //function SslCtxSetCipherList(arg0: PSSL_CTX; str: PChar):Integer;
  1021. function SslCtxSetCipherList(arg0: PSSL_CTX; var str: AnsiString):Integer;
  1022. begin
  1023. if InitSSLInterface and Assigned(_SslCtxSetCipherList) then
  1024. Result := _SslCtxSetCipherList(arg0, PAnsiChar(str))
  1025. else
  1026. Result := 0;
  1027. end;
  1028. function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
  1029. begin
  1030. if InitSSLInterface and Assigned(_SslCtxNew) then
  1031. Result := _SslCtxNew(meth)
  1032. else
  1033. Result := nil;
  1034. end;
  1035. procedure SslCtxFree(arg0: PSSL_CTX);
  1036. begin
  1037. if InitSSLInterface and Assigned(_SslCtxFree) then
  1038. _SslCtxFree(arg0);
  1039. end;
  1040. function SslSetFd(s: PSSL; fd: Integer):Integer;
  1041. begin
  1042. if InitSSLInterface and Assigned(_SslSetFd) then
  1043. Result := _SslSetFd(s, fd)
  1044. else
  1045. Result := 0;
  1046. end;
  1047. function SslMethodV2:PSSL_METHOD;
  1048. begin
  1049. if InitSSLInterface and Assigned(_SslMethodV2) then
  1050. Result := _SslMethodV2
  1051. else
  1052. Result := nil;
  1053. end;
  1054. function SslMethodV3:PSSL_METHOD;
  1055. begin
  1056. if InitSSLInterface and Assigned(_SslMethodV3) then
  1057. Result := _SslMethodV3
  1058. else
  1059. Result := nil;
  1060. end;
  1061. function SslMethodTLSV1:PSSL_METHOD;
  1062. begin
  1063. if InitSSLInterface and Assigned(_SslMethodTLSV1) then
  1064. Result := _SslMethodTLSV1
  1065. else
  1066. Result := nil;
  1067. end;
  1068. function SslMethodTLSV11:PSSL_METHOD;
  1069. begin
  1070. if InitSSLInterface and Assigned(_SslMethodTLSV11) then
  1071. Result := _SslMethodTLSV11
  1072. else
  1073. Result := nil;
  1074. end;
  1075. function SslMethodTLSV12:PSSL_METHOD;
  1076. begin
  1077. if InitSSLInterface and Assigned(_SslMethodTLSV12) then
  1078. Result := _SslMethodTLSV12
  1079. else
  1080. Result := nil;
  1081. end;
  1082. function SslMethodV23:PSSL_METHOD;
  1083. begin
  1084. if InitSSLInterface and Assigned(_SslMethodV23) then
  1085. Result := _SslMethodV23
  1086. else
  1087. Result := nil;
  1088. end;
  1089. function SslMethodTLS:PSSL_METHOD;
  1090. begin
  1091. if InitSSLInterface and Assigned(_SslMethodTLS) then
  1092. Result := _SslMethodTLS
  1093. else
  1094. Result := nil;
  1095. end;
  1096. function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):Integer;
  1097. begin
  1098. if InitSSLInterface and Assigned(_SslCtxUsePrivateKey) then
  1099. Result := _SslCtxUsePrivateKey(ctx, pkey)
  1100. else
  1101. Result := 0;
  1102. end;
  1103. function SslCtxUsePrivateKeyASN1(pk: integer; ctx: PSSL_CTX; d: AnsiString; len: integer):Integer;
  1104. begin
  1105. if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyASN1) then
  1106. Result := _SslCtxUsePrivateKeyASN1(pk, ctx, Sslptr(d), len)
  1107. else
  1108. Result := 0;
  1109. end;
  1110. //function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer;
  1111. function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: AnsiString; _type: Integer):Integer;
  1112. begin
  1113. if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyFile) then
  1114. Result := _SslCtxUsePrivateKeyFile(ctx, PAnsiChar(_file), _type)
  1115. else
  1116. Result := 0;
  1117. end;
  1118. function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):Integer;
  1119. begin
  1120. if InitSSLInterface and Assigned(_SslCtxUseCertificate) then
  1121. Result := _SslCtxUseCertificate(ctx, x)
  1122. else
  1123. Result := 0;
  1124. end;
  1125. function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: integer; d: AnsiString):Integer;
  1126. begin
  1127. if InitSSLInterface and Assigned(_SslCtxUseCertificateASN1) then
  1128. Result := _SslCtxUseCertificateASN1(ctx, len, SslPtr(d))
  1129. else
  1130. Result := 0;
  1131. end;
  1132. function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: AnsiString; _type: Integer):Integer;
  1133. begin
  1134. if InitSSLInterface and Assigned(_SslCtxUseCertificateFile) then
  1135. Result := _SslCtxUseCertificateFile(ctx, PAnsiChar(_file), _type)
  1136. else
  1137. Result := 0;
  1138. end;
  1139. //function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: PChar):Integer;
  1140. function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: AnsiString):Integer;
  1141. begin
  1142. if InitSSLInterface and Assigned(_SslCtxUseCertificateChainFile) then
  1143. Result := _SslCtxUseCertificateChainFile(ctx, PAnsiChar(_file))
  1144. else
  1145. Result := 0;
  1146. end;
  1147. function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer;
  1148. begin
  1149. if InitSSLInterface and Assigned(_SslCtxCheckPrivateKeyFile) then
  1150. Result := _SslCtxCheckPrivateKeyFile(ctx)
  1151. else
  1152. Result := 0;
  1153. end;
  1154. procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
  1155. begin
  1156. if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCb) then
  1157. _SslCtxSetDefaultPasswdCb(ctx, cb);
  1158. end;
  1159. procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
  1160. begin
  1161. if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCbUserdata) then
  1162. _SslCtxSetDefaultPasswdCbUserdata(ctx, u);
  1163. end;
  1164. //function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):Integer;
  1165. function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: AnsiString; const CApath: AnsiString):Integer;
  1166. begin
  1167. if InitSSLInterface and Assigned(_SslCtxLoadVerifyLocations) then
  1168. Result := _SslCtxLoadVerifyLocations(ctx, SslPtr(CAfile), SslPtr(CApath))
  1169. else
  1170. Result := 0;
  1171. end;
  1172. function SslCtxCtrl(ctx: PSSL_CTX; cmd: integer; larg: integer; parg: SslPtr): integer;
  1173. begin
  1174. if InitSSLInterface and Assigned(_SslCtxCtrl) then
  1175. Result := _SslCtxCtrl(ctx, cmd, larg, parg)
  1176. else
  1177. Result := 0;
  1178. end;
  1179. function SslNew(ctx: PSSL_CTX):PSSL;
  1180. begin
  1181. if InitSSLInterface and Assigned(_SslNew) then
  1182. Result := _SslNew(ctx)
  1183. else
  1184. Result := nil;
  1185. end;
  1186. procedure SslFree(ssl: PSSL);
  1187. begin
  1188. if InitSSLInterface and Assigned(_SslFree) then
  1189. _SslFree(ssl);
  1190. end;
  1191. function SslAccept(ssl: PSSL):Integer;
  1192. begin
  1193. if InitSSLInterface and Assigned(_SslAccept) then
  1194. Result := _SslAccept(ssl)
  1195. else
  1196. Result := -1;
  1197. end;
  1198. function SslConnect(ssl: PSSL):Integer;
  1199. begin
  1200. if InitSSLInterface and Assigned(_SslConnect) then
  1201. Result := _SslConnect(ssl)
  1202. else
  1203. Result := -1;
  1204. end;
  1205. function SslShutdown(ssl: PSSL):Integer;
  1206. begin
  1207. if InitSSLInterface and Assigned(_SslShutdown) then
  1208. Result := _SslShutdown(ssl)
  1209. else
  1210. Result := -1;
  1211. end;
  1212. //function SslRead(ssl: PSSL; buf: PChar; num: Integer):Integer;
  1213. function SslRead(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  1214. begin
  1215. if InitSSLInterface and Assigned(_SslRead) then
  1216. Result := _SslRead(ssl, PAnsiChar(buf), num)
  1217. else
  1218. Result := -1;
  1219. end;
  1220. //function SslPeek(ssl: PSSL; buf: PChar; num: Integer):Integer;
  1221. function SslPeek(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  1222. begin
  1223. if InitSSLInterface and Assigned(_SslPeek) then
  1224. Result := _SslPeek(ssl, PAnsiChar(buf), num)
  1225. else
  1226. Result := -1;
  1227. end;
  1228. //function SslWrite(ssl: PSSL; const buf: PChar; num: Integer):Integer;
  1229. function SslWrite(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
  1230. begin
  1231. if InitSSLInterface and Assigned(_SslWrite) then
  1232. Result := _SslWrite(ssl, PAnsiChar(buf), num)
  1233. else
  1234. Result := -1;
  1235. end;
  1236. function SslPending(ssl: PSSL):Integer;
  1237. begin
  1238. if InitSSLInterface and Assigned(_SslPending) then
  1239. Result := _SslPending(ssl)
  1240. else
  1241. Result := 0;
  1242. end;
  1243. //function SslGetVersion(ssl: PSSL):PChar;
  1244. function SslGetVersion(ssl: PSSL):AnsiString;
  1245. begin
  1246. if InitSSLInterface and Assigned(_SslGetVersion) then
  1247. Result := _SslGetVersion(ssl)
  1248. else
  1249. Result := '';
  1250. end;
  1251. function SslGetPeerCertificate(ssl: PSSL):PX509;
  1252. begin
  1253. if InitSSLInterface and Assigned(_SslGetPeerCertificate) then
  1254. Result := _SslGetPeerCertificate(ssl)
  1255. else
  1256. Result := nil;
  1257. end;
  1258. //procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: SslPtr);
  1259. procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction);
  1260. begin
  1261. if InitSSLInterface and Assigned(_SslCtxSetVerify) then
  1262. _SslCtxSetVerify(ctx, mode, @arg2);
  1263. end;
  1264. function SSLGetCurrentCipher(s: PSSL):SslPtr;
  1265. begin
  1266. if InitSSLInterface and Assigned(_SSLGetCurrentCipher) then
  1267. {$IFDEF CIL}
  1268. {$ELSE}
  1269. Result := _SSLGetCurrentCipher(s)
  1270. {$ENDIF}
  1271. else
  1272. Result := nil;
  1273. end;
  1274. //function SSLCipherGetName(c: SslPtr):PChar;
  1275. function SSLCipherGetName(c: SslPtr):AnsiString;
  1276. begin
  1277. if InitSSLInterface and Assigned(_SSLCipherGetName) then
  1278. Result := _SSLCipherGetName(c)
  1279. else
  1280. Result := '';
  1281. end;
  1282. //function SSLCipherGetBits(c: SslPtr; alg_bits: PInteger):Integer;
  1283. function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer;
  1284. begin
  1285. if InitSSLInterface and Assigned(_SSLCipherGetBits) then
  1286. Result := _SSLCipherGetBits(c, @alg_bits)
  1287. else
  1288. Result := 0;
  1289. end;
  1290. function SSLGetVerifyResult(ssl: PSSL):Integer;
  1291. begin
  1292. if InitSSLInterface and Assigned(_SSLGetVerifyResult) then
  1293. Result := _SSLGetVerifyResult(ssl)
  1294. else
  1295. Result := X509_V_ERR_APPLICATION_VERIFICATION;
  1296. end;
  1297. function SSLCtrl(ssl: PSSL; cmd: integer; larg: integer; parg: SslPtr):Integer;
  1298. begin
  1299. if InitSSLInterface and Assigned(_SSLCtrl) then
  1300. Result := _SSLCtrl(ssl, cmd, larg, parg)
  1301. else
  1302. Result := X509_V_ERR_APPLICATION_VERIFICATION;
  1303. end;
  1304. function SslSet1Host(ssl: PSSL; hostname: PAnsiChar):Integer;
  1305. begin
  1306. if InitSSLInterface and Assigned(_SslSet1Host) then
  1307. Result := _SslSet1Host(ssl, hostname)
  1308. else
  1309. Result := 0;
  1310. end;
  1311. procedure SslSessionFree(session: PSslPtr);
  1312. begin
  1313. if InitSSLInterface and Assigned(_SslSessionFree) then
  1314. _SslSessionFree(session);
  1315. end;
  1316. function SslGet1Session(ssl: PSSL): PSslPtr;
  1317. begin
  1318. if InitSSLInterface and Assigned(_SslGet1Session) then
  1319. Result := _SslGet1Session(ssl)
  1320. else
  1321. Result := nil;
  1322. end;
  1323. function SslSetSession(ssl: PSSL; session: PSslPtr): Integer;
  1324. begin
  1325. if InitSSLInterface and Assigned(_SslSetSession) then
  1326. Result := _SslSetSession(ssl, session)
  1327. else
  1328. Result := 0;
  1329. end;
  1330. // libeay.dll
  1331. function X509New: PX509;
  1332. begin
  1333. if InitSSLInterface and Assigned(_X509New) then
  1334. Result := _X509New
  1335. else
  1336. Result := nil;
  1337. end;
  1338. procedure X509Free(x: PX509);
  1339. begin
  1340. if InitSSLInterface and Assigned(_X509Free) then
  1341. _X509Free(x);
  1342. end;
  1343. //function SslX509NameOneline(a: PX509_NAME; buf: PChar; size: Integer):PChar;
  1344. function X509NameOneline(a: PX509_NAME; var buf: AnsiString; size: Integer):AnsiString;
  1345. begin
  1346. if InitSSLInterface and Assigned(_X509NameOneline) then
  1347. Result := _X509NameOneline(a, PAnsiChar(buf),size)
  1348. else
  1349. Result := '';
  1350. end;
  1351. function X509GetSubjectName(a: PX509):PX509_NAME;
  1352. begin
  1353. if InitSSLInterface and Assigned(_X509GetSubjectName) then
  1354. Result := _X509GetSubjectName(a)
  1355. else
  1356. Result := nil;
  1357. end;
  1358. function X509GetIssuerName(a: PX509):PX509_NAME;
  1359. begin
  1360. if InitSSLInterface and Assigned(_X509GetIssuerName) then
  1361. Result := _X509GetIssuerName(a)
  1362. else
  1363. Result := nil;
  1364. end;
  1365. function X509NameHash(x: PX509_NAME):Cardinal;
  1366. begin
  1367. if InitSSLInterface and Assigned(_X509NameHash) then
  1368. Result := _X509NameHash(x)
  1369. else
  1370. Result := 0;
  1371. end;
  1372. //function SslX509Digest(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer;
  1373. function X509Digest(data: PX509; _type: PEVP_MD; md: AnsiString; var len: Integer):Integer;
  1374. begin
  1375. if InitSSLInterface and Assigned(_X509Digest) then
  1376. Result := _X509Digest(data, _type, PAnsiChar(md), @len)
  1377. else
  1378. Result := 0;
  1379. end;
  1380. function EvpPkeyNew: EVP_PKEY;
  1381. begin
  1382. if InitSSLInterface and Assigned(_EvpPkeyNew) then
  1383. Result := _EvpPkeyNew
  1384. else
  1385. Result := nil;
  1386. end;
  1387. procedure EvpPkeyFree(pk: EVP_PKEY);
  1388. begin
  1389. if InitSSLInterface and Assigned(_EvpPkeyFree) then
  1390. _EvpPkeyFree(pk);
  1391. end;
  1392. function SSLeayversion(t: integer): Ansistring;
  1393. begin
  1394. if InitSSLInterface and Assigned(_SSLeayversion) then
  1395. Result := PAnsiChar(_SSLeayversion(t))
  1396. else
  1397. Result := '';
  1398. end;
  1399. procedure ErrErrorString(e: integer; var buf: Ansistring; len: integer);
  1400. begin
  1401. if InitSSLInterface and Assigned(_ErrErrorString) then
  1402. _ErrErrorString(e, Pointer(buf), len);
  1403. buf := PAnsiChar(Buf);
  1404. end;
  1405. function ErrGetError: integer;
  1406. begin
  1407. if InitSSLInterface and Assigned(_ErrGetError) then
  1408. Result := _ErrGetError
  1409. else
  1410. Result := SSL_ERROR_SSL;
  1411. end;
  1412. procedure ErrClearError;
  1413. begin
  1414. if InitSSLInterface and Assigned(_ErrClearError) then
  1415. _ErrClearError;
  1416. end;
  1417. procedure ErrFreeStrings;
  1418. begin
  1419. if InitSSLInterface and Assigned(_ErrFreeStrings) then
  1420. _ErrFreeStrings;
  1421. end;
  1422. procedure ErrRemoveState(pid: integer);
  1423. begin
  1424. if InitSSLInterface and Assigned(_ErrRemoveState) then
  1425. _ErrRemoveState(pid);
  1426. end;
  1427. procedure OPENSSLaddallalgorithms;
  1428. begin
  1429. if InitSSLInterface and Assigned(_OPENSSLaddallalgorithms) then
  1430. _OPENSSLaddallalgorithms;
  1431. end;
  1432. procedure EVPcleanup;
  1433. begin
  1434. if InitSSLInterface and Assigned(_EVPcleanup) then
  1435. _EVPcleanup;
  1436. end;
  1437. procedure CRYPTOcleanupAllExData;
  1438. begin
  1439. if InitSSLInterface and Assigned(_CRYPTOcleanupAllExData) then
  1440. _CRYPTOcleanupAllExData;
  1441. end;
  1442. procedure RandScreen;
  1443. begin
  1444. if InitSSLInterface and Assigned(_RandScreen) then
  1445. _RandScreen;
  1446. end;
  1447. function BioNew(b: PBIO_METHOD): PBIO;
  1448. begin
  1449. if InitSSLInterface and Assigned(_BioNew) then
  1450. Result := _BioNew(b)
  1451. else
  1452. Result := nil;
  1453. end;
  1454. procedure BioFreeAll(b: PBIO);
  1455. begin
  1456. if InitSSLInterface and Assigned(_BioFreeAll) then
  1457. _BioFreeAll(b);
  1458. end;
  1459. function BioSMem: PBIO_METHOD;
  1460. begin
  1461. if InitSSLInterface and Assigned(_BioSMem) then
  1462. Result := _BioSMem
  1463. else
  1464. Result := nil;
  1465. end;
  1466. function BioCtrlPending(b: PBIO): integer;
  1467. begin
  1468. if InitSSLInterface and Assigned(_BioCtrlPending) then
  1469. Result := _BioCtrlPending(b)
  1470. else
  1471. Result := 0;
  1472. end;
  1473. //function BioRead(b: PBIO; Buf: PChar; Len: integer): integer;
  1474. function BioRead(b: PBIO; var Buf: AnsiString; Len: integer): integer;
  1475. begin
  1476. if InitSSLInterface and Assigned(_BioRead) then
  1477. Result := _BioRead(b, PAnsiChar(Buf), Len)
  1478. else
  1479. Result := -2;
  1480. end;
  1481. //function BioWrite(b: PBIO; Buf: PChar; Len: integer): integer;
  1482. function BioWrite(b: PBIO; Buf: AnsiString; Len: integer): integer;
  1483. begin
  1484. if InitSSLInterface and Assigned(_BioWrite) then
  1485. Result := _BioWrite(b, PAnsiChar(Buf), Len)
  1486. else
  1487. Result := -2;
  1488. end;
  1489. function X509print(b: PBIO; a: PX509): integer;
  1490. begin
  1491. if InitSSLInterface and Assigned(_X509print) then
  1492. Result := _X509print(b, a)
  1493. else
  1494. Result := 0;
  1495. end;
  1496. function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
  1497. begin
  1498. if InitSSLInterface and Assigned(_d2iPKCS12bio) then
  1499. Result := _d2iPKCS12bio(b, Pkcs12)
  1500. else
  1501. Result := nil;
  1502. end;
  1503. function PKCS12parse(p12: SslPtr; pass: Ansistring; var pkey, cert, ca: SslPtr): integer;
  1504. begin
  1505. if InitSSLInterface and Assigned(_PKCS12parse) then
  1506. Result := _PKCS12parse(p12, SslPtr(pass), pkey, cert, ca)
  1507. else
  1508. Result := 0;
  1509. end;
  1510. procedure PKCS12free(p12: SslPtr);
  1511. begin
  1512. if InitSSLInterface and Assigned(_PKCS12free) then
  1513. _PKCS12free(p12);
  1514. end;
  1515. function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA;
  1516. begin
  1517. if InitSSLInterface and Assigned(_RsaGenerateKey) then
  1518. Result := _RsaGenerateKey(bits, e, callback, cb_arg)
  1519. else
  1520. Result := nil;
  1521. end;
  1522. function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer;
  1523. begin
  1524. if InitSSLInterface and Assigned(_EvpPkeyAssign) then
  1525. Result := _EvpPkeyAssign(pkey, _type, key)
  1526. else
  1527. Result := 0;
  1528. end;
  1529. function X509SetVersion(x: PX509; version: integer): integer;
  1530. begin
  1531. if InitSSLInterface and Assigned(_X509SetVersion) then
  1532. Result := _X509SetVersion(x, version)
  1533. else
  1534. Result := 0;
  1535. end;
  1536. function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer;
  1537. begin
  1538. if InitSSLInterface and Assigned(_X509SetPubkey) then
  1539. Result := _X509SetPubkey(x, pkey)
  1540. else
  1541. Result := 0;
  1542. end;
  1543. function X509SetIssuerName(x: PX509; name: PX509_NAME): integer;
  1544. begin
  1545. if InitSSLInterface and Assigned(_X509SetIssuerName) then
  1546. Result := _X509SetIssuerName(x, name)
  1547. else
  1548. Result := 0;
  1549. end;
  1550. function X509NameAddEntryByTxt(name: PX509_NAME; field: Ansistring; _type: integer;
  1551. bytes: Ansistring; len, loc, _set: integer): integer;
  1552. begin
  1553. if InitSSLInterface and Assigned(_X509NameAddEntryByTxt) then
  1554. Result := _X509NameAddEntryByTxt(name, PAnsiChar(field), _type, PAnsiChar(Bytes), len, loc, _set)
  1555. else
  1556. Result := 0;
  1557. end;
  1558. function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer;
  1559. begin
  1560. if InitSSLInterface and Assigned(_X509Sign) then
  1561. Result := _X509Sign(x, pkey, md)
  1562. else
  1563. Result := 0;
  1564. end;
  1565. function Asn1UtctimeNew: PASN1_UTCTIME;
  1566. begin
  1567. if InitSSLInterface and Assigned(_Asn1UtctimeNew) then
  1568. Result := _Asn1UtctimeNew
  1569. else
  1570. Result := nil;
  1571. end;
  1572. procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
  1573. begin
  1574. if InitSSLInterface and Assigned(_Asn1UtctimeFree) then
  1575. _Asn1UtctimeFree(a);
  1576. end;
  1577. function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME;
  1578. begin
  1579. if InitSSLInterface and Assigned(_X509GmtimeAdj) then
  1580. Result := _X509GmtimeAdj(s, adj)
  1581. else
  1582. Result := nil;
  1583. end;
  1584. function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer;
  1585. begin
  1586. if InitSSLInterface and Assigned(_X509SetNotBefore) then
  1587. Result := _X509SetNotBefore(x, tm)
  1588. else
  1589. Result := 0;
  1590. end;
  1591. function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer;
  1592. begin
  1593. if InitSSLInterface and Assigned(_X509SetNotAfter) then
  1594. Result := _X509SetNotAfter(x, tm)
  1595. else
  1596. Result := 0;
  1597. end;
  1598. function i2dX509bio(b: PBIO; x: PX509): integer;
  1599. begin
  1600. if InitSSLInterface and Assigned(_i2dX509bio) then
  1601. Result := _i2dX509bio(b, x)
  1602. else
  1603. Result := 0;
  1604. end;
  1605. function d2iX509bio(b: PBIO; x: PX509): PX509; {pf}
  1606. begin
  1607. if InitSSLInterface and Assigned(_d2iX509bio) then
  1608. Result := _d2iX509bio(b, x)
  1609. else
  1610. Result := nil;
  1611. end;
  1612. function PEMReadBioX509(b:PBIO; {var x:PX509;}x:PSslPtr; callback:PFunction; cb_arg: SslPtr): PX509; {pf}
  1613. begin
  1614. if InitSSLInterface and Assigned(_PEMReadBioX509) then
  1615. Result := _PEMReadBioX509(b,x,callback,cb_arg)
  1616. else
  1617. Result := nil;
  1618. end;
  1619. procedure SkX509PopFree(st: PSTACK; func:TSkPopFreeFunc); {pf}
  1620. begin
  1621. if InitSSLInterface and Assigned(_SkX509PopFree) then
  1622. _SkX509PopFree(st,func);
  1623. end;
  1624. function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer;
  1625. begin
  1626. if InitSSLInterface and Assigned(_i2dPrivateKeyBio) then
  1627. Result := _i2dPrivateKeyBio(b, pkey)
  1628. else
  1629. Result := 0;
  1630. end;
  1631. function EvpGetDigestByName(Name: AnsiString): PEVP_MD;
  1632. begin
  1633. if InitSSLInterface and Assigned(_EvpGetDigestByName) then
  1634. Result := _EvpGetDigestByName(PAnsiChar(Name))
  1635. else
  1636. Result := nil;
  1637. end;
  1638. function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
  1639. begin
  1640. if InitSSLInterface and Assigned(_Asn1IntegerSet) then
  1641. Result := _Asn1IntegerSet(a, v)
  1642. else
  1643. Result := 0;
  1644. end;
  1645. function Asn1IntegerGet(a: PASN1_INTEGER): integer; {pf}
  1646. begin
  1647. if InitSSLInterface and Assigned(_Asn1IntegerGet) then
  1648. Result := _Asn1IntegerGet(a)
  1649. else
  1650. Result := 0;
  1651. end;
  1652. function X509GetSerialNumber(x: PX509): PASN1_INTEGER;
  1653. begin
  1654. if InitSSLInterface and Assigned(_X509GetSerialNumber) then
  1655. Result := _X509GetSerialNumber(x)
  1656. else
  1657. Result := nil;
  1658. end;
  1659. // 3DES functions
  1660. procedure DESsetoddparity(Key: des_cblock);
  1661. begin
  1662. if InitSSLInterface and Assigned(_DESsetoddparity) then
  1663. _DESsetoddparity(Key);
  1664. end;
  1665. function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer;
  1666. begin
  1667. if InitSSLInterface and Assigned(_DESsetkeychecked) then
  1668. Result := _DESsetkeychecked(key, schedule)
  1669. else
  1670. Result := -1;
  1671. end;
  1672. procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer);
  1673. begin
  1674. if InitSSLInterface and Assigned(_DESecbencrypt) then
  1675. _DESecbencrypt(Input, output, ks, enc);
  1676. end;
  1677. procedure locking_callback(mode, ltype: integer; lfile: PChar; line: integer); cdecl;
  1678. begin
  1679. if (mode and 1) > 0 then
  1680. TCriticalSection(Locks[ltype]).Enter
  1681. else
  1682. TCriticalSection(Locks[ltype]).Leave;
  1683. end;
  1684. procedure InitLocks;
  1685. var
  1686. n: integer;
  1687. max: integer;
  1688. begin
  1689. Locks := TList.Create;
  1690. max := _CRYPTOnumlocks;
  1691. for n := 1 to max do
  1692. Locks.Add(TCriticalSection.Create);
  1693. _CRYPTOsetlockingcallback(@locking_callback);
  1694. end;
  1695. procedure FreeLocks;
  1696. var
  1697. n: integer;
  1698. begin
  1699. _CRYPTOsetlockingcallback(nil);
  1700. for n := 0 to Locks.Count - 1 do
  1701. TCriticalSection(Locks[n]).Free;
  1702. Locks.Free;
  1703. end;
  1704. {$ENDIF}
  1705. function LoadLib(const Value: String): HModule;
  1706. begin
  1707. {$IFDEF CIL}
  1708. Result := LoadLibrary(Value);
  1709. {$ELSE}
  1710. Result := LoadLibrary(PChar(Value));
  1711. {$ENDIF}
  1712. end;
  1713. function GetProcAddr(module: HModule; const ProcName: string): SslPtr;
  1714. begin
  1715. {$IFDEF CIL}
  1716. Result := GetProcAddress(module, ProcName);
  1717. {$ELSE}
  1718. Result := GetProcAddress(module, PChar(ProcName));
  1719. {$ENDIF}
  1720. end;
  1721. function GetLibFileName(Handle: TLibHandle): string;
  1722. var
  1723. n: integer;
  1724. begin
  1725. n := MAX_PATH + 1024;
  1726. SetLength(Result, n);
  1727. n := GetModuleFilename(Handle, PChar(Result), n);
  1728. SetLength(Result, n);
  1729. end;
  1730. function InitSSLInterface: Boolean;
  1731. var
  1732. s: string;
  1733. i: integer;
  1734. begin
  1735. {pf}
  1736. if SSLLoaded then
  1737. begin
  1738. Result := TRUE;
  1739. exit;
  1740. end;
  1741. {/pf}
  1742. SSLCS.Enter;
  1743. try
  1744. if not IsSSLloaded then
  1745. begin
  1746. {$IFDEF CIL}
  1747. SSLLibHandle := 1;
  1748. SSLUtilHandle := 1;
  1749. {$ELSE}
  1750. // Note: It's important to ensure that the libraries both come from the
  1751. // same directory, preferably the one of the executable. Otherwise a
  1752. // version mismatch could easily occur.
  1753. {$IFDEF MSWINDOWS}
  1754. for i := 0 to Pred(LibCount) do
  1755. begin
  1756. SSLUtilHandle := LoadLib(CryptoLibNames[i]);
  1757. if SSLUtilHandle <> 0 then
  1758. begin
  1759. s := ExtractFilePath(GetLibFileName(SSLUtilHandle));
  1760. SSLLibHandle := LoadLib(s + SSLLibNames[i]);
  1761. Break;
  1762. end;
  1763. end;
  1764. {$ELSE}
  1765. SSLUtilHandle := LoadLib(DLLUtilName);
  1766. SSLLibHandle := LoadLib(DLLSSLName);
  1767. {$ENDIF}
  1768. {$ENDIF}
  1769. if (SSLLibHandle <> 0) and (SSLUtilHandle <> 0) then
  1770. begin
  1771. {$IFNDEF CIL}
  1772. _SslGetError := GetProcAddr(SSLLibHandle, 'SSL_get_error');
  1773. _SslLibraryInit := GetProcAddr(SSLLibHandle, 'SSL_library_init');
  1774. _SslLoadErrorStrings := GetProcAddr(SSLLibHandle, 'SSL_load_error_strings');
  1775. _SslCtxSetCipherList := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_cipher_list');
  1776. _SslCtxNew := GetProcAddr(SSLLibHandle, 'SSL_CTX_new');
  1777. _SslCtxFree := GetProcAddr(SSLLibHandle, 'SSL_CTX_free');
  1778. _SslSetFd := GetProcAddr(SSLLibHandle, 'SSL_set_fd');
  1779. _SslMethodV2 := GetProcAddr(SSLLibHandle, 'SSLv2_method');
  1780. _SslMethodV3 := GetProcAddr(SSLLibHandle, 'SSLv3_method');
  1781. _SslMethodTLSV1 := GetProcAddr(SSLLibHandle, 'TLSv1_method');
  1782. _SslMethodTLSV11 := GetProcAddr(SSLLibHandle, 'TLSv1_1_method');
  1783. _SslMethodTLSV12 := GetProcAddr(SSLLibHandle, 'TLSv1_2_method');
  1784. _SslMethodV23 := GetProcAddr(SSLLibHandle, 'SSLv23_method');
  1785. _SslMethodTLS := GetProcAddr(SSLLibHandle, 'TLS_method');
  1786. _SslCtxUsePrivateKey := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey');
  1787. _SslCtxUsePrivateKeyASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey_ASN1');
  1788. //use SSL_CTX_use_RSAPrivateKey_file instead SSL_CTX_use_PrivateKey_file,
  1789. //because SSL_CTX_use_PrivateKey_file not support DER format. :-O
  1790. _SslCtxUsePrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_RSAPrivateKey_file');
  1791. _SslCtxUseCertificate := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate');
  1792. _SslCtxUseCertificateASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_ASN1');
  1793. _SslCtxUseCertificateFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_file');
  1794. _SslCtxUseCertificateChainFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_chain_file');
  1795. _SslCtxCheckPrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_check_private_key');
  1796. _SslCtxSetDefaultPasswdCb := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb');
  1797. _SslCtxSetDefaultPasswdCbUserdata := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb_userdata');
  1798. _SslCtxLoadVerifyLocations := GetProcAddr(SSLLibHandle, 'SSL_CTX_load_verify_locations');
  1799. _SslCtxCtrl := GetProcAddr(SSLLibHandle, 'SSL_CTX_ctrl');
  1800. _SslNew := GetProcAddr(SSLLibHandle, 'SSL_new');
  1801. _SslFree := GetProcAddr(SSLLibHandle, 'SSL_free');
  1802. _SslAccept := GetProcAddr(SSLLibHandle, 'SSL_accept');
  1803. _SslConnect := GetProcAddr(SSLLibHandle, 'SSL_connect');
  1804. _SslShutdown := GetProcAddr(SSLLibHandle, 'SSL_shutdown');
  1805. _SslRead := GetProcAddr(SSLLibHandle, 'SSL_read');
  1806. _SslPeek := GetProcAddr(SSLLibHandle, 'SSL_peek');
  1807. _SslWrite := GetProcAddr(SSLLibHandle, 'SSL_write');
  1808. _SslPending := GetProcAddr(SSLLibHandle, 'SSL_pending');
  1809. _SslGetPeerCertificate := GetProcAddr(SSLLibHandle, 'SSL_get_peer_certificate');
  1810. _SslGetVersion := GetProcAddr(SSLLibHandle, 'SSL_get_version');
  1811. _SslCtxSetVerify := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_verify');
  1812. _SslGetCurrentCipher := GetProcAddr(SSLLibHandle, 'SSL_get_current_cipher');
  1813. _SslCipherGetName := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_name');
  1814. _SslCipherGetBits := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_bits');
  1815. _SslGetVerifyResult := GetProcAddr(SSLLibHandle, 'SSL_get_verify_result');
  1816. _SslCtrl := GetProcAddr(SSLLibHandle, 'SSL_ctrl');
  1817. _SslSet1Host := GetProcAddr(SSLLibHandle, 'SSL_set1_host');
  1818. _SslSessionFree := GetProcAddr(SSLLibHandle, 'SSL_SESSION_free');
  1819. _SslGet1Session := GetProcAddr(SSLLibHandle, 'SSL_get1_session');
  1820. _SslSetSession := GetProcAddr(SSLLibHandle, 'SSL_set_session');
  1821. _X509New := GetProcAddr(SSLUtilHandle, 'X509_new');
  1822. _X509Free := GetProcAddr(SSLUtilHandle, 'X509_free');
  1823. _X509NameOneline := GetProcAddr(SSLUtilHandle, 'X509_NAME_oneline');
  1824. _X509GetSubjectName := GetProcAddr(SSLUtilHandle, 'X509_get_subject_name');
  1825. _X509GetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_get_issuer_name');
  1826. _X509NameHash := GetProcAddr(SSLUtilHandle, 'X509_NAME_hash');
  1827. _X509Digest := GetProcAddr(SSLUtilHandle, 'X509_digest');
  1828. _X509print := GetProcAddr(SSLUtilHandle, 'X509_print');
  1829. _X509SetVersion := GetProcAddr(SSLUtilHandle, 'X509_set_version');
  1830. _X509SetPubkey := GetProcAddr(SSLUtilHandle, 'X509_set_pubkey');
  1831. _X509SetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_set_issuer_name');
  1832. _X509NameAddEntryByTxt := GetProcAddr(SSLUtilHandle, 'X509_NAME_add_entry_by_txt');
  1833. _X509Sign := GetProcAddr(SSLUtilHandle, 'X509_sign');
  1834. _X509GmtimeAdj := GetProcAddr(SSLUtilHandle, 'X509_gmtime_adj');
  1835. _X509SetNotBefore := GetProcAddr(SSLUtilHandle, 'X509_set_notBefore');
  1836. _X509SetNotAfter := GetProcAddr(SSLUtilHandle, 'X509_set_notAfter');
  1837. _X509GetSerialNumber := GetProcAddr(SSLUtilHandle, 'X509_get_serialNumber');
  1838. _EvpPkeyNew := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_new');
  1839. _EvpPkeyFree := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_free');
  1840. _EvpPkeyAssign := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_assign');
  1841. _EVPCleanup := GetProcAddr(SSLUtilHandle, 'EVP_cleanup');
  1842. _EvpGetDigestByName := GetProcAddr(SSLUtilHandle, 'EVP_get_digestbyname');
  1843. _SSLeayversion := GetProcAddr(SSLUtilHandle, 'SSLeay_version');
  1844. _ErrErrorString := GetProcAddr(SSLUtilHandle, 'ERR_error_string_n');
  1845. _ErrGetError := GetProcAddr(SSLUtilHandle, 'ERR_get_error');
  1846. _ErrClearError := GetProcAddr(SSLUtilHandle, 'ERR_clear_error');
  1847. _ErrFreeStrings := GetProcAddr(SSLUtilHandle, 'ERR_free_strings');
  1848. _ErrRemoveState := GetProcAddr(SSLUtilHandle, 'ERR_remove_state');
  1849. _OPENSSLaddallalgorithms := GetProcAddr(SSLUtilHandle, 'OPENSSL_add_all_algorithms_noconf');
  1850. _CRYPTOcleanupAllExData := GetProcAddr(SSLUtilHandle, 'CRYPTO_cleanup_all_ex_data');
  1851. _RandScreen := GetProcAddr(SSLUtilHandle, 'RAND_screen');
  1852. _BioNew := GetProcAddr(SSLUtilHandle, 'BIO_new');
  1853. _BioFreeAll := GetProcAddr(SSLUtilHandle, 'BIO_free_all');
  1854. _BioSMem := GetProcAddr(SSLUtilHandle, 'BIO_s_mem');
  1855. _BioCtrlPending := GetProcAddr(SSLUtilHandle, 'BIO_ctrl_pending');
  1856. _BioRead := GetProcAddr(SSLUtilHandle, 'BIO_read');
  1857. _BioWrite := GetProcAddr(SSLUtilHandle, 'BIO_write');
  1858. _d2iPKCS12bio := GetProcAddr(SSLUtilHandle, 'd2i_PKCS12_bio');
  1859. _PKCS12parse := GetProcAddr(SSLUtilHandle, 'PKCS12_parse');
  1860. _PKCS12free := GetProcAddr(SSLUtilHandle, 'PKCS12_free');
  1861. _RsaGenerateKey := GetProcAddr(SSLUtilHandle, 'RSA_generate_key');
  1862. _Asn1UtctimeNew := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_new');
  1863. _Asn1UtctimeFree := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_free');
  1864. _Asn1IntegerSet := GetProcAddr(SSLUtilHandle, 'ASN1_INTEGER_set');
  1865. _Asn1IntegerGet := GetProcAddr(SSLUtilHandle, 'ASN1_INTEGER_get'); {pf}
  1866. _i2dX509bio := GetProcAddr(SSLUtilHandle, 'i2d_X509_bio');
  1867. _d2iX509bio := GetProcAddr(SSLUtilHandle, 'd2i_X509_bio'); {pf}
  1868. _PEMReadBioX509 := GetProcAddr(SSLUtilHandle, 'PEM_read_bio_X509'); {pf}
  1869. _SkX509PopFree := GetProcAddr(SSLUtilHandle, 'SK_X509_POP_FREE'); {pf}
  1870. _i2dPrivateKeyBio := GetProcAddr(SSLUtilHandle, 'i2d_PrivateKey_bio');
  1871. // 3DES functions
  1872. _DESsetoddparity := GetProcAddr(SSLUtilHandle, 'DES_set_odd_parity');
  1873. _DESsetkeychecked := GetProcAddr(SSLUtilHandle, 'DES_set_key_checked');
  1874. _DESecbencrypt := GetProcAddr(SSLUtilHandle, 'DES_ecb_encrypt');
  1875. //
  1876. _CRYPTOnumlocks := GetProcAddr(SSLUtilHandle, 'CRYPTO_num_locks');
  1877. _CRYPTOsetlockingcallback := GetProcAddr(SSLUtilHandle, 'CRYPTO_set_locking_callback');
  1878. {$ENDIF}
  1879. {$IFDEF CIL}
  1880. SslLibraryInit;
  1881. SslLoadErrorStrings;
  1882. OPENSSLaddallalgorithms;
  1883. RandScreen;
  1884. {$ELSE}
  1885. SSLLibFile := GetLibFileName(SSLLibHandle);
  1886. SSLUtilFile := GetLibFileName(SSLUtilHandle);
  1887. //init library
  1888. if assigned(_SslLibraryInit) then
  1889. _SslLibraryInit;
  1890. if assigned(_SslLoadErrorStrings) then
  1891. _SslLoadErrorStrings;
  1892. if assigned(_OPENSSLaddallalgorithms) then
  1893. _OPENSSLaddallalgorithms;
  1894. if assigned(_RandScreen) then
  1895. _RandScreen;
  1896. if assigned(_CRYPTOnumlocks) and assigned(_CRYPTOsetlockingcallback) then
  1897. InitLocks;
  1898. {$ENDIF}
  1899. SSLloaded := True;
  1900. {$IFDEF OS2}
  1901. Result := InitEMXHandles;
  1902. {$ELSE OS2}
  1903. Result := True;
  1904. {$ENDIF OS2}
  1905. end
  1906. else
  1907. begin
  1908. //load failed!
  1909. if SSLLibHandle <> 0 then
  1910. begin
  1911. {$IFNDEF CIL}
  1912. FreeLibrary(SSLLibHandle);
  1913. {$ENDIF}
  1914. SSLLibHandle := 0;
  1915. end;
  1916. if SSLUtilHandle <> 0 then
  1917. begin
  1918. {$IFNDEF CIL}
  1919. FreeLibrary(SSLUtilHandle);
  1920. {$ENDIF}
  1921. SSLLibHandle := 0;
  1922. end;
  1923. Result := False;
  1924. end;
  1925. end
  1926. else
  1927. //loaded before...
  1928. Result := true;
  1929. finally
  1930. SSLCS.Leave;
  1931. end;
  1932. end;
  1933. function DestroySSLInterface: Boolean;
  1934. begin
  1935. SSLCS.Enter;
  1936. try
  1937. if IsSSLLoaded then
  1938. begin
  1939. //deinit library
  1940. {$IFNDEF CIL}
  1941. if assigned(_CRYPTOnumlocks) and assigned(_CRYPTOsetlockingcallback) then
  1942. FreeLocks;
  1943. {$ENDIF}
  1944. EVPCleanup;
  1945. CRYPTOcleanupAllExData;
  1946. ErrRemoveState(0);
  1947. end;
  1948. SSLloaded := false;
  1949. if SSLLibHandle <> 0 then
  1950. begin
  1951. {$IFNDEF CIL}
  1952. FreeLibrary(SSLLibHandle);
  1953. {$ENDIF}
  1954. SSLLibHandle := 0;
  1955. end;
  1956. if SSLUtilHandle <> 0 then
  1957. begin
  1958. {$IFNDEF CIL}
  1959. FreeLibrary(SSLUtilHandle);
  1960. {$ENDIF}
  1961. SSLLibHandle := 0;
  1962. end;
  1963. {$IFNDEF CIL}
  1964. _SslGetError := nil;
  1965. _SslLibraryInit := nil;
  1966. _SslLoadErrorStrings := nil;
  1967. _SslCtxSetCipherList := nil;
  1968. _SslCtxNew := nil;
  1969. _SslCtxFree := nil;
  1970. _SslSetFd := nil;
  1971. _SslMethodV2 := nil;
  1972. _SslMethodV3 := nil;
  1973. _SslMethodTLSV1 := nil;
  1974. _SslMethodTLSV11 := nil;
  1975. _SslMethodTLSV12 := nil;
  1976. _SslMethodV23 := nil;
  1977. _SslMethodTLS := nil;
  1978. _SslCtxUsePrivateKey := nil;
  1979. _SslCtxUsePrivateKeyASN1 := nil;
  1980. _SslCtxUsePrivateKeyFile := nil;
  1981. _SslCtxUseCertificate := nil;
  1982. _SslCtxUseCertificateASN1 := nil;
  1983. _SslCtxUseCertificateFile := nil;
  1984. _SslCtxUseCertificateChainFile := nil;
  1985. _SslCtxCheckPrivateKeyFile := nil;
  1986. _SslCtxSetDefaultPasswdCb := nil;
  1987. _SslCtxSetDefaultPasswdCbUserdata := nil;
  1988. _SslCtxLoadVerifyLocations := nil;
  1989. _SslCtxCtrl := nil;
  1990. _SslNew := nil;
  1991. _SslFree := nil;
  1992. _SslAccept := nil;
  1993. _SslConnect := nil;
  1994. _SslShutdown := nil;
  1995. _SslRead := nil;
  1996. _SslPeek := nil;
  1997. _SslWrite := nil;
  1998. _SslPending := nil;
  1999. _SslGetPeerCertificate := nil;
  2000. _SslGetVersion := nil;
  2001. _SslCtxSetVerify := nil;
  2002. _SslGetCurrentCipher := nil;
  2003. _SslCipherGetName := nil;
  2004. _SslCipherGetBits := nil;
  2005. _SslGetVerifyResult := nil;
  2006. _SslCtrl := nil;
  2007. _SslSet1Host := nil;
  2008. _SslSessionFree := nil;
  2009. _SslGet1Session := nil;
  2010. _SslSetSession := nil;
  2011. _X509New := nil;
  2012. _X509Free := nil;
  2013. _X509NameOneline := nil;
  2014. _X509GetSubjectName := nil;
  2015. _X509GetIssuerName := nil;
  2016. _X509NameHash := nil;
  2017. _X509Digest := nil;
  2018. _X509print := nil;
  2019. _X509SetVersion := nil;
  2020. _X509SetPubkey := nil;
  2021. _X509SetIssuerName := nil;
  2022. _X509NameAddEntryByTxt := nil;
  2023. _X509Sign := nil;
  2024. _X509GmtimeAdj := nil;
  2025. _X509SetNotBefore := nil;
  2026. _X509SetNotAfter := nil;
  2027. _X509GetSerialNumber := nil;
  2028. _EvpPkeyNew := nil;
  2029. _EvpPkeyFree := nil;
  2030. _EvpPkeyAssign := nil;
  2031. _EVPCleanup := nil;
  2032. _EvpGetDigestByName := nil;
  2033. _SSLeayversion := nil;
  2034. _ErrErrorString := nil;
  2035. _ErrGetError := nil;
  2036. _ErrClearError := nil;
  2037. _ErrFreeStrings := nil;
  2038. _ErrRemoveState := nil;
  2039. _OPENSSLaddallalgorithms := nil;
  2040. _CRYPTOcleanupAllExData := nil;
  2041. _RandScreen := nil;
  2042. _BioNew := nil;
  2043. _BioFreeAll := nil;
  2044. _BioSMem := nil;
  2045. _BioCtrlPending := nil;
  2046. _BioRead := nil;
  2047. _BioWrite := nil;
  2048. _d2iPKCS12bio := nil;
  2049. _PKCS12parse := nil;
  2050. _PKCS12free := nil;
  2051. _RsaGenerateKey := nil;
  2052. _Asn1UtctimeNew := nil;
  2053. _Asn1UtctimeFree := nil;
  2054. _Asn1IntegerSet := nil;
  2055. _Asn1IntegerGet := nil; {pf}
  2056. _SkX509PopFree := nil; {pf}
  2057. _i2dX509bio := nil;
  2058. _i2dPrivateKeyBio := nil;
  2059. // 3DES functions
  2060. _DESsetoddparity := nil;
  2061. _DESsetkeychecked := nil;
  2062. _DESecbencrypt := nil;
  2063. //
  2064. _CRYPTOnumlocks := nil;
  2065. _CRYPTOsetlockingcallback := nil;
  2066. {$ENDIF}
  2067. finally
  2068. SSLCS.Leave;
  2069. end;
  2070. Result := True;
  2071. end;
  2072. function IsSSLloaded: Boolean;
  2073. begin
  2074. Result := SSLLoaded;
  2075. end;
  2076. initialization
  2077. begin
  2078. SSLCS:= TCriticalSection.Create;
  2079. end;
  2080. finalization
  2081. begin
  2082. {$IFNDEF CIL}
  2083. DestroySSLInterface;
  2084. {$ENDIF}
  2085. SSLCS.Free;
  2086. end;
  2087. end.