Unit SChannel.SyncHandshake

Description

Helper function that implements synchronous TLS handshake by means of Windows SChannel. The function is transport-agnostic so it could be applied to any socket implementation or even other transport.

Inspired by TLS-Sample

Uses JEDI API units

(c) Fr0sT-Brutal

License MIT

Overview

Classes, Interfaces, Objects and Records

Name Description
Class EHandshakeCommError Specific exception class raised by PerformClientHandshake on communication failures.

Functions and Procedures

procedure PerformClientHandshake(var SessionData: TSessionData; const ServerName: string; DebugLogFn: TDebugFn; SendFn: TSendFn; RecvFn: TRecvFn; out hContext: CtxtHandle; out ExtraData: TBytes);

Types

TSendFn = function (Buf: Pointer; BufLen: Integer): Integer of object;
TRecvFn = function (Buf: Pointer; BufLen: Integer): Integer of object;

Description

Functions and Procedures

procedure PerformClientHandshake(var SessionData: TSessionData; const ServerName: string; DebugLogFn: TDebugFn; SendFn: TSendFn; RecvFn: TRecvFn; out hContext: CtxtHandle; out ExtraData: TBytes);

Synchronously perform full handshake process including communication with server. Communication is done via two callback functions. EHandshakeCommError on communication failure

Parameters
SessionData
- [IN/OUT] record with session data
ServerName
- name of domain to connect to
DebugLogFn
- logging callback, could be Nil
Data
- any data with which SendFn and RecvFn will be called
SendFn
- data send callback
RecvFn
- data read callback
hContext
- [OUT] receives current session context
ExtraData
- [OUT] receives extra data sent by server to be decrypted
Exceptions raised
ESSPIError
on SChannel-related failure,

Types

TSendFn = function (Buf: Pointer; BufLen: Integer): Integer of object;

Synchronous communication method.

Parameters
Buf
- buffer with data
BufLen
- size of data in buffer
Returns

amount of data sent if >= 0 or error code if < 0. Error code is used to log and create exception. FormatMessage is used to generate a string from error code. Must try to send all data in full, as no retries or repeated sends is done.

Exceptions raised
exception
on some non-network error
TRecvFn = function (Buf: Pointer; BufLen: Integer): Integer of object;

Synchronous communication method.

Parameters
Buf
- buffer to receive data
BufLen
- size of free space in buffer
Returns

amount of data received if >= 0 or error code if < 0. Error code is used to log and create exception. FormatMessage is used to generate a string from error code. Could receive only some of the data available as incomplete packet is read in loop

Exceptions raised
exception
on some non-network error

Generated by PasDoc 0.16.0.