📄 ssl_openssl_lib.pas
字号:
_EVPcleanup;
end;
procedure CRYPTOcleanupAllExData;
begin
if InitSSLInterface and Assigned(_CRYPTOcleanupAllExData) then
_CRYPTOcleanupAllExData;
end;
procedure RandScreen;
begin
if InitSSLInterface and Assigned(_RandScreen) then
_RandScreen;
end;
function BioNew(b: PBIO_METHOD): PBIO;
begin
if InitSSLInterface and Assigned(_BioNew) then
Result := _BioNew(b)
else
Result := nil;
end;
procedure BioFreeAll(b: PBIO);
begin
if InitSSLInterface and Assigned(_BioFreeAll) then
_BioFreeAll(b);
end;
function BioSMem: PBIO_METHOD;
begin
if InitSSLInterface and Assigned(_BioSMem) then
Result := _BioSMem
else
Result := nil;
end;
function BioCtrlPending(b: PBIO): integer;
begin
if InitSSLInterface and Assigned(_BioCtrlPending) then
Result := _BioCtrlPending(b)
else
Result := 0;
end;
//function BioRead(b: PBIO; Buf: PChar; Len: integer): integer;
function BioRead(b: PBIO; var Buf: String; Len: integer): integer;
begin
if InitSSLInterface and Assigned(_BioRead) then
Result := _BioRead(b, PChar(Buf), Len)
else
Result := -2;
end;
//function BioWrite(b: PBIO; Buf: PChar; Len: integer): integer;
function BioWrite(b: PBIO; Buf: String; Len: integer): integer;
begin
if InitSSLInterface and Assigned(_BioWrite) then
Result := _BioWrite(b, PChar(Buf), Len)
else
Result := -2;
end;
function X509print(b: PBIO; a: PX509): integer;
begin
if InitSSLInterface and Assigned(_X509print) then
Result := _X509print(b, a)
else
Result := 0;
end;
function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
begin
if InitSSLInterface and Assigned(_d2iPKCS12bio) then
Result := _d2iPKCS12bio(b, Pkcs12)
else
Result := nil;
end;
function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): integer;
begin
if InitSSLInterface and Assigned(_PKCS12parse) then
Result := _PKCS12parse(p12, SslPtr(pass), pkey, cert, ca)
else
Result := 0;
end;
procedure PKCS12free(p12: SslPtr);
begin
if InitSSLInterface and Assigned(_PKCS12free) then
_PKCS12free(p12);
end;
function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA;
begin
if InitSSLInterface and Assigned(_RsaGenerateKey) then
Result := _RsaGenerateKey(bits, e, callback, cb_arg)
else
Result := nil;
end;
function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer;
begin
if InitSSLInterface and Assigned(_EvpPkeyAssign) then
Result := _EvpPkeyAssign(pkey, _type, key)
else
Result := 0;
end;
function X509SetVersion(x: PX509; version: integer): integer;
begin
if InitSSLInterface and Assigned(_X509SetVersion) then
Result := _X509SetVersion(x, version)
else
Result := 0;
end;
function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer;
begin
if InitSSLInterface and Assigned(_X509SetPubkey) then
Result := _X509SetPubkey(x, pkey)
else
Result := 0;
end;
function X509SetIssuerName(x: PX509; name: PX509_NAME): integer;
begin
if InitSSLInterface and Assigned(_X509SetIssuerName) then
Result := _X509SetIssuerName(x, name)
else
Result := 0;
end;
function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: integer;
bytes: string; len, loc, _set: integer): integer;
begin
if InitSSLInterface and Assigned(_X509NameAddEntryByTxt) then
Result := _X509NameAddEntryByTxt(name, PChar(field), _type, PChar(Bytes), len, loc, _set)
else
Result := 0;
end;
function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer;
begin
if InitSSLInterface and Assigned(_X509Sign) then
Result := _X509Sign(x, pkey, md)
else
Result := 0;
end;
function Asn1UtctimeNew: PASN1_UTCTIME;
begin
if InitSSLInterface and Assigned(_Asn1UtctimeNew) then
Result := _Asn1UtctimeNew
else
Result := nil;
end;
procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
begin
if InitSSLInterface and Assigned(_Asn1UtctimeFree) then
_Asn1UtctimeFree(a);
end;
function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME;
begin
if InitSSLInterface and Assigned(_X509GmtimeAdj) then
Result := _X509GmtimeAdj(s, adj)
else
Result := nil;
end;
function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer;
begin
if InitSSLInterface and Assigned(_X509SetNotBefore) then
Result := _X509SetNotBefore(x, tm)
else
Result := 0;
end;
function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer;
begin
if InitSSLInterface and Assigned(_X509SetNotAfter) then
Result := _X509SetNotAfter(x, tm)
else
Result := 0;
end;
function i2dX509bio(b: PBIO; x: PX509): integer;
begin
if InitSSLInterface and Assigned(_i2dX509bio) then
Result := _i2dX509bio(b, x)
else
Result := 0;
end;
function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer;
begin
if InitSSLInterface and Assigned(_i2dPrivateKeyBio) then
Result := _i2dPrivateKeyBio(b, pkey)
else
Result := 0;
end;
function EvpGetDigestByName(Name: String): PEVP_MD;
begin
if InitSSLInterface and Assigned(_EvpGetDigestByName) then
Result := _EvpGetDigestByName(PChar(Name))
else
Result := nil;
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 X509GetSerialNumber(x: PX509): PASN1_INTEGER;
begin
if InitSSLInterface and Assigned(_X509GetSerialNumber) then
Result := _X509GetSerialNumber(x)
else
Result := nil;
end;
// 3DES functions
procedure DESsetoddparity(Key: des_cblock);
begin
if InitSSLInterface and Assigned(_DESsetoddparity) then
_DESsetoddparity(Key);
end;
function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer;
begin
if InitSSLInterface and Assigned(_DESsetkeychecked) then
Result := _DESsetkeychecked(key, schedule)
else
Result := -1;
end;
procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer);
begin
if InitSSLInterface and Assigned(_DESecbencrypt) then
_DESecbencrypt(Input, output, ks, enc);
end;
procedure locking_callback(mode, ltype: integer; lfile: PChar; line: integer); cdecl;
begin
if (mode and 1) > 0 then
TCriticalSection(Locks[ltype]).Enter
else
TCriticalSection(Locks[ltype]).Leave;
end;
procedure InitLocks;
var
n: integer;
max: integer;
begin
Locks := TList.Create;
max := _CRYPTOnumlocks;
for n := 1 to max do
Locks.Add(TCriticalSection.Create);
_CRYPTOsetlockingcallback(@locking_callback);
end;
procedure FreeLocks;
var
n: integer;
begin
_CRYPTOsetlockingcallback(nil);
for n := 0 to Locks.Count - 1 do
TCriticalSection(Locks[n]).Free;
Locks.Free;
end;
{$ENDIF}
function LoadLib(const Value: String): HModule;
begin
{$IFDEF CIL}
Result := LoadLibrary(Value);
{$ELSE}
Result := LoadLibrary(PChar(Value));
{$ENDIF}
end;
function GetProcAddr(module: HModule; const ProcName: string): SslPtr;
begin
{$IFDEF CIL}
Result := GetProcAddress(module, ProcName);
{$ELSE}
Result := GetProcAddress(module, PChar(ProcName));
{$ENDIF}
end;
function InitSSLInterface: Boolean;
var
s: string;
x: integer;
begin
SSLCS.Enter;
try
if not IsSSLloaded then
begin
{$IFDEF CIL}
SSLLibHandle := 1;
SSLUtilHandle := 1;
{$ELSE}
SSLLibHandle := LoadLib(DLLSSLName);
SSLUtilHandle := LoadLib(DLLUtilName);
{$IFNDEF LINUX}
if (SSLLibHandle = 0) then
SSLLibHandle := LoadLib(DLLSSLName2);
{$ENDIF}
{$ENDIF}
if (SSLLibHandle <> 0) and (SSLUtilHandle <> 0) then
begin
{$IFNDEF CIL}
_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');
_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(SSLLibHan
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -