# Class TTCPBlockSocket

Description | Hierarchy | Fields | Methods | Properties

## Unit

blcksock

## Declaration

`type TTCPBlockSocket = class(TSocksBlockSocket)`

## Description

Implementation of TCP socket.

Supported features: IPv4, IPv6, SSL/TLS (SSL2, SSL3 and TLS), SOCKS5 proxy (outgoing connections and limited incomming), SOCKS4/4a proxy (outgoing connections and limited incomming), TCP through HTTP proxy tunnel.

## Hierarchy

TTCPBlockSocket > TSocksBlockSocket > TBlockSocket > TObject

## Methods

### Overview

| `constructor Create;`
| `function Accept: TSocket;`
| `procedure CloseSocket; override;`
| `procedure Connect(IP, Port: string); override;`
| `function GetLocalSinIP: string; override;`
| `function GetLocalSinPort: Integer; override;`
| `function GetRemoteSinIP: string; override;`
| `function GetRemoteSinPort: Integer; override;`
| `function GetSocketProtocol: integer; override;`
| `function GetSocketType: integer; override;`
| `procedure Listen; virtual;`
| `function RecvBuffer(Buffer: TMemory; Len: Integer): Integer; override;`
| `function SendBuffer(Buffer: TMemory; Length: Integer): Integer; override;`
| `function SSLAcceptConnection: Boolean;`
| `function SSLCheck: Boolean;`
| `procedure SSLDoConnect;`
| `procedure SSLDoShutdown;`
| `function SSLGetCertInfo: string;`
| `function SSLGetCipherAlgBits: integer;`
| `function SSLGetCipherBits: integer;`
| `function SSLGetCipherName: string;`
| `function SSLGetPeerFingerprint: string;`
| `function SSLGetPeerIssuer: string;`
| `function SSLGetPeerIssuerHash: Cardinal;`
| `function SSLGetPeerName: string;`
| `function SSLGetPeerSubject: string;`
| `function SSLGetPeerSubjectHash: Cardinal;`
| `function SSLGetSSLVersion: string;`
| `function SSLGetVerifyCert: integer;`
| `function WaitingData: Integer; override;`

### Description

| `function Accept: TSocket;`

Waits until new incoming connection comes. After it comes a new socket is automatically created (socket handler is returned by this function as result).

If you use SOCKS, new socket is not created! In this case is used same socket as socket for listening! So, you can accept only one connection in SOCKS mode.

| `procedure CloseSocket; override;`

See CloseSocket

| `procedure Connect(IP, Port: string); override;`

Connects socket to remote IP address and PORT. The same rules as with Bind method are valid. The only exception is that PORT with 0 value will not be connected. After call to this method a communication channel between local and remote socket is created. Local socket is assigned automatically if not controlled by previous call to Bind method. Structures LocalSin and RemoteSin will be filled with valid values.

If you use SOCKS, activate outgoing TCP connection by SOCKS proxy specified in SocksIP. (By CONNECT method of SOCKS.)

If you use HTTP-tunnel mode, activate outgoing TCP connection by HTTP tunnel specified in HTTPTunnelIP. (By CONNECT method of HTTP protocol.)

If you additionally use SSL mode, then SSL/TLS session was started.

Note: If you call this on non-created socket, then socket is created automaticly.

| `constructor Create;`

| `function GetLocalSinIP: string; override;`

See GetLocalSinIP

| `function GetLocalSinPort: Integer; override;`

See GetLocalSinPort

| `function GetRemoteSinIP: string; override;`

See GetRemoteSinIP

| `function GetRemoteSinPort: Integer; override;`

See GetRemoteSinPort

| `function GetSocketProtocol: integer; override;`

Return value of protocol type for socket creation. For TCP return IPPROTO_TCP.

| `function GetSocketType: integer; override;`

Return value of socket type. For TCP return SOCK_STREAM.

| `procedure Listen; virtual;`

Sets socket to receive mode for new incoming connections. It is necessary to use Bind function call before this method to select receiving port!

If you use SOCKS, activate incoming TCP connection by this proxy. (By BIND method of SOCKS.)

| `function RecvBuffer(Buffer: TMemory; Len: Integer): Integer; override;`

See RecvBuffer

| `function SendBuffer(Buffer: TMemory; Length: Integer): Integer; override;`

See SendBuffer

| `function SSLAcceptConnection: Boolean;`

If you need use this component as SSL/TLS TCP server, then after accepting of inbound connection you need start SSL/TLS session by this method. Before call this function, you must have assigned all neeeded certificates and keys!

| `function SSLCheck: Boolean;`

Test last SSL operation for errors. If error occured, then is filled SSLLastError and SSLLastErrorDesc properties.

| `procedure SSLDoConnect;`

If you need upgrade existing TCP connection to SSL/TLS mode, then call this method. This method switch this class to SSL mode and do SSL/TSL handshake.

| `procedure SSLDoShutdown;`

By this method you can downgrade existing SSL/TLS connection to normal TCP connection.

| `function SSLGetCertInfo: string;`

Return all detailed information about certificate from remote side of SSL/TLS connection. Result string is multilined!

| `function SSLGetCipherAlgBits: integer;`

Return number of bits in current Cipher algorythm.

| `function SSLGetCipherBits: integer;`

Return currently used number of bits in current Cipher algorythm.

| `function SSLGetCipherName: string;`

Return currently used Cipher.

| `function SSLGetPeerFingerprint: string;`

Return fingerprint of remote SSL peer.

| `function SSLGetPeerIssuer: string;`

Return issuer certificate of remote SSL peer.

| `function SSLGetPeerIssuerHash: Cardinal;`

Return issuer's certificate hash of remote SSL peer.

| `function SSLGetPeerName: string;`

Return peer name from remote side certificate. This is good for verify, if certificate is generated for remote side IP name.

| `function SSLGetPeerSubject: string;`

Return subject of remote SSL peer.

| `function SSLGetPeerSubjectHash: Cardinal;`

Return subject's hash of remote SSL peer.

| `function SSLGetSSLVersion: string;`

Return string with identificator of SSL/TLS version of existing connection.

| `function SSLGetVerifyCert: integer;`

Return result value of verify remote side certificate. Look to OpenSSL documentation for possible values. For example 0 is successfuly verified certificate, or 18 is self-signed certificate.

| `function WaitingData: Integer; override;`

See WaitingData

## Properties

### Overview

| `property HTTPTunnel: Boolean;`
| `property HTTPTunnelIP: string;`
| `property HTTPTunnelPass: string;`
| `property HTTPTunnelPort: string;`
| `property HTTPTunnelTimeout: integer;`
| `property HTTPTunnelUser: string;`
| `property SSLBypass: Boolean;`
| `property SSLCertCAFile: string;`
| `property SSLCertificateFile: string;`
| `property SSLCiphers: string;`
| `property SSLEnabled: Boolean;`
| `property SSLLastError: integer;`
| `property SSLLastErrorDesc: string;`
| `property SSLLoaded: Boolean;`
| `property SSLPassword: string;`
| `property SSLPrivateKeyFile: string;`
| `property SSLType: TSSLType;`
| `property SSLverifyCert: Boolean;`

### Description

| `property HTTPTunnel: Boolean;`

`True` if is used HTTP tunnel mode.

| `property HTTPTunnelIP: string;`

Specify IP address of HTTP proxy. Assingning non-empty value to this property enable HTTP-tunnel mode. This mode is for tunnelling any outgoing TCP connection through HTTP proxy server. (If policy on HTTP proxy server allow this!) Warning: You cannot combine this mode with SOCK5 mode!

| `property HTTPTunnelPass: string;`

Specify authorisation password for access to HTTP proxy in HTTP-tunnel mode.

| `property HTTPTunnelPort: string;`

Specify port of HTTP proxy for HTTP-tunneling.

| `property HTTPTunnelTimeout: integer;`

Specify timeout for communication with HTTP proxy in HTTPtunnel mode.

| `property HTTPTunnelUser: string;`

Specify authorisation username for access to HTTP proxy in HTTP-tunnel mode. If you not need authorisation, then let this property empty.

| `property SSLBypass: Boolean;`

If is SSL mode enabled and this property is `True`, then all data (read and write) will not be encrypted/decrypted.

| `property SSLCertCAFile: string;`

filename and path to file with bundle of CA certificates. (you may use ca-bundle.crt file from SynaCert.zip)

| `property SSLCertificateFile: string;`

Filename and path to PEM file with your certificate. If certificate need password for decrypt, you can assign this password to SSLPassword property.

| `property SSLCiphers: string;`

By this property you can modify default set of SSL/TLS ciphers.

| `property SSLEnabled: Boolean;`

By this property you can enable or disable SSL mode. Enabling loads needed OpenSSL or SSLeay libraries. Libraries is loaded to memory only once for all Synapse's objects.

Note: when you enable SSL mode, all keys and certificates are loaded (if needed property is unempty)

| `property SSLLastError: integer;`

Contains last SSL error code.

| `property SSLLastErrorDesc: string;`

If some SSL error is occured, then contains human readable description of this error.

| `property SSLLoaded: Boolean;`

Is SSL interface loaded or not?

| `property SSLPassword: string;`

Password for decrypting of encoded certificate.

Note: This not work with delphi8. You cannot use password protected certificates with .NET!

| `property SSLPrivateKeyFile: string;`

Filename and path to PEM file with your private key.

| `property SSLType: TSSLType;`

Here you can specify requested SSL/TLS mode. Default is autodetection, but on some servers autodetection not working properly. In this case you must specify requested SSL/TLS mode by your hand!

| `property SSLverifyCert: Boolean;`

If `True`, then is verified client certificate. (it is good for writing SSL/TLS servers.) When you are not server, but you are client, then if this property is `True`, verify servers certificate.

Generated by PasDoc 0.8.8.2 on 2005-01-19 20:01:17