openssl.pas 49 KB

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