diff --git a/packages/openssl/src/openssl.pas b/packages/openssl/src/openssl.pas index 275af08da5..f9e86ed4a0 100644 --- a/packages/openssl/src/openssl.pas +++ b/packages/openssl/src/openssl.pas @@ -1,4 +1,4 @@ -unit OpenSSL; +unit openssl; {==============================================================================| | Project : Ararat Synapse | 003.004.001 | @@ -118,6 +118,7 @@ type PEVP_MD = SslPtr; PBIO_METHOD = SslPtr; PBIO = SslPtr; + PASN1_INTEGER = SSlPtr; PRSA = pointer; PDH = pointer; @@ -419,60 +420,49 @@ const SSL_ERROR_WANT_CONNECT = 7; SSL_ERROR_WANT_ACCEPT = 8; - SSL_CTRL_NEED_TMP_RSA = 1; - SSL_CTRL_SET_TMP_RSA = 2; - SSL_CTRL_SET_TMP_DH = 3; - SSL_CTRL_SET_TMP_ECDH = 4; - SSL_CTRL_SET_TMP_RSA_CB = 5; - SSL_CTRL_SET_TMP_DH_CB = 6; - SSL_CTRL_SET_TMP_ECDH_CB = 7; - SSL_CTRL_GET_SESSION_REUSED = 8; - SSL_CTRL_GET_CLIENT_CERT_REQUEST = 9; - SSL_CTRL_GET_NUM_RENEGOTIATIONS = 10; - SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS = 11; - SSL_CTRL_GET_TOTAL_RENEGOTIATIONS = 12; - SSL_CTRL_GET_FLAGS = 13; - SSL_CTRL_EXTRA_CHAIN_CERT = 14; - SSL_CTRL_SET_MSG_CALLBACK = 15; - SSL_CTRL_SET_MSG_CALLBACK_ARG = 16; - { only applies to datagram connections } - SSL_CTRL_SET_MTU = 17; - { Stats } - SSL_CTRL_SESS_NUMBER = 20; - SSL_CTRL_SESS_CONNECT = 21; - SSL_CTRL_SESS_CONNECT_GOOD = 22; - SSL_CTRL_SESS_CONNECT_RENEGOTIATE = 23; - SSL_CTRL_SESS_ACCEPT = 24; - SSL_CTRL_SESS_ACCEPT_GOOD = 25; - SSL_CTRL_SESS_ACCEPT_RENEGOTIATE = 26; - SSL_CTRL_SESS_HIT = 27; - SSL_CTRL_SESS_CB_HIT = 28; - SSL_CTRL_SESS_MISSES = 29; - SSL_CTRL_SESS_TIMEOUTS = 30; - SSL_CTRL_SESS_CACHE_FULL = 31; - SSL_CTRL_OPTIONS = 32; - SSL_CTRL_MODE = 33; - SSL_CTRL_GET_READ_AHEAD = 40; - SSL_CTRL_SET_READ_AHEAD = 41; - SSL_CTRL_SET_SESS_CACHE_SIZE = 42; - SSL_CTRL_GET_SESS_CACHE_SIZE = 43; - SSL_CTRL_SET_SESS_CACHE_MODE = 44; - SSL_CTRL_GET_SESS_CACHE_MODE = 45; - SSL_CTRL_GET_MAX_CERT_LIST = 50; - SSL_CTRL_SET_MAX_CERT_LIST = 51; + SSL_CTRL_NEED_TMP_RSA = 1; + SSL_CTRL_SET_TMP_RSA = 2; + SSL_CTRL_SET_TMP_DH = 3; + SSL_CTRL_SET_TMP_ECDH = 4; + SSL_CTRL_SET_TMP_RSA_CB = 5; + SSL_CTRL_SET_TMP_DH_CB = 6; + SSL_CTRL_SET_TMP_ECDH_CB = 7; + SSL_CTRL_GET_SESSION_REUSED = 8; + SSL_CTRL_GET_CLIENT_CERT_REQUEST = 9; + SSL_CTRL_GET_NUM_RENEGOTIATIONS = 10; + SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS = 11; + SSL_CTRL_GET_TOTAL_RENEGOTIATIONS = 12; + SSL_CTRL_GET_FLAGS = 13; + SSL_CTRL_EXTRA_CHAIN_CERT = 14; + SSL_CTRL_SET_MSG_CALLBACK = 15; + SSL_CTRL_SET_MSG_CALLBACK_ARG = 16; + SSL_CTRL_SET_MTU = 17; + SSL_CTRL_SESS_NUMBER = 20; + SSL_CTRL_SESS_CONNECT = 21; + SSL_CTRL_SESS_CONNECT_GOOD = 22; + SSL_CTRL_SESS_CONNECT_RENEGOTIATE = 23; + SSL_CTRL_SESS_ACCEPT = 24; + SSL_CTRL_SESS_ACCEPT_GOOD = 25; + SSL_CTRL_SESS_ACCEPT_RENEGOTIATE = 26; + SSL_CTRL_SESS_HIT = 27; + SSL_CTRL_SESS_CB_HIT = 28; + SSL_CTRL_SESS_MISSES = 29; + SSL_CTRL_SESS_TIMEOUTS = 30; + SSL_CTRL_SESS_CACHE_FULL = 31; + SSL_CTRL_OPTIONS = 32; + SSL_CTRL_MODE = 33; + SSL_CTRL_GET_READ_AHEAD = 40; + SSL_CTRL_SET_READ_AHEAD = 41; + SSL_CTRL_SET_SESS_CACHE_SIZE = 42; + SSL_CTRL_GET_SESS_CACHE_SIZE = 43; + SSL_CTRL_SET_SESS_CACHE_MODE = 44; + SSL_CTRL_GET_SESS_CACHE_MODE = 45; + SSL_CTRL_GET_MAX_CERT_LIST = 50; + SSL_CTRL_SET_MAX_CERT_LIST = 51; -{* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success - * when just a single record has been written): *} SSL_MODE_ENABLE_PARTIAL_WRITE = 1; -{* Make it possible to retry SSL_write() with changed buffer location - * (buffer contents must stay the same!); this is not the default to avoid - * the misconception that non-blocking SSL_write() behaves like - * non-blocking write(): *} SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER = 2; -{* Never bother the application with retries if the transport - * is blocking: *} SSL_MODE_AUTO_RETRY = 4; -{* Don't attempt to automatically build certificate chain *} SSL_MODE_NO_AUTO_CHAIN = 8; SSL_OP_NO_SSLv2 = $01000000; @@ -750,6 +740,8 @@ var procedure PKCS12free(p12: SslPtr); function Asn1UtctimeNew: PASN1_UTCTIME; procedure Asn1UtctimeFree(a: PASN1_UTCTIME); + function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer; + function Asn1IntegerGet(a: PASN1_INTEGER): integer; function i2dX509bio(b: PBIO; x: PX509): cInt; function i2dPrivateKeyBio(b: PBIO; pkey: PEVP_PKEY): cInt; @@ -900,23 +892,100 @@ var function BIO_s_file: pBIO_METHOD; function BIO_new_file(const filename: PChar; const mode: PChar): pBIO; function BIO_new_mem_buf(buf: pointer; len: integer): pBIO; - - + procedure CRYPTOcleanupAllExData; + procedure OPENSSLaddallalgorithms; function IsSSLloaded: Boolean; -function Islibealoaded: Boolean; -function InitSSLInterface(AVerboseLoading: Boolean = False): Boolean; +function InitSSLInterface: Boolean; overload; function DestroySSLInterface: Boolean; -function InitSSLEAInterface(AVerboseLoading: Boolean = False): Boolean; -function InitLibeaInterface(AVerboseLoading: Boolean = False): Boolean; -function DestroySSLEAInterface: Boolean; -function DestroyLibeaInterface: Boolean; + +// compatibility with old versions. +function Islibealoaded: Boolean; deprecated; +function InitSSLInterface(AVerboseLoading: Boolean): Boolean ; overload; deprecated; +function InitSSLEAInterface(AVerboseLoading: Boolean): Boolean; deprecated; +function InitLibeaInterface(AVerboseLoading: Boolean = false): Boolean; deprecated; +function DestroySSLEAInterface: Boolean; deprecated; +function DestroyLibeaInterface: Boolean; deprecated; + var OpenSSL_unavailable_functions: string; implementation +{ + Compatibility functions +} + +Var + SSLloaded: boolean = false; + LoadVerbose : Boolean; + SSLCS : TRTLCriticalSection; + Locks: Array of TRTLCriticalSection; + + +function Islibealoaded: Boolean; deprecated; +begin + Result:=isSSLLoaded; +end; + +function InitSSLInterface(AVerboseLoading: Boolean): Boolean ; deprecated; + +Var + B : Boolean; + +begin + B:=LoadVerbose; + LoadVerbose:=AVerboseLoading; + try + Result:=InitSSLInterface; + finally + LoadVerbose:=B; + end; +end; + +function InitSSLEAInterface(AVerboseLoading: Boolean): Boolean; deprecated; + +Var + B : Boolean; + +begin + B:=LoadVerbose; + LoadVerbose:=AVerboseLoading; + try + Result:=InitSSLInterface; + finally + LoadVerbose:=B; + end; +end; + +function InitLibeaInterface(AVerboseLoading: Boolean = false): Boolean; deprecated; + +Var + B : Boolean; + +begin + B:=LoadVerbose; + LoadVerbose:=AVerboseLoading; + try + Result:=InitSSLInterface; + finally + LoadVerbose:=B; + end; +end; + +function DestroySSLEAInterface: Boolean; deprecated; + +begin + Result:=DestroySSLInterface; +end; + +function DestroyLibeaInterface: Boolean; deprecated; + +begin + Result:=DestroySSLInterface; +end; + type // libssl.dll TSslGetError = function(s: PSSL; ret_code: cInt):cInt; cdecl; @@ -1003,6 +1072,8 @@ type TPKCS12free = procedure(p12: SslPtr); cdecl; TAsn1UtctimeNew = function: PASN1_UTCTIME; cdecl; TAsn1UtctimeFree = procedure(a: PASN1_UTCTIME); cdecl; + TAsn1IntegerSet = function(a: PASN1_INTEGER; v: integer): integer; cdecl; + TAsn1IntegerGet = function(a: PASN1_INTEGER): integer; cdecl; Ti2dX509bio = function(b: PBIO; x: PX509): cInt; cdecl; Ti2dPrivateKeyBio= function(b: PBIO; pkey: PEVP_PKEY): cInt; cdecl; @@ -1066,6 +1137,8 @@ type // Crypto Functions TSSLeay_version = function(t: cint): PChar; cdecl; + TCRYPTOcleanupAllExData = procedure; cdecl; + TOPENSSLaddallalgorithms = procedure; cdecl; // EVP Functions @@ -1210,6 +1283,8 @@ var _PKCS12free: TPKCS12free = nil; _Asn1UtctimeNew: TAsn1UtctimeNew = nil; _Asn1UtctimeFree: TAsn1UtctimeFree = nil; + _Asn1IntegerSet: TAsn1IntegerSet = nil; + _Asn1IntegerGet: TAsn1IntegerGet = nil; _i2dX509bio: Ti2dX509bio = nil; _i2dPrivateKeyBio: Ti2dPrivateKeyBio = nil; _EVP_enc_null : TEVP_CIPHERFunction = nil; @@ -1290,6 +1365,8 @@ var // Crypto Functions _SSLeay_version: TSSLeay_version = nil; + _CRYPTOcleanupAllExData: TCRYPTOcleanupAllExData = nil; + _OPENSSLaddallalgorithms: TOPENSSLaddallalgorithms = nil; // EVP Functions @@ -1337,14 +1414,12 @@ var _BIO_new_file: TBIO_new_file = nil; _BIO_new_mem_buf: TBIO_new_mem_buf = nil; -var - SSLloaded: boolean = false; - libealoaded: boolean = false; // libssl.dll + function SslGetError(s: PSSL; ret_code: cInt):cInt; begin - if InitSSLEAInterface and Assigned(_SslGetError) then + if InitSSLInterface and Assigned(_SslGetError) then Result := _SslGetError(s, ret_code) else Result := SSL_ERROR_SSL; @@ -1352,7 +1427,7 @@ end; function SslLibraryInit:cInt; begin - if InitSSLEAInterface and Assigned(_SslLibraryInit) then + if InitSSLInterface and Assigned(_SslLibraryInit) then Result := _SslLibraryInit else Result := 1; @@ -1360,13 +1435,13 @@ end; procedure SslLoadErrorStrings; begin - if InitSSLEAInterface and Assigned(_SslLoadErrorStrings) then + if InitSSLInterface and Assigned(_SslLoadErrorStrings) then _SslLoadErrorStrings; end; function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String):cInt; begin - if InitSSLEAInterface and Assigned(_SslCtxSetCipherList) then + if InitSSLInterface and Assigned(_SslCtxSetCipherList) then Result := _SslCtxSetCipherList(arg0, PChar(str)) else Result := 0; @@ -1374,7 +1449,7 @@ end; function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX; begin - if InitSSLEAInterface and Assigned(_SslCtxNew) then + if InitSSLInterface and Assigned(_SslCtxNew) then Result := _SslCtxNew(meth) else Result := nil; @@ -1382,13 +1457,13 @@ end; procedure SslCtxFree(arg0: PSSL_CTX); begin - if InitSSLEAInterface and Assigned(_SslCtxFree) then + if InitSSLInterface and Assigned(_SslCtxFree) then _SslCtxFree(arg0); end; function SslSetFd(s: PSSL; fd: cInt):cInt; begin - if InitSSLEAInterface and Assigned(_SslSetFd) then + if InitSSLInterface and Assigned(_SslSetFd) then Result := _SslSetFd(s, fd) else Result := 0; @@ -1396,7 +1471,7 @@ end; function SslCtrl(ssl: PSSL; cmd: cInt; larg: clong; parg: Pointer): cLong; begin - if InitSSLEAInterface and Assigned(_SslCtrl) then + if InitSSLInterface and Assigned(_SslCtrl) then Result := _SslCtrl(ssl, cmd, larg, parg) else Result := 0; @@ -1405,7 +1480,7 @@ end; function SslCTXCtrl(ctx: PSSL_CTX; cmd: cInt; larg: clong; parg: Pointer ): cLong; begin - if InitSSLEAInterface and Assigned(_SslCTXCtrl) then + if InitSSLInterface and Assigned(_SslCTXCtrl) then Result := _SslCTXCtrl(ctx, cmd, larg, parg) else Result := 0; @@ -1433,7 +1508,7 @@ end; function SslMethodV2:PSSL_METHOD; begin - if InitSSLEAInterface and Assigned(_SslMethodV2) then + if InitSSLInterface and Assigned(_SslMethodV2) then Result := _SslMethodV2 else Result := nil; @@ -1441,7 +1516,7 @@ end; function SslMethodV3:PSSL_METHOD; begin - if InitSSLEAInterface and Assigned(_SslMethodV3) then + if InitSSLInterface and Assigned(_SslMethodV3) then Result := _SslMethodV3 else Result := nil; @@ -1449,7 +1524,7 @@ end; function SslMethodTLSV1:PSSL_METHOD; begin - if InitSSLEAInterface and Assigned(_SslMethodTLSV1) then + if InitSSLInterface and Assigned(_SslMethodTLSV1) then Result := _SslMethodTLSV1 else Result := nil; @@ -1457,7 +1532,7 @@ end; function SslMethodV23:PSSL_METHOD; begin - if InitSSLEAInterface and Assigned(_SslMethodV23) then + if InitSSLInterface and Assigned(_SslMethodV23) then Result := _SslMethodV23 else Result := nil; @@ -1465,7 +1540,7 @@ end; function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):cInt; begin - if InitSSLEAInterface and Assigned(_SslCtxUsePrivateKey) then + if InitSSLInterface and Assigned(_SslCtxUsePrivateKey) then Result := _SslCtxUsePrivateKey(ctx, pkey) else Result := 0; @@ -1473,7 +1548,7 @@ end; function SslCtxUsePrivateKeyASN1(pk: cInt; ctx: PSSL_CTX; d: String; len: cLong):cInt; begin - if InitSSLEAInterface and Assigned(_SslCtxUsePrivateKeyASN1) then + if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyASN1) then Result := _SslCtxUsePrivateKeyASN1(pk, ctx, Sslptr(d), len) else Result := 0; @@ -1481,7 +1556,7 @@ end; function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: cInt):cInt; begin - if InitSSLEAInterface and Assigned(_SslCtxUsePrivateKeyFile) then + if InitSSLInterface and Assigned(_SslCtxUsePrivateKeyFile) then Result := _SslCtxUsePrivateKeyFile(ctx, PChar(_file), _type) else Result := 0; @@ -1489,7 +1564,7 @@ end; function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):cInt; begin - if InitSSLEAInterface and Assigned(_SslCtxUseCertificate) then + if InitSSLInterface and Assigned(_SslCtxUseCertificate) then Result := _SslCtxUseCertificate(ctx, x) else Result := 0; @@ -1497,7 +1572,7 @@ end; function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: cLong; d: String):cInt; begin - if InitSSLEAInterface and Assigned(_SslCtxUseCertificateASN1) then + if InitSSLInterface and Assigned(_SslCtxUseCertificateASN1) then Result := _SslCtxUseCertificateASN1(ctx, len, SslPtr(d)) else Result := 0; @@ -1505,7 +1580,7 @@ end; function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: String; _type: cInt):cInt; begin - if InitSSLEAInterface and Assigned(_SslCtxUseCertificateFile) then + if InitSSLInterface and Assigned(_SslCtxUseCertificateFile) then Result := _SslCtxUseCertificateFile(ctx, PChar(_file), _type) else Result := 0; @@ -1513,7 +1588,7 @@ end; function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):cInt; begin - if InitSSLEAInterface and Assigned(_SslCtxUseCertificateChainFile) then + if InitSSLInterface and Assigned(_SslCtxUseCertificateChainFile) then Result := _SslCtxUseCertificateChainFile(ctx, PChar(_file)) else Result := 0; @@ -1521,7 +1596,7 @@ end; function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):cInt; begin - if InitSSLEAInterface and Assigned(_SslCtxCheckPrivateKeyFile) then + if InitSSLInterface and Assigned(_SslCtxCheckPrivateKeyFile) then Result := _SslCtxCheckPrivateKeyFile(ctx) else Result := 0; @@ -1529,19 +1604,19 @@ end; procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb); begin - if InitSSLEAInterface and Assigned(_SslCtxSetDefaultPasswdCb) then + if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCb) then _SslCtxSetDefaultPasswdCb(ctx, cb); end; procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr); begin - if InitSSLEAInterface and Assigned(_SslCtxSetDefaultPasswdCbUserdata) then + if InitSSLInterface and Assigned(_SslCtxSetDefaultPasswdCbUserdata) then _SslCtxSetDefaultPasswdCbUserdata(ctx, u); end; function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: String; const CApath: String):cInt; begin - if InitSSLEAInterface and Assigned(_SslCtxLoadVerifyLocations) then + if InitSSLInterface and Assigned(_SslCtxLoadVerifyLocations) then Result := _SslCtxLoadVerifyLocations(ctx, SslPtr(CAfile), SslPtr(CApath)) else Result := 0; @@ -1549,7 +1624,7 @@ end; function SslNew(ctx: PSSL_CTX):PSSL; begin - if InitSSLEAInterface and Assigned(_SslNew) then + if InitSSLInterface and Assigned(_SslNew) then Result := _SslNew(ctx) else Result := nil; @@ -1557,13 +1632,13 @@ end; procedure SslFree(ssl: PSSL); begin - if InitSSLEAInterface and Assigned(_SslFree) then + if InitSSLInterface and Assigned(_SslFree) then _SslFree(ssl); end; function SslAccept(ssl: PSSL):cInt; begin - if InitSSLEAInterface and Assigned(_SslAccept) then + if InitSSLInterface and Assigned(_SslAccept) then Result := _SslAccept(ssl) else Result := -1; @@ -1571,7 +1646,7 @@ end; function SslConnect(ssl: PSSL):cInt; begin - if InitSSLEAInterface and Assigned(_SslConnect) then + if InitSSLInterface and Assigned(_SslConnect) then Result := _SslConnect(ssl) else Result := -1; @@ -1579,7 +1654,7 @@ end; function SslShutdown(ssl: PSSL):cInt; begin - if InitSSLEAInterface and Assigned(_SslShutdown) then + if InitSSLInterface and Assigned(_SslShutdown) then Result := _SslShutdown(ssl) else Result := -1; @@ -1587,7 +1662,7 @@ end; function SslRead(ssl: PSSL; buf: SslPtr; num: cInt):cInt; begin - if InitSSLEAInterface and Assigned(_SslRead) then + if InitSSLInterface and Assigned(_SslRead) then Result := _SslRead(ssl, PChar(buf), num) else Result := -1; @@ -1595,7 +1670,7 @@ end; function SslPeek(ssl: PSSL; buf: SslPtr; num: cInt):cInt; begin - if InitSSLEAInterface and Assigned(_SslPeek) then + if InitSSLInterface and Assigned(_SslPeek) then Result := _SslPeek(ssl, PChar(buf), num) else Result := -1; @@ -1603,7 +1678,7 @@ end; function SslWrite(ssl: PSSL; buf: SslPtr; num: cInt):cInt; begin - if InitSSLEAInterface and Assigned(_SslWrite) then + if InitSSLInterface and Assigned(_SslWrite) then Result := _SslWrite(ssl, PChar(buf), num) else Result := -1; @@ -1611,7 +1686,7 @@ end; function SslPending(ssl: PSSL):cInt; begin - if InitSSLEAInterface and Assigned(_SslPending) then + if InitSSLInterface and Assigned(_SslPending) then Result := _SslPending(ssl) else Result := 0; @@ -1620,7 +1695,7 @@ end; //function SslGetVersion(ssl: PSSL):PChar; function SslGetVersion(ssl: PSSL):String; begin - if InitSSLEAInterface and Assigned(_SslGetVersion) then + if InitSSLInterface and Assigned(_SslGetVersion) then Result := _SslGetVersion(ssl) else Result := ''; @@ -1628,7 +1703,7 @@ end; function SslGetPeerCertificate(ssl: PSSL):PX509; begin - if InitSSLEAInterface and Assigned(_SslGetPeerCertificate) then + if InitSSLInterface and Assigned(_SslGetPeerCertificate) then Result := _SslGetPeerCertificate(ssl) else Result := nil; @@ -1636,13 +1711,13 @@ end; procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: cInt; arg2: PFunction); begin - if InitSSLEAInterface and Assigned(_SslCtxSetVerify) then + if InitSSLInterface and Assigned(_SslCtxSetVerify) then _SslCtxSetVerify(ctx, mode, @arg2); end; function SSLGetCurrentCipher(s: PSSL):SslPtr; begin - if InitSSLEAInterface and Assigned(_SSLGetCurrentCipher) then + if InitSSLInterface and Assigned(_SSLGetCurrentCipher) then {$IFDEF CIL} {$ELSE} Result := _SSLGetCurrentCipher(s) @@ -1653,7 +1728,7 @@ end; function SSLCipherGetName(c: SslPtr):String; begin - if InitSSLEAInterface and Assigned(_SSLCipherGetName) then + if InitSSLInterface and Assigned(_SSLCipherGetName) then Result := _SSLCipherGetName(c) else Result := ''; @@ -1661,7 +1736,7 @@ end; function SSLCipherGetBits(c: SslPtr; var alg_bits: cInt):cInt; begin - if InitSSLEAInterface and Assigned(_SSLCipherGetBits) then + if InitSSLInterface and Assigned(_SSLCipherGetBits) then Result := _SSLCipherGetBits(c, @alg_bits) else Result := 0; @@ -1669,7 +1744,7 @@ end; function SSLGetVerifyResult(ssl: PSSL):cLong; begin - if InitSSLEAInterface and Assigned(_SSLGetVerifyResult) then + if InitSSLInterface and Assigned(_SSLGetVerifyResult) then Result := _SSLGetVerifyResult(ssl) else Result := X509_V_ERR_APPLICATION_VERIFICATION; @@ -1679,7 +1754,7 @@ end; // libeay.dll function SSLeayversion(t: cInt): string; begin - if InitlibeaInterface and Assigned(_SSLeayversion) then + if InitSSLInterface and Assigned(_SSLeayversion) then Result := PChar(_SSLeayversion(t)) else Result := ''; @@ -1687,13 +1762,13 @@ end; procedure ERR_load_crypto_strings; Begin - if InitlibeaInterface and Assigned(_ERR_load_crypto_strings) then + if InitSSLInterface and Assigned(_ERR_load_crypto_strings) then _ERR_load_crypto_strings; end; function X509New: PX509; begin - if InitlibeaInterface and Assigned(_X509New) then + if InitSSLInterface and Assigned(_X509New) then Result := _X509New else Result := nil; @@ -1701,13 +1776,13 @@ end; procedure X509Free(x: PX509); begin - if InitlibeaInterface and Assigned(_X509Free) then + if InitSSLInterface and Assigned(_X509Free) then _X509Free(x); end; function X509NameOneline(a: PX509_NAME; var buf: String; size: cInt):String; begin - if InitlibeaInterface and Assigned(_X509NameOneline) then + if InitSSLInterface and Assigned(_X509NameOneline) then Result := _X509NameOneline(a, PChar(buf),size) else Result := ''; @@ -1715,7 +1790,7 @@ end; function X509GetSubjectName(a: PX509):PX509_NAME; begin - if InitlibeaInterface and Assigned(_X509GetSubjectName) then + if InitSSLInterface and Assigned(_X509GetSubjectName) then Result := _X509GetSubjectName(a) else Result := nil; @@ -1723,7 +1798,7 @@ end; function X509GetIssuerName(a: PX509):PX509_NAME; begin - if InitlibeaInterface and Assigned(_X509GetIssuerName) then + if InitSSLInterface and Assigned(_X509GetIssuerName) then Result := _X509GetIssuerName(a) else Result := nil; @@ -1731,7 +1806,7 @@ end; function X509NameHash(x: PX509_NAME):cuLong; begin - if InitlibeaInterface and Assigned(_X509NameHash) then + if InitSSLInterface and Assigned(_X509NameHash) then Result := _X509NameHash(x) else Result := 0; @@ -1739,7 +1814,7 @@ end; function X509Digest(data: PX509; _type: PEVP_MD; md: String; var len: cInt):cInt; begin - if InitlibeaInterface and Assigned(_X509Digest) then + if InitSSLInterface and Assigned(_X509Digest) then Result := _X509Digest(data, _type, PChar(md), @len) else Result := 0; @@ -1747,7 +1822,7 @@ end; function EvpPkeyNew: PEVP_PKEY; begin - if InitlibeaInterface and Assigned(_EvpPkeyNew) then + if InitSSLInterface and Assigned(_EvpPkeyNew) then Result := _EvpPkeyNew else Result := nil; @@ -1755,20 +1830,20 @@ end; procedure EvpPkeyFree(pk: PEVP_PKEY); begin - if InitlibeaInterface and Assigned(_EvpPkeyFree) then + if InitSSLInterface and Assigned(_EvpPkeyFree) then _EvpPkeyFree(pk); end; procedure ErrErrorString(e: cInt; var buf: string; len: cInt); begin - if InitlibeaInterface and Assigned(_ErrErrorString) then + if InitSSLInterface and Assigned(_ErrErrorString) then _ErrErrorString(e, Pointer(buf), len); buf := PChar(Buf); end; function ErrGetError: cInt; begin - if InitlibeaInterface and Assigned(_ErrGetError) then + if InitSSLInterface and Assigned(_ErrGetError) then Result := _ErrGetError else Result := SSL_ERROR_SSL; @@ -1776,37 +1851,37 @@ end; procedure ErrClearError; begin - if InitlibeaInterface and Assigned(_ErrClearError) then + if InitSSLInterface and Assigned(_ErrClearError) then _ErrClearError; end; procedure ErrFreeStrings; begin - if InitlibeaInterface and Assigned(_ErrFreeStrings) then + if InitSSLInterface and Assigned(_ErrFreeStrings) then _ErrFreeStrings; end; procedure ErrRemoveState(pid: cInt); begin - if InitlibeaInterface and Assigned(_ErrRemoveState) then + if InitSSLInterface and Assigned(_ErrRemoveState) then _ErrRemoveState(pid); end; procedure EVPcleanup; begin - if InitlibeaInterface and Assigned(_EVPcleanup) then + if InitSSLInterface and Assigned(_EVPcleanup) then _EVPcleanup; end; procedure RandScreen; begin - if InitlibeaInterface and Assigned(_RandScreen) then + if InitSSLInterface and Assigned(_RandScreen) then _RandScreen; end; function BioNew(b: PBIO_METHOD): PBIO; begin - if InitlibeaInterface and Assigned(_BioNew) then + if InitSSLInterface and Assigned(_BioNew) then Result := _BioNew(b) else Result := nil; @@ -1814,13 +1889,13 @@ end; procedure BioFreeAll(b: PBIO); begin - if InitlibeaInterface and Assigned(_BioFreeAll) then + if InitSSLInterface and Assigned(_BioFreeAll) then _BioFreeAll(b); end; function BioSMem: PBIO_METHOD; begin - if InitlibeaInterface and Assigned(_BioSMem) then + if InitSSLInterface and Assigned(_BioSMem) then Result := _BioSMem else Result := nil; @@ -1829,7 +1904,7 @@ end; function BioCtrlPending(b: PBIO): cInt; begin - if InitlibeaInterface and Assigned(_BioCtrlPending) then + if InitSSLInterface and Assigned(_BioCtrlPending) then Result := _BioCtrlPending(b) else Result := 0; @@ -1837,7 +1912,7 @@ end; function BioRead(b: PBIO; var Buf: String; Len: cInt): cInt; begin - if InitlibeaInterface and Assigned(_BioRead) then + if InitSSLInterface and Assigned(_BioRead) then Result := _BioRead(b, PChar(Buf), Len) else Result := -2; @@ -1846,7 +1921,7 @@ end; //function BioWrite(b: PBIO; Buf: PChar; Len: cInt): cInt; function BioWrite(b: PBIO; Buf: String; Len: cInt): cInt; begin - if InitlibeaInterface and Assigned(_BioWrite) then + if InitSSLInterface and Assigned(_BioWrite) then Result := _BioWrite(b, PChar(Buf), Len) else Result := -2; @@ -1854,7 +1929,7 @@ end; function X509print(b: PBIO; a: PX509): cInt; begin - if InitlibeaInterface and Assigned(_X509print) then + if InitSSLInterface and Assigned(_X509print) then Result := _X509print(b, a) else Result := 0; @@ -1862,7 +1937,7 @@ end; function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr; begin - if InitlibeaInterface and Assigned(_d2iPKCS12bio) then + if InitSSLInterface and Assigned(_d2iPKCS12bio) then Result := _d2iPKCS12bio(b, Pkcs12) else Result := nil; @@ -1870,7 +1945,7 @@ end; function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): cInt; begin - if InitlibeaInterface and Assigned(_PKCS12parse) then + if InitSSLInterface and Assigned(_PKCS12parse) then Result := _PKCS12parse(p12, SslPtr(pass), pkey, cert, ca) else Result := 0; @@ -1878,13 +1953,13 @@ end; procedure PKCS12free(p12: SslPtr); begin - if InitlibeaInterface and Assigned(_PKCS12free) then + if InitSSLInterface and Assigned(_PKCS12free) then _PKCS12free(p12); end; function EvpPkeyAssign(pkey: PEVP_PKEY; _type: cInt; key: Prsa): cInt; begin - if InitlibeaInterface and Assigned(_EvpPkeyAssign) then + if InitSSLInterface and Assigned(_EvpPkeyAssign) then Result := _EvpPkeyAssign(pkey, _type, key) else Result := 0; @@ -1892,7 +1967,7 @@ end; function X509SetVersion(x: PX509; version: cInt): cInt; begin - if InitlibeaInterface and Assigned(_X509SetVersion) then + if InitSSLInterface and Assigned(_X509SetVersion) then Result := _X509SetVersion(x, version) else Result := 0; @@ -1900,7 +1975,7 @@ end; function X509SetPubkey(x: PX509; pkey: PEVP_PKEY): cInt; begin - if InitlibeaInterface and Assigned(_X509SetPubkey) then + if InitSSLInterface and Assigned(_X509SetPubkey) then Result := _X509SetPubkey(x, pkey) else Result := 0; @@ -1908,7 +1983,7 @@ end; function X509SetIssuerName(x: PX509; name: PX509_NAME): cInt; begin - if InitlibeaInterface and Assigned(_X509SetIssuerName) then + if InitSSLInterface and Assigned(_X509SetIssuerName) then Result := _X509SetIssuerName(x, name) else Result := 0; @@ -1917,7 +1992,7 @@ end; function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: cInt; bytes: string; len, loc, _set: cInt): cInt; begin - if InitlibeaInterface and Assigned(_X509NameAddEntryByTxt) then + if InitSSLInterface and Assigned(_X509NameAddEntryByTxt) then Result := _X509NameAddEntryByTxt(name, PChar(field), _type, PChar(Bytes), len, loc, _set) else Result := 0; @@ -1925,7 +2000,7 @@ end; function X509Sign(x: PX509; pkey: PEVP_PKEY; const md: PEVP_MD): cInt; begin - if InitlibeaInterface and Assigned(_X509Sign) then + if InitSSLInterface and Assigned(_X509Sign) then Result := _X509Sign(x, pkey, md) else Result := 0; @@ -1933,7 +2008,7 @@ end; function Asn1UtctimeNew: PASN1_UTCTIME; begin - if InitlibeaInterface and Assigned(_Asn1UtctimeNew) then + if InitSSLInterface and Assigned(_Asn1UtctimeNew) then Result := _Asn1UtctimeNew else Result := nil; @@ -1941,13 +2016,29 @@ end; procedure Asn1UtctimeFree(a: PASN1_UTCTIME); begin - if InitlibeaInterface and Assigned(_Asn1UtctimeFree) then + if InitSSLInterface and Assigned(_Asn1UtctimeFree) then _Asn1UtctimeFree(a); end; +function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer; +begin + if InitSSLInterface and Assigned(_Asn1IntegerSet) then + Result := _Asn1IntegerSet(a, v) + else + Result := 0; +end; + +function Asn1IntegerGet(a: PASN1_INTEGER): integer; +begin + if InitSSLInterface and Assigned(_Asn1IntegerGet) then + Result := _Asn1IntegerGet(a) + else + Result := 0; +end; + function X509GmtimeAdj(s: PASN1_UTCTIME; adj: cInt): PASN1_UTCTIME; begin - if InitlibeaInterface and Assigned(_X509GmtimeAdj) then + if InitSSLInterface and Assigned(_X509GmtimeAdj) then Result := _X509GmtimeAdj(s, adj) else Result := nil; @@ -1955,7 +2046,7 @@ end; function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): cInt; begin - if InitlibeaInterface and Assigned(_X509SetNotBefore) then + if InitSSLInterface and Assigned(_X509SetNotBefore) then Result := _X509SetNotBefore(x, tm) else Result := 0; @@ -1963,7 +2054,7 @@ end; function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): cInt; begin - if InitlibeaInterface and Assigned(_X509SetNotAfter) then + if InitSSLInterface and Assigned(_X509SetNotAfter) then Result := _X509SetNotAfter(x, tm) else Result := 0; @@ -1971,7 +2062,7 @@ end; function i2dX509bio(b: PBIO; x: PX509): cInt; begin - if InitlibeaInterface and Assigned(_i2dX509bio) then + if InitSSLInterface and Assigned(_i2dX509bio) then Result := _i2dX509bio(b, x) else Result := 0; @@ -1979,7 +2070,7 @@ end; function i2dPrivateKeyBio(b: PBIO; pkey: PEVP_PKEY): cInt; begin - if InitlibeaInterface and Assigned(_i2dPrivateKeyBio) then + if InitSSLInterface and Assigned(_i2dPrivateKeyBio) then Result := _i2dPrivateKeyBio(b, pkey) else Result := 0; @@ -1987,7 +2078,7 @@ end; function EvpGetDigestByName(Name: String): PEVP_MD; begin - if InitlibeaInterface and Assigned(_EvpGetDigestByName) then + if InitSSLInterface and Assigned(_EvpGetDigestByName) then Result := _EvpGetDigestByName(PChar(Name)) else Result := nil; @@ -1995,7 +2086,7 @@ end; function X509GetSerialNumber(x: PX509): PASN1_cInt; begin - if InitlibeaInterface and Assigned(_X509GetSerialNumber) then + if InitSSLInterface and Assigned(_X509GetSerialNumber) then Result := _X509GetSerialNumber(x) else Result := nil; @@ -2004,7 +2095,7 @@ end; // 3DES functions procedure DESsetoddparity(Key: des_cblock); begin - if InitlibeaInterface and Assigned(_DESsetoddparity) then + if InitSSLInterface and Assigned(_DESsetoddparity) then _DESsetoddparity(Key); end; @@ -2018,7 +2109,7 @@ end; function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): cInt; begin - if InitlibeaInterface and Assigned(_DESsetkeychecked) then + if InitSSLInterface and Assigned(_DESsetkeychecked) then Result := _DESsetkeychecked(key, schedule) else Result := -1; @@ -2026,14 +2117,14 @@ end; procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: cInt); begin - if InitlibeaInterface and Assigned(_DESecbencrypt) then + if InitSSLInterface and Assigned(_DESecbencrypt) then _DESecbencrypt(Input, output, ks, enc); end; // RAND functions function RAND_set_rand_method(const meth: PRAND_METHOD): cint; begin - if InitlibeaInterface and Assigned(_RAND_set_rand_method) then + if InitSSLInterface and Assigned(_RAND_set_rand_method) then Result := _RAND_set_rand_method(meth) else Result := -1; @@ -2041,7 +2132,7 @@ end; function RAND_get_rand_method: PRAND_METHOD; begin - if InitlibeaInterface and Assigned(_RAND_get_rand_method) then + if InitSSLInterface and Assigned(_RAND_get_rand_method) then Result := _RAND_get_rand_method() else Result := nil; @@ -2049,7 +2140,7 @@ end; function RAND_SSLeay: PRAND_METHOD; begin - if InitlibeaInterface and Assigned(_RAND_SSLeay) then + if InitSSLInterface and Assigned(_RAND_SSLeay) then Result := _RAND_SSLeay() else Result := nil; @@ -2057,13 +2148,13 @@ end; procedure RAND_cleanup; begin - if InitlibeaInterface and Assigned(_RAND_cleanup) then + if InitSSLInterface and Assigned(_RAND_cleanup) then _RAND_cleanup(); end; function RAND_bytes(buf: PByte; num: cint): cint; begin - if InitlibeaInterface and Assigned(_RAND_bytes) then + if InitSSLInterface and Assigned(_RAND_bytes) then Result := _RAND_bytes(buf, num) else Result := -1; @@ -2071,7 +2162,7 @@ end; function RAND_pseudo_bytes(buf: PByte; num: cint): cint; begin - if InitlibeaInterface and Assigned(_RAND_pseudo_bytes) then + if InitSSLInterface and Assigned(_RAND_pseudo_bytes) then Result := _RAND_pseudo_bytes(buf, num) else Result := -1; @@ -2079,19 +2170,19 @@ end; procedure RAND_seed(const buf: Pointer; num: cint); begin - if InitlibeaInterface and Assigned(_RAND_seed) then + if InitSSLInterface and Assigned(_RAND_seed) then _RAND_seed(buf, num); end; procedure RAND_add(const buf: Pointer; num: cint; entropy: cdouble); begin - if InitlibeaInterface and Assigned(_RAND_add) then + if InitSSLInterface and Assigned(_RAND_add) then _RAND_add(buf, num, entropy); end; function RAND_load_file(const file_name: PChar; max_bytes: clong): cint; begin - if InitlibeaInterface and Assigned(_RAND_load_file) then + if InitSSLInterface and Assigned(_RAND_load_file) then Result := _RAND_load_file(file_name, max_bytes) else Result := -1; @@ -2099,7 +2190,7 @@ end; function RAND_write_file(const file_name: PChar): cint; begin - if InitlibeaInterface and Assigned(_RAND_write_file) then + if InitSSLInterface and Assigned(_RAND_write_file) then Result := _RAND_write_file(file_name) else Result := -1; @@ -2107,7 +2198,7 @@ end; function RAND_file_name(file_name: PChar; num: csize_t): PChar; begin - if InitlibeaInterface and Assigned(_RAND_file_name) then + if InitSSLInterface and Assigned(_RAND_file_name) then Result := _RAND_file_name(file_name, num) else Result := nil; @@ -2115,7 +2206,7 @@ end; function RAND_status: cint; begin - if InitlibeaInterface and Assigned(_RAND_status) then + if InitSSLInterface and Assigned(_RAND_status) then Result := _RAND_status() else Result := -1; @@ -2123,7 +2214,7 @@ end; function RAND_query_egd_bytes(const path: PChar; buf: PByte; bytes: cint): cint; begin - if InitlibeaInterface and Assigned(_RAND_query_egd_bytes) then + if InitSSLInterface and Assigned(_RAND_query_egd_bytes) then Result := _RAND_query_egd_bytes(path, buf, bytes) else Result := -1; @@ -2131,7 +2222,7 @@ end; function RAND_egd(const path: PChar): cint; begin - if InitlibeaInterface and Assigned(_RAND_egd) then + if InitSSLInterface and Assigned(_RAND_egd) then Result := _RAND_egd(path) else Result := -1; @@ -2139,7 +2230,7 @@ end; function RAND_egd_bytes(const path: PChar; bytes: cint): cint; begin - if InitlibeaInterface and Assigned(_RAND_egd_bytes) then + if InitSSLInterface and Assigned(_RAND_egd_bytes) then Result := _RAND_egd_bytes(path, bytes) else Result := -1; @@ -2147,13 +2238,13 @@ end; procedure ERR_load_RAND_strings; begin - if InitlibeaInterface and Assigned(_ERR_load_RAND_strings) then + if InitSSLInterface and Assigned(_ERR_load_RAND_strings) then _ERR_load_RAND_strings(); end; function RAND_poll: cint; begin - if InitlibeaInterface and Assigned(_RAND_poll) then + if InitSSLInterface and Assigned(_RAND_poll) then Result := _RAND_poll() else Result := -1; @@ -2163,7 +2254,7 @@ end; function RSA_new(): PRSA; begin - if InitlibeaInterface and Assigned(_RSA_new) then + if InitSSLInterface and Assigned(_RSA_new) then Result := _RSA_new() else Result := nil; @@ -2171,7 +2262,7 @@ end; function RSA_new_method(method: PENGINE): PRSA; begin - if InitlibeaInterface and Assigned(_RSA_new_method) then + if InitSSLInterface and Assigned(_RSA_new_method) then Result := _RSA_new_method(method) else Result := nil; @@ -2179,7 +2270,7 @@ end; function RSA_size(arsa: PRSA): cint; begin - if InitlibeaInterface and Assigned(_RSA_size) then + if InitSSLInterface and Assigned(_RSA_size) then Result := _RSA_size(arsa) else Result := -1; @@ -2187,7 +2278,7 @@ end; function RsaGenerateKey(bits, e: cInt; callback: PFunction; cb_arg: SslPtr): PRSA; begin - if InitlibeaInterface and Assigned(_RsaGenerateKey) then + if InitSSLInterface and Assigned(_RsaGenerateKey) then Result := _RsaGenerateKey(bits, e, callback, cb_arg) else Result := nil; @@ -2195,7 +2286,7 @@ end; function RSA_generate_key_ex(arsa: PRSA; bits: cInt; e: PBIGNUM; cb: PBN_GENCB): PRSA; begin - if InitlibeaInterface and Assigned(_RSA_generate_key_ex) then + if InitSSLInterface and Assigned(_RSA_generate_key_ex) then Result := _RSA_generate_key_ex(arsa, bits, e, cb) else Result := nil; @@ -2203,7 +2294,7 @@ end; function RSA_check_key(arsa: PRSA): cint; begin - if InitlibeaInterface and Assigned(_RSA_check_key) then + if InitSSLInterface and Assigned(_RSA_check_key) then Result := _RSA_check_key(arsa) else Result := -1; @@ -2211,7 +2302,7 @@ end; function RSA_public_encrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint; begin - if InitlibeaInterface and Assigned(_RSA_public_encrypt) then + if InitSSLInterface and Assigned(_RSA_public_encrypt) then Result := _RSA_public_encrypt(flen, from_buf, to_buf, arsa, padding) else Result := -1; @@ -2219,7 +2310,7 @@ end; function RSA_private_encrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint; begin - if InitlibeaInterface and Assigned(_RSA_private_encrypt) then + if InitSSLInterface and Assigned(_RSA_private_encrypt) then Result := _RSA_private_encrypt(flen, from_buf, to_buf, arsa, padding) else Result := -1; @@ -2227,7 +2318,7 @@ end; function RSA_public_decrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint; begin - if InitlibeaInterface and Assigned(_RSA_public_decrypt) then + if InitSSLInterface and Assigned(_RSA_public_decrypt) then Result := _RSA_public_decrypt(flen, from_buf, to_buf, arsa, padding) else Result := -1; @@ -2235,7 +2326,7 @@ end; function RSA_private_decrypt(flen: cint; from_buf, to_buf: PByte; arsa: PRSA; padding: cint): cint; begin - if InitlibeaInterface and Assigned(_RSA_private_decrypt) then + if InitSSLInterface and Assigned(_RSA_private_decrypt) then Result := _RSA_private_decrypt(flen, from_buf, to_buf, arsa, padding) else Result := -1; @@ -2243,13 +2334,13 @@ end; procedure RSA_free(arsa: PRSA); begin - if InitlibeaInterface and Assigned(_RSA_free) then + if InitSSLInterface and Assigned(_RSA_free) then _RSA_free(arsa); end; function RSA_flags(arsa: PRSA): Integer; begin - if InitlibeaInterface and Assigned(_RSA_flags) then + if InitSSLInterface and Assigned(_RSA_flags) then Result := _RSA_flags(arsa) else Result := -1; @@ -2257,13 +2348,13 @@ end; procedure RSA_set_default_method(method: PRSA_METHOD); begin - if InitlibeaInterface and Assigned(_RSA_set_default_method) then + if InitSSLInterface and Assigned(_RSA_set_default_method) then _RSA_set_default_method(method); end; function RSA_get_default_method: PRSA_METHOD; begin - if InitlibeaInterface and Assigned(_RSA_get_default_method) then + if InitSSLInterface and Assigned(_RSA_get_default_method) then Result := _RSA_get_default_method() else Result := nil; @@ -2271,7 +2362,7 @@ end; function RSA_get_method(arsa: PRSA): PRSA_METHOD; begin - if InitlibeaInterface and Assigned(_RSA_get_method) then + if InitSSLInterface and Assigned(_RSA_get_method) then Result := _RSA_get_method(arsa) else Result := nil; @@ -2279,7 +2370,7 @@ end; function RSA_set_method(arsa: PRSA; method: PRSA_METHOD): PRSA_METHOD; begin - if InitlibeaInterface and Assigned(_RSA_set_method) then + if InitSSLInterface and Assigned(_RSA_set_method) then Result := _RSA_set_method(arsa, method) else Result := nil; @@ -2287,7 +2378,7 @@ end; function d2i_RSAPublicKey(arsa: PPRSA; pp: PPByte; len: cint): PRSA; begin - if InitlibeaInterface and Assigned(_d2i_RSAPublicKey) then + if InitSSLInterface and Assigned(_d2i_RSAPublicKey) then Result := _d2i_RSAPublicKey(arsa, pp, len) else Result := nil; @@ -2295,7 +2386,7 @@ end; function i2d_RSAPublicKey(arsa: PRSA; pp: PPByte): cint; begin - if InitlibeaInterface and Assigned(_i2d_RSAPublicKey) then + if InitSSLInterface and Assigned(_i2d_RSAPublicKey) then Result := _i2d_RSAPublicKey(arsa, pp) else Result := -1; @@ -2303,7 +2394,7 @@ end; function d2i_RSAPrivateKey(arsa: PPRSA; pp: PPByte; len: cint): PRSA; begin - if InitlibeaInterface and Assigned(_d2i_RSAPrivateKey) then + if InitSSLInterface and Assigned(_d2i_RSAPrivateKey) then Result := _d2i_RSAPrivateKey(arsa, pp, len) else Result := nil; @@ -2311,7 +2402,7 @@ end; function i2d_RSAPrivateKey(arsa: PRSA; pp: PPByte): cint; begin - if InitlibeaInterface and Assigned(_i2d_RSAPrivateKey) then + if InitSSLInterface and Assigned(_i2d_RSAPrivateKey) then Result := _i2d_RSAPrivateKey(arsa, pp) else Result := -1; @@ -2321,7 +2412,7 @@ end; function Err_Error_String(e: cInt; buf: PChar): PChar; begin - if InitlibeaInterface and Assigned(_Err_Error_String) then + if InitSSLInterface and Assigned(_Err_Error_String) then Result := _Err_Error_String(e, buf) else Result := nil; @@ -2331,7 +2422,7 @@ end; function SSLeay_version(t: cint): PChar; begin - if InitlibeaInterface and Assigned(_SSLeay_version) then + if InitSSLInterface and Assigned(_SSLeay_version) then Result := _SSLeay_version(t) else Result := nil; @@ -2341,7 +2432,7 @@ end; function EVP_des_ede3_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_des_ede3_cbc) then + if InitSSLInterface and Assigned(_EVP_des_ede3_cbc) then Result := _EVP_des_ede3_cbc() else Result := Nil; @@ -2349,7 +2440,7 @@ end; function EVP_enc_null: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_enc_null) then + if InitSSLInterface and Assigned(_EVP_enc_null) then Result := _EVP_enc_null() else Result := Nil; @@ -2357,7 +2448,7 @@ end; function EVP_rc2_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_rc2_cbc) then + if InitSSLInterface and Assigned(_EVP_rc2_cbc) then Result := _EVP_rc2_cbc() else Result := Nil; @@ -2365,7 +2456,7 @@ end; function EVP_rc2_40_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_rc2_40_cbc) then + if InitSSLInterface and Assigned(_EVP_rc2_40_cbc) then Result := _EVP_rc2_40_cbc() else Result := Nil; @@ -2373,7 +2464,7 @@ end; function EVP_rc2_64_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_rc2_64_cbc) then + if InitSSLInterface and Assigned(_EVP_rc2_64_cbc) then Result := _EVP_rc2_64_cbc() else Result := Nil; @@ -2381,7 +2472,7 @@ end; function EVP_rc4: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_rc4) then + if InitSSLInterface and Assigned(_EVP_rc4) then Result := _EVP_rc4() else Result := Nil; @@ -2389,7 +2480,7 @@ end; function EVP_rc4_40: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_rc4_40) then + if InitSSLInterface and Assigned(_EVP_rc4_40) then Result := _EVP_rc4_40() else Result := Nil; @@ -2397,7 +2488,7 @@ end; function EVP_des_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_des_cbc) then + if InitSSLInterface and Assigned(_EVP_des_cbc) then Result := _EVP_des_cbc() else Result := Nil; @@ -2405,7 +2496,7 @@ end; function EVP_aes_128_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_aes_128_cbc) then + if InitSSLInterface and Assigned(_EVP_aes_128_cbc) then Result := _EVP_aes_128_cbc() else Result := Nil; @@ -2413,7 +2504,7 @@ end; function EVP_aes_192_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_aes_192_cbc) then + if InitSSLInterface and Assigned(_EVP_aes_192_cbc) then Result := _EVP_aes_192_cbc() else Result := Nil; @@ -2421,7 +2512,7 @@ end; function EVP_aes_256_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_aes_256_cbc) then + if InitSSLInterface and Assigned(_EVP_aes_256_cbc) then Result := _EVP_aes_256_cbc() else Result := Nil; @@ -2429,7 +2520,7 @@ end; function EVP_aes_128_cfb8: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_aes_128_cfb8) then + if InitSSLInterface and Assigned(_EVP_aes_128_cfb8) then Result := _EVP_aes_128_cfb8() else Result := Nil; @@ -2437,7 +2528,7 @@ end; function EVP_aes_192_cfb8: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_aes_192_cfb8) then + if InitSSLInterface and Assigned(_EVP_aes_192_cfb8) then Result := _EVP_aes_192_cfb8() else Result := Nil; @@ -2445,7 +2536,7 @@ end; function EVP_aes_256_cfb8: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_aes_256_cfb8) then + if InitSSLInterface and Assigned(_EVP_aes_256_cfb8) then Result := _EVP_aes_256_cfb8() else Result := Nil; @@ -2453,7 +2544,7 @@ end; function EVP_camellia_128_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_camellia_128_cbc) then + if InitSSLInterface and Assigned(_EVP_camellia_128_cbc) then Result := _EVP_camellia_128_cbc() else Result := Nil; @@ -2461,7 +2552,7 @@ end; function EVP_camellia_192_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_camellia_192_cbc) then + if InitSSLInterface and Assigned(_EVP_camellia_192_cbc) then Result := _EVP_camellia_192_cbc() else Result := Nil; @@ -2469,7 +2560,7 @@ end; function EVP_camellia_256_cbc: PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_camellia_256_cbc) then + if InitSSLInterface and Assigned(_EVP_camellia_256_cbc) then Result := _EVP_camellia_256_cbc() else Result := Nil; @@ -2477,25 +2568,25 @@ end; procedure OpenSSL_add_all_algorithms; begin - if InitlibeaInterface and Assigned(_OpenSSL_add_all_algorithms) then + if InitSSLInterface and Assigned(_OpenSSL_add_all_algorithms) then _OpenSSL_add_all_algorithms(); end; procedure OpenSSL_add_all_ciphers; begin - if InitlibeaInterface and Assigned(_OpenSSL_add_all_ciphers) then + if InitSSLInterface and Assigned(_OpenSSL_add_all_ciphers) then _OpenSSL_add_all_ciphers(); end; procedure OpenSSL_add_all_digests; begin - if InitlibeaInterface and Assigned(_OpenSSL_add_all_digests) then + if InitSSLInterface and Assigned(_OpenSSL_add_all_digests) then _OpenSSL_add_all_digests(); end; // function EVP_DigestInit(ctx: PEVP_MD_CTX; type_: PEVP_MD): cint; begin - if InitlibeaInterface and Assigned(_EVP_DigestInit) then + if InitSSLInterface and Assigned(_EVP_DigestInit) then Result := _EVP_DigestInit(ctx, type_) else Result := -1; @@ -2503,7 +2594,7 @@ end; function EVP_DigestUpdate(ctx: PEVP_MD_CTX; const data: Pointer; cnt: csize_t): cint; begin - if InitlibeaInterface and Assigned(_EVP_DigestUpdate) then + if InitSSLInterface and Assigned(_EVP_DigestUpdate) then Result := _EVP_DigestUpdate(ctx, data, cnt) else Result := -1; @@ -2511,7 +2602,7 @@ end; function EVP_DigestFinal(ctx: PEVP_MD_CTX; md: PByte; s: pcuint): cint; begin - if InitlibeaInterface and Assigned(_EVP_DigestFinal) then + if InitSSLInterface and Assigned(_EVP_DigestFinal) then Result := _EVP_DigestFinal(ctx, md, s) else Result := -1; @@ -2520,7 +2611,7 @@ end; function EVP_SignFinal(ctx: pEVP_MD_CTX; sig: pointer; var s: cardinal; key: pEVP_PKEY): integer; begin - if InitlibeaInterface and Assigned(_EVP_SignFinal) then + if InitSSLInterface and Assigned(_EVP_SignFinal) then Result := _EVP_SignFinal(ctx, sig, s, key) else Result := -1; @@ -2528,7 +2619,7 @@ end; function EVP_PKEY_size(key: pEVP_PKEY): integer; begin - if InitlibeaInterface and Assigned(_EVP_PKEY_size) then + if InitSSLInterface and Assigned(_EVP_PKEY_size) then Result := _EVP_PKEY_size(key) else Result := -1; @@ -2536,14 +2627,14 @@ end; procedure EVP_PKEY_free(key: pEVP_PKEY); begin - if InitlibeaInterface and Assigned(_EVP_PKEY_free) then + if InitSSLInterface and Assigned(_EVP_PKEY_free) then _EVP_PKEY_free(key); end; function EVP_VerifyFinal(ctx: pEVP_MD_CTX; sigbuf: pointer; siglen: cardinal; pkey: pEVP_PKEY): integer; begin - if InitlibeaInterface and Assigned(_EVP_VerifyFinal) then + if InitSSLInterface and Assigned(_EVP_VerifyFinal) then Result := _EVP_VerifyFinal(ctx, sigbuf, siglen, pkey) else Result := -1; @@ -2553,7 +2644,7 @@ end; // function EVP_get_cipherbyname(const name: PChar): PEVP_CIPHER; begin - if InitlibeaInterface and Assigned(_EVP_get_cipherbyname) then + if InitSSLInterface and Assigned(_EVP_get_cipherbyname) then Result := _EVP_get_cipherbyname(name) else Result := nil; @@ -2561,7 +2652,7 @@ end; function EVP_get_digestbyname(const name: PChar): PEVP_MD; begin - if InitlibeaInterface and Assigned(_EVP_get_digestbyname) then + if InitSSLInterface and Assigned(_EVP_get_digestbyname) then Result := _EVP_get_digestbyname(name) else Result := nil; @@ -2569,13 +2660,13 @@ end; // procedure EVP_CIPHER_CTX_init(a: PEVP_CIPHER_CTX); begin - if InitlibeaInterface and Assigned(_EVP_CIPHER_CTX_init) then + if InitSSLInterface and Assigned(_EVP_CIPHER_CTX_init) then _EVP_CIPHER_CTX_init(a); end; function EVP_CIPHER_CTX_cleanup(a: PEVP_CIPHER_CTX): cint; begin - if InitlibeaInterface and Assigned(_EVP_CIPHER_CTX_cleanup) then + if InitSSLInterface and Assigned(_EVP_CIPHER_CTX_cleanup) then Result := _EVP_CIPHER_CTX_cleanup(a) else Result := -1; @@ -2583,7 +2674,7 @@ end; function EVP_CIPHER_CTX_set_key_length(x: PEVP_CIPHER_CTX; keylen: cint): cint; begin - if InitlibeaInterface and Assigned(_EVP_CIPHER_CTX_set_key_length) then + if InitSSLInterface and Assigned(_EVP_CIPHER_CTX_set_key_length) then Result := _EVP_CIPHER_CTX_set_key_length(x, keylen) else Result := -1; @@ -2591,7 +2682,7 @@ end; function EVP_CIPHER_CTX_ctrl(ctx: PEVP_CIPHER_CTX; type_, arg: cint; ptr: Pointer): cint; begin - if InitlibeaInterface and Assigned(_EVP_CIPHER_CTX_ctrl) then + if InitSSLInterface and Assigned(_EVP_CIPHER_CTX_ctrl) then Result := _EVP_CIPHER_CTX_ctrl(ctx, type_, arg, ptr) else Result := -1; @@ -2600,7 +2691,7 @@ end; function EVP_EncryptInit(ctx: PEVP_CIPHER_CTX; const chipher_: PEVP_CIPHER; const key, iv: PByte): cint; begin - if InitlibeaInterface and Assigned(_EVP_EncryptInit) then + if InitSSLInterface and Assigned(_EVP_EncryptInit) then Result := _EVP_EncryptInit(ctx, chipher_, key, iv) else Result := -1; @@ -2609,7 +2700,7 @@ end; function EVP_EncryptUpdate(ctx: PEVP_CIPHER_CTX; out_: pcuchar; outlen: pcint; const in_: pcuchar; inlen: cint): cint; begin - if InitlibeaInterface and Assigned(_EVP_EncryptUpdate) then + if InitSSLInterface and Assigned(_EVP_EncryptUpdate) then Result := _EVP_EncryptUpdate(ctx, out_, outlen, in_, inlen) else Result := -1; @@ -2617,7 +2708,7 @@ end; function EVP_EncryptFinal(ctx: PEVP_CIPHER_CTX; out_data: PByte; outlen: pcint): cint; begin - if InitlibeaInterface and Assigned(_EVP_EncryptFinal) then + if InitSSLInterface and Assigned(_EVP_EncryptFinal) then Result := _EVP_EncryptFinal(ctx, out_data, outlen) else Result := -1; @@ -2626,7 +2717,7 @@ end; function EVP_DecryptInit(ctx: PEVP_CIPHER_CTX; chiphir_type: PEVP_CIPHER; const key, iv: PByte): cint; begin - if InitlibeaInterface and Assigned(_EVP_DecryptInit) then + if InitSSLInterface and Assigned(_EVP_DecryptInit) then Result := _EVP_DecryptInit(ctx, chiphir_type, key, iv) else Result := -1; @@ -2635,7 +2726,7 @@ end; function EVP_DecryptUpdate(ctx: PEVP_CIPHER_CTX; out_data: PByte; outl: pcint; const in_: PByte; inl: cint): cint; begin - if InitlibeaInterface and Assigned(_EVP_DecryptUpdate) then + if InitSSLInterface and Assigned(_EVP_DecryptUpdate) then Result := _EVP_DecryptUpdate(ctx, out_data, outl, in_, inl) else Result := -1; @@ -2643,7 +2734,7 @@ end; function EVP_DecryptFinal(ctx: PEVP_CIPHER_CTX; outm: PByte; outlen: pcint): cint; begin - if InitlibeaInterface and Assigned(_EVP_DecryptFinal) then + if InitSSLInterface and Assigned(_EVP_DecryptFinal) then Result := _EVP_DecryptFinal(ctx, outm, outlen) else Result := -1; @@ -2654,7 +2745,7 @@ end; function PEM_read_bio_PrivateKey(bp: PBIO; X: PPEVP_PKEY; cb: Ppem_password_cb; u: Pointer): PEVP_PKEY; begin - if InitlibeaInterface and Assigned(_PEM_read_bio_PrivateKey) then + if InitSSLInterface and Assigned(_PEM_read_bio_PrivateKey) then Result := _PEM_read_bio_PrivateKey(bp, x, cb, u) else Result := nil; @@ -2663,7 +2754,7 @@ end; function PEM_read_bio_PUBKEY(bp: pBIO; var x: pEVP_PKEY; cb: Ppem_password_cb; u: pointer): pEVP_PKEY; begin - if InitlibeaInterface and Assigned(_PEM_read_bio_PUBKEY) then + if InitSSLInterface and Assigned(_PEM_read_bio_PUBKEY) then Result := _PEM_read_bio_PUBKEY(bp, x, cb, u) else Result := nil; @@ -2673,7 +2764,7 @@ function PEM_write_bio_PrivateKey(bp: pBIO; x: pEVP_PKEY; const enc: pEVP_CIPHER; kstr: PChar; klen: Integer; cb: Ppem_password_cb; u: pointer): integer; Begin - if InitlibeaInterface and Assigned(_PEM_write_bio_PrivateKey) then + if InitSSLInterface and Assigned(_PEM_write_bio_PrivateKey) then Result := _PEM_write_bio_PrivateKey(bp, x, enc ,kstr ,klen ,cb, u) else Result := -1; @@ -2681,7 +2772,7 @@ end; function PEM_write_bio_PUBKEY(bp: pBIO; x: pEVP_PKEY): integer; Begin - if InitlibeaInterface and Assigned(_PEM_write_bio_PUBKEY) then + if InitSSLInterface and Assigned(_PEM_write_bio_PUBKEY) then Result := _PEM_write_bio_PUBKEY(bp, x) else Result := -1; @@ -2691,7 +2782,7 @@ end; function BIO_ctrl(bp: PBIO; cmd: cint; larg: clong; parg: Pointer): clong; begin - if InitlibeaInterface and Assigned(_BIO_ctrl) then + if InitSSLInterface and Assigned(_BIO_ctrl) then Result := _BIO_ctrl(bp, cmd, larg, parg) else Result := -1; @@ -2704,7 +2795,7 @@ end; function BIO_s_file: PBIO_METHOD; begin - if InitlibeaInterface and Assigned(_BIO_s_file) then + if InitSSLInterface and Assigned(_BIO_s_file) then Result := _BIO_s_file else Result := nil; @@ -2712,7 +2803,7 @@ end; function BIO_new_file(const filename: PChar; const mode: PChar): pBIO; begin - if InitlibeaInterface and Assigned(_BIO_new_file) then + if InitSSLInterface and Assigned(_BIO_new_file) then Result := _BIO_new_file(filename, mode) else Result := nil; @@ -2720,12 +2811,23 @@ end; function BIO_new_mem_buf(buf: pointer; len: integer): pBIO; begin - if InitlibeaInterface and Assigned(_BIO_new_mem_buf) then + if InitSSLInterface and Assigned(_BIO_new_mem_buf) then Result := _BIO_new_mem_buf(buf, len) else Result := nil; end; +procedure CRYPTOcleanupAllExData; +begin + if InitSSLInterface and Assigned(_CRYPTOcleanupAllExData) then + _CRYPTOcleanupAllExData; +end; + +procedure OPENSSLaddallalgorithms; +begin + if InitSSLInterface and Assigned(_OPENSSLaddallalgorithms) then + _OPENSSLaddallalgorithms; +end; {$IFNDEF WINDOWS} { Try to load all library versions until you find or run out } @@ -2757,573 +2859,577 @@ begin {$ENDIF} end; -function GetProcAddr(module: HModule; const ProcName: string; - AVerboseLoading: Boolean): SslPtr; +function GetProcAddr(module: HModule; const ProcName: string): SslPtr; begin Result := GetProcAddress(module, PChar(ProcName)); - if AVerboseLoading and (Result = nil) then + if LoadVerbose and (Result = nil) then OpenSSL_unavailable_functions := OpenSSL_unavailable_functions + ProcName + LineEnding; end; // The AVerboseLoading parameter can be used to check which particular // functions weren't loaded correctly. They will be available in the // global variable OpenSSL_unavailable_functions -function InitSSLInterface(AVerboseLoading: Boolean = False): Boolean; -Begin - try - if InitLIBEAInterface(AVerboseLoading) then - if InitSSLEAInterface(AVerboseLoading) then - result:=true - else - result:=false - else - result:=false; - except - result:=false; - end; -end; - -function InitSSLEAInterface(AVerboseLoading: Boolean = False): Boolean; -begin - if not IsLibEaloaded then - begin - SSLLibHandle := LoadLib(DLLSSLName); - {$IFNDEF UNIX} - if (SSLLibHandle = 0) then - SSLLibHandle := LoadLib(DLLSSLName2); - {$ENDIF} - if (SSLLibHandle <> 0) then - begin - _SslGetError := GetProcAddr(SSLLibHandle, 'SSL_get_error', AVerboseLoading); - _SslLibraryInit := GetProcAddr(SSLLibHandle, 'SSL_library_init', AVerboseLoading); - _SslLoadErrorStrings := GetProcAddr(SSLLibHandle, 'SSL_load_error_strings', AVerboseLoading); - _SslCtxSetCipherList := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_cipher_list', AVerboseLoading); - _SslCtxNew := GetProcAddr(SSLLibHandle, 'SSL_CTX_new', AVerboseLoading); - _SslCtxFree := GetProcAddr(SSLLibHandle, 'SSL_CTX_free', AVerboseLoading); - _SslSetFd := GetProcAddr(SSLLibHandle, 'SSL_set_fd', AVerboseLoading); - _SslCtrl := GetProcAddr(SSLLibHandle, 'SSL_ctrl', AVerboseLoading); - _SslCTXCtrl := GetProcAddr(SSLLibHandle, 'SSL_CTX_ctrl', AVerboseLoading); - _SslMethodV2 := GetProcAddr(SSLLibHandle, 'SSLv2_method', AVerboseLoading); - _SslMethodV3 := GetProcAddr(SSLLibHandle, 'SSLv3_method', AVerboseLoading); - _SslMethodTLSV1 := GetProcAddr(SSLLibHandle, 'TLSv1_method', AVerboseLoading); - _SslMethodV23 := GetProcAddr(SSLLibHandle, 'SSLv23_method', AVerboseLoading); - _SslCtxUsePrivateKey := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey', AVerboseLoading); - _SslCtxUsePrivateKeyASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey_ASN1', AVerboseLoading); - //use SSL_CTX_use_RSAPrivateKey_file instead SSL_CTX_use_PrivateKey_file, - //because SSL_CTX_use_PrivateKey_file not support DER format. :-O - _SslCtxUsePrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_RSAPrivateKey_file', AVerboseLoading); - _SslCtxUseCertificate := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate', AVerboseLoading); - _SslCtxUseCertificateASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_ASN1', AVerboseLoading); - _SslCtxUseCertificateFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_file', AVerboseLoading); - _SslCtxUseCertificateChainFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_chain_file', AVerboseLoading); - _SslCtxCheckPrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_check_private_key', AVerboseLoading); - _SslCtxSetDefaultPasswdCb := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb', AVerboseLoading); - _SslCtxSetDefaultPasswdCbUserdata := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb_userdata', AVerboseLoading); - _SslCtxLoadVerifyLocations := GetProcAddr(SSLLibHandle, 'SSL_CTX_load_verify_locations', AVerboseLoading); - _SslNew := GetProcAddr(SSLLibHandle, 'SSL_new', AVerboseLoading); - _SslFree := GetProcAddr(SSLLibHandle, 'SSL_free', AVerboseLoading); - _SslAccept := GetProcAddr(SSLLibHandle, 'SSL_accept', AVerboseLoading); - _SslConnect := GetProcAddr(SSLLibHandle, 'SSL_connect', AVerboseLoading); - _SslShutdown := GetProcAddr(SSLLibHandle, 'SSL_shutdown', AVerboseLoading); - _SslRead := GetProcAddr(SSLLibHandle, 'SSL_read', AVerboseLoading); - _SslPeek := GetProcAddr(SSLLibHandle, 'SSL_peek', AVerboseLoading); - _SslWrite := GetProcAddr(SSLLibHandle, 'SSL_write', AVerboseLoading); - _SslPending := GetProcAddr(SSLLibHandle, 'SSL_pending', AVerboseLoading); - _SslGetPeerCertificate := GetProcAddr(SSLLibHandle, 'SSL_get_peer_certificate', AVerboseLoading); - _SslGetVersion := GetProcAddr(SSLLibHandle, 'SSL_get_version', AVerboseLoading); - _SslCtxSetVerify := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_verify', AVerboseLoading); - _SslGetCurrentCipher := GetProcAddr(SSLLibHandle, 'SSL_get_current_cipher', AVerboseLoading); - _SslCipherGetName := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_name', AVerboseLoading); - _SslCipherGetBits := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_bits', AVerboseLoading); - _SslGetVerifyResult := GetProcAddr(SSLLibHandle, 'SSL_get_verify_result', AVerboseLoading); - - //init library - if assigned(_SslLibraryInit) then - _SslLibraryInit; - if assigned(_SslLoadErrorStrings) then - _SslLoadErrorStrings; - if assigned(_OPENSSL_add_all_algorithms) then - _OPENSSL_add_all_algorithms; - if assigned(_RandScreen) then - _RandScreen; - - Result := True; - SSLloaded := True; - end - else - begin - //load failed! - if SSLLibHandle <> 0 then - begin - FreeLibrary(SSLLibHandle); - SSLLibHandle := 0; - end; - Result := False; - end; - end - else - //loaded before... - Result := true; -end; - -function InitlibeaInterface(AVerboseLoading: Boolean = False): Boolean; -begin - if not Islibealoaded then - begin - SSLUtilHandle := LoadLib(DLLUtilName); - - if (SSLUtilHandle <> 0) then - begin - _ERR_load_crypto_strings := GetProcAddr(SSLUtilHandle, 'ERR_load_crypto_strings', AVerboseLoading); - _X509New := GetProcAddr(SSLUtilHandle, 'X509_new', AVerboseLoading); - _X509Free := GetProcAddr(SSLUtilHandle, 'X509_free', AVerboseLoading); - _X509NameOneline := GetProcAddr(SSLUtilHandle, 'X509_NAME_oneline', AVerboseLoading); - _X509GetSubjectName := GetProcAddr(SSLUtilHandle, 'X509_get_subject_name', AVerboseLoading); - _X509GetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_get_issuer_name', AVerboseLoading); - _X509NameHash := GetProcAddr(SSLUtilHandle, 'X509_NAME_hash', AVerboseLoading); - _X509Digest := GetProcAddr(SSLUtilHandle, 'X509_digest', AVerboseLoading); - _X509print := GetProcAddr(SSLUtilHandle, 'X509_print', AVerboseLoading); - _X509SetVersion := GetProcAddr(SSLUtilHandle, 'X509_set_version', AVerboseLoading); - _X509SetPubkey := GetProcAddr(SSLUtilHandle, 'X509_set_pubkey', AVerboseLoading); - _X509SetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_set_issuer_name', AVerboseLoading); - _X509NameAddEntryByTxt := GetProcAddr(SSLUtilHandle, 'X509_NAME_add_entry_by_txt', AVerboseLoading); - _X509Sign := GetProcAddr(SSLUtilHandle, 'X509_sign', AVerboseLoading); - _X509GmtimeAdj := GetProcAddr(SSLUtilHandle, 'X509_gmtime_adj', AVerboseLoading); - _X509SetNotBefore := GetProcAddr(SSLUtilHandle, 'X509_set_notBefore', AVerboseLoading); - _X509SetNotAfter := GetProcAddr(SSLUtilHandle, 'X509_set_notAfter', AVerboseLoading); - _X509GetSerialNumber := GetProcAddr(SSLUtilHandle, 'X509_get_serialNumber', AVerboseLoading); - _EvpPkeyNew := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_new', AVerboseLoading); - _EvpPkeyFree := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_free', AVerboseLoading); - _EvpPkeyAssign := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_assign', AVerboseLoading); - _EVPCleanup := GetProcAddr(SSLUtilHandle, 'EVP_cleanup', AVerboseLoading); - _EvpGetDigestByName := GetProcAddr(SSLUtilHandle, 'EVP_get_digestbyname', AVerboseLoading); - _SSLeayversion := GetProcAddr(SSLUtilHandle, 'SSLeay_version', AVerboseLoading); - _ErrErrorString := GetProcAddr(SSLUtilHandle, 'ERR_error_string_n', AVerboseLoading); - _ErrGetError := GetProcAddr(SSLUtilHandle, 'ERR_get_error', AVerboseLoading); - _ErrClearError := GetProcAddr(SSLUtilHandle, 'ERR_clear_error', AVerboseLoading); - _ErrFreeStrings := GetProcAddr(SSLUtilHandle, 'ERR_free_strings', AVerboseLoading); - _ErrRemoveState := GetProcAddr(SSLUtilHandle, 'ERR_remove_state', AVerboseLoading); - _RandScreen := GetProcAddr(SSLUtilHandle, 'RAND_screen', AVerboseLoading); - _BioNew := GetProcAddr(SSLUtilHandle, 'BIO_new', AVerboseLoading); - _BioFreeAll := GetProcAddr(SSLUtilHandle, 'BIO_free_all', AVerboseLoading); - _BioSMem := GetProcAddr(SSLUtilHandle, 'BIO_s_mem', AVerboseLoading); - _BioCtrlPending := GetProcAddr(SSLUtilHandle, 'BIO_ctrl_pending', AVerboseLoading); - _BioRead := GetProcAddr(SSLUtilHandle, 'BIO_read', AVerboseLoading); - _BioWrite := GetProcAddr(SSLUtilHandle, 'BIO_write', AVerboseLoading); - _d2iPKCS12bio := GetProcAddr(SSLUtilHandle, 'd2i_PKCS12_bio', AVerboseLoading); - _PKCS12parse := GetProcAddr(SSLUtilHandle, 'PKCS12_parse', AVerboseLoading); - _PKCS12free := GetProcAddr(SSLUtilHandle, 'PKCS12_free', AVerboseLoading); - _Asn1UtctimeNew := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_new', AVerboseLoading); - _Asn1UtctimeFree := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_free', AVerboseLoading); - _i2dX509bio := GetProcAddr(SSLUtilHandle, 'i2d_X509_bio', AVerboseLoading); - _i2dPrivateKeyBio := GetProcAddr(SSLUtilHandle, 'i2d_PrivateKey_bio', AVerboseLoading); - _EVP_enc_null := GetProcAddr(SSLUtilHandle, 'EVP_enc_null', AVerboseLoading);; - _EVP_rc2_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_cbc', AVerboseLoading);; - _EVP_rc2_40_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_40_cbc', AVerboseLoading);; - _EVP_rc2_64_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_64_cbc', AVerboseLoading);; - _EVP_rc4 := GetProcAddr(SSLUtilHandle, 'EVP_rc4', AVerboseLoading);; - _EVP_rc4_40 := GetProcAddr(SSLUtilHandle, 'EVP_rc4_40', AVerboseLoading);; - _EVP_des_cbc := GetProcAddr(SSLUtilHandle, 'EVP_des_cbc', AVerboseLoading);; - _EVP_des_ede3_cbc := GetProcAddr(SSLUtilHandle, 'EVP_des_ede3_cbc', AVerboseLoading);; - _EVP_aes_128_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_128_cbc', AVerboseLoading);; - _EVP_aes_192_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_192_cbc', AVerboseLoading);; - _EVP_aes_256_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_256_cbc', AVerboseLoading);; - _EVP_aes_128_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_128_cfb8', AVerboseLoading);; - _EVP_aes_192_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_192_cfb8', AVerboseLoading);; - _EVP_aes_256_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_256_cfb8', AVerboseLoading);; - _EVP_camellia_128_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_128_cbc', AVerboseLoading);; - _EVP_camellia_192_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_192_cbc', AVerboseLoading);; - _EVP_camellia_256_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_256_cbc', AVerboseLoading);; - - // 3DES functions - _DESsetoddparity := GetProcAddr(SSLUtilHandle, 'des_set_odd_parity', AVerboseLoading); - _DESsetkeychecked := GetProcAddr(SSLUtilHandle, 'des_set_key_checked', AVerboseLoading); - _DESsetkey := GetProcAddr(SSLUtilHandle, 'des_set_key', AVerboseLoading); - _DESecbencrypt := GetProcAddr(SSLUtilHandle, 'des_ecb_encrypt', AVerboseLoading); - // - _CRYPTOnumlocks := GetProcAddr(SSLUtilHandle, 'CRYPTO_num_locks', AVerboseLoading); - _CRYPTOsetlockingcallback := GetProcAddr(SSLUtilHandle, 'CRYPTO_set_locking_callback', AVerboseLoading); - - // RAND functions - _RAND_set_rand_method := GetProcAddr(SSLUtilHandle, 'RAND_set_rand_method', AVerboseLoading); - _RAND_get_rand_method := GetProcAddr(SSLUtilHandle, 'RAND_get_rand_method', AVerboseLoading); - _RAND_SSLeay := GetProcAddr(SSLUtilHandle, 'RAND_SSLeay', AVerboseLoading); - _RAND_cleanup := GetProcAddr(SSLUtilHandle, 'RAND_cleanup', AVerboseLoading); - _RAND_bytes := GetProcAddr(SSLUtilHandle, 'RAND_bytes', AVerboseLoading); - _RAND_pseudo_bytes := GetProcAddr(SSLUtilHandle, 'RAND_pseudo_bytes', AVerboseLoading); - _RAND_seed := GetProcAddr(SSLUtilHandle, 'RAND_seed', AVerboseLoading); - _RAND_add := GetProcAddr(SSLUtilHandle, 'RAND_add', AVerboseLoading); - _RAND_load_file := GetProcAddr(SSLUtilHandle, 'RAND_load_file', AVerboseLoading); - _RAND_write_file := GetProcAddr(SSLUtilHandle, 'RAND_write_file', AVerboseLoading); - _RAND_file_name := GetProcAddr(SSLUtilHandle, 'RAND_file_name', AVerboseLoading); - _RAND_status := GetProcAddr(SSLUtilHandle, 'RAND_status', AVerboseLoading); - _RAND_query_egd_bytes := GetProcAddr(SSLUtilHandle, 'RAND_query_egd_bytes', AVerboseLoading); // 0.9.7+ - _RAND_egd := GetProcAddr(SSLUtilHandle, 'RAND_egd', AVerboseLoading); - _RAND_egd_bytes := GetProcAddr(SSLUtilHandle, 'RAND_egd_bytes', AVerboseLoading); - _ERR_load_RAND_strings := GetProcAddr(SSLUtilHandle, 'ERR_load_RAND_strings', AVerboseLoading); - _RAND_poll := GetProcAddr(SSLUtilHandle, 'RAND_poll', AVerboseLoading); - - // RSA Functions - _RSA_new := GetProcAddr(SSLUtilHandle, 'RSA_new', AVerboseLoading); - _RSA_new_method := GetProcAddr(SSLUtilHandle, 'RSA_new_method', AVerboseLoading); - _RSA_size := GetProcAddr(SSLUtilHandle, 'RSA_size', AVerboseLoading); - _RsaGenerateKey := GetProcAddr(SSLUtilHandle, 'RSA_generate_key', AVerboseLoading); - _RSA_generate_key_ex := GetProcAddr(SSLUtilHandle, 'RSA_generate_key_ex', AVerboseLoading); - _RSA_check_key := GetProcAddr(SSLUtilHandle, 'RSA_check_key', AVerboseLoading); - _RSA_public_encrypt := GetProcAddr(SSLUtilHandle, 'RSA_public_encrypt', AVerboseLoading); - _RSA_private_encrypt := GetProcAddr(SSLUtilHandle, 'RSA_private_encrypt', AVerboseLoading); - _RSA_public_decrypt := GetProcAddr(SSLUtilHandle, 'RSA_public_decrypt', AVerboseLoading); - _RSA_private_decrypt := GetProcAddr(SSLUtilHandle, 'RSA_private_decrypt', AVerboseLoading); - _RSA_free := GetProcAddr(SSLUtilHandle, 'RSA_free', AVerboseLoading); - _RSA_flags := GetProcAddr(SSLUtilHandle, 'RSA_flags', AVerboseLoading); - _RSA_set_default_method := GetProcAddr(SSLUtilHandle, 'RSA_set_default_method', AVerboseLoading); - _RSA_get_default_method := GetProcAddr(SSLUtilHandle, 'RSA_get_default_method', AVerboseLoading); - _RSA_get_method := GetProcAddr(SSLUtilHandle, 'RSA_get_method', AVerboseLoading); - _RSA_set_method := GetProcAddr(SSLUtilHandle, 'RSA_set_method', AVerboseLoading); - - // X509 Functions - - _d2i_RSAPublicKey := GetProcAddr(SSLUtilHandle, 'd2i_RSAPublicKey', AVerboseLoading); - _i2d_RSAPublicKey := GetProcAddr(SSLUtilHandle, 'i2d_RSAPublicKey', AVerboseLoading); - _d2i_RSAPrivateKey := GetProcAddr(SSLUtilHandle, 'd2i_RSAPrivateKey', AVerboseLoading); - _i2d_RSAPrivateKey := GetProcAddr(SSLUtilHandle, 'i2d_RSAPrivateKey', AVerboseLoading); - - // ERR Functions - _ERR_error_string := GetProcAddr(SSLUtilHandle, 'ERR_error_string', AVerboseLoading); - - // EVP Functions - - _OpenSSL_add_all_algorithms := GetProcAddr(SSLUtilHandle, 'OpenSSL_add_all_algorithms', AVerboseLoading); - _OpenSSL_add_all_ciphers := GetProcAddr(SSLUtilHandle, 'OpenSSL_add_all_ciphers', AVerboseLoading); - _OpenSSL_add_all_digests := GetProcAddr(SSLUtilHandle, 'OpenSSL_add_all_digests', AVerboseLoading); - // - _EVP_DigestInit := GetProcAddr(SSLUtilHandle, 'EVP_DigestInit', AVerboseLoading); - _EVP_DigestUpdate := GetProcAddr(SSLUtilHandle, 'EVP_DigestUpdate', AVerboseLoading); - _EVP_DigestFinal := GetProcAddr(SSLUtilHandle, 'EVP_DigestFinal', AVerboseLoading); - - _EVP_SignFinal := GetProcAddr(SSLUtilHandle, 'EVP_SignFinal', AVerboseLoading); - _EVP_PKEY_size := GetProcAddr(SSLUtilHandle,'EVP_PKEY_size', AVerboseLoading); - _EVP_PKEY_free := GetProcAddr(SSLUtilHandle,'EVP_PKEY_free', AVerboseLoading); - _EVP_VerifyFinal := GetProcAddr(SSLUtilHandle,'EVP_VerifyFinal', AverboseLoading); - // - _EVP_get_cipherbyname := GetProcAddr(SSLUtilHandle, 'EVP_get_cipherbyname', AVerboseLoading); - _EVP_get_digestbyname := GetProcAddr(SSLUtilHandle, 'EVP_get_digestbyname', AVerboseLoading); - // - _EVP_CIPHER_CTX_init := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_init', AVerboseLoading); - _EVP_CIPHER_CTX_cleanup := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_cleanup', AVerboseLoading); - _EVP_CIPHER_CTX_set_key_length := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_set_key_length', AVerboseLoading); - _EVP_CIPHER_CTX_ctrl := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_ctrl', AVerboseLoading); - // - _EVP_EncryptInit := GetProcAddr(SSLUtilHandle, 'EVP_EncryptInit', AVerboseLoading); - _EVP_EncryptUpdate := GetProcAddr(SSLUtilHandle, 'EVP_EncryptUpdate', AVerboseLoading); - _EVP_EncryptFinal := GetProcAddr(SSLUtilHandle, 'EVP_EncryptFinal', AVerboseLoading); - // - _EVP_DecryptInit := GetProcAddr(SSLUtilHandle, 'EVP_DecryptInit', AVerboseLoading); - _EVP_DecryptUpdate := GetProcAddr(SSLUtilHandle, 'EVP_DecryptUpdate', AVerboseLoading); - _EVP_DecryptFinal := GetProcAddr(SSLUtilHandle, 'EVP_DecryptFinal', AVerboseLoading); - - // PEM - - _PEM_read_bio_PrivateKey := GetProcAddr(SSLUtilHandle, 'PEM_read_bio_PrivateKey', AVerboseLoading); - _PEM_read_bio_PUBKEY := GetProcAddr(SSLUtilHandle, 'PEM_read_bio_PUBKEY', AVerboseLoading); - _PEM_write_bio_PrivateKey := GetProcAddr(SSLUtilHandle, 'PEM_write_bio_PrivateKey', AVerboseLoading); - _PEM_write_bio_PUBKEY := GetProcAddr(SSLUtilHandle, 'PEM_write_bio_PUBKEY', AVerboseLoading); - - // BIO - - _BIO_ctrl := GetProcAddr(SSLUtilHandle, 'BIO_ctrl', AVerboseLoading); - - _BIO_s_file := GetProcAddr(SSLUtilHandle, 'BIO_s_file', AVerboseLoading); - _BIO_new_file := GetProcAddr(SSLUtilHandle, 'BIO_new_file', AVerboseLoading); - _BIO_new_mem_buf := GetProcAddr(SSLUtilHandle, 'BIO_new_mem_buf', AVerboseLoading); - - // Crypto Functions - - _SSLeay_version := GetProcAddr(SSLUtilHandle, 'SSLeay_version', AVerboseLoading); - - //init library - if assigned(_SslLibraryInit) then - _SslLibraryInit; - if assigned(_SslLoadErrorStrings) then - _SslLoadErrorStrings; - if assigned(_OPENSSL_add_all_algorithms) then - _OPENSSL_add_all_algorithms; - if assigned(_RandScreen) then - _RandScreen; - - Result := True; - libealoaded := True; - end - else - begin - if SSLUtilHandle <> 0 then - begin - FreeLibrary(SSLUtilHandle); - end; - Result := False; - end; - end - else - //loaded before... - Result := true; -end; - -function DestroySSLEAInterface: Boolean; -begin - if IsSSLLoaded then - begin - //deinit library - EVPCleanup; - ErrRemoveState(0); - end; - SSLloaded := false; - if SSLLibHandle <> 0 then - begin - FreeLibrary(SSLLibHandle); - SSLLibHandle := 0; - end; - - _SslGetError := nil; - _SslLibraryInit := nil; - _SslLoadErrorStrings := nil; - _SslCtxSetCipherList := nil; - _SslCtxNew := nil; - _SslCtxFree := nil; - _SslSetFd := nil; - _SslCtrl := nil; - _SslCTXCtrl := nil; - _SslMethodV2 := nil; - _SslMethodV3 := nil; - _SslMethodTLSV1 := nil; - _SslMethodV23 := nil; - _SslCtxUsePrivateKey := nil; - _SslCtxUsePrivateKeyASN1 := nil; - _SslCtxUsePrivateKeyFile := nil; - _SslCtxUseCertificate := nil; - _SslCtxUseCertificateASN1 := nil; - _SslCtxUseCertificateFile := nil; - _SslCtxUseCertificateChainFile := nil; - _SslCtxCheckPrivateKeyFile := nil; - _SslCtxSetDefaultPasswdCb := nil; - _SslCtxSetDefaultPasswdCbUserdata := nil; - _SslCtxLoadVerifyLocations := nil; - _SslNew := nil; - _SslFree := nil; - _SslAccept := nil; - _SslConnect := nil; - _SslShutdown := nil; - _SslRead := nil; - _SslPeek := nil; - _SslWrite := nil; - _SslPending := nil; - _SslGetPeerCertificate := nil; - _SslGetVersion := nil; - _SslCtxSetVerify := nil; - _SslGetCurrentCipher := nil; - _SslCipherGetName := nil; - _SslCipherGetBits := nil; - _SslGetVerifyResult := nil; - - - Result := True; -end; - - -function DestroylibeaInterface: Boolean; -begin - if IslibeaLoaded then - begin - //deinit library - EVPCleanup; - ErrRemoveState(0); - end; - libealoaded := false; - if SSLUtilHandle <> 0 then - begin - FreeLibrary(SSLUtilHandle); - SSLUtilHandle := 0; - end; - - _SSLeayversion := nil; - _ERR_load_crypto_strings := nil; - _X509New := nil; - _X509Free := nil; - _X509NameOneline := nil; - _X509GetSubjectName := nil; - _X509GetIssuerName := nil; - _X509NameHash := nil; - _X509Digest := nil; - _X509print := nil; - _X509SetVersion := nil; - _X509SetPubkey := nil; - _X509SetIssuerName := nil; - _X509NameAddEntryByTxt := nil; - _X509Sign := nil; - _X509GmtimeAdj := nil; - _X509SetNotBefore := nil; - _X509SetNotAfter := nil; - _X509GetSerialNumber := nil; - _EvpPkeyNew := nil; - _EvpPkeyFree := nil; - _EvpPkeyAssign := nil; - _EVPCleanup := nil; - _EvpGetDigestByName := nil; - _ErrErrorString := nil; - _ErrGetError := nil; - _ErrClearError := nil; - _ErrFreeStrings := nil; - _ErrRemoveState := nil; - _RandScreen := nil; - _BioNew := nil; - _BioFreeAll := nil; - _BioSMem := nil; - _BioCtrlPending := nil; - _BioRead := nil; - _BioWrite := nil; - _d2iPKCS12bio := nil; - _PKCS12parse := nil; - _PKCS12free := nil; - _Asn1UtctimeNew := nil; - _Asn1UtctimeFree := nil; - _i2dX509bio := nil; - _i2dPrivateKeyBio := nil; - - // 3DES functions - _DESsetoddparity := nil; - _DESsetkeychecked := nil; - _DESecbencrypt := nil; - // - _CRYPTOnumlocks := nil; - _CRYPTOsetlockingcallback := nil; - - // RAND functions - _RAND_set_rand_method := nil; - _RAND_get_rand_method := nil; - _RAND_SSLeay := nil; - _RAND_cleanup := nil; - _RAND_bytes := nil; - _RAND_pseudo_bytes := nil; - _RAND_seed := nil; - _RAND_add := nil; - _RAND_load_file := nil; - _RAND_write_file := nil; - _RAND_file_name := nil; - _RAND_status := nil; - _RAND_query_egd_bytes := nil; - _RAND_egd := nil; - _RAND_egd_bytes := nil; - _ERR_load_RAND_strings := nil; - _RAND_poll := nil; - - // RSA Functions - _RSA_new := nil; - _RSA_new_method := nil; - _RSA_size := nil; - _RsaGenerateKey := nil; - _RSA_generate_key_ex := nil; - _RSA_check_key := nil; - _RSA_public_encrypt := nil; - _RSA_private_encrypt := nil; - _RSA_public_decrypt := nil; - _RSA_private_decrypt := nil; - _RSA_free := nil; - _RSA_flags := nil; - _RSA_set_default_method := nil; - _RSA_get_default_method := nil; - _RSA_get_method := nil; - _RSA_set_method := nil; - - // X509 Functions - - _d2i_RSAPublicKey := nil; - _i2d_RSAPublicKey := nil; - _d2i_RSAPrivateKey := nil; - _i2d_RSAPrivateKey := nil; - - // ERR Functions - _ERR_error_string := nil; - - // EVP Functions - - _OpenSSL_add_all_algorithms := nil; - _OpenSSL_add_all_ciphers := nil; - _OpenSSL_add_all_digests := nil; - // - _EVP_DigestInit := nil; - _EVP_DigestUpdate := nil; - _EVP_DigestFinal := nil; - - _EVP_SignFinal := nil; - _EVP_PKEY_size := nil; - _EVP_PKEY_free := nil; - _EVP_VerifyFinal := nil; - // - _EVP_get_cipherbyname := nil; - _EVP_get_digestbyname := nil; - // - _EVP_CIPHER_CTX_init := nil; - _EVP_CIPHER_CTX_cleanup := nil; - _EVP_CIPHER_CTX_set_key_length := nil; - _EVP_CIPHER_CTX_ctrl := nil; - // - _EVP_EncryptInit := nil; - _EVP_EncryptUpdate := nil; - _EVP_EncryptFinal := nil; - // - _EVP_DecryptInit := nil; - _EVP_DecryptUpdate := nil; - _EVP_DecryptFinal := nil; - - // PEM - - _PEM_read_bio_PrivateKey := nil; - _PEM_read_bio_PrivateKey := nil; - _PEM_read_bio_PUBKEY := nil; - _PEM_write_bio_PrivateKey := nil; - _PEM_write_bio_PUBKEY := nil; - - // BIO - - _BIO_ctrl := nil; - _BIO_s_file := nil; - _BIO_new_file := nil; - _BIO_new_mem_buf := nil; - - // Crypto Functions - - _SSLeay_version := nil; - - Result := True; -end; - -function DestroySSLInterface: Boolean; -begin -result:=false; - try - if DestroySSLEAInterface then - if DestroylibeaInterface then - result := true - else - result := False - else - result:=false; - except - result:=false; - end; -end; - - function IsSSLloaded: Boolean; + begin Result := SSLLoaded; end; -function Islibealoaded: Boolean; +Procedure LoadSSLEntryPoints; + begin - Result := libeaLoaded; + _SslGetError := GetProcAddr(SSLLibHandle, 'SSL_get_error'); + _SslLibraryInit := GetProcAddr(SSLLibHandle, 'SSL_library_init'); + _SslLoadErrorStrings := GetProcAddr(SSLLibHandle, 'SSL_load_error_strings'); + _SslCtxSetCipherList := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_cipher_list'); + _SslCtxNew := GetProcAddr(SSLLibHandle, 'SSL_CTX_new'); + _SslCtxFree := GetProcAddr(SSLLibHandle, 'SSL_CTX_free'); + _SslSetFd := GetProcAddr(SSLLibHandle, 'SSL_set_fd'); + _SslCtrl := GetProcAddr(SSLLibHandle, 'SSL_ctrl'); + _SslCTXCtrl := GetProcAddr(SSLLibHandle, 'SSL_CTX_ctrl'); + _SslMethodV2 := GetProcAddr(SSLLibHandle, 'SSLv2_method'); + _SslMethodV3 := GetProcAddr(SSLLibHandle, 'SSLv3_method'); + _SslMethodTLSV1 := GetProcAddr(SSLLibHandle, 'TLSv1_method'); + _SslMethodV23 := GetProcAddr(SSLLibHandle, 'SSLv23_method'); + _SslCtxUsePrivateKey := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey'); + _SslCtxUsePrivateKeyASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_PrivateKey_ASN1'); + //use SSL_CTX_use_RSAPrivateKey_file instead SSL_CTX_use_PrivateKey_file, + //because SSL_CTX_use_PrivateKey_file not support DER format. :-O + _SslCtxUsePrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_RSAPrivateKey_file'); + _SslCtxUseCertificate := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate'); + _SslCtxUseCertificateASN1 := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_ASN1'); + _SslCtxUseCertificateFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_file'); + _SslCtxUseCertificateChainFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_use_certificate_chain_file'); + _SslCtxCheckPrivateKeyFile := GetProcAddr(SSLLibHandle, 'SSL_CTX_check_private_key'); + _SslCtxSetDefaultPasswdCb := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb'); + _SslCtxSetDefaultPasswdCbUserdata := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_default_passwd_cb_userdata'); + _SslCtxLoadVerifyLocations := GetProcAddr(SSLLibHandle, 'SSL_CTX_load_verify_locations'); + _SslNew := GetProcAddr(SSLLibHandle, 'SSL_new'); + _SslFree := GetProcAddr(SSLLibHandle, 'SSL_free'); + _SslAccept := GetProcAddr(SSLLibHandle, 'SSL_accept'); + _SslConnect := GetProcAddr(SSLLibHandle, 'SSL_connect'); + _SslShutdown := GetProcAddr(SSLLibHandle, 'SSL_shutdown'); + _SslRead := GetProcAddr(SSLLibHandle, 'SSL_read'); + _SslPeek := GetProcAddr(SSLLibHandle, 'SSL_peek'); + _SslWrite := GetProcAddr(SSLLibHandle, 'SSL_write'); + _SslPending := GetProcAddr(SSLLibHandle, 'SSL_pending'); + _SslGetPeerCertificate := GetProcAddr(SSLLibHandle, 'SSL_get_peer_certificate'); + _SslGetVersion := GetProcAddr(SSLLibHandle, 'SSL_get_version'); + _SslCtxSetVerify := GetProcAddr(SSLLibHandle, 'SSL_CTX_set_verify'); + _SslGetCurrentCipher := GetProcAddr(SSLLibHandle, 'SSL_get_current_cipher'); + _SslCipherGetName := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_name'); + _SslCipherGetBits := GetProcAddr(SSLLibHandle, 'SSL_CIPHER_get_bits'); + _SslGetVerifyResult := GetProcAddr(SSLLibHandle, 'SSL_get_verify_result'); end; +Procedure LoadUtilEntryPoints; + +begin + _ERR_load_crypto_strings := GetProcAddr(SSLUtilHandle, 'ERR_load_crypto_strings'); + _X509New := GetProcAddr(SSLUtilHandle, 'X509_new'); + _X509Free := GetProcAddr(SSLUtilHandle, 'X509_free'); + _X509NameOneline := GetProcAddr(SSLUtilHandle, 'X509_NAME_oneline'); + _X509GetSubjectName := GetProcAddr(SSLUtilHandle, 'X509_get_subject_name'); + _X509GetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_get_issuer_name'); + _X509NameHash := GetProcAddr(SSLUtilHandle, 'X509_NAME_hash'); + _X509Digest := GetProcAddr(SSLUtilHandle, 'X509_digest'); + _X509print := GetProcAddr(SSLUtilHandle, 'X509_print'); + _X509SetVersion := GetProcAddr(SSLUtilHandle, 'X509_set_version'); + _X509SetPubkey := GetProcAddr(SSLUtilHandle, 'X509_set_pubkey'); + _X509SetIssuerName := GetProcAddr(SSLUtilHandle, 'X509_set_issuer_name'); + _X509NameAddEntryByTxt := GetProcAddr(SSLUtilHandle, 'X509_NAME_add_entry_by_txt'); + _X509Sign := GetProcAddr(SSLUtilHandle, 'X509_sign'); + _X509GmtimeAdj := GetProcAddr(SSLUtilHandle, 'X509_gmtime_adj'); + _X509SetNotBefore := GetProcAddr(SSLUtilHandle, 'X509_set_notBefore'); + _X509SetNotAfter := GetProcAddr(SSLUtilHandle, 'X509_set_notAfter'); + _X509GetSerialNumber := GetProcAddr(SSLUtilHandle, 'X509_get_serialNumber'); + _EvpPkeyNew := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_new'); + _EvpPkeyFree := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_free'); + _EvpPkeyAssign := GetProcAddr(SSLUtilHandle, 'EVP_PKEY_assign'); + _EVPCleanup := GetProcAddr(SSLUtilHandle, 'EVP_cleanup'); + _EvpGetDigestByName := GetProcAddr(SSLUtilHandle, 'EVP_get_digestbyname'); + _SSLeayversion := GetProcAddr(SSLUtilHandle, 'SSLeay_version'); + _ErrErrorString := GetProcAddr(SSLUtilHandle, 'ERR_error_string_n'); + _ErrGetError := GetProcAddr(SSLUtilHandle, 'ERR_get_error'); + _ErrClearError := GetProcAddr(SSLUtilHandle, 'ERR_clear_error'); + _ErrFreeStrings := GetProcAddr(SSLUtilHandle, 'ERR_free_strings'); + _ErrRemoveState := GetProcAddr(SSLUtilHandle, 'ERR_remove_state'); + _RandScreen := GetProcAddr(SSLUtilHandle, 'RAND_screen'); + _BioNew := GetProcAddr(SSLUtilHandle, 'BIO_new'); + _BioFreeAll := GetProcAddr(SSLUtilHandle, 'BIO_free_all'); + _BioSMem := GetProcAddr(SSLUtilHandle, 'BIO_s_mem'); + _BioCtrlPending := GetProcAddr(SSLUtilHandle, 'BIO_ctrl_pending'); + _BioRead := GetProcAddr(SSLUtilHandle, 'BIO_read'); + _BioWrite := GetProcAddr(SSLUtilHandle, 'BIO_write'); + _d2iPKCS12bio := GetProcAddr(SSLUtilHandle, 'd2i_PKCS12_bio'); + _PKCS12parse := GetProcAddr(SSLUtilHandle, 'PKCS12_parse'); + _PKCS12free := GetProcAddr(SSLUtilHandle, 'PKCS12_free'); + _Asn1UtctimeNew := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_new'); + _Asn1UtctimeFree := GetProcAddr(SSLUtilHandle, 'ASN1_UTCTIME_free'); + _Asn1IntegerSet := GetProcAddr(SSLUtilHandle, 'ASN1_INTEGER_set'); + _Asn1IntegerGet := GetProcAddr(SSLUtilHandle, 'ASN1_INTEGER_get'); + _i2dX509bio := GetProcAddr(SSLUtilHandle, 'i2d_X509_bio'); + _i2dPrivateKeyBio := GetProcAddr(SSLUtilHandle, 'i2d_PrivateKey_bio'); + _EVP_enc_null := GetProcAddr(SSLUtilHandle, 'EVP_enc_null'); + _EVP_rc2_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_cbc'); + _EVP_rc2_40_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_40_cbc'); + _EVP_rc2_64_cbc := GetProcAddr(SSLUtilHandle, 'EVP_rc2_64_cbc'); + _EVP_rc4 := GetProcAddr(SSLUtilHandle, 'EVP_rc4'); + _EVP_rc4_40 := GetProcAddr(SSLUtilHandle, 'EVP_rc4_40'); + _EVP_des_cbc := GetProcAddr(SSLUtilHandle, 'EVP_des_cbc'); + _EVP_des_ede3_cbc := GetProcAddr(SSLUtilHandle, 'EVP_des_ede3_cbc'); + _EVP_aes_128_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_128_cbc'); + _EVP_aes_192_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_192_cbc'); + _EVP_aes_256_cbc := GetProcAddr(SSLUtilHandle, 'EVP_aes_256_cbc'); + _EVP_aes_128_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_128_cfb8'); + _EVP_aes_192_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_192_cfb8'); + _EVP_aes_256_cfb8 := GetProcAddr(SSLUtilHandle, 'EVP_aes_256_cfb8'); + _EVP_camellia_128_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_128_cbc'); + _EVP_camellia_192_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_192_cbc'); + _EVP_camellia_256_cbc := GetProcAddr(SSLUtilHandle, 'EVP_camellia_256_cbc'); + // 3DES functions + _DESsetoddparity := GetProcAddr(SSLUtilHandle, 'des_set_odd_parity'); + _DESsetkeychecked := GetProcAddr(SSLUtilHandle, 'des_set_key_checked'); + _DESsetkey := GetProcAddr(SSLUtilHandle, 'des_set_key'); + _DESecbencrypt := GetProcAddr(SSLUtilHandle, 'des_ecb_encrypt'); + // + _CRYPTOnumlocks := GetProcAddr(SSLUtilHandle, 'CRYPTO_num_locks'); + _CRYPTOsetlockingcallback := GetProcAddr(SSLUtilHandle, 'CRYPTO_set_locking_callback'); + // RAND functions + _RAND_set_rand_method := GetProcAddr(SSLUtilHandle, 'RAND_set_rand_method'); + _RAND_get_rand_method := GetProcAddr(SSLUtilHandle, 'RAND_get_rand_method'); + _RAND_SSLeay := GetProcAddr(SSLUtilHandle, 'RAND_SSLeay'); + _RAND_cleanup := GetProcAddr(SSLUtilHandle, 'RAND_cleanup'); + _RAND_bytes := GetProcAddr(SSLUtilHandle, 'RAND_bytes'); + _RAND_pseudo_bytes := GetProcAddr(SSLUtilHandle, 'RAND_pseudo_bytes'); + _RAND_seed := GetProcAddr(SSLUtilHandle, 'RAND_seed'); + _RAND_add := GetProcAddr(SSLUtilHandle, 'RAND_add'); + _RAND_load_file := GetProcAddr(SSLUtilHandle, 'RAND_load_file'); + _RAND_write_file := GetProcAddr(SSLUtilHandle, 'RAND_write_file'); + _RAND_file_name := GetProcAddr(SSLUtilHandle, 'RAND_file_name'); + _RAND_status := GetProcAddr(SSLUtilHandle, 'RAND_status'); + _RAND_query_egd_bytes := GetProcAddr(SSLUtilHandle, 'RAND_query_egd_bytes'); // 0.9.7+ + _RAND_egd := GetProcAddr(SSLUtilHandle, 'RAND_egd'); + _RAND_egd_bytes := GetProcAddr(SSLUtilHandle, 'RAND_egd_bytes'); + _ERR_load_RAND_strings := GetProcAddr(SSLUtilHandle, 'ERR_load_RAND_strings'); + _RAND_poll := GetProcAddr(SSLUtilHandle, 'RAND_poll'); + // RSA Functions + _RSA_new := GetProcAddr(SSLUtilHandle, 'RSA_new'); + _RSA_new_method := GetProcAddr(SSLUtilHandle, 'RSA_new_method'); + _RSA_size := GetProcAddr(SSLUtilHandle, 'RSA_size'); + _RsaGenerateKey := GetProcAddr(SSLUtilHandle, 'RSA_generate_key'); + _RSA_generate_key_ex := GetProcAddr(SSLUtilHandle, 'RSA_generate_key_ex'); + _RSA_check_key := GetProcAddr(SSLUtilHandle, 'RSA_check_key'); + _RSA_public_encrypt := GetProcAddr(SSLUtilHandle, 'RSA_public_encrypt'); + _RSA_private_encrypt := GetProcAddr(SSLUtilHandle, 'RSA_private_encrypt'); + _RSA_public_decrypt := GetProcAddr(SSLUtilHandle, 'RSA_public_decrypt'); + _RSA_private_decrypt := GetProcAddr(SSLUtilHandle, 'RSA_private_decrypt'); + _RSA_free := GetProcAddr(SSLUtilHandle, 'RSA_free'); + _RSA_flags := GetProcAddr(SSLUtilHandle, 'RSA_flags'); + _RSA_set_default_method := GetProcAddr(SSLUtilHandle, 'RSA_set_default_method'); + _RSA_get_default_method := GetProcAddr(SSLUtilHandle, 'RSA_get_default_method'); + _RSA_get_method := GetProcAddr(SSLUtilHandle, 'RSA_get_method'); + _RSA_set_method := GetProcAddr(SSLUtilHandle, 'RSA_set_method'); + // X509 Functions + _d2i_RSAPublicKey := GetProcAddr(SSLUtilHandle, 'd2i_RSAPublicKey'); + _i2d_RSAPublicKey := GetProcAddr(SSLUtilHandle, 'i2d_RSAPublicKey'); + _d2i_RSAPrivateKey := GetProcAddr(SSLUtilHandle, 'd2i_RSAPrivateKey'); + _i2d_RSAPrivateKey := GetProcAddr(SSLUtilHandle, 'i2d_RSAPrivateKey'); + // ERR Functions + _ERR_error_string := GetProcAddr(SSLUtilHandle, 'ERR_error_string'); + // EVP Functions + _OpenSSL_add_all_algorithms := GetProcAddr(SSLUtilHandle, 'OpenSSL_add_all_algorithms'); + _OpenSSL_add_all_ciphers := GetProcAddr(SSLUtilHandle, 'OpenSSL_add_all_ciphers'); + _OpenSSL_add_all_digests := GetProcAddr(SSLUtilHandle, 'OpenSSL_add_all_digests'); + _EVP_DigestInit := GetProcAddr(SSLUtilHandle, 'EVP_DigestInit'); + _EVP_DigestUpdate := GetProcAddr(SSLUtilHandle, 'EVP_DigestUpdate'); + _EVP_DigestFinal := GetProcAddr(SSLUtilHandle, 'EVP_DigestFinal'); + _EVP_SignFinal := GetProcAddr(SSLUtilHandle, 'EVP_SignFinal'); + _EVP_PKEY_size := GetProcAddr(SSLUtilHandle,'EVP_PKEY_size'); + _EVP_PKEY_free := GetProcAddr(SSLUtilHandle,'EVP_PKEY_free'); + _EVP_VerifyFinal := GetProcAddr(SSLUtilHandle,'EVP_VerifyFinal'); + _EVP_get_cipherbyname := GetProcAddr(SSLUtilHandle, 'EVP_get_cipherbyname'); + _EVP_get_digestbyname := GetProcAddr(SSLUtilHandle, 'EVP_get_digestbyname'); + _EVP_CIPHER_CTX_init := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_init'); + _EVP_CIPHER_CTX_cleanup := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_cleanup'); + _EVP_CIPHER_CTX_set_key_length := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_set_key_length'); + _EVP_CIPHER_CTX_ctrl := GetProcAddr(SSLUtilHandle, 'EVP_CIPHER_CTX_ctrl'); + _EVP_EncryptInit := GetProcAddr(SSLUtilHandle, 'EVP_EncryptInit'); + _EVP_EncryptUpdate := GetProcAddr(SSLUtilHandle, 'EVP_EncryptUpdate'); + _EVP_EncryptFinal := GetProcAddr(SSLUtilHandle, 'EVP_EncryptFinal'); + _EVP_DecryptInit := GetProcAddr(SSLUtilHandle, 'EVP_DecryptInit'); + _EVP_DecryptUpdate := GetProcAddr(SSLUtilHandle, 'EVP_DecryptUpdate'); + _EVP_DecryptFinal := GetProcAddr(SSLUtilHandle, 'EVP_DecryptFinal'); + // PEM + _PEM_read_bio_PrivateKey := GetProcAddr(SSLUtilHandle, 'PEM_read_bio_PrivateKey'); + _PEM_read_bio_PUBKEY := GetProcAddr(SSLUtilHandle, 'PEM_read_bio_PUBKEY'); + _PEM_write_bio_PrivateKey := GetProcAddr(SSLUtilHandle, 'PEM_write_bio_PrivateKey'); + _PEM_write_bio_PUBKEY := GetProcAddr(SSLUtilHandle, 'PEM_write_bio_PUBKEY'); + // BIO + _BIO_ctrl := GetProcAddr(SSLUtilHandle, 'BIO_ctrl'); + _BIO_s_file := GetProcAddr(SSLUtilHandle, 'BIO_s_file'); + _BIO_new_file := GetProcAddr(SSLUtilHandle, 'BIO_new_file'); + _BIO_new_mem_buf := GetProcAddr(SSLUtilHandle, 'BIO_new_mem_buf'); + // Crypto Functions + _SSLeay_version := GetProcAddr(SSLUtilHandle, 'SSLeay_version'); +end; + +Function LoadUtilLibrary : Boolean; + +begin + Result:=(SSLUtilHandle<>0); + if not Result then + begin + SSLUtilHandle := LoadLib(DLLUtilName); + Result:=(SSLUtilHandle<>0); + end; +end; + + + +Procedure ClearSSLEntryPoints; + +begin + _SslGetError := nil; + _SslLibraryInit := nil; + _SslLoadErrorStrings := nil; + _SslCtxSetCipherList := nil; + _SslCtxNew := nil; + _SslCtxFree := nil; + _SslSetFd := nil; + _SslCtrl := nil; + _SslCTXCtrl := nil; + _SslMethodV2 := nil; + _SslMethodV3 := nil; + _SslMethodTLSV1 := nil; + _SslMethodV23 := nil; + _SslCtxUsePrivateKey := nil; + _SslCtxUsePrivateKeyASN1 := nil; + _SslCtxUsePrivateKeyFile := nil; + _SslCtxUseCertificate := nil; + _SslCtxUseCertificateASN1 := nil; + _SslCtxUseCertificateFile := nil; + _SslCtxUseCertificateChainFile := nil; + _SslCtxCheckPrivateKeyFile := nil; + _SslCtxSetDefaultPasswdCb := nil; + _SslCtxSetDefaultPasswdCbUserdata := nil; + _SslCtxLoadVerifyLocations := nil; + _SslNew := nil; + _SslFree := nil; + _SslAccept := nil; + _SslConnect := nil; + _SslShutdown := nil; + _SslRead := nil; + _SslPeek := nil; + _SslWrite := nil; + _SslPending := nil; + _SslGetPeerCertificate := nil; + _SslGetVersion := nil; + _SslCtxSetVerify := nil; + _SslGetCurrentCipher := nil; + _SslCipherGetName := nil; + _SslCipherGetBits := nil; + _SslGetVerifyResult := nil; +end; + +Procedure UnloadSSLLib; + +begin + if (SSLLibHandle<>0) then + begin + FreeLibrary(SSLLibHandle); + SSLLibHandle:=0; + end; +end; + +Procedure UnloadUtilLib; + +begin + if (SSLUtilHandle<>0) then + begin + FreeLibrary(SSLUtilHandle); + SSLUtilHandle := 0; + end; +end; + +Procedure ClearUtilEntryPoints; + +begin + _SSLeayversion := nil; + _ERR_load_crypto_strings := nil; + _X509New := nil; + _X509Free := nil; + _X509NameOneline := nil; + _X509GetSubjectName := nil; + _X509GetIssuerName := nil; + _X509NameHash := nil; + _X509Digest := nil; + _X509print := nil; + _X509SetVersion := nil; + _X509SetPubkey := nil; + _X509SetIssuerName := nil; + _X509NameAddEntryByTxt := nil; + _X509Sign := nil; + _X509GmtimeAdj := nil; + _X509SetNotBefore := nil; + _X509SetNotAfter := nil; + _X509GetSerialNumber := nil; + _EvpPkeyNew := nil; + _EvpPkeyFree := nil; + _EvpPkeyAssign := nil; + _EVPCleanup := nil; + _EvpGetDigestByName := nil; + _ErrErrorString := nil; + _ErrGetError := nil; + _ErrClearError := nil; + _ErrFreeStrings := nil; + _ErrRemoveState := nil; + _RandScreen := nil; + _BioNew := nil; + _BioFreeAll := nil; + _BioSMem := nil; + _BioCtrlPending := nil; + _BioRead := nil; + _BioWrite := nil; + _d2iPKCS12bio := nil; + _PKCS12parse := nil; + _PKCS12free := nil; + _Asn1UtctimeNew := nil; + _Asn1UtctimeFree := nil; + _Asn1IntegerSet:= nil; + _Asn1IntegerGet:= nil; + _i2dX509bio := nil; + _i2dPrivateKeyBio := nil; + + // 3DES functions + _DESsetoddparity := nil; + _DESsetkeychecked := nil; + _DESecbencrypt := nil; + // + _CRYPTOnumlocks := nil; + _CRYPTOsetlockingcallback := nil; + + // RAND functions + _RAND_set_rand_method := nil; + _RAND_get_rand_method := nil; + _RAND_SSLeay := nil; + _RAND_cleanup := nil; + _RAND_bytes := nil; + _RAND_pseudo_bytes := nil; + _RAND_seed := nil; + _RAND_add := nil; + _RAND_load_file := nil; + _RAND_write_file := nil; + _RAND_file_name := nil; + _RAND_status := nil; + _RAND_query_egd_bytes := nil; + _RAND_egd := nil; + _RAND_egd_bytes := nil; + _ERR_load_RAND_strings := nil; + _RAND_poll := nil; + + // RSA Functions + _RSA_new := nil; + _RSA_new_method := nil; + _RSA_size := nil; + _RsaGenerateKey := nil; + _RSA_generate_key_ex := nil; + _RSA_check_key := nil; + _RSA_public_encrypt := nil; + _RSA_private_encrypt := nil; + _RSA_public_decrypt := nil; + _RSA_private_decrypt := nil; + _RSA_free := nil; + _RSA_flags := nil; + _RSA_set_default_method := nil; + _RSA_get_default_method := nil; + _RSA_get_method := nil; + _RSA_set_method := nil; + + // X509 Functions + + _d2i_RSAPublicKey := nil; + _i2d_RSAPublicKey := nil; + _d2i_RSAPrivateKey := nil; + _i2d_RSAPrivateKey := nil; + + // ERR Functions + _ERR_error_string := nil; + + // EVP Functions + + _OpenSSL_add_all_algorithms := nil; + _OpenSSL_add_all_ciphers := nil; + _OpenSSL_add_all_digests := nil; + // + _EVP_DigestInit := nil; + _EVP_DigestUpdate := nil; + _EVP_DigestFinal := nil; + + _EVP_SignFinal := nil; + _EVP_PKEY_size := nil; + _EVP_PKEY_free := nil; + _EVP_VerifyFinal := nil; + // + _EVP_get_cipherbyname := nil; + _EVP_get_digestbyname := nil; + // + _EVP_CIPHER_CTX_init := nil; + _EVP_CIPHER_CTX_cleanup := nil; + _EVP_CIPHER_CTX_set_key_length := nil; + _EVP_CIPHER_CTX_ctrl := nil; + // + _EVP_EncryptInit := nil; + _EVP_EncryptUpdate := nil; + _EVP_EncryptFinal := nil; + // + _EVP_DecryptInit := nil; + _EVP_DecryptUpdate := nil; + _EVP_DecryptFinal := nil; + + // PEM + + _PEM_read_bio_PrivateKey := nil; + _PEM_read_bio_PrivateKey := nil; + _PEM_read_bio_PUBKEY := nil; + _PEM_write_bio_PrivateKey := nil; + _PEM_write_bio_PUBKEY := nil; + + // BIO + + _BIO_ctrl := nil; + _BIO_s_file := nil; + _BIO_new_file := nil; + _BIO_new_mem_buf := nil; + + // Crypto Functions + + _SSLeay_version := nil; +end; + +procedure locking_callback(mode, ltype: integer; lfile: PChar; line: integer); cdecl; +begin + if (mode and 1) > 0 then + EnterCriticalSection(Locks[ltype]) + else + LeaveCriticalSection(Locks[ltype]); +end; + +procedure InitLocks; +var + n: integer; + max: integer; +begin + max:=_CRYPTOnumlocks; + SetLength(Locks,Max); + for n := 0 to max-1 do + InitCriticalSection(Locks[n]); + _CRYPTOsetlockingcallback(@locking_callback); +end; + +procedure FreeLocks; +var + n: integer; +begin + _CRYPTOsetlockingcallback(nil); + for n := 0 to Length(Locks)-1 do + DoneCriticalSection(Locks[n]); + SetLength(Locks,0); +end; + +Procedure UnloadLibraries; + +begin + SSLloaded := false; + if SSLLibHandle <> 0 then + begin + FreeLibrary(SSLLibHandle); + SSLLibHandle := 0; + end; + if SSLUtilHandle <> 0 then + begin + FreeLibrary(SSLUtilHandle); + SSLUtilHandle := 0; + end; +end; + +Function LoadLibraries : Boolean; + +begin + Result:=False; + SSLUtilHandle := LoadLib(DLLUtilName); + SSLLibHandle := LoadLib(DLLSSLName); + {$IFDEF MSWINDOWS} + if (SSLLibHandle = 0) then + SSLLibHandle := LoadLib(DLLSSLName2); + {$ENDIF} + Result:=(SSLLibHandle<>0) and (SSLUtilHandle<>0); +end; + +function InitSSLInterface: Boolean; +begin + Result:=SSLLoaded; + if Result then + exit; + EnterCriticalSection(SSLCS); + try + if SSLloaded then + Exit; + Result:=LoadLibraries; + if Not Result then + begin + UnloadLibraries; + Exit; + end; + LoadSSLEntryPoints; + LoadUtilEntryPoints; + //init library + if assigned(_SslLibraryInit) then + _SslLibraryInit; + if assigned(_SslLoadErrorStrings) then + _SslLoadErrorStrings; + if assigned(_OPENSSLaddallalgorithms) then + _OPENSSLaddallalgorithms; + if assigned(_RandScreen) then + _RandScreen; + if assigned(_CRYPTOnumlocks) and assigned(_CRYPTOsetlockingcallback) then + InitLocks; + Result := True; + SSLloaded := True; + finally + LeaveCriticalSection(SSLCS); + end; +end; + +function DestroySSLInterface: Boolean; +begin + Result:=Not isSSLLoaded; + if Result then + exit; + EnterCriticalSection(SSLCS); + try + if assigned(_CRYPTOnumlocks) and assigned(_CRYPTOsetlockingcallback) then + FreeLocks; + EVPCleanup; + CRYPTOcleanupAllExData; + ErrRemoveState(0); + ClearUtilEntryPoints; + ClearSSLEntryPoints; + UnloadLibraries; + Result := True; + finally + LeaveCriticalSection(SSLCS); + end; +end; + + + + +initialization + InitCriticalSection(SSLCS); + finalization DestroySSLInterface; + DoneCriticalSection(SSLCS); end.