ssl_openssl_lib.pas 95 KB

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