source: trunk/Packages/synapse/ssl_openssl_lib.pas

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