📄 ssl_openssl_lib.pas
字号:
function X509NameOneline(a: PX509_NAME; var buf: String; size: Integer):String;
function X509GetSubjectName(a: PX509):PX509_NAME;
function X509GetIssuerName(a: PX509):PX509_NAME;
function X509NameHash(x: PX509_NAME):Cardinal;
// function SslX509Digest(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer;
function X509Digest(data: PX509; _type: PEVP_MD; md: String; var len: Integer):Integer;
function X509print(b: PBIO; a: PX509): integer;
function X509SetVersion(x: PX509; version: integer): integer;
function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer;
function X509SetIssuerName(x: PX509; name: PX509_NAME): integer;
function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: integer;
bytes: string; len, loc, _set: integer): integer;
function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer;
function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME;
function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer;
function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer;
function X509GetSerialNumber(x: PX509): PASN1_INTEGER;
function EvpPkeyNew: EVP_PKEY;
procedure EvpPkeyFree(pk: EVP_PKEY);
function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer;
function EvpGetDigestByName(Name: String): PEVP_MD;
procedure EVPcleanup;
// function ErrErrorString(e: integer; buf: PChar): PChar;
function SSLeayversion(t: integer): string;
procedure ErrErrorString(e: integer; var buf: string; len: integer);
function ErrGetError: integer;
procedure ErrClearError;
procedure ErrFreeStrings;
procedure ErrRemoveState(pid: integer);
procedure OPENSSLaddallalgorithms;
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 d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): integer;
procedure PKCS12free(p12: SslPtr);
function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA;
function Asn1UtctimeNew: PASN1_UTCTIME;
procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
function i2dX509bio(b: PBIO; x: PX509): integer;
function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): 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;
TSslCtxUsePrivateKey = function(ctx: PSSL_CTX; pkey: sslptr):Integer; cdecl;
TSslCtxUsePrivateKeyASN1 = function(pk: integer; ctx: PSSL_CTX; d: sslptr; len: integer):Integer; cdecl;
TSslCtxUsePrivateKeyFile = function(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer; cdecl;
TSslCtxUseCertificate = function(ctx: PSSL_CTX; x: SslPtr):Integer; cdecl;
TSslCtxUseCertificateASN1 = function(ctx: PSSL_CTX; len: Integer; d: SslPtr):Integer; cdecl;
TSslCtxUseCertificateFile = 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: SslPtr); cdecl;
TSslCtxSetDefaultPasswdCbUserdata = procedure(ctx: PSSL_CTX; u: SslPtr); 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: SslPtr); cdecl;
TSSLGetCurrentCipher = function(s: PSSL):SslPtr; cdecl;
TSSLCipherGetName = function(c: Sslptr):PChar; cdecl;
TSSLCipherGetBits = function(c: SslPtr; alg_bits: PInteger):Integer; cdecl;
TSSLGetVerifyResult = function(ssl: PSSL):Integer; cdecl;
// libeay.dll
TX509New = function: PX509; cdecl;
TX509Free = procedure(x: PX509); cdecl;
TX509NameOneline = function(a: PX509_NAME; buf: PChar; size: Integer):PChar; cdecl;
TX509GetSubjectName = function(a: PX509):PX509_NAME; cdecl;
TX509GetIssuerName = function(a: PX509):PX509_NAME; cdecl;
TX509NameHash = function(x: PX509_NAME):Cardinal; cdecl;
TX509Digest = function(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer; cdecl;
TX509print = function(b: PBIO; a: PX509): integer; cdecl;
TX509SetVersion = function(x: PX509; version: integer): integer; cdecl;
TX509SetPubkey = function(x: PX509; pkey: EVP_PKEY): integer; cdecl;
TX509SetIssuerName = function(x: PX509; name: PX509_NAME): integer; cdecl;
TX509NameAddEntryByTxt = function(name: PX509_NAME; field: PChar; _type: integer;
bytes: PChar; len, loc, _set: integer): integer; cdecl;
TX509Sign = function(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer; cdecl;
TX509GmtimeAdj = function(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME; cdecl;
TX509SetNotBefore = function(x: PX509; tm: PASN1_UTCTIME): integer; cdecl;
TX509SetNotAfter = function(x: PX509; tm: PASN1_UTCTIME): integer; cdecl;
TX509GetSerialNumber = function(x: PX509): PASN1_INTEGER; cdecl;
TEvpPkeyNew = function: EVP_PKEY; cdecl;
TEvpPkeyFree = procedure(pk: EVP_PKEY); cdecl;
TEvpPkeyAssign = function(pkey: EVP_PKEY; _type: integer; key: Prsa): integer; cdecl;
TEvpGetDigestByName = function(Name: PChar): PEVP_MD; cdecl;
TEVPcleanup = procedure; cdecl;
TSSLeayversion = function(t: integer): PChar; cdecl;
TErrErrorString = procedure(e: integer; buf: PChar; len: integer); cdecl;
TErrGetError = function: integer; cdecl;
TErrClearError = procedure; cdecl;
TErrFreeStrings = procedure; cdecl;
TErrRemoveState = procedure(pid: integer); cdecl;
TOPENSSLaddallalgorithms = 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;
Td2iPKCS12bio = function(b:PBIO; Pkcs12: SslPtr): SslPtr; cdecl;
TPKCS12parse = function(p12: SslPtr; pass: PChar; var pkey, cert, ca: SslPtr): integer; cdecl;
TPKCS12free = procedure(p12: SslPtr); cdecl;
TRsaGenerateKey = function(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA; cdecl;
TAsn1UtctimeNew = function: PASN1_UTCTIME; cdecl;
TAsn1UtctimeFree = procedure(a: PASN1_UTCTIME); cdecl;
TAsn1IntegerSet = function(a: PASN1_INTEGER; v: integer): integer; cdecl;
Ti2dX509bio = function(b: PBIO; x: PX509): integer; cdecl;
Ti2dPrivateKeyBio= function(b: PBIO; pkey: EVP_PKEY): 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;
//thread lock functions
TCRYPTOnumlocks = function: integer; cdecl;
TCRYPTOSetLockingCallback = procedure(cb: Sslptr); 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;
_SslCtxUsePrivateKey: TSslCtxUsePrivateKey = nil;
_SslCtxUsePrivateKeyASN1: TSslCtxUsePrivateKeyASN1 = nil;
_SslCtxUsePrivateKeyFile: TSslCtxUsePrivateKeyFile = nil;
_SslCtxUseCertificate: TSslCtxUseCertificate = nil;
_SslCtxUseCertificateASN1: TSslCtxUseCertificateASN1 = nil;
_SslCtxUseCertificateFile: TSslCtxUseCertificateFile = 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
_X509New: TX509New = nil;
_X509Free: TX509Free = nil;
_X509NameOneline: TX509NameOneline = nil;
_X509GetSubjectName: TX509GetSubjectName = nil;
_X509GetIssuerName: TX509GetIssuerName = nil;
_X509NameHash: TX509NameHash = nil;
_X509Digest: TX509Digest = nil;
_X509print: TX509print = nil;
_X509SetVersion: TX509SetVersion = nil;
_X509SetPubkey: TX509SetPubkey = nil;
_X509SetIssuerName: TX509SetIssuerName = nil;
_X509NameAddEntryByTxt: TX509NameAddEntryByTxt = nil;
_X509Sign: TX509Sign = nil;
_X509GmtimeAdj: TX509GmtimeAdj = nil;
_X509SetNotBefore: TX509SetNotBefore = nil;
_X509SetNotAfter: TX509SetNotAfter = nil;
_X509GetSerialNumber: TX509GetSerialNumber = nil;
_EvpPkeyNew: TEvpPkeyNew = nil;
_EvpPkeyFree: TEvpPkeyFree = nil;
_EvpPkeyAssign: TEvpPkeyAssign = nil;
_EvpGetDigestByName: TEvpGetDigestByName = nil;
_EVPcleanup: TEVPcleanup = nil;
_SSLeayversion: TSSLeayversion = nil;
_ErrErrorString: TErrErrorString = nil;
_ErrGetError: TErrGetError = nil;
_ErrClearError: TErrClearError = nil;
_ErrFreeStrings: TErrFreeStrings = nil;
_ErrRemoveState: TErrRemoveState = nil;
_OPENSSLaddallalgorithms: TOPENSSLaddallalgorithms = 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;
_d2iPKCS12bio: Td2iPKCS12bio = nil;
_PKCS12parse: TPKCS12parse = nil;
_PKCS12free: TPKCS12free = nil;
_RsaGenerateKey: TRsaGenerateKey = nil;
_Asn1UtctimeNew: TAsn1UtctimeNew = nil;
_Asn1UtctimeFree: TAsn1UtctimeFree = nil;
_Asn1IntegerSet: TAsn1IntegerSet = nil;
_i2dX509bio: Ti2dX509bio = nil;
_i2dPrivateKeyBio: Ti2dPrivateKeyBio = nil;
// 3DES functions
_DESsetoddparity: TDESsetoddparity = nil;
_DESsetkeychecked: TDESsetkeychecked = nil;
_DESecbencrypt: TDESecbencrypt = nil;
//thread lock functions
_CRYPTOnumlocks: TCRYPTOnumlocks = nil;
_CRYPTOSetLockingCallback: TCRYPTOSetLockingCallback = nil;
{$ENDIF}
var
SSLCS: TCriticalSection;
SSLloaded: boolean = false;
{$IFNDEF CIL}
Locks: TList;
{$ENDIF}
{$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;
begin
if InitSSLInterface and Assigned(_SslLibraryInit) then
Result := _SslLibraryInit
else
Result := 1;
end;
procedure SslLoadErrorStrings;
begin
if InitSSLInterface and Assigned(_SslLoadErrorStrings) then
_SslLoadErrorStrings;
end;
//function SslCtxSetCipherList(arg0: PSSL_CTX; str: PChar):Integer;
function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String):Integer;
begin
if InitSSLInterface and Assigned(_SslCtxSetCipherList) then
Result := _SslCtxSetCipherList(arg0, PChar(str))
else
Result := 0;
end;
function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
begin
if InitSSLInterface and Assigned(_SslCtxNew) then
Result := _SslCtxNew(meth)
else
Result := nil;
end;
procedure SslCtxFree(arg0: PSSL_CTX);
begin
if InitSSLInterface and Assigned(_SslCtxFree) then
_SslCtxFree(arg0);
end;
function SslSetFd(s: PSSL; fd: Integer):Integer;
begin
if InitSSLInterface and Assigned(_SslSetFd) then
Result := _SslSetFd(s, fd)
else
Result := 0;
end;
function SslMethodV2:PSSL_METHOD;
begin
if InitSSLInterface and Assigned(_SslMethodV2) then
Result := _SslMethodV2
else
Result := nil;
end;
function SslMethodV3:PSSL_METHOD;
begin
if InitSSLInterface and Assigned(_SslMethodV3) then
Result := _SslMethodV3
else
Result := nil;
end;
function SslMethodTLSV1:PSSL_METHOD;
begin
if InitSSLInterface and Assigned(_SslMethodTLSV1) then
Result := _SslMethodTLSV1
else
Result := nil;
end;
function SslMethodV23:PSSL_METHOD;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -