📄 synassl.pas
字号:
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_get_verify_result')]
function SSLGetVerifyResult(ssl: PSSL):Integer;external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_free')]
procedure SslX509Free(x: PX509); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_NAME_oneline')]
function SslX509NameOneline(a: PX509_NAME; buf: StringBuilder; size: Integer): String; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_get_subject_name')]
function SslX509GetSubjectName(a: PX509):PX509_NAME; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_get_issuer_name')]
function SslX509GetIssuerName(a: PX509):PX509_NAME; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_NAME_hash')]
function SslX509NameHash(x: PX509_NAME):Cardinal; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_digest')]
function SslX509Digest (data: PX509; _type: PEVP_MD; md: StringBuilder; var len: Integer):Integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'EVP_md5')]
function SslEvpMd5:PEVP_MD; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ERR_error_string')]
function ErrErrorString(e: integer; var buf: String): String; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ERR_get_error')]
function ErrGetError: integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ERR_clean_error')]
procedure ErrClearError; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ERR_free_strings')]
procedure ErrFreeStrings; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ERR_remove_state')]
procedure ErrRemoveState(pid: integer); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'EVP_cleanup')]
procedure EVPcleanup; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'CRYPTO_cleanup_all_ex_data')]
procedure CRYPTOcleanupAllExData; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'RAND_screen')]
procedure RandScreen; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_new')]
function BioNew(b: PBIO_METHOD): PBIO; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_free_all')]
procedure BioFreeAll(b: PBIO); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_s_mem')]
function BioSMem: PBIO_METHOD; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_ctrl_pending')]
function BioCtrlPending(b: PBIO): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_read')]
function BioRead(b: PBIO; Buf: StringBuilder; Len: integer): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_write')]
function BioWrite(b: PBIO; var Buf: String; Len: integer): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_print')]
function X509print(b: PBIO; a: PX509): integer; external;
// 3DES functions
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'DES_set_odd_parity')]
procedure DESsetoddparity(Key: des_cblock); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'DES_set_key_checked')]
function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'DES_ecb_encrypt')]
procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer); external;
{$ELSE}
// libssl.dll
function SslGetError(s: PSSL; ret_code: Integer):Integer;
function SslLibraryInit:Integer;
procedure SslLoadErrorStrings;
// function SslCtxSetCipherList(arg0: PSSL_CTX; str: PChar):Integer;
function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String):Integer;
function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
procedure SslCtxFree(arg0: PSSL_CTX);
function SslSetFd(s: PSSL; fd: Integer):Integer;
function SslMethodV2:PSSL_METHOD;
function SslMethodV3:PSSL_METHOD;
function SslMethodTLSV1:PSSL_METHOD;
function SslMethodV23:PSSL_METHOD;
// function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer;
function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;
// function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: PChar):Integer;
function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):Integer;
function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer;
procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
// function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):Integer;
function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: String; const CApath: String):Integer;
function SslNew(ctx: PSSL_CTX):PSSL;
procedure SslFree(ssl: PSSL);
function SslAccept(ssl: PSSL):Integer;
function SslConnect(ssl: PSSL):Integer;
function SslShutdown(ssl: PSSL):Integer;
function SslRead(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
function SslPeek(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
function SslWrite(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
function SslPending(ssl: PSSL):Integer;
function SslGetVersion(ssl: PSSL):String;
function SslGetPeerCertificate(ssl: PSSL):PX509;
procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction);
function SSLGetCurrentCipher(s: PSSL):SslPtr;
function SSLCipherGetName(c: SslPtr): String;
function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer;
function SSLGetVerifyResult(ssl: PSSL):Integer;
// libeay.dll
procedure SslX509Free(x: PX509);
function SslX509NameOneline(a: PX509_NAME; var buf: String; size: Integer):String;
function SslX509GetSubjectName(a: PX509):PX509_NAME;
function SslX509GetIssuerName(a: PX509):PX509_NAME;
function SslX509NameHash(x: PX509_NAME):Cardinal;
// function SslX509Digest(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer;
function SslX509Digest(data: PX509; _type: PEVP_MD; md: String; var len: Integer):Integer;
function SslEvpMd5:PEVP_MD;
// function ErrErrorString(e: integer; buf: PChar): PChar;
function ErrErrorString(e: integer; var buf: String): String;
function ErrGetError: integer;
procedure ErrClearError;
procedure ErrFreeStrings;
procedure ErrRemoveState(pid: integer);
procedure EVPcleanup;
procedure CRYPTOcleanupAllExData;
procedure RandScreen;
function BioNew(b: PBIO_METHOD): PBIO;
procedure BioFreeAll(b: PBIO);
function BioSMem: PBIO_METHOD;
function BioCtrlPending(b: PBIO): integer;
function BioRead(b: PBIO; var Buf: String; Len: integer): integer;
function BioWrite(b: PBIO; Buf: String; Len: integer): integer;
function X509print(b: PBIO; a: PX509): integer;
// 3DES functions
procedure DESsetoddparity(Key: des_cblock);
function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer;
procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer);
{$ENDIF}
function IsSSLloaded: Boolean;
function InitSSLInterface: Boolean;
function DestroySSLInterface: Boolean;
implementation
uses SyncObjs;
{$IFNDEF CIL}
type
// libssl.dll
TSslGetError = function(s: PSSL; ret_code: Integer):Integer; cdecl;
TSslLibraryInit = function:Integer; cdecl;
TSslLoadErrorStrings = procedure; cdecl;
TSslCtxSetCipherList = function(arg0: PSSL_CTX; str: PChar):Integer; cdecl;
TSslCtxNew = function(meth: PSSL_METHOD):PSSL_CTX; cdecl;
TSslCtxFree = procedure(arg0: PSSL_CTX); cdecl;
TSslSetFd = function(s: PSSL; fd: Integer):Integer; cdecl;
TSslMethodV2 = function:PSSL_METHOD; cdecl;
TSslMethodV3 = function:PSSL_METHOD; cdecl;
TSslMethodTLSV1 = function:PSSL_METHOD; cdecl;
TSslMethodV23 = function:PSSL_METHOD; cdecl;
TSslCtxUsePrivateKeyFile = function(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer; cdecl;
TSslCtxUseCertificateChainFile = function(ctx: PSSL_CTX; const _file: PChar):Integer; cdecl;
TSslCtxCheckPrivateKeyFile = function(ctx: PSSL_CTX):Integer; cdecl;
TSslCtxSetDefaultPasswdCb = procedure(ctx: PSSL_CTX; cb: Pointer); cdecl;
TSslCtxSetDefaultPasswdCbUserdata = procedure(ctx: PSSL_CTX; u: Pointer); cdecl;
TSslCtxLoadVerifyLocations = function(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):Integer; cdecl;
TSslNew = function(ctx: PSSL_CTX):PSSL; cdecl;
TSslFree = procedure(ssl: PSSL); cdecl;
TSslAccept = function(ssl: PSSL):Integer; cdecl;
TSslConnect = function(ssl: PSSL):Integer; cdecl;
TSslShutdown = function(ssl: PSSL):Integer; cdecl;
TSslRead = function(ssl: PSSL; buf: PChar; num: Integer):Integer; cdecl;
TSslPeek = function(ssl: PSSL; buf: PChar; num: Integer):Integer; cdecl;
TSslWrite = function(ssl: PSSL; const buf: PChar; num: Integer):Integer; cdecl;
TSslPending = function(ssl: PSSL):Integer; cdecl;
TSslGetVersion = function(ssl: PSSL):PChar; cdecl;
TSslGetPeerCertificate = function(ssl: PSSL):PX509; cdecl;
TSslCtxSetVerify = procedure(ctx: PSSL_CTX; mode: Integer; arg2: Pointer); cdecl;
TSSLGetCurrentCipher = function(s: PSSL):pointer; cdecl;
TSSLCipherGetName = function(c: pointer):PChar; cdecl;
TSSLCipherGetBits = function(c: pointer; alg_bits: PInteger):Integer; cdecl;
TSSLGetVerifyResult = function(ssl: PSSL):Integer; cdecl;
// libeay.dll
TSslX509Free = procedure(x: PX509); cdecl;
TSslX509NameOneline = function(a: PX509_NAME; buf: PChar; size: Integer):PChar; cdecl;
TSslX509GetSubjectName = function(a: PX509):PX509_NAME; cdecl;
TSslX509GetIssuerName = function(a: PX509):PX509_NAME; cdecl;
TSslX509NameHash = function(x: PX509_NAME):Cardinal; cdecl;
TSslX509Digest = function(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer; cdecl;
TSslEvpMd5 = function:PEVP_MD; cdecl;
TErrErrorString = function(e: integer; buf: PChar): PChar; cdecl;
TErrGetError = function: integer; cdecl;
TErrClearError = procedure; cdecl;
TErrFreeStrings = procedure; cdecl;
TErrRemoveState = procedure(pid: integer); cdecl;
TEVPcleanup = procedure; cdecl;
TCRYPTOcleanupAllExData = procedure; cdecl;
TRandScreen = procedure; cdecl;
TBioNew = function(b: PBIO_METHOD): PBIO; cdecl;
TBioFreeAll = procedure(b: PBIO); cdecl;
TBioSMem = function: PBIO_METHOD; cdecl;
TBioCtrlPending = function(b: PBIO): integer; cdecl;
TBioRead = function(b: PBIO; Buf: PChar; Len: integer): integer; cdecl;
TBioWrite = function(b: PBIO; Buf: PChar; Len: integer): integer; cdecl;
TX509print = function(b: PBIO; a: PX509): integer; cdecl;
// 3DES functions
TDESsetoddparity = procedure(Key: des_cblock); cdecl;
TDESsetkeychecked = function(key: des_cblock; schedule: des_key_schedule): Integer; cdecl;
TDESecbencrypt = procedure(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer); cdecl;
var
// libssl.dll
_SslGetError: TSslGetError = nil;
_SslLibraryInit: TSslLibraryInit = nil;
_SslLoadErrorStrings: TSslLoadErrorStrings = nil;
_SslCtxSetCipherList: TSslCtxSetCipherList = nil;
_SslCtxNew: TSslCtxNew = nil;
_SslCtxFree: TSslCtxFree = nil;
_SslSetFd: TSslSetFd = nil;
_SslMethodV2: TSslMethodV2 = nil;
_SslMethodV3: TSslMethodV3 = nil;
_SslMethodTLSV1: TSslMethodTLSV1 = nil;
_SslMethodV23: TSslMethodV23 = nil;
_SslCtxUsePrivateKeyFile: TSslCtxUsePrivateKeyFile = nil;
_SslCtxUseCertificateChainFile: TSslCtxUseCertificateChainFile = nil;
_SslCtxCheckPrivateKeyFile: TSslCtxCheckPrivateKeyFile = nil;
_SslCtxSetDefaultPasswdCb: TSslCtxSetDefaultPasswdCb = nil;
_SslCtxSetDefaultPasswdCbUserdata: TSslCtxSetDefaultPasswdCbUserdata = nil;
_SslCtxLoadVerifyLocations: TSslCtxLoadVerifyLocations = nil;
_SslNew: TSslNew = nil;
_SslFree: TSslFree = nil;
_SslAccept: TSslAccept = nil;
_SslConnect: TSslConnect = nil;
_SslShutdown: TSslShutdown = nil;
_SslRead: TSslRead = nil;
_SslPeek: TSslPeek = nil;
_SslWrite: TSslWrite = nil;
_SslPending: TSslPending = nil;
_SslGetVersion: TSslGetVersion = nil;
_SslGetPeerCertificate: TSslGetPeerCertificate = nil;
_SslCtxSetVerify: TSslCtxSetVerify = nil;
_SSLGetCurrentCipher: TSSLGetCurrentCipher = nil;
_SSLCipherGetName: TSSLCipherGetName = nil;
_SSLCipherGetBits: TSSLCipherGetBits = nil;
_SSLGetVerifyResult: TSSLGetVerifyResult = nil;
// libeay.dll
_SslX509Free: TSslX509Free = nil;
_SslX509NameOneline: TSslX509NameOneline = nil;
_SslX509GetSubjectName: TSslX509GetSubjectName = nil;
_SslX509GetIssuerName: TSslX509GetIssuerName = nil;
_SslX509NameHash: TSslX509NameHash = nil;
_SslX509Digest: TSslX509Digest = nil;
_SslEvpMd5: TSslEvpMd5 = nil;
_ErrErrorString: TErrErrorString = nil;
_ErrGetError: TErrGetError = nil;
_ErrClearError: TErrClearError = nil;
_ErrFreeStrings: TErrFreeStrings = nil;
_ErrRemoveState: TErrRemoveState = nil;
_EVPcleanup: TEVPcleanup = nil;
_CRYPTOcleanupAllExData: TCRYPTOcleanupAllExData = nil;
_RandScreen: TRandScreen = nil;
_BioNew: TBioNew = nil;
_BioFreeAll: TBioFreeAll = nil;
_BioSMem: TBioSMem = nil;
_BioCtrlPending: TBioCtrlPending = nil;
_BioRead: TBioRead = nil;
_BioWrite: TBioWrite = nil;
_X509print: TX509print = nil;
// 3DES functions
_DESsetoddparity: TDESsetoddparity = nil;
_DESsetkeychecked: TDESsetkeychecked = nil;
_DESecbencrypt: TDESecbencrypt = nil;
{$ENDIF}
var
SSLCS: TCriticalSection;
SSLloaded: boolean = false;
{$IFNDEF CIL}
// libssl.dll
function SslGetError(s: PSSL; ret_code: Integer):Integer;
begin
if InitSSLInterface and Assigned(_SslGetError) then
Result := _SslGetError(s, ret_code)
else
Result := SSL_ERROR_SSL;
end;
function SslLibraryInit:Integer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -