3
{==============================================================================|
4
| Project : Ararat Synapse | 003.004.001 |
5
|==============================================================================|
6
| Content: SSL support by OpenSSL |
7
|==============================================================================|
8
| Copyright (c)1999-2005, Lukas Gebauer |
9
| All rights reserved. |
11
| Redistribution and use in source and binary forms, with or without |
12
| modification, are permitted provided that the following conditions are met: |
14
| Redistributions of source code must retain the above copyright notice, this |
15
| list of conditions and the following disclaimer. |
17
| Redistributions in binary form must reproduce the above copyright notice, |
18
| this list of conditions and the following disclaimer in the documentation |
19
| and/or other materials provided with the distribution. |
21
| Neither the name of Lukas Gebauer nor the names of its contributors may |
22
| be used to endorse or promote products derived from this software without |
23
| specific prior written permission. |
25
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
26
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
27
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
28
| ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
29
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
30
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
31
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
32
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
33
| LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
34
| OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
36
|==============================================================================|
37
| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
38
| Portions created by Lukas Gebauer are Copyright (c)2002-2005. |
39
| All Rights Reserved. |
40
|==============================================================================|
42
|==============================================================================|
43
| FreePascal basic cleanup (original worked too): Ales Katona |
44
| WARNING: due to reliance on some units, I have removed the ThreadLocks init |
45
| if need be, it should be re-added, or handled by the |
46
| OS threading init somehow |
47
|==============================================================================|
48
| History: see HISTORY.HTM from distribution package |
49
| (Found at URL: http://www.ararat.cz/synapse/) |
50
|==============================================================================}
53
Special thanks to Gregor Ibic <gregor.ibic@intelicom.si>
54
(Intelicom d.o.o., http://www.intelicom.si)
55
for good inspiration about begin with SSL programming.
60
{:@abstract(OpenSSL support)
62
This unit is Pascal interface to OpenSSL library (used by @link(ssl_openssl) unit).
63
OpenSSL is loaded dynamicly on-demand. If this library is not found in system,
64
requested OpenSSL function just return errorcode.
74
DLLSSLName: string = 'ssleay32.dll';
75
DLLSSLName2: string = 'libssl32.dll';
76
DLLUtilName: string = 'libeay32.dll';
78
DLLSSLName: string = 'libssl.so';
79
DLLUtilName: string = 'libcrypto.so';
96
PASN1_UTCTIME = SslPtr;
97
PASN1_INTEGER = SslPtr;
99
PFunction = procedure;
101
DES_cblock = array[0..7] of Byte;
102
PDES_cblock = ^DES_cblock;
103
des_ks_struct = packed record
107
des_key_schedule = array[1..16] of des_ks_struct;
110
EVP_MAX_MD_SIZE = 16 + 20;
114
SSL_ERROR_WANT_READ = 2;
115
SSL_ERROR_WANT_WRITE = 3;
116
SSL_ERROR_WANT_X509_LOOKUP = 4;
117
SSL_ERROR_SYSCALL = 5; //look at error stack/return value/errno
118
SSL_ERROR_ZERO_RETURN = 6;
119
SSL_ERROR_WANT_CONNECT = 7;
120
SSL_ERROR_WANT_ACCEPT = 8;
122
SSL_OP_NO_SSLv2 = $01000000;
123
SSL_OP_NO_SSLv3 = $02000000;
124
SSL_OP_NO_TLSv1 = $04000000;
125
SSL_OP_ALL = $000FFFFF;
126
SSL_VERIFY_NONE = $00;
127
SSL_VERIFY_PEER = $01;
129
OPENSSL_DES_DECRYPT = 0;
130
OPENSSL_DES_ENCRYPT = 1;
134
X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT = 2;
135
X509_V_ERR_UNABLE_TO_GET_CRL = 3;
136
X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE = 4;
137
X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE = 5;
138
X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY = 6;
139
X509_V_ERR_CERT_SIGNATURE_FAILURE = 7;
140
X509_V_ERR_CRL_SIGNATURE_FAILURE = 8;
141
X509_V_ERR_CERT_NOT_YET_VALID = 9;
142
X509_V_ERR_CERT_HAS_EXPIRED = 10;
143
X509_V_ERR_CRL_NOT_YET_VALID = 11;
144
X509_V_ERR_CRL_HAS_EXPIRED = 12;
145
X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD = 13;
146
X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD = 14;
147
X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD = 15;
148
X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD = 16;
149
X509_V_ERR_OUT_OF_MEM = 17;
150
X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT = 18;
151
X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN = 19;
152
X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY = 20;
153
X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE = 21;
154
X509_V_ERR_CERT_CHAIN_TOO_LONG = 22;
155
X509_V_ERR_CERT_REVOKED = 23;
156
X509_V_ERR_INVALID_CA = 24;
157
X509_V_ERR_PATH_LENGTH_EXCEEDED = 25;
158
X509_V_ERR_INVALID_PURPOSE = 26;
159
X509_V_ERR_CERT_UNTRUSTED = 27;
160
X509_V_ERR_CERT_REJECTED = 28;
161
//These are 'informational' when looking for issuer cert
162
X509_V_ERR_SUBJECT_ISSUER_MISMATCH = 29;
163
X509_V_ERR_AKID_SKID_MISMATCH = 30;
164
X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH = 31;
165
X509_V_ERR_KEYUSAGE_NO_CERTSIGN = 32;
166
X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER = 33;
167
X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION = 34;
168
//The application is not happy
169
X509_V_ERR_APPLICATION_VERIFICATION = 50;
171
SSL_FILETYPE_ASN1 = 2;
172
SSL_FILETYPE_PEM = 1;
176
SSLLibHandle: TLibHandle = 0;
177
SSLUtilHandle: TLibHandle = 0;
178
SSLLibFile: string = '';
179
SSLUtilFile: string = '';
182
function SslGetError(s: PSSL; ret_code: Integer):Integer;
183
function SslLibraryInit:Integer;
184
procedure SslLoadErrorStrings;
185
// function SslCtxSetCipherList(arg0: PSSL_CTX; str: PChar):Integer;
186
function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String):Integer;
187
function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
188
procedure SslCtxFree(arg0: PSSL_CTX);
189
function SslSetFd(s: PSSL; fd: Integer):Integer;
190
function SslMethodV2:PSSL_METHOD;
191
function SslMethodV3:PSSL_METHOD;
192
function SslMethodTLSV1:PSSL_METHOD;
193
function SslMethodV23:PSSL_METHOD;
194
function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):Integer;
195
function SslCtxUsePrivateKeyASN1(pk: integer; ctx: PSSL_CTX; d: String; len: integer):Integer;
196
// function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer;
197
function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
198
function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):Integer;
199
function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: integer; d: String):Integer;
200
function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
201
// function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: PChar):Integer;
202
function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):Integer;
203
function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer;
204
procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
205
procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
206
// function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):Integer;
207
function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: String; const CApath: String):Integer;
208
function SslNew(ctx: PSSL_CTX):PSSL;
209
procedure SslFree(ssl: PSSL);
210
function SslAccept(ssl: PSSL):Integer;
211
function SslConnect(ssl: PSSL):Integer;
212
function SslShutdown(ssl: PSSL):Integer;
213
function SslRead(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
214
function SslPeek(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
215
function SslWrite(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
216
function SslPending(ssl: PSSL):Integer;
217
function SslGetVersion(ssl: PSSL):String;
218
function SslGetPeerCertificate(ssl: PSSL):PX509;
219
procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction);
220
function SSLGetCurrentCipher(s: PSSL):SslPtr;
221
function SSLCipherGetName(c: SslPtr): String;
222
function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer;
223
function SSLGetVerifyResult(ssl: PSSL):Integer;
226
function X509New: PX509;
227
procedure X509Free(x: PX509);
228
function X509NameOneline(a: PX509_NAME; var buf: String; size: Integer):String;
229
function X509GetSubjectName(a: PX509):PX509_NAME;
230
function X509GetIssuerName(a: PX509):PX509_NAME;
231
function X509NameHash(x: PX509_NAME):Cardinal;
232
// function SslX509Digest(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer;
233
function X509Digest(data: PX509; _type: PEVP_MD; md: String; var len: Integer):Integer;
234
function X509print(b: PBIO; a: PX509): integer;
235
function X509SetVersion(x: PX509; version: integer): integer;
236
function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer;
237
function X509SetIssuerName(x: PX509; name: PX509_NAME): integer;
238
function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: integer;
239
bytes: string; len, loc, _set: integer): integer;
240
function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer;
241
function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME;
242
function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer;
243
function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer;
244
function X509GetSerialNumber(x: PX509): PASN1_INTEGER;
245
function EvpPkeyNew: EVP_PKEY;
246
procedure EvpPkeyFree(pk: EVP_PKEY);
247
function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer;
248
function EvpGetDigestByName(Name: String): PEVP_MD;
249
procedure EVPcleanup;
250
// function ErrErrorString(e: integer; buf: PChar): PChar;
251
function SSLeayversion(t: integer): string;
252
procedure ErrErrorString(e: integer; var buf: string; len: integer);
253
function ErrGetError: integer;
254
procedure ErrClearError;
255
procedure ErrFreeStrings;
256
procedure ErrRemoveState(pid: integer);
257
procedure OPENSSLaddallalgorithms;
258
procedure CRYPTOcleanupAllExData;
259
procedure RandScreen;
260
function BioNew(b: PBIO_METHOD): PBIO;
261
procedure BioFreeAll(b: PBIO);
262
function BioSMem: PBIO_METHOD;
263
function BioCtrlPending(b: PBIO): integer;
264
function BioRead(b: PBIO; var Buf: String; Len: integer): integer;
265
function BioWrite(b: PBIO; Buf: String; Len: integer): integer;
266
function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
267
function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): integer;
268
procedure PKCS12free(p12: SslPtr);
269
function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA;
270
function Asn1UtctimeNew: PASN1_UTCTIME;
271
procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
272
function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
273
function i2dX509bio(b: PBIO; x: PX509): integer;
274
function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer;
277
procedure DESsetoddparity(Key: des_cblock);
278
function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer;
279
procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer);
281
function IsSSLloaded: Boolean;
282
function InitSSLInterface: Boolean;
283
function DestroySSLInterface: Boolean;
289
TSslGetError = function(s: PSSL; ret_code: Integer):Integer; cdecl;
290
TSslLibraryInit = function:Integer; cdecl;
291
TSslLoadErrorStrings = procedure; cdecl;
292
TSslCtxSetCipherList = function(arg0: PSSL_CTX; str: PChar):Integer; cdecl;
293
TSslCtxNew = function(meth: PSSL_METHOD):PSSL_CTX; cdecl;
294
TSslCtxFree = procedure(arg0: PSSL_CTX); cdecl;
295
TSslSetFd = function(s: PSSL; fd: Integer):Integer; cdecl;
296
TSslMethodV2 = function:PSSL_METHOD; cdecl;
297
TSslMethodV3 = function:PSSL_METHOD; cdecl;
298
TSslMethodTLSV1 = function:PSSL_METHOD; cdecl;
299
TSslMethodV23 = function:PSSL_METHOD; cdecl;
300
TSslCtxUsePrivateKey = function(ctx: PSSL_CTX; pkey: sslptr):Integer; cdecl;
301
TSslCtxUsePrivateKeyASN1 = function(pk: integer; ctx: PSSL_CTX; d: sslptr; len: integer):Integer; cdecl;
302
TSslCtxUsePrivateKeyFile = function(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer; cdecl;
303
TSslCtxUseCertificate = function(ctx: PSSL_CTX; x: SslPtr):Integer; cdecl;
304
TSslCtxUseCertificateASN1 = function(ctx: PSSL_CTX; len: Integer; d: SslPtr):Integer; cdecl;
305
TSslCtxUseCertificateFile = function(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer; cdecl;
306
TSslCtxUseCertificateChainFile = function(ctx: PSSL_CTX; const _file: PChar):Integer; cdecl;
307
TSslCtxCheckPrivateKeyFile = function(ctx: PSSL_CTX):Integer; cdecl;
308
TSslCtxSetDefaultPasswdCb = procedure(ctx: PSSL_CTX; cb: SslPtr); cdecl;
309
TSslCtxSetDefaultPasswdCbUserdata = procedure(ctx: PSSL_CTX; u: SslPtr); cdecl;
310
TSslCtxLoadVerifyLocations = function(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):Integer; cdecl;
311
TSslNew = function(ctx: PSSL_CTX):PSSL; cdecl;
312
TSslFree = procedure(ssl: PSSL); cdecl;
313
TSslAccept = function(ssl: PSSL):Integer; cdecl;
314
TSslConnect = function(ssl: PSSL):Integer; cdecl;
315
TSslShutdown = function(ssl: PSSL):Integer; cdecl;
316
TSslRead = function(ssl: PSSL; buf: PChar; num: Integer):Integer; cdecl;
317
TSslPeek = function(ssl: PSSL; buf: PChar; num: Integer):Integer; cdecl;
318
TSslWrite = function(ssl: PSSL; const buf: PChar; num: Integer):Integer; cdecl;
319
TSslPending = function(ssl: PSSL):Integer; cdecl;
320
TSslGetVersion = function(ssl: PSSL):PChar; cdecl;
321
TSslGetPeerCertificate = function(ssl: PSSL):PX509; cdecl;
322
TSslCtxSetVerify = procedure(ctx: PSSL_CTX; mode: Integer; arg2: SslPtr); cdecl;
323
TSSLGetCurrentCipher = function(s: PSSL):SslPtr; cdecl;
324
TSSLCipherGetName = function(c: Sslptr):PChar; cdecl;
325
TSSLCipherGetBits = function(c: SslPtr; alg_bits: PInteger):Integer; cdecl;
326
TSSLGetVerifyResult = function(ssl: PSSL):Integer; cdecl;
329
TX509New = function: PX509; cdecl;
330
TX509Free = procedure(x: PX509); cdecl;
331
TX509NameOneline = function(a: PX509_NAME; buf: PChar; size: Integer):PChar; cdecl;
332
TX509GetSubjectName = function(a: PX509):PX509_NAME; cdecl;
333
TX509GetIssuerName = function(a: PX509):PX509_NAME; cdecl;
334
TX509NameHash = function(x: PX509_NAME):Cardinal; cdecl;
335
TX509Digest = function(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer; cdecl;
336
TX509print = function(b: PBIO; a: PX509): integer; cdecl;
337
TX509SetVersion = function(x: PX509; version: integer): integer; cdecl;
338
TX509SetPubkey = function(x: PX509; pkey: EVP_PKEY): integer; cdecl;
339
TX509SetIssuerName = function(x: PX509; name: PX509_NAME): integer; cdecl;
340
TX509NameAddEntryByTxt = function(name: PX509_NAME; field: PChar; _type: integer;
341
bytes: PChar; len, loc, _set: integer): integer; cdecl;
342
TX509Sign = function(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer; cdecl;
343
TX509GmtimeAdj = function(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME; cdecl;
344
TX509SetNotBefore = function(x: PX509; tm: PASN1_UTCTIME): integer; cdecl;
345
TX509SetNotAfter = function(x: PX509; tm: PASN1_UTCTIME): integer; cdecl;
346
TX509GetSerialNumber = function(x: PX509): PASN1_INTEGER; cdecl;
347
TEvpPkeyNew = function: EVP_PKEY; cdecl;
348
TEvpPkeyFree = procedure(pk: EVP_PKEY); cdecl;
349
TEvpPkeyAssign = function(pkey: EVP_PKEY; _type: integer; key: Prsa): integer; cdecl;
350
TEvpGetDigestByName = function(Name: PChar): PEVP_MD; cdecl;
351
TEVPcleanup = procedure; cdecl;
352
TSSLeayversion = function(t: integer): PChar; cdecl;
353
TErrErrorString = procedure(e: integer; buf: PChar; len: integer); cdecl;
354
TErrGetError = function: integer; cdecl;
355
TErrClearError = procedure; cdecl;
356
TErrFreeStrings = procedure; cdecl;
357
TErrRemoveState = procedure(pid: integer); cdecl;
358
TOPENSSLaddallalgorithms = procedure; cdecl;
359
TCRYPTOcleanupAllExData = procedure; cdecl;
360
TRandScreen = procedure; cdecl;
361
TBioNew = function(b: PBIO_METHOD): PBIO; cdecl;
362
TBioFreeAll = procedure(b: PBIO); cdecl;
363
TBioSMem = function: PBIO_METHOD; cdecl;
364
TBioCtrlPending = function(b: PBIO): integer; cdecl;
365
TBioRead = function(b: PBIO; Buf: PChar; Len: integer): integer; cdecl;
366
TBioWrite = function(b: PBIO; Buf: PChar; Len: integer): integer; cdecl;
367
Td2iPKCS12bio = function(b:PBIO; Pkcs12: SslPtr): SslPtr; cdecl;
368
TPKCS12parse = function(p12: SslPtr; pass: PChar; var pkey, cert, ca: SslPtr): integer; cdecl;
369
TPKCS12free = procedure(p12: SslPtr); cdecl;
370
TRsaGenerateKey = function(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA; cdecl;
371
TAsn1UtctimeNew = function: PASN1_UTCTIME; cdecl;
372
TAsn1UtctimeFree = procedure(a: PASN1_UTCTIME); cdecl;
373
TAsn1IntegerSet = function(a: PASN1_INTEGER; v: integer): integer; cdecl;
374
Ti2dX509bio = function(b: PBIO; x: PX509): integer; cdecl;
375
Ti2dPrivateKeyBio= function(b: PBIO; pkey: EVP_PKEY): integer; cdecl;
378
TDESsetoddparity = procedure(Key: des_cblock); cdecl;
379
TDESsetkeychecked = function(key: des_cblock; schedule: des_key_schedule): Integer; cdecl;
380
TDESecbencrypt = procedure(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer); cdecl;
381
//thread lock functions
382
TCRYPTOnumlocks = function: integer; cdecl;
383
TCRYPTOSetLockingCallback = procedure(cb: Sslptr); cdecl;
387
_SslGetError: TSslGetError = nil;
388
_SslLibraryInit: TSslLibraryInit = nil;
389
_SslLoadErrorStrings: TSslLoadErrorStrings = nil;
390
_SslCtxSetCipherList: TSslCtxSetCipherList = nil;
391
_SslCtxNew: TSslCtxNew = nil;
392
_SslCtxFree: TSslCtxFree = nil;
393
_SslSetFd: TSslSetFd = nil;
394
_SslMethodV2: TSslMethodV2 = nil;
395
_SslMethodV3: TSslMethodV3 = nil;
396
_SslMethodTLSV1: TSslMethodTLSV1 = nil;
397
_SslMethodV23: TSslMethodV23 = nil;
398
_SslCtxUsePrivateKey: TSslCtxUsePrivateKey = nil;
399
_SslCtxUsePrivateKeyASN1: TSslCtxUsePrivateKeyASN1 = nil;
400
_SslCtxUsePrivateKeyFile: TSslCtxUsePrivateKeyFile = nil;
401
_SslCtxUseCertificate: TSslCtxUseCertificate = nil;
402
_SslCtxUseCertificateASN1: TSslCtxUseCertificateASN1 = nil;
403
_SslCtxUseCertificateFile: TSslCtxUseCertificateFile = nil;
404
_SslCtxUseCertificateChainFile: TSslCtxUseCertificateChainFile = nil;
405
_SslCtxCheckPrivateKeyFile: TSslCtxCheckPrivateKeyFile = nil;
406
_SslCtxSetDefaultPasswdCb: TSslCtxSetDefaultPasswdCb = nil;
407
_SslCtxSetDefaultPasswdCbUserdata: TSslCtxSetDefaultPasswdCbUserdata = nil;
408
_SslCtxLoadVerifyLocations: TSslCtxLoadVerifyLocations = nil;
409
_SslNew: TSslNew = nil;
410
_SslFree: TSslFree = nil;
411
_SslAccept: TSslAccept = nil;
412
_SslConnect: TSslConnect = nil;
413
_SslShutdown: TSslShutdown = nil;
414
_SslRead: TSslRead = nil;
415
_SslPeek: TSslPeek = nil;
416
_SslWrite: TSslWrite = nil;
417
_SslPending: TSslPending = nil;
418
_SslGetVersion: TSslGetVersion = nil;
419
_SslGetPeerCertificate: TSslGetPeerCertificate = nil;
420
_SslCtxSetVerify: TSslCtxSetVerify = nil;
421
_SSLGetCurrentCipher: TSSLGetCurrentCipher = nil;
422
_SSLCipherGetName: TSSLCipherGetName = nil;
423
_SSLCipherGetBits: TSSLCipherGetBits = nil;
424
_SSLGetVerifyResult: TSSLGetVerifyResult = nil;
427
_X509New: TX509New = nil;
428
_X509Free: TX509Free = nil;
429
_X509NameOneline: TX509NameOneline = nil;
430
_X509GetSubjectName: TX509GetSubjectName = nil;
431
_X509GetIssuerName: TX509GetIssuerName = nil;
432
_X509NameHash: TX509NameHash = nil;
433
_X509Digest: TX509Digest = nil;
434
_X509print: TX509print = nil;
435
_X509SetVersion: TX509SetVersion = nil;
436
_X509SetPubkey: TX509SetPubkey = nil;
437
_X509SetIssuerName: TX509SetIssuerName = nil;
438
_X509NameAddEntryByTxt: TX509NameAddEntryByTxt = nil;
439
_X509Sign: TX509Sign = nil;
440
_X509GmtimeAdj: TX509GmtimeAdj = nil;
441
_X509SetNotBefore: TX509SetNotBefore = nil;
442
_X509SetNotAfter: TX509SetNotAfter = nil;
443
_X509GetSerialNumber: TX509GetSerialNumber = nil;
444
_EvpPkeyNew: TEvpPkeyNew = nil;
445
_EvpPkeyFree: TEvpPkeyFree = nil;
446
_EvpPkeyAssign: TEvpPkeyAssign = nil;
447
_EvpGetDigestByName: TEvpGetDigestByName = nil;
448
_EVPcleanup: TEVPcleanup = nil;
449
_SSLeayversion: TSSLeayversion = nil;
450
_ErrErrorString: TErrErrorString = nil;
451
_ErrGetError: TErrGetError = nil;
452
_ErrClearError: TErrClearError = nil;
453
_ErrFreeStrings: TErrFreeStrings = nil;
454
_ErrRemoveState: TErrRemoveState = nil;
455
_OPENSSLaddallalgorithms: TOPENSSLaddallalgorithms = nil;
456
_CRYPTOcleanupAllExData: TCRYPTOcleanupAllExData = nil;
457
_RandScreen: TRandScreen = nil;
458
_BioNew: TBioNew = nil;
459
_BioFreeAll: TBioFreeAll = nil;
460
_BioSMem: TBioSMem = nil;
461
_BioCtrlPending: TBioCtrlPending = nil;
462
_BioRead: TBioRead = nil;
463
_BioWrite: TBioWrite = nil;
464
_d2iPKCS12bio: Td2iPKCS12bio = nil;
465
_PKCS12parse: TPKCS12parse = nil;
466
_PKCS12free: TPKCS12free = nil;
467
_RsaGenerateKey: TRsaGenerateKey = nil;
468
_Asn1UtctimeNew: TAsn1UtctimeNew = nil;
469
_Asn1UtctimeFree: TAsn1UtctimeFree = nil;
470
_Asn1IntegerSet: TAsn1IntegerSet = nil;
471
_i2dX509bio: Ti2dX509bio = nil;
472
_i2dPrivateKeyBio: Ti2dPrivateKeyBio = nil;
475
_DESsetoddparity: TDESsetoddparity = nil;
476
_DESsetkeychecked: TDESsetkeychecked = nil;
477
_DESecbencrypt: TDESecbencrypt = nil;
478
//thread lock functions
479
_CRYPTOnumlocks: TCRYPTOnumlocks = nil;
480
_CRYPTOSetLockingCallback: TCRYPTOSetLockingCallback = nil;
483
SSLloaded: boolean = false;
486
function SslGetError(s: PSSL; ret_code: Integer):Integer;
488
if InitSSLInterface and Assigned(_SslGetError) then
489
Result := _SslGetError(s, ret_code)
491
Result := SSL_ERROR_SSL;
494
function SslLibraryInit:Integer;
496
if InitSSLInterface and Assigned(_SslLibraryInit) then
497
Result := _SslLibraryInit
502
procedure SslLoadErrorStrings;
504
if InitSSLInterface and Assigned(_SslLoadErrorStrings) then
505
_SslLoadErrorStrings;
508
function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String):Integer;
510
if InitSSLInterface and Assigned(_SslCtxSetCipherList) then
511
Result := _SslCtxSetCipherList(arg0, PChar(str))
516
function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
518
if InitSSLInterface and Assigned(_SslCtxNew) then
519
Result := _SslCtxNew(meth)
524
procedure SslCtxFree(arg0: PSSL_CTX);
526
if InitSSLInterface and Assigned(_SslCtxFree) then
530
function SslSetFd(s: PSSL; fd: Integer):Integer;
532
if InitSSLInterface and Assigned(_SslSetFd) then
533
Result := _SslSetFd(s, fd)
538
function SslMethodV2:PSSL_METHOD;
540
if InitSSLInterface and Assigned(_SslMethodV2) then
541
Result := _SslMethodV2
546
function SslMethodV3:PSSL_METHOD;
548
if InitSSLInterface and Assigned(_SslMethodV3) then
549
Result := _SslMethodV3
554
function SslMethodTLSV1:PSSL_METHOD;
556
if InitSSLInterface and Assigned(_SslMethodTLSV1) then
557
Result := _SslMethodTLSV1
562
function SslMethodV23:PSSL_METHOD;
564
if InitSSLInterface and Assigned(_SslMethodV23) then
565
Result := _SslMethodV23
570
function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):Integer;
572
if InitSSLInterface and Assigned(_SslCtxUsePrivateKey) then
573
Result := _SslCtxUsePrivateKey(ctx, pkey)
578
function SslCtxUsePrivateKeyASN1(pk: integer; ctx: PSSL_CTX; d: String; len: integer):Integer;
580
if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyASN1) then
581
Result := _SslCtxUsePrivateKeyASN1(pk, ctx, Sslptr(d), len)
586
function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
588
if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyFile) then
589
Result := _SslCtxUsePrivateKeyFile(ctx, PChar(_file), _type)
594
function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):Integer;
596
if InitSSLInterface and Assigned(_SslCtxUseCertificate) then
597
Result := _SslCtxUseCertificate(ctx, x)
602
function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: integer; d: String):Integer;
604
if InitSSLInterface and Assigned(_SslCtxUseCertificateASN1) then
605
Result := _SslCtxUseCertificateASN1(ctx, len, SslPtr(d))
610
function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
612
if InitSSLInterface and Assigned(_SslCtxUseCertificateFile) then
613
Result := _SslCtxUseCertificateFile(ctx, PChar(_file), _type)
618
function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):Integer;
620
if InitSSLInterface and Assigned(_SslCtxUseCertificateChainFile) then
621
Result := _SslCtxUseCertificateChainFile(ctx, PChar(_file))
626
function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer;
628
if InitSSLInterface and Assigned(_SslCtxCheckPrivateKeyFile) then
629
Result := _SslCtxCheckPrivateKeyFile(ctx)
634
procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
636
if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCb) then
637
_SslCtxSetDefaultPasswdCb(ctx, cb);
640
procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
642
if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCbUserdata) then
643
_SslCtxSetDefaultPasswdCbUserdata(ctx, u);
646
function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: String; const CApath: String):Integer;
648
if InitSSLInterface and Assigned(_SslCtxLoadVerifyLocations) then
649
Result := _SslCtxLoadVerifyLocations(ctx, SslPtr(CAfile), SslPtr(CApath))
654
function SslNew(ctx: PSSL_CTX):PSSL;
656
if InitSSLInterface and Assigned(_SslNew) then
657
Result := _SslNew(ctx)
662
procedure SslFree(ssl: PSSL);
664
if InitSSLInterface and Assigned(_SslFree) then
668
function SslAccept(ssl: PSSL):Integer;
670
if InitSSLInterface and Assigned(_SslAccept) then
671
Result := _SslAccept(ssl)
676
function SslConnect(ssl: PSSL):Integer;
678
if InitSSLInterface and Assigned(_SslConnect) then
679
Result := _SslConnect(ssl)
684
function SslShutdown(ssl: PSSL):Integer;
686
if InitSSLInterface and Assigned(_SslShutdown) then
687
Result := _SslShutdown(ssl)
692
function SslRead(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
694
if InitSSLInterface and Assigned(_SslRead) then
695
Result := _SslRead(ssl, PChar(buf), num)
700
function SslPeek(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
702
if InitSSLInterface and Assigned(_SslPeek) then
703
Result := _SslPeek(ssl, PChar(buf), num)
708
function SslWrite(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
710
if InitSSLInterface and Assigned(_SslWrite) then
711
Result := _SslWrite(ssl, PChar(buf), num)
716
function SslPending(ssl: PSSL):Integer;
718
if InitSSLInterface and Assigned(_SslPending) then
719
Result := _SslPending(ssl)
724
//function SslGetVersion(ssl: PSSL):PChar;
725
function SslGetVersion(ssl: PSSL):String;
727
if InitSSLInterface and Assigned(_SslGetVersion) then
728
Result := _SslGetVersion(ssl)
733
function SslGetPeerCertificate(ssl: PSSL):PX509;
735
if InitSSLInterface and Assigned(_SslGetPeerCertificate) then
736
Result := _SslGetPeerCertificate(ssl)
741
procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction);
743
if InitSSLInterface and Assigned(_SslCtxSetVerify) then
744
_SslCtxSetVerify(ctx, mode, @arg2);
747
function SSLGetCurrentCipher(s: PSSL):SslPtr;
749
if InitSSLInterface and Assigned(_SSLGetCurrentCipher) then
752
Result := _SSLGetCurrentCipher(s)
758
function SSLCipherGetName(c: SslPtr):String;
760
if InitSSLInterface and Assigned(_SSLCipherGetName) then
761
Result := _SSLCipherGetName(c)
766
function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer;
768
if InitSSLInterface and Assigned(_SSLCipherGetBits) then
769
Result := _SSLCipherGetBits(c, @alg_bits)
774
function SSLGetVerifyResult(ssl: PSSL):Integer;
776
if InitSSLInterface and Assigned(_SSLGetVerifyResult) then
777
Result := _SSLGetVerifyResult(ssl)
779
Result := X509_V_ERR_APPLICATION_VERIFICATION;
783
function X509New: PX509;
785
if InitSSLInterface and Assigned(_X509New) then
791
procedure X509Free(x: PX509);
793
if InitSSLInterface and Assigned(_X509Free) then
797
function X509NameOneline(a: PX509_NAME; var buf: String; size: Integer):String;
799
if InitSSLInterface and Assigned(_X509NameOneline) then
800
Result := _X509NameOneline(a, PChar(buf),size)
805
function X509GetSubjectName(a: PX509):PX509_NAME;
807
if InitSSLInterface and Assigned(_X509GetSubjectName) then
808
Result := _X509GetSubjectName(a)
813
function X509GetIssuerName(a: PX509):PX509_NAME;
815
if InitSSLInterface and Assigned(_X509GetIssuerName) then
816
Result := _X509GetIssuerName(a)
821
function X509NameHash(x: PX509_NAME):Cardinal;
823
if InitSSLInterface and Assigned(_X509NameHash) then
824
Result := _X509NameHash(x)
829
function X509Digest(data: PX509; _type: PEVP_MD; md: String; var len: Integer):Integer;
831
if InitSSLInterface and Assigned(_X509Digest) then
832
Result := _X509Digest(data, _type, PChar(md), @len)
837
function EvpPkeyNew: EVP_PKEY;
839
if InitSSLInterface and Assigned(_EvpPkeyNew) then
840
Result := _EvpPkeyNew
845
procedure EvpPkeyFree(pk: EVP_PKEY);
847
if InitSSLInterface and Assigned(_EvpPkeyFree) then
851
function SSLeayversion(t: integer): string;
853
if InitSSLInterface and Assigned(_SSLeayversion) then
854
Result := PChar(_SSLeayversion(t))
859
procedure ErrErrorString(e: integer; var buf: string; len: integer);
861
if InitSSLInterface and Assigned(_ErrErrorString) then
862
_ErrErrorString(e, Pointer(buf), len);
866
function ErrGetError: integer;
868
if InitSSLInterface and Assigned(_ErrGetError) then
869
Result := _ErrGetError
871
Result := SSL_ERROR_SSL;
874
procedure ErrClearError;
876
if InitSSLInterface and Assigned(_ErrClearError) then
880
procedure ErrFreeStrings;
882
if InitSSLInterface and Assigned(_ErrFreeStrings) then
886
procedure ErrRemoveState(pid: integer);
888
if InitSSLInterface and Assigned(_ErrRemoveState) then
889
_ErrRemoveState(pid);
892
procedure OPENSSLaddallalgorithms;
894
if InitSSLInterface and Assigned(_OPENSSLaddallalgorithms) then
895
_OPENSSLaddallalgorithms;
898
procedure EVPcleanup;
900
if InitSSLInterface and Assigned(_EVPcleanup) then
904
procedure CRYPTOcleanupAllExData;
906
if InitSSLInterface and Assigned(_CRYPTOcleanupAllExData) then
907
_CRYPTOcleanupAllExData;
910
procedure RandScreen;
912
if InitSSLInterface and Assigned(_RandScreen) then
916
function BioNew(b: PBIO_METHOD): PBIO;
918
if InitSSLInterface and Assigned(_BioNew) then
924
procedure BioFreeAll(b: PBIO);
926
if InitSSLInterface and Assigned(_BioFreeAll) then
930
function BioSMem: PBIO_METHOD;
932
if InitSSLInterface and Assigned(_BioSMem) then
938
function BioCtrlPending(b: PBIO): integer;
940
if InitSSLInterface and Assigned(_BioCtrlPending) then
941
Result := _BioCtrlPending(b)
946
function BioRead(b: PBIO; var Buf: String; Len: integer): integer;
948
if InitSSLInterface and Assigned(_BioRead) then
949
Result := _BioRead(b, PChar(Buf), Len)
954
//function BioWrite(b: PBIO; Buf: PChar; Len: integer): integer;
955
function BioWrite(b: PBIO; Buf: String; Len: integer): integer;
957
if InitSSLInterface and Assigned(_BioWrite) then
958
Result := _BioWrite(b, PChar(Buf), Len)
963
function X509print(b: PBIO; a: PX509): integer;
965
if InitSSLInterface and Assigned(_X509print) then
966
Result := _X509print(b, a)
971
function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
973
if InitSSLInterface and Assigned(_d2iPKCS12bio) then
974
Result := _d2iPKCS12bio(b, Pkcs12)
979
function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): integer;
981
if InitSSLInterface and Assigned(_PKCS12parse) then
982
Result := _PKCS12parse(p12, SslPtr(pass), pkey, cert, ca)
987
procedure PKCS12free(p12: SslPtr);
989
if InitSSLInterface and Assigned(_PKCS12free) then
993
function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA;
995
if InitSSLInterface and Assigned(_RsaGenerateKey) then
996
Result := _RsaGenerateKey(bits, e, callback, cb_arg)
1001
function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer;
1003
if InitSSLInterface and Assigned(_EvpPkeyAssign) then
1004
Result := _EvpPkeyAssign(pkey, _type, key)
1009
function X509SetVersion(x: PX509; version: integer): integer;
1011
if InitSSLInterface and Assigned(_X509SetVersion) then
1012
Result := _X509SetVersion(x, version)
1017
function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer;
1019
if InitSSLInterface and Assigned(_X509SetPubkey) then
1020
Result := _X509SetPubkey(x, pkey)
1025
function X509SetIssuerName(x: PX509; name: PX509_NAME): integer;
1027
if InitSSLInterface and Assigned(_X509SetIssuerName) then
1028
Result := _X509SetIssuerName(x, name)
1033
function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: integer;
1034
bytes: string; len, loc, _set: integer): integer;
1036
if InitSSLInterface and Assigned(_X509NameAddEntryByTxt) then
1037
Result := _X509NameAddEntryByTxt(name, PChar(field), _type, PChar(Bytes), len, loc, _set)
1042
function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer;
1044
if InitSSLInterface and Assigned(_X509Sign) then
1045
Result := _X509Sign(x, pkey, md)
1050
function Asn1UtctimeNew: PASN1_UTCTIME;
1052
if InitSSLInterface and Assigned(_Asn1UtctimeNew) then
1053
Result := _Asn1UtctimeNew
1058
procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
1060
if InitSSLInterface and Assigned(_Asn1UtctimeFree) then
1061
_Asn1UtctimeFree(a);
1064
function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME;
1066
if InitSSLInterface and Assigned(_X509GmtimeAdj) then
1067
Result := _X509GmtimeAdj(s, adj)
1072
function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer;
1074
if InitSSLInterface and Assigned(_X509SetNotBefore) then
1075
Result := _X509SetNotBefore(x, tm)
1080
function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer;
1082
if InitSSLInterface and Assigned(_X509SetNotAfter) then
1083
Result := _X509SetNotAfter(x, tm)
1088
function i2dX509bio(b: PBIO; x: PX509): integer;
1090
if InitSSLInterface and Assigned(_i2dX509bio) then
1091
Result := _i2dX509bio(b, x)
1096
function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer;
1098
if InitSSLInterface and Assigned(_i2dPrivateKeyBio) then
1099
Result := _i2dPrivateKeyBio(b, pkey)
1104
function EvpGetDigestByName(Name: String): PEVP_MD;
1106
if InitSSLInterface and Assigned(_EvpGetDigestByName) then
1107
Result := _EvpGetDigestByName(PChar(Name))
1112
function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
1114
if InitSSLInterface and Assigned(_Asn1IntegerSet) then
1115
Result := _Asn1IntegerSet(a, v)
1120
function X509GetSerialNumber(x: PX509): PASN1_INTEGER;
1122
if InitSSLInterface and Assigned(_X509GetSerialNumber) then
1123
Result := _X509GetSerialNumber(x)
1129
procedure DESsetoddparity(Key: des_cblock);
1131
if InitSSLInterface and Assigned(_DESsetoddparity) then
1132
_DESsetoddparity(Key);
1135
function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer;
1137
if InitSSLInterface and Assigned(_DESsetkeychecked) then
1138
Result := _DESsetkeychecked(key, schedule)
1143
procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer);
1145
if InitSSLInterface and Assigned(_DESecbencrypt) then
1146
_DESecbencrypt(Input, output, ks, enc);
1149
function LoadLib(const Value: String): HModule;
1151
Result := LoadLibrary(Value);
1154
function GetProcAddr(module: HModule; const ProcName: string): SslPtr;
1156
Result := GetProcAddress(module, PChar(ProcName));
1159
function InitSSLInterface: Boolean;
1161
if not IsSSLloaded then
1163
SSLLibHandle := LoadLib(DLLSSLName);
1164
SSLUtilHandle := LoadLib(DLLUtilName);
1166
if (SSLLibHandle = 0) then
1167
SSLLibHandle := LoadLib(DLLSSLName2);
1169
if (SSLLibHandle <> 0) and (SSLUtilHandle <> 0) then
1171
_SslGetError := GetProcAddr(SSLLibHandle, 'SSL_get_error');
1172
_SslLibraryInit := GetProcAddr(SSLLibHandle, 'SSL_library_init');
1173
_SslLoadErrorStrings := GetProcAddr(SSLLibHandle, 'SSL_load_error_strings');
1174
_SslCtxSetCipherList := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_cipher_list');
1175
_SslCtxNew := GetProcAddr(SSLLibHandle, 'SSL_CTX_new');
1176
_SslCtxFree := GetProcAddr(SSLLibHandle, 'SSL_CTX_free');
1177
_SslSetFd := GetProcAddr(SSLLibHandle, 'SSL_set_fd');
1178
_SslMethodV2 := GetProcAddr(SSLLibHandle, 'SSLv2_method');
1179
_SslMethodV3 := GetProcAddr(SSLLibHandle, 'SSLv3_method');
1180
_SslMethodTLSV1 := GetProcAddr(SSLLibHandle, 'TLSv1_method');
1181
_SslMethodV23 := GetProcAddr(SSLLibHandle, 'SSLv23_method');
1182
_SslCtxUsePrivateKey := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey');
1183
_SslCtxUsePrivateKeyASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey_ASN1');
1184
//use SSL_CTX_use_RSAPrivateKey_file instead SSL_CTX_use_PrivateKey_file,
1185
//because SSL_CTX_use_PrivateKey_file not support DER format. :-O
1186
_SslCtxUsePrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_RSAPrivateKey_file');
1187
_SslCtxUseCertificate := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate');
1188
_SslCtxUseCertificateASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_ASN1');
1189
_SslCtxUseCertificateFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_file');
1190
_SslCtxUseCertificateChainFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_chain_file');
1191
_SslCtxCheckPrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_check_private_key');
1192
_SslCtxSetDefaultPasswdCb := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb');
1193
_SslCtxSetDefaultPasswdCbUserdata := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb_userdata');
1194
_SslCtxLoadVerifyLocations := GetProcAddr(SSLLibHandle, 'SSL_CTX_load_verify_locations');
1195
_SslNew := GetProcAddr(SSLLibHandle, 'SSL_new');
1196
_SslFree := GetProcAddr(SSLLibHandle, 'SSL_free');
1197
_SslAccept := GetProcAddr(SSLLibHandle, 'SSL_accept');
1198
_SslConnect := GetProcAddr(SSLLibHandle, 'SSL_connect');
1199
_SslShutdown := GetProcAddr(SSLLibHandle, 'SSL_shutdown');
1200
_SslRead := GetProcAddr(SSLLibHandle, 'SSL_read');
1201
_SslPeek := GetProcAddr(SSLLibHandle, 'SSL_peek');
1202
_SslWrite := GetProcAddr(SSLLibHandle, 'SSL_write');
1203
_SslPending := GetProcAddr(SSLLibHandle, 'SSL_pending');
1204
_SslGetPeerCertificate := GetProcAddr(SSLLibHandle, 'SSL_get_peer_certificate');
1205
_SslGetVersion := GetProcAddr(SSLLibHandle, 'SSL_get_version');
1206
_SslCtxSetVerify := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_verify');
1207
_SslGetCurrentCipher := GetProcAddr(SSLLibHandle, 'SSL_get_current_cipher');
1208
_SslCipherGetName := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_name');
1209
_SslCipherGetBits := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_bits');
1210
_SslGetVerifyResult := GetProcAddr(SSLLibHandle, 'SSL_get_verify_result');
1212
_X509New := GetProcAddr(SSLUtilHandle, 'X509_new');
1213
_X509Free := GetProcAddr(SSLUtilHandle, 'X509_free');
1214
_X509NameOneline := GetProcAddr(SSLUtilHandle, 'X509_NAME_oneline');
1215
_X509GetSubjectName := GetProcAddr(SSLUtilHandle, 'X509_get_subject_name');
1216
_X509GetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_get_issuer_name');
1217
_X509NameHash := GetProcAddr(SSLUtilHandle, 'X509_NAME_hash');
1218
_X509Digest := GetProcAddr(SSLUtilHandle, 'X509_digest');
1219
_X509print := GetProcAddr(SSLUtilHandle, 'X509_print');
1220
_X509SetVersion := GetProcAddr(SSLUtilHandle, 'X509_set_version');
1221
_X509SetPubkey := GetProcAddr(SSLUtilHandle, 'X509_set_pubkey');
1222
_X509SetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_set_issuer_name');
1223
_X509NameAddEntryByTxt := GetProcAddr(SSLUtilHandle, 'X509_NAME_add_entry_by_txt');
1224
_X509Sign := GetProcAddr(SSLUtilHandle, 'X509_sign');
1225
_X509GmtimeAdj := GetProcAddr(SSLUtilHandle, 'X509_gmtime_adj');
1226
_X509SetNotBefore := GetProcAddr(SSLUtilHandle, 'X509_set_notBefore');
1227
_X509SetNotAfter := GetProcAddr(SSLUtilHandle, 'X509_set_notAfter');
1228
_X509GetSerialNumber := GetProcAddr(SSLUtilHandle, 'X509_get_serialNumber');
1229
_EvpPkeyNew := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_new');
1230
_EvpPkeyFree := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_free');
1231
_EvpPkeyAssign := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_assign');
1232
_EVPCleanup := GetProcAddr(SSLUtilHandle, 'EVP_cleanup');
1233
_EvpGetDigestByName := GetProcAddr(SSLUtilHandle, 'EVP_get_digestbyname');
1234
_SSLeayversion := GetProcAddr(SSLUtilHandle, 'SSLeay_version');
1235
_ErrErrorString := GetProcAddr(SSLUtilHandle, 'ERR_error_string_n');
1236
_ErrGetError := GetProcAddr(SSLUtilHandle, 'ERR_get_error');
1237
_ErrClearError := GetProcAddr(SSLUtilHandle, 'ERR_clear_error');
1238
_ErrFreeStrings := GetProcAddr(SSLUtilHandle, 'ERR_free_strings');
1239
_ErrRemoveState := GetProcAddr(SSLUtilHandle, 'ERR_remove_state');
1240
_OPENSSLaddallalgorithms := GetProcAddr(SSLUtilHandle, 'OPENSSL_add_all_algorithms_noconf');
1241
_CRYPTOcleanupAllExData := GetProcAddr(SSLUtilHandle, 'CRYPTO_cleanup_all_ex_data');
1242
_RandScreen := GetProcAddr(SSLUtilHandle, 'RAND_screen');
1243
_BioNew := GetProcAddr(SSLUtilHandle, 'BIO_new');
1244
_BioFreeAll := GetProcAddr(SSLUtilHandle, 'BIO_free_all');
1245
_BioSMem := GetProcAddr(SSLUtilHandle, 'BIO_s_mem');
1246
_BioCtrlPending := GetProcAddr(SSLUtilHandle, 'BIO_ctrl_pending');
1247
_BioRead := GetProcAddr(SSLUtilHandle, 'BIO_read');
1248
_BioWrite := GetProcAddr(SSLUtilHandle, 'BIO_write');
1249
_d2iPKCS12bio := GetProcAddr(SSLUtilHandle, 'd2i_PKCS12_bio');
1250
_PKCS12parse := GetProcAddr(SSLUtilHandle, 'PKCS12_parse');
1251
_PKCS12free := GetProcAddr(SSLUtilHandle, 'PKCS12_free');
1252
_RsaGenerateKey := GetProcAddr(SSLUtilHandle, 'RSA_generate_key');
1253
_Asn1UtctimeNew := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_new');
1254
_Asn1UtctimeFree := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_free');
1255
_Asn1IntegerSet := GetProcAddr(SSLUtilHandle, 'ASN1_INTEGER_set');
1256
_i2dX509bio := GetProcAddr(SSLUtilHandle, 'i2d_X509_bio');
1257
_i2dPrivateKeyBio := GetProcAddr(SSLUtilHandle, 'i2d_PrivateKey_bio');
1260
_DESsetoddparity := GetProcAddr(SSLUtilHandle, 'DES_set_odd_parity');
1261
_DESsetkeychecked := GetProcAddr(SSLUtilHandle, 'DES_set_key_checked');
1262
_DESecbencrypt := GetProcAddr(SSLUtilHandle, 'DES_ecb_encrypt');
1264
_CRYPTOnumlocks := GetProcAddr(SSLUtilHandle, 'CRYPTO_num_locks');
1265
_CRYPTOsetlockingcallback := GetProcAddr(SSLUtilHandle, 'CRYPTO_set_locking_callback');
1268
if assigned(_SslLibraryInit) then
1270
if assigned(_SslLoadErrorStrings) then
1271
_SslLoadErrorStrings;
1272
if assigned(_OPENSSLaddallalgorithms) then
1273
_OPENSSLaddallalgorithms;
1274
if assigned(_RandScreen) then
1283
if SSLLibHandle <> 0 then
1285
FreeLibrary(SSLLibHandle);
1288
if SSLUtilHandle <> 0 then
1290
FreeLibrary(SSLUtilHandle);
1301
function DestroySSLInterface: Boolean;
1307
CRYPTOcleanupAllExData;
1311
if SSLLibHandle <> 0 then
1313
FreeLibrary(SSLLibHandle);
1316
if SSLUtilHandle <> 0 then
1318
FreeLibrary(SSLUtilHandle);
1322
_SslGetError := nil;
1323
_SslLibraryInit := nil;
1324
_SslLoadErrorStrings := nil;
1325
_SslCtxSetCipherList := nil;
1329
_SslMethodV2 := nil;
1330
_SslMethodV3 := nil;
1331
_SslMethodTLSV1 := nil;
1332
_SslMethodV23 := nil;
1333
_SslCtxUsePrivateKey := nil;
1334
_SslCtxUsePrivateKeyASN1 := nil;
1335
_SslCtxUsePrivateKeyFile := nil;
1336
_SslCtxUseCertificate := nil;
1337
_SslCtxUseCertificateASN1 := nil;
1338
_SslCtxUseCertificateFile := nil;
1339
_SslCtxUseCertificateChainFile := nil;
1340
_SslCtxCheckPrivateKeyFile := nil;
1341
_SslCtxSetDefaultPasswdCb := nil;
1342
_SslCtxSetDefaultPasswdCbUserdata := nil;
1343
_SslCtxLoadVerifyLocations := nil;
1348
_SslShutdown := nil;
1353
_SslGetPeerCertificate := nil;
1354
_SslGetVersion := nil;
1355
_SslCtxSetVerify := nil;
1356
_SslGetCurrentCipher := nil;
1357
_SslCipherGetName := nil;
1358
_SslCipherGetBits := nil;
1359
_SslGetVerifyResult := nil;
1363
_X509NameOneline := nil;
1364
_X509GetSubjectName := nil;
1365
_X509GetIssuerName := nil;
1366
_X509NameHash := nil;
1369
_X509SetVersion := nil;
1370
_X509SetPubkey := nil;
1371
_X509SetIssuerName := nil;
1372
_X509NameAddEntryByTxt := nil;
1374
_X509GmtimeAdj := nil;
1375
_X509SetNotBefore := nil;
1376
_X509SetNotAfter := nil;
1377
_X509GetSerialNumber := nil;
1379
_EvpPkeyFree := nil;
1380
_EvpPkeyAssign := nil;
1382
_EvpGetDigestByName := nil;
1383
_SSLeayversion := nil;
1384
_ErrErrorString := nil;
1385
_ErrGetError := nil;
1386
_ErrClearError := nil;
1387
_ErrFreeStrings := nil;
1388
_ErrRemoveState := nil;
1389
_OPENSSLaddallalgorithms := nil;
1390
_CRYPTOcleanupAllExData := nil;
1395
_BioCtrlPending := nil;
1398
_d2iPKCS12bio := nil;
1399
_PKCS12parse := nil;
1401
_RsaGenerateKey := nil;
1402
_Asn1UtctimeNew := nil;
1403
_Asn1UtctimeFree := nil;
1404
_Asn1IntegerSet := nil;
1406
_i2dPrivateKeyBio := nil;
1409
_DESsetoddparity := nil;
1410
_DESsetkeychecked := nil;
1411
_DESecbencrypt := nil;
1413
_CRYPTOnumlocks := nil;
1414
_CRYPTOsetlockingcallback := nil;
1418
function IsSSLloaded: Boolean;
1420
Result := SSLLoaded;
1424
DestroySSLInterface;