~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to fpcsrc/packages/extra/openssl/openssl.pas

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
unit OpenSSL;
 
2
 
 
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.                                                         |
 
10
|                                                                              |
 
11
| Redistribution and use in source and binary forms, with or without           |
 
12
| modification, are permitted provided that the following conditions are met:  |
 
13
|                                                                              |
 
14
| Redistributions of source code must retain the above copyright notice, this  |
 
15
| list of conditions and the following disclaimer.                             |
 
16
|                                                                              |
 
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.                       |
 
20
|                                                                              |
 
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.                                           |
 
24
|                                                                              |
 
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  |
 
35
| DAMAGE.                                                                      |
 
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
|==============================================================================|
 
41
| Contributor(s):                                                              |
 
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
|==============================================================================}
 
51
 
 
52
{
 
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.
 
56
}
 
57
 
 
58
{$MODE DELPHI}{$H+}
 
59
 
 
60
{:@abstract(OpenSSL support)
 
61
 
 
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.
 
65
}
 
66
 
 
67
interface
 
68
 
 
69
uses
 
70
  DynLibs;
 
71
 
 
72
var
 
73
  {$IFDEF WINDOWS}
 
74
  DLLSSLName: string = 'ssleay32.dll';
 
75
  DLLSSLName2: string = 'libssl32.dll';
 
76
  DLLUtilName: string = 'libeay32.dll';
 
77
  {$ELSE}
 
78
  DLLSSLName: string = 'libssl.so';
 
79
  DLLUtilName: string = 'libcrypto.so';
 
80
  {$ENDIF}
 
81
 
 
82
type
 
83
  SslPtr = Pointer;
 
84
  PSslPtr = ^SslPtr;
 
85
  PSSL_CTX = SslPtr;
 
86
  PSSL = SslPtr;
 
87
  PSSL_METHOD = SslPtr;
 
88
  PX509 = SslPtr;
 
89
  PX509_NAME = SslPtr;
 
90
  PEVP_MD       = SslPtr;
 
91
  PInteger = ^Integer;
 
92
  PBIO_METHOD = SslPtr;
 
93
  PBIO = SslPtr;
 
94
  EVP_PKEY = SslPtr;
 
95
  PRSA = SslPtr;
 
96
  PASN1_UTCTIME = SslPtr;
 
97
  PASN1_INTEGER = SslPtr;
 
98
  PPasswdCb = SslPtr;
 
99
  PFunction = procedure;
 
100
 
 
101
  DES_cblock = array[0..7] of Byte;
 
102
  PDES_cblock = ^DES_cblock;
 
103
  des_ks_struct = packed record
 
104
    ks: DES_cblock;
 
105
    weak_key: Integer;
 
106
  end;
 
107
  des_key_schedule = array[1..16] of des_ks_struct;
 
108
 
 
109
const
 
110
  EVP_MAX_MD_SIZE = 16 + 20;
 
111
 
 
112
  SSL_ERROR_NONE = 0;
 
113
  SSL_ERROR_SSL = 1;
 
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;
 
121
 
 
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;
 
128
 
 
129
  OPENSSL_DES_DECRYPT = 0;
 
130
  OPENSSL_DES_ENCRYPT = 1;
 
131
 
 
132
  X509_V_OK =   0;
 
133
  X509_V_ILLEGAL = 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;
 
170
 
 
171
  SSL_FILETYPE_ASN1     = 2;
 
172
  SSL_FILETYPE_PEM = 1;
 
173
  EVP_PKEY_RSA = 6;
 
174
 
 
175
var
 
176
  SSLLibHandle: TLibHandle = 0;
 
177
  SSLUtilHandle: TLibHandle = 0;
 
178
  SSLLibFile: string = '';
 
179
  SSLUtilFile: string = '';
 
180
 
 
181
// libssl.dll
 
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;
 
224
 
 
225
// libeay.dll
 
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;
 
275
 
 
276
  // 3DES functions
 
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);
 
280
 
 
281
function IsSSLloaded: Boolean;
 
282
function InitSSLInterface: Boolean;
 
283
function DestroySSLInterface: Boolean;
 
284
 
 
285
implementation
 
286
 
 
287
type
 
288
// libssl.dll
 
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;
 
327
 
 
328
// libeay.dll
 
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;
 
376
 
 
377
  // 3DES functions
 
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;
 
384
 
 
385
var
 
386
// libssl.dll
 
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;
 
425
 
 
426
// libeay.dll
 
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;
 
473
 
 
474
  // 3DES functions
 
475
  _DESsetoddparity: TDESsetoddparity = nil;
 
476
  _DESsetkeychecked: TDESsetkeychecked = nil;
 
477
  _DESecbencrypt: TDESecbencrypt = nil;
 
478
  //thread lock functions
 
479
  _CRYPTOnumlocks: TCRYPTOnumlocks = nil;
 
480
  _CRYPTOSetLockingCallback: TCRYPTOSetLockingCallback = nil;
 
481
 
 
482
var
 
483
  SSLloaded: boolean = false;
 
484
 
 
485
// libssl.dll
 
486
function SslGetError(s: PSSL; ret_code: Integer):Integer;
 
487
begin
 
488
  if InitSSLInterface and Assigned(_SslGetError) then
 
489
    Result := _SslGetError(s, ret_code)
 
490
  else
 
491
    Result := SSL_ERROR_SSL;
 
492
end;
 
493
 
 
494
function SslLibraryInit:Integer;
 
495
begin
 
496
  if InitSSLInterface and Assigned(_SslLibraryInit) then
 
497
    Result := _SslLibraryInit
 
498
  else
 
499
    Result := 1;
 
500
end;
 
501
 
 
502
procedure SslLoadErrorStrings;
 
503
begin
 
504
  if InitSSLInterface and Assigned(_SslLoadErrorStrings) then
 
505
    _SslLoadErrorStrings;
 
506
end;
 
507
 
 
508
function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String):Integer;
 
509
begin
 
510
  if InitSSLInterface and Assigned(_SslCtxSetCipherList) then
 
511
    Result := _SslCtxSetCipherList(arg0, PChar(str))
 
512
  else
 
513
    Result := 0;
 
514
end;
 
515
 
 
516
function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
 
517
begin
 
518
  if InitSSLInterface and Assigned(_SslCtxNew) then
 
519
    Result := _SslCtxNew(meth)
 
520
  else
 
521
    Result := nil;
 
522
end;
 
523
 
 
524
procedure SslCtxFree(arg0: PSSL_CTX);
 
525
begin
 
526
  if InitSSLInterface and Assigned(_SslCtxFree) then
 
527
    _SslCtxFree(arg0);
 
528
end;
 
529
 
 
530
function SslSetFd(s: PSSL; fd: Integer):Integer;
 
531
begin
 
532
  if InitSSLInterface and Assigned(_SslSetFd) then
 
533
    Result := _SslSetFd(s, fd)
 
534
  else
 
535
    Result := 0;
 
536
end;
 
537
 
 
538
function SslMethodV2:PSSL_METHOD;
 
539
begin
 
540
  if InitSSLInterface and Assigned(_SslMethodV2) then
 
541
    Result := _SslMethodV2
 
542
  else
 
543
    Result := nil;
 
544
end;
 
545
 
 
546
function SslMethodV3:PSSL_METHOD;
 
547
begin
 
548
  if InitSSLInterface and Assigned(_SslMethodV3) then
 
549
    Result := _SslMethodV3
 
550
  else
 
551
    Result := nil;
 
552
end;
 
553
 
 
554
function SslMethodTLSV1:PSSL_METHOD;
 
555
begin
 
556
  if InitSSLInterface and Assigned(_SslMethodTLSV1) then
 
557
    Result := _SslMethodTLSV1
 
558
  else
 
559
    Result := nil;
 
560
end;
 
561
 
 
562
function SslMethodV23:PSSL_METHOD;
 
563
begin
 
564
  if InitSSLInterface and Assigned(_SslMethodV23) then
 
565
    Result := _SslMethodV23
 
566
  else
 
567
    Result := nil;
 
568
end;
 
569
 
 
570
function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):Integer;
 
571
begin
 
572
  if InitSSLInterface and Assigned(_SslCtxUsePrivateKey) then
 
573
    Result := _SslCtxUsePrivateKey(ctx, pkey)
 
574
  else
 
575
    Result := 0;
 
576
end;
 
577
 
 
578
function SslCtxUsePrivateKeyASN1(pk: integer; ctx: PSSL_CTX; d: String; len: integer):Integer;
 
579
begin
 
580
  if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyASN1) then
 
581
    Result := _SslCtxUsePrivateKeyASN1(pk, ctx, Sslptr(d), len)
 
582
  else
 
583
    Result := 0;
 
584
end;
 
585
 
 
586
function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
 
587
begin
 
588
  if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyFile) then
 
589
    Result := _SslCtxUsePrivateKeyFile(ctx, PChar(_file), _type)
 
590
  else
 
591
    Result := 0;
 
592
end;
 
593
 
 
594
function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):Integer;
 
595
begin
 
596
  if InitSSLInterface and Assigned(_SslCtxUseCertificate) then
 
597
    Result := _SslCtxUseCertificate(ctx, x)
 
598
  else
 
599
    Result := 0;
 
600
end;
 
601
 
 
602
function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: integer; d: String):Integer;
 
603
begin
 
604
  if InitSSLInterface and Assigned(_SslCtxUseCertificateASN1) then
 
605
    Result := _SslCtxUseCertificateASN1(ctx, len, SslPtr(d))
 
606
  else
 
607
    Result := 0;
 
608
end;
 
609
 
 
610
function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
 
611
begin
 
612
  if InitSSLInterface and Assigned(_SslCtxUseCertificateFile) then
 
613
    Result := _SslCtxUseCertificateFile(ctx, PChar(_file), _type)
 
614
  else
 
615
    Result := 0;
 
616
end;
 
617
 
 
618
function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):Integer;
 
619
begin
 
620
  if InitSSLInterface and Assigned(_SslCtxUseCertificateChainFile) then
 
621
    Result := _SslCtxUseCertificateChainFile(ctx, PChar(_file))
 
622
  else
 
623
    Result := 0;
 
624
end;
 
625
 
 
626
function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer;
 
627
begin
 
628
  if InitSSLInterface and Assigned(_SslCtxCheckPrivateKeyFile) then
 
629
    Result := _SslCtxCheckPrivateKeyFile(ctx)
 
630
  else
 
631
    Result := 0;
 
632
end;
 
633
 
 
634
procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
 
635
begin
 
636
  if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCb) then
 
637
    _SslCtxSetDefaultPasswdCb(ctx, cb);
 
638
end;
 
639
 
 
640
procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
 
641
begin
 
642
  if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCbUserdata) then
 
643
    _SslCtxSetDefaultPasswdCbUserdata(ctx, u);
 
644
end;
 
645
 
 
646
function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: String; const CApath: String):Integer;
 
647
begin
 
648
  if InitSSLInterface and Assigned(_SslCtxLoadVerifyLocations) then
 
649
    Result := _SslCtxLoadVerifyLocations(ctx, SslPtr(CAfile), SslPtr(CApath))
 
650
  else
 
651
    Result := 0;
 
652
end;
 
653
 
 
654
function SslNew(ctx: PSSL_CTX):PSSL;
 
655
begin
 
656
  if InitSSLInterface and Assigned(_SslNew) then
 
657
    Result := _SslNew(ctx)
 
658
  else
 
659
    Result := nil;
 
660
end;
 
661
 
 
662
procedure SslFree(ssl: PSSL);
 
663
begin
 
664
  if InitSSLInterface and Assigned(_SslFree) then
 
665
    _SslFree(ssl);
 
666
end;
 
667
 
 
668
function SslAccept(ssl: PSSL):Integer;
 
669
begin
 
670
  if InitSSLInterface and Assigned(_SslAccept) then
 
671
    Result := _SslAccept(ssl)
 
672
  else
 
673
    Result := -1;
 
674
end;
 
675
 
 
676
function SslConnect(ssl: PSSL):Integer;
 
677
begin
 
678
  if InitSSLInterface and Assigned(_SslConnect) then
 
679
    Result := _SslConnect(ssl)
 
680
  else
 
681
    Result := -1;
 
682
end;
 
683
 
 
684
function SslShutdown(ssl: PSSL):Integer;
 
685
begin
 
686
  if InitSSLInterface and Assigned(_SslShutdown) then
 
687
    Result := _SslShutdown(ssl)
 
688
  else
 
689
    Result := -1;
 
690
end;
 
691
 
 
692
function SslRead(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
 
693
begin
 
694
  if InitSSLInterface and Assigned(_SslRead) then
 
695
    Result := _SslRead(ssl, PChar(buf), num)
 
696
  else
 
697
    Result := -1;
 
698
end;
 
699
 
 
700
function SslPeek(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
 
701
begin
 
702
  if InitSSLInterface and Assigned(_SslPeek) then
 
703
    Result := _SslPeek(ssl, PChar(buf), num)
 
704
  else
 
705
    Result := -1;
 
706
end;
 
707
 
 
708
function SslWrite(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
 
709
begin
 
710
  if InitSSLInterface and Assigned(_SslWrite) then
 
711
    Result := _SslWrite(ssl, PChar(buf), num)
 
712
  else
 
713
    Result := -1;
 
714
end;
 
715
 
 
716
function SslPending(ssl: PSSL):Integer;
 
717
begin
 
718
  if InitSSLInterface and Assigned(_SslPending) then
 
719
    Result := _SslPending(ssl)
 
720
  else
 
721
    Result := 0;
 
722
end;
 
723
 
 
724
//function SslGetVersion(ssl: PSSL):PChar;
 
725
function SslGetVersion(ssl: PSSL):String;
 
726
begin
 
727
  if InitSSLInterface and Assigned(_SslGetVersion) then
 
728
    Result := _SslGetVersion(ssl)
 
729
  else
 
730
    Result := '';
 
731
end;
 
732
 
 
733
function SslGetPeerCertificate(ssl: PSSL):PX509;
 
734
begin
 
735
  if InitSSLInterface and Assigned(_SslGetPeerCertificate) then
 
736
    Result := _SslGetPeerCertificate(ssl)
 
737
  else
 
738
    Result := nil;
 
739
end;
 
740
 
 
741
procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction);
 
742
begin
 
743
  if InitSSLInterface and Assigned(_SslCtxSetVerify) then
 
744
    _SslCtxSetVerify(ctx, mode, @arg2);
 
745
end;
 
746
 
 
747
function SSLGetCurrentCipher(s: PSSL):SslPtr;
 
748
begin
 
749
  if InitSSLInterface and Assigned(_SSLGetCurrentCipher) then
 
750
{$IFDEF CIL}
 
751
{$ELSE}
 
752
    Result := _SSLGetCurrentCipher(s)
 
753
{$ENDIF}
 
754
  else
 
755
    Result := nil;
 
756
end;
 
757
 
 
758
function SSLCipherGetName(c: SslPtr):String;
 
759
begin
 
760
  if InitSSLInterface and Assigned(_SSLCipherGetName) then
 
761
    Result := _SSLCipherGetName(c)
 
762
  else
 
763
    Result := '';
 
764
end;
 
765
 
 
766
function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer;
 
767
begin
 
768
  if InitSSLInterface and Assigned(_SSLCipherGetBits) then
 
769
    Result := _SSLCipherGetBits(c, @alg_bits)
 
770
  else
 
771
    Result := 0;
 
772
end;
 
773
 
 
774
function SSLGetVerifyResult(ssl: PSSL):Integer;
 
775
begin
 
776
  if InitSSLInterface and Assigned(_SSLGetVerifyResult) then
 
777
    Result := _SSLGetVerifyResult(ssl)
 
778
  else
 
779
    Result := X509_V_ERR_APPLICATION_VERIFICATION;
 
780
end;
 
781
 
 
782
// libeay.dll
 
783
function X509New: PX509;
 
784
begin
 
785
  if InitSSLInterface and Assigned(_X509New) then
 
786
    Result := _X509New
 
787
  else
 
788
    Result := nil;
 
789
end;
 
790
 
 
791
procedure X509Free(x: PX509);
 
792
begin
 
793
  if InitSSLInterface and Assigned(_X509Free) then
 
794
    _X509Free(x);
 
795
end;
 
796
 
 
797
function X509NameOneline(a: PX509_NAME; var buf: String; size: Integer):String;
 
798
begin
 
799
  if InitSSLInterface and Assigned(_X509NameOneline) then
 
800
    Result := _X509NameOneline(a, PChar(buf),size)
 
801
  else
 
802
    Result := '';
 
803
end;
 
804
 
 
805
function X509GetSubjectName(a: PX509):PX509_NAME;
 
806
begin
 
807
  if InitSSLInterface and Assigned(_X509GetSubjectName) then
 
808
    Result := _X509GetSubjectName(a)
 
809
  else
 
810
    Result := nil;
 
811
end;
 
812
 
 
813
function X509GetIssuerName(a: PX509):PX509_NAME;
 
814
begin
 
815
  if InitSSLInterface and Assigned(_X509GetIssuerName) then
 
816
    Result := _X509GetIssuerName(a)
 
817
  else
 
818
    Result := nil;
 
819
end;
 
820
 
 
821
function X509NameHash(x: PX509_NAME):Cardinal;
 
822
begin
 
823
  if InitSSLInterface and Assigned(_X509NameHash) then
 
824
    Result := _X509NameHash(x)
 
825
  else
 
826
    Result := 0;
 
827
end;
 
828
 
 
829
function X509Digest(data: PX509; _type: PEVP_MD; md: String; var len: Integer):Integer;
 
830
begin
 
831
  if InitSSLInterface and Assigned(_X509Digest) then
 
832
    Result := _X509Digest(data, _type, PChar(md), @len)
 
833
  else
 
834
    Result := 0;
 
835
end;
 
836
 
 
837
function EvpPkeyNew: EVP_PKEY;
 
838
begin
 
839
  if InitSSLInterface and Assigned(_EvpPkeyNew) then
 
840
    Result := _EvpPkeyNew
 
841
  else
 
842
    Result := nil;
 
843
end;
 
844
 
 
845
procedure EvpPkeyFree(pk: EVP_PKEY);
 
846
begin
 
847
  if InitSSLInterface and Assigned(_EvpPkeyFree) then
 
848
    _EvpPkeyFree(pk);
 
849
end;
 
850
 
 
851
function SSLeayversion(t: integer): string;
 
852
begin
 
853
  if InitSSLInterface and Assigned(_SSLeayversion) then
 
854
    Result := PChar(_SSLeayversion(t))
 
855
  else
 
856
    Result := '';
 
857
end;
 
858
 
 
859
procedure ErrErrorString(e: integer; var buf: string; len: integer);
 
860
begin
 
861
  if InitSSLInterface and Assigned(_ErrErrorString) then
 
862
    _ErrErrorString(e, Pointer(buf), len);
 
863
  buf := PChar(Buf);
 
864
end;
 
865
 
 
866
function ErrGetError: integer;
 
867
begin
 
868
  if InitSSLInterface and Assigned(_ErrGetError) then
 
869
    Result := _ErrGetError
 
870
  else
 
871
    Result := SSL_ERROR_SSL;
 
872
end;
 
873
 
 
874
procedure ErrClearError;
 
875
begin
 
876
  if InitSSLInterface and Assigned(_ErrClearError) then
 
877
    _ErrClearError;
 
878
end;
 
879
 
 
880
procedure ErrFreeStrings;
 
881
begin
 
882
  if InitSSLInterface and Assigned(_ErrFreeStrings) then
 
883
    _ErrFreeStrings;
 
884
end;
 
885
 
 
886
procedure ErrRemoveState(pid: integer);
 
887
begin
 
888
  if InitSSLInterface and Assigned(_ErrRemoveState) then
 
889
    _ErrRemoveState(pid);
 
890
end;
 
891
 
 
892
procedure OPENSSLaddallalgorithms;
 
893
begin
 
894
  if InitSSLInterface and Assigned(_OPENSSLaddallalgorithms) then
 
895
    _OPENSSLaddallalgorithms;
 
896
end;
 
897
 
 
898
procedure EVPcleanup;
 
899
begin
 
900
  if InitSSLInterface and Assigned(_EVPcleanup) then
 
901
    _EVPcleanup;
 
902
end;
 
903
 
 
904
procedure CRYPTOcleanupAllExData;
 
905
begin
 
906
  if InitSSLInterface and Assigned(_CRYPTOcleanupAllExData) then
 
907
    _CRYPTOcleanupAllExData;
 
908
end;
 
909
 
 
910
procedure RandScreen;
 
911
begin
 
912
  if InitSSLInterface and Assigned(_RandScreen) then
 
913
    _RandScreen;
 
914
end;
 
915
 
 
916
function BioNew(b: PBIO_METHOD): PBIO;
 
917
begin
 
918
  if InitSSLInterface and Assigned(_BioNew) then
 
919
    Result := _BioNew(b)
 
920
  else
 
921
    Result := nil;
 
922
end;
 
923
 
 
924
procedure BioFreeAll(b: PBIO);
 
925
begin
 
926
  if InitSSLInterface and Assigned(_BioFreeAll) then
 
927
    _BioFreeAll(b);
 
928
end;
 
929
 
 
930
function BioSMem: PBIO_METHOD;
 
931
begin
 
932
  if InitSSLInterface and Assigned(_BioSMem) then
 
933
    Result := _BioSMem
 
934
  else
 
935
    Result := nil;
 
936
end;
 
937
 
 
938
function BioCtrlPending(b: PBIO): integer;
 
939
begin
 
940
  if InitSSLInterface and Assigned(_BioCtrlPending) then
 
941
    Result := _BioCtrlPending(b)
 
942
  else
 
943
    Result := 0;
 
944
end;
 
945
 
 
946
function BioRead(b: PBIO; var Buf: String; Len: integer): integer;
 
947
begin
 
948
  if InitSSLInterface and Assigned(_BioRead) then
 
949
    Result := _BioRead(b, PChar(Buf), Len)
 
950
  else
 
951
    Result := -2;
 
952
end;
 
953
 
 
954
//function BioWrite(b: PBIO; Buf: PChar; Len: integer): integer;
 
955
function BioWrite(b: PBIO; Buf: String; Len: integer): integer;
 
956
begin
 
957
  if InitSSLInterface and Assigned(_BioWrite) then
 
958
    Result := _BioWrite(b, PChar(Buf), Len)
 
959
  else
 
960
    Result := -2;
 
961
end;
 
962
 
 
963
function X509print(b: PBIO; a: PX509): integer;
 
964
begin
 
965
  if InitSSLInterface and Assigned(_X509print) then
 
966
    Result := _X509print(b, a)
 
967
  else
 
968
    Result := 0;
 
969
end;
 
970
 
 
971
function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
 
972
begin
 
973
  if InitSSLInterface and Assigned(_d2iPKCS12bio) then
 
974
    Result := _d2iPKCS12bio(b, Pkcs12)
 
975
  else
 
976
    Result := nil;
 
977
end;
 
978
 
 
979
function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): integer;
 
980
begin
 
981
  if InitSSLInterface and Assigned(_PKCS12parse) then
 
982
    Result := _PKCS12parse(p12, SslPtr(pass), pkey, cert, ca)
 
983
  else
 
984
    Result := 0;
 
985
end;
 
986
 
 
987
procedure PKCS12free(p12: SslPtr);
 
988
begin
 
989
  if InitSSLInterface and Assigned(_PKCS12free) then
 
990
    _PKCS12free(p12);
 
991
end;
 
992
 
 
993
function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA;
 
994
begin
 
995
  if InitSSLInterface and Assigned(_RsaGenerateKey) then
 
996
    Result := _RsaGenerateKey(bits, e, callback, cb_arg)
 
997
  else
 
998
    Result := nil;
 
999
end;
 
1000
 
 
1001
function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer;
 
1002
begin
 
1003
  if InitSSLInterface and Assigned(_EvpPkeyAssign) then
 
1004
    Result := _EvpPkeyAssign(pkey, _type, key)
 
1005
  else
 
1006
    Result := 0;
 
1007
end;
 
1008
 
 
1009
function X509SetVersion(x: PX509; version: integer): integer;
 
1010
begin
 
1011
  if InitSSLInterface and Assigned(_X509SetVersion) then
 
1012
    Result := _X509SetVersion(x, version)
 
1013
  else
 
1014
    Result := 0;
 
1015
end;
 
1016
 
 
1017
function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer;
 
1018
begin
 
1019
  if InitSSLInterface and Assigned(_X509SetPubkey) then
 
1020
    Result := _X509SetPubkey(x, pkey)
 
1021
  else
 
1022
    Result := 0;
 
1023
end;
 
1024
 
 
1025
function X509SetIssuerName(x: PX509; name: PX509_NAME): integer;
 
1026
begin
 
1027
  if InitSSLInterface and Assigned(_X509SetIssuerName) then
 
1028
    Result := _X509SetIssuerName(x, name)
 
1029
  else
 
1030
    Result := 0;
 
1031
end;
 
1032
 
 
1033
function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: integer;
 
1034
  bytes: string; len, loc, _set: integer): integer;
 
1035
begin
 
1036
  if InitSSLInterface and Assigned(_X509NameAddEntryByTxt) then
 
1037
    Result := _X509NameAddEntryByTxt(name, PChar(field), _type, PChar(Bytes), len, loc, _set)
 
1038
  else
 
1039
    Result := 0;
 
1040
end;
 
1041
 
 
1042
function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer;
 
1043
begin
 
1044
  if InitSSLInterface and Assigned(_X509Sign) then
 
1045
    Result := _X509Sign(x, pkey, md)
 
1046
  else
 
1047
    Result := 0;
 
1048
end;
 
1049
 
 
1050
function Asn1UtctimeNew: PASN1_UTCTIME;
 
1051
begin
 
1052
  if InitSSLInterface and Assigned(_Asn1UtctimeNew) then
 
1053
    Result := _Asn1UtctimeNew
 
1054
  else
 
1055
    Result := nil;
 
1056
end;
 
1057
 
 
1058
procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
 
1059
begin
 
1060
  if InitSSLInterface and Assigned(_Asn1UtctimeFree) then
 
1061
    _Asn1UtctimeFree(a);
 
1062
end;
 
1063
 
 
1064
function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME;
 
1065
begin
 
1066
  if InitSSLInterface and Assigned(_X509GmtimeAdj) then
 
1067
    Result := _X509GmtimeAdj(s, adj)
 
1068
  else
 
1069
    Result := nil;
 
1070
end;
 
1071
 
 
1072
function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer;
 
1073
begin
 
1074
  if InitSSLInterface and Assigned(_X509SetNotBefore) then
 
1075
    Result := _X509SetNotBefore(x, tm)
 
1076
  else
 
1077
    Result := 0;
 
1078
end;
 
1079
 
 
1080
function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer;
 
1081
begin
 
1082
  if InitSSLInterface and Assigned(_X509SetNotAfter) then
 
1083
    Result := _X509SetNotAfter(x, tm)
 
1084
  else
 
1085
    Result := 0;
 
1086
end;
 
1087
 
 
1088
function i2dX509bio(b: PBIO; x: PX509): integer;
 
1089
begin
 
1090
  if InitSSLInterface and Assigned(_i2dX509bio) then
 
1091
    Result := _i2dX509bio(b, x)
 
1092
  else
 
1093
    Result := 0;
 
1094
end;
 
1095
 
 
1096
function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer;
 
1097
begin
 
1098
  if InitSSLInterface and Assigned(_i2dPrivateKeyBio) then
 
1099
    Result := _i2dPrivateKeyBio(b, pkey)
 
1100
  else
 
1101
    Result := 0;
 
1102
end;
 
1103
 
 
1104
function EvpGetDigestByName(Name: String): PEVP_MD;
 
1105
begin
 
1106
  if InitSSLInterface and Assigned(_EvpGetDigestByName) then
 
1107
    Result := _EvpGetDigestByName(PChar(Name))
 
1108
  else
 
1109
    Result := nil;
 
1110
end;
 
1111
 
 
1112
function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
 
1113
begin
 
1114
  if InitSSLInterface and Assigned(_Asn1IntegerSet) then
 
1115
    Result := _Asn1IntegerSet(a, v)
 
1116
  else
 
1117
    Result := 0;
 
1118
end;
 
1119
 
 
1120
function X509GetSerialNumber(x: PX509): PASN1_INTEGER;
 
1121
begin
 
1122
  if InitSSLInterface and Assigned(_X509GetSerialNumber) then
 
1123
    Result := _X509GetSerialNumber(x)
 
1124
  else
 
1125
    Result := nil;
 
1126
end;
 
1127
 
 
1128
// 3DES functions
 
1129
procedure DESsetoddparity(Key: des_cblock);
 
1130
begin
 
1131
  if InitSSLInterface and Assigned(_DESsetoddparity) then
 
1132
    _DESsetoddparity(Key);
 
1133
end;
 
1134
 
 
1135
function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer;
 
1136
begin
 
1137
  if InitSSLInterface and Assigned(_DESsetkeychecked) then
 
1138
    Result := _DESsetkeychecked(key, schedule)
 
1139
  else
 
1140
    Result := -1;
 
1141
end;
 
1142
 
 
1143
procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer);
 
1144
begin
 
1145
  if InitSSLInterface and Assigned(_DESecbencrypt) then
 
1146
    _DESecbencrypt(Input, output, ks, enc);
 
1147
end;
 
1148
 
 
1149
function LoadLib(const Value: String): HModule;
 
1150
begin
 
1151
  Result := LoadLibrary(Value);
 
1152
end;
 
1153
 
 
1154
function GetProcAddr(module: HModule; const ProcName: string): SslPtr;
 
1155
begin
 
1156
  Result := GetProcAddress(module, PChar(ProcName));
 
1157
end;
 
1158
 
 
1159
function InitSSLInterface: Boolean;
 
1160
begin
 
1161
    if not IsSSLloaded then
 
1162
    begin
 
1163
      SSLLibHandle := LoadLib(DLLSSLName);
 
1164
      SSLUtilHandle := LoadLib(DLLUtilName);
 
1165
  {$IFNDEF UNIX}
 
1166
      if (SSLLibHandle = 0) then
 
1167
        SSLLibHandle := LoadLib(DLLSSLName2);
 
1168
  {$ENDIF}
 
1169
      if (SSLLibHandle <> 0) and (SSLUtilHandle <> 0) then
 
1170
      begin
 
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');
 
1211
 
 
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');
 
1258
 
 
1259
        // 3DES functions
 
1260
        _DESsetoddparity := GetProcAddr(SSLUtilHandle, 'DES_set_odd_parity');
 
1261
        _DESsetkeychecked := GetProcAddr(SSLUtilHandle, 'DES_set_key_checked');
 
1262
        _DESecbencrypt := GetProcAddr(SSLUtilHandle, 'DES_ecb_encrypt');
 
1263
        //
 
1264
        _CRYPTOnumlocks := GetProcAddr(SSLUtilHandle, 'CRYPTO_num_locks');
 
1265
        _CRYPTOsetlockingcallback := GetProcAddr(SSLUtilHandle, 'CRYPTO_set_locking_callback');
 
1266
 
 
1267
        //init library
 
1268
        if assigned(_SslLibraryInit) then
 
1269
          _SslLibraryInit;
 
1270
        if assigned(_SslLoadErrorStrings) then
 
1271
          _SslLoadErrorStrings;
 
1272
        if assigned(_OPENSSLaddallalgorithms) then
 
1273
          _OPENSSLaddallalgorithms;
 
1274
        if assigned(_RandScreen) then
 
1275
          _RandScreen;
 
1276
 
 
1277
        Result := True;
 
1278
        SSLloaded := True;
 
1279
      end
 
1280
      else
 
1281
      begin
 
1282
        //load failed!
 
1283
        if SSLLibHandle <> 0 then
 
1284
        begin
 
1285
          FreeLibrary(SSLLibHandle);
 
1286
          SSLLibHandle := 0;
 
1287
        end;
 
1288
        if SSLUtilHandle <> 0 then
 
1289
        begin
 
1290
          FreeLibrary(SSLUtilHandle);
 
1291
          SSLLibHandle := 0;
 
1292
        end;
 
1293
        Result := False;
 
1294
      end;
 
1295
    end
 
1296
    else
 
1297
      //loaded before...
 
1298
      Result := true;
 
1299
end;
 
1300
 
 
1301
function DestroySSLInterface: Boolean;
 
1302
begin
 
1303
    if IsSSLLoaded then
 
1304
    begin
 
1305
      //deinit library
 
1306
      EVPCleanup;
 
1307
      CRYPTOcleanupAllExData;
 
1308
      ErrRemoveState(0);
 
1309
    end;
 
1310
    SSLloaded := false;
 
1311
    if SSLLibHandle <> 0 then
 
1312
    begin
 
1313
      FreeLibrary(SSLLibHandle);
 
1314
      SSLLibHandle := 0;
 
1315
    end;
 
1316
    if SSLUtilHandle <> 0 then
 
1317
    begin
 
1318
      FreeLibrary(SSLUtilHandle);
 
1319
      SSLLibHandle := 0;
 
1320
    end;
 
1321
 
 
1322
    _SslGetError := nil;
 
1323
    _SslLibraryInit := nil;
 
1324
    _SslLoadErrorStrings := nil;
 
1325
    _SslCtxSetCipherList := nil;
 
1326
    _SslCtxNew := nil;
 
1327
    _SslCtxFree := nil;
 
1328
    _SslSetFd := 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;
 
1344
    _SslNew := nil;
 
1345
    _SslFree := nil;
 
1346
    _SslAccept := nil;
 
1347
    _SslConnect := nil;
 
1348
    _SslShutdown := nil;
 
1349
    _SslRead := nil;
 
1350
    _SslPeek := nil;
 
1351
    _SslWrite := nil;
 
1352
    _SslPending := nil;
 
1353
    _SslGetPeerCertificate := nil;
 
1354
    _SslGetVersion := nil;
 
1355
    _SslCtxSetVerify := nil;
 
1356
    _SslGetCurrentCipher := nil;
 
1357
    _SslCipherGetName := nil;
 
1358
    _SslCipherGetBits := nil;
 
1359
    _SslGetVerifyResult := nil;
 
1360
 
 
1361
    _X509New := nil;
 
1362
    _X509Free := nil;
 
1363
    _X509NameOneline := nil;
 
1364
    _X509GetSubjectName := nil;
 
1365
    _X509GetIssuerName := nil;
 
1366
    _X509NameHash := nil;
 
1367
    _X509Digest := nil;
 
1368
    _X509print := nil;
 
1369
    _X509SetVersion := nil;
 
1370
    _X509SetPubkey := nil;
 
1371
    _X509SetIssuerName := nil;
 
1372
    _X509NameAddEntryByTxt := nil;
 
1373
    _X509Sign := nil;
 
1374
    _X509GmtimeAdj := nil;
 
1375
    _X509SetNotBefore := nil;
 
1376
    _X509SetNotAfter := nil;
 
1377
    _X509GetSerialNumber := nil;
 
1378
    _EvpPkeyNew := nil;
 
1379
    _EvpPkeyFree := nil;
 
1380
    _EvpPkeyAssign := nil;
 
1381
    _EVPCleanup := 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;
 
1391
    _RandScreen := nil;
 
1392
    _BioNew := nil;
 
1393
    _BioFreeAll := nil;
 
1394
    _BioSMem := nil;
 
1395
    _BioCtrlPending := nil;
 
1396
    _BioRead := nil;
 
1397
    _BioWrite := nil;
 
1398
    _d2iPKCS12bio := nil;
 
1399
    _PKCS12parse := nil;
 
1400
    _PKCS12free := nil;
 
1401
    _RsaGenerateKey := nil;
 
1402
    _Asn1UtctimeNew := nil;
 
1403
    _Asn1UtctimeFree := nil;
 
1404
    _Asn1IntegerSet := nil;
 
1405
    _i2dX509bio := nil;
 
1406
    _i2dPrivateKeyBio := nil;
 
1407
 
 
1408
    // 3DES functions
 
1409
    _DESsetoddparity := nil;
 
1410
    _DESsetkeychecked := nil;
 
1411
    _DESecbencrypt := nil;
 
1412
    //
 
1413
    _CRYPTOnumlocks := nil;
 
1414
    _CRYPTOsetlockingcallback := nil;
 
1415
  Result := True;
 
1416
end;
 
1417
 
 
1418
function IsSSLloaded: Boolean;
 
1419
begin
 
1420
  Result := SSLLoaded;
 
1421
end;
 
1422
 
 
1423
finalization
 
1424
  DestroySSLInterface;
 
1425
 
 
1426
end.