C# Class Org.Mentalis.Security.Ssl.SecureSocket

Implements the Berkeley sockets interface and optionally encrypts/decrypts transmitted data.
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
Inheritance: VirtualSocket
Show file Open project: ElanHasson/SSIS-Extensions Class Usage Examples

Public Methods

Method Description
Accept ( ) : VirtualSocket

Creates a new SecureSocket to handle an incoming connection request.

The returned VirtualSocket can be cast to a SecureSocket if necessary.

BeginAccept ( AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous request to create a new SecureSocket to accept an incoming connection request.

BeginConnect ( EndPoint remoteEP, AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous request for a connection to a network device.

BeginReceive ( byte buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state ) : IAsyncResult

Begins to asynchronously receive data from a connected SecureSocket.

BeginSend ( byte buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state ) : IAsyncResult

Sends data asynchronously to a connected SecureSocket.

BeginShutdown ( AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous request to shut the connection down.

ChangeSecurityProtocol ( Org.Mentalis.Security.Ssl.SecurityOptions options ) : void

Changes the security protocol. This method can only be used to 'upgrade' a connection from no-security to either SSL or TLS.

Programs should only call this method if there is no active Connect, Accept, Send or Receive!

Close ( ) : void

Forces a SecureSocket connection to close.

Connect ( EndPoint remoteEP ) : void

Establishes a connection to a remote device and optionally negotiates a secure transport protocol.

EndAccept ( IAsyncResult asyncResult ) : VirtualSocket

Ends an asynchronous request to create a new SecureSocket to accept an incoming connection request.

The returned VirtualSocket can be cast to a SecureSocket if necessary.

EndConnect ( IAsyncResult asyncResult ) : void

Ends a pending asynchronous connection request.

EndReceive ( IAsyncResult asyncResult ) : int

Ends a pending asynchronous read.

EndSend ( IAsyncResult asyncResult ) : int

Ends a pending asynchronous send.

EndShutdown ( IAsyncResult asyncResult ) : void

Ends an asynchronous request to shut the connection down.

Poll ( int microSeconds, SelectMode mode ) : bool

Determines the status of the VirtualSocket.

This property is not supported for SSL/TLS sockets. It can only be used if the SecureProtocol is set to None. Asynchronous behavior in SSL or TLS mode can be achieved by calling the asynchronous methods.Set microSeconds parameter to a negative integer if you would like to wait indefinitely for a response.

QueueRenegotiate ( ) : void

Queues a renegotiation request.

Use the QueueRenegotiate function with caution. Some SSL/TLS clients or server do not support renegotiation. For instance, requesting a renegotiation in the middle of sending a HTTP request to a MS IIS server causes the connection to be shut down. Renegotiations should only be used when a small private key [512 bits] is used and the connection is active for a long period of time.

Receive ( byte buffer ) : int

Receives data from a connected SecureSocket into a specific location of the receive buffer.

Receive ( byte buffer, SocketFlags socketFlags ) : int

Receives data from a connected SecureSocket into a specific location of the receive buffer.

Receive ( byte buffer, int size, SocketFlags socketFlags ) : int

Receives data from a connected SecureSocket into a specific location of the receive buffer.

Receive ( byte buffer, int offset, int size, SocketFlags socketFlags ) : int

Receives data from a connected SecureSocket into a specific location of the receive buffer.

SecureSocket ( AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType ) : System

Initializes a new instance of the SecureSocket class.

The SecureSocket will act like a normal Socket and will not use a secure transfer protocol.

SecureSocket ( AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, Org.Mentalis.Security.Ssl.SecurityOptions options ) : System

Initializes a new instance of the SecureSocket class.

Send ( byte buffer ) : int

Sends data to a connected SecureSocket, starting at the indicated location in the data.

Send ( byte buffer, SocketFlags socketFlags ) : int

Sends data to a connected SecureSocket, starting at the indicated location in the data.

Send ( byte buffer, int size, SocketFlags socketFlags ) : int

Sends data to a connected SecureSocket, starting at the indicated location in the data.

Send ( byte buffer, int offset, int size, SocketFlags socketFlags ) : int

Sends data to a connected SecureSocket, starting at the indicated location in the data.

Shutdown ( SocketShutdown how ) : void

Shuts down the secure connection.

Private Methods

Method Description
OnAccept ( IAsyncResult ar ) : void
OnConnect ( IAsyncResult ar ) : void

Called then the SecureSocket connects to the remote host.

OnShutdown ( IAsyncResult ar ) : void

Called when the shutdown data has been sent to the remote server.

SecureSocket ( Socket accepted, Org.Mentalis.Security.Ssl.SecurityOptions options ) : System

Initializes a new instance of the SecureSocket class.

Method Details

Accept() public method

Creates a new SecureSocket to handle an incoming connection request.
The returned VirtualSocket can be cast to a SecureSocket if necessary.
An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. Unable to create the credentials.
public Accept ( ) : VirtualSocket
return VirtualSocket

BeginAccept() public method

Begins an asynchronous request to create a new SecureSocket to accept an incoming connection request.
is a null reference (Nothing in Visual Basic). An operating system error occurs while creating the SecureSocket. The SecureSocket has been closed.
public BeginAccept ( AsyncCallback callback, object state ) : IAsyncResult
callback AsyncCallback The delegate.
state object An object containing state information for this request.
return IAsyncResult

BeginConnect() public method

Begins an asynchronous request for a connection to a network device.
is a null reference (Nothing in Visual Basic). An operating system error occurs while creating the SecureSocket. The SecureSocket has been closed.
public BeginConnect ( EndPoint remoteEP, AsyncCallback callback, object state ) : IAsyncResult
remoteEP System.Net.EndPoint An that represents the remote device.
callback AsyncCallback The delegate.
state object An object that contains state information for this request.
return IAsyncResult

BeginReceive() public method

Begins to asynchronously receive data from a connected SecureSocket.
is a null reference (Nothing in Visual Basic). An operating system error occurs while accessing the SecureSocket. SecureSocket has been closed. The offset parameter is outside the bounds of buffer or size is either smaller or larger than the buffer size.
public BeginReceive ( byte buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state ) : IAsyncResult
buffer byte The storage location for the received data.
offset int The zero-based position in the buffer parameter at which to store the received data.
size int The number of bytes to receive.
socketFlags SocketFlags A bitwise combination of the values.
callback AsyncCallback The delegate.
state object An object containing state information for this request.
return IAsyncResult

BeginSend() public method

Sends data asynchronously to a connected SecureSocket.
is a null reference (Nothing in Visual Basic). An operating system error occurs while accessing the SecureSocket. The specified offset or size exceeds the size of buffer. The specified size is zero. The SecureSocket has been closed. An error occurred while encrypting the data.
public BeginSend ( byte buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state ) : IAsyncResult
buffer byte The data to send.
offset int The zero-based position in the buffer parameter at which to begin sending data.
size int The number of bytes to send.
socketFlags SocketFlags A bitwise combination of the values.
callback AsyncCallback The delegate.
state object An object containing state information for this request.
return IAsyncResult

BeginShutdown() public method

Begins an asynchronous request to shut the connection down.
has already been called.
public BeginShutdown ( AsyncCallback callback, object state ) : IAsyncResult
callback AsyncCallback The delegate.
state object An object containing state information for this request.
return IAsyncResult

ChangeSecurityProtocol() public method

Changes the security protocol. This method can only be used to 'upgrade' a connection from no-security to either SSL or TLS.
Programs should only call this method if there is no active Connect, Accept, Send or Receive!
An error occurs while changing the security protocol.
public ChangeSecurityProtocol ( Org.Mentalis.Security.Ssl.SecurityOptions options ) : void
options Org.Mentalis.Security.Ssl.SecurityOptions The new parameters.
return void

Close() public method

Forces a SecureSocket connection to close.
public Close ( ) : void
return void

Connect() public method

Establishes a connection to a remote device and optionally negotiates a secure transport protocol.
The remoteEP parameter is a null reference (Nothing in Visual Basic). An operating system error occurs while accessing the . The SecureSocket has been closed. The security negotiation failed.
public Connect ( EndPoint remoteEP ) : void
remoteEP System.Net.EndPoint An that represents the remote device.
return void

EndAccept() public method

Ends an asynchronous request to create a new SecureSocket to accept an incoming connection request.
The returned VirtualSocket can be cast to a SecureSocket if necessary.
is a null reference (Nothing in Visual Basic). was not created by a call to . An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. Unable to create the credentials -or- client authentication error.
public EndAccept ( IAsyncResult asyncResult ) : VirtualSocket
asyncResult IAsyncResult Stores state information for this asynchronous operation as well as any user defined data.
return VirtualSocket

EndConnect() public method

Ends a pending asynchronous connection request.
is a null reference (Nothing in Visual Basic). was not returned by a call to the method. was previously called for the asynchronous connection. An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. An error occurred while negotiating the security protocol.
public EndConnect ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult The result of the asynchronous operation.
return void

EndReceive() public method

Ends a pending asynchronous read.
is a null reference (Nothing in Visual Basic). was not returned by a call to the method. was previously called for the asynchronous read. An operating system error occurs while accessing the socket. The has been closed. An error occurs while communicating with the remote host.
public EndReceive ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult Stores state information for this asynchronous operation as well as any user defined data.
return int

EndSend() public method

Ends a pending asynchronous send.
is a null reference (Nothing in Visual Basic). was not returned by a call to the method. was previously called for the asynchronous read. An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. An error occurs while communicating with the remote host.
public EndSend ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult The result of the asynchronous operation.
return int

EndShutdown() public method

Ends an asynchronous request to shut the connection down.
is a null reference (Nothing in Visual Basic). has not been called first. has not been returned by a call to .
public EndShutdown ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult An that references the asynchronous shutdown.
return void

Poll() public method

Determines the status of the VirtualSocket.
This property is not supported for SSL/TLS sockets. It can only be used if the SecureProtocol is set to None. Asynchronous behavior in SSL or TLS mode can be achieved by calling the asynchronous methods. Set microSeconds parameter to a negative integer if you would like to wait indefinitely for a response.
The mode parameter is not one of the SelectMode values -or- the socket is in SSL or TLS mode. An operating system error occurs while accessing the VirtualSocket. The VirtualSocket has been closed.
public Poll ( int microSeconds, SelectMode mode ) : bool
microSeconds int The time to wait for a response, in microseconds.
mode SelectMode One of the values.
return bool

QueueRenegotiate() public method

Queues a renegotiation request.
Use the QueueRenegotiate function with caution. Some SSL/TLS clients or server do not support renegotiation. For instance, requesting a renegotiation in the middle of sending a HTTP request to a MS IIS server causes the connection to be shut down. Renegotiations should only be used when a small private key [512 bits] is used and the connection is active for a long period of time.
An operating system error occurs while accessing the SecureSocket.
public QueueRenegotiate ( ) : void
return void

Receive() public method

Receives data from a connected SecureSocket into a specific location of the receive buffer.
is a null reference (Nothing in Visual Basic). An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. An error occurred while decrypting the received data.
public Receive ( byte buffer ) : int
buffer byte The storage location for the received data.
return int

Receive() public method

Receives data from a connected SecureSocket into a specific location of the receive buffer.
is a null reference (Nothing in Visual Basic). An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. An error occurred while decrypting the received data.
public Receive ( byte buffer, SocketFlags socketFlags ) : int
buffer byte The storage location for the received data.
socketFlags SocketFlags A bitwise combination of the values.
return int

Receive() public method

Receives data from a connected SecureSocket into a specific location of the receive buffer.
is a null reference (Nothing in Visual Basic). The size exceeds the size of buffer. An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. An error occurred while decrypting the received data.
public Receive ( byte buffer, int size, SocketFlags socketFlags ) : int
buffer byte The storage location for the received data.
size int The number of bytes to receive.
socketFlags SocketFlags A bitwise combination of the values.
return int

Receive() public method

Receives data from a connected SecureSocket into a specific location of the receive buffer.
is a null reference (Nothing in Visual Basic). The size exceeds the size of buffer. An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. An error occurred while decrypting the received data.
public Receive ( byte buffer, int offset, int size, SocketFlags socketFlags ) : int
buffer byte The storage location for the received data.
offset int The location in buffer to store the received data.
size int The number of bytes to receive.
socketFlags SocketFlags A bitwise combination of the values.
return int

SecureSocket() public method

Initializes a new instance of the SecureSocket class.
The SecureSocket will act like a normal Socket and will not use a secure transfer protocol.
The combination of addressFamily, socketType, and protocolType results in an invalid socket.
public SecureSocket ( AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType ) : System
addressFamily AddressFamily One of the values.
socketType SocketType One of the values.
protocolType ProtocolType One of the values.
return System

SecureSocket() public method

Initializes a new instance of the SecureSocket class.
An error occurs while changing the security protocol.
public SecureSocket ( AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, Org.Mentalis.Security.Ssl.SecurityOptions options ) : System
addressFamily AddressFamily One of the values.
socketType SocketType One of the values.
protocolType ProtocolType One of the values.
options Org.Mentalis.Security.Ssl.SecurityOptions The to use.
return System

Send() public method

Sends data to a connected SecureSocket, starting at the indicated location in the data.
is a null reference (Nothing in Visual Basic). The specified size is zero. An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. Unable to encrypt the data.
public Send ( byte buffer ) : int
buffer byte The data to be sent.
return int

Send() public method

Sends data to a connected SecureSocket, starting at the indicated location in the data.
is a null reference (Nothing in Visual Basic). The specified size is zero. An operating system error occurs while accessing the SecureSocket. The SecureSocket has been closed. Unable to encrypt the data.
public Send ( byte buffer, SocketFlags socketFlags ) : int
buffer byte The data to be sent.
socketFlags SocketFlags A bitwise combination of the values.
return int

Send() public method

Sends data to a connected SecureSocket, starting at the indicated location in the data.
is a null reference (Nothing in Visual Basic). An operating system error occurs while accessing the SecureSocket. The size parameter exceeds the size of buffer. The specified size is zero. The SecureSocket has been closed. Unable to encrypt the data.
public Send ( byte buffer, int size, SocketFlags socketFlags ) : int
buffer byte The data to be sent.
size int The number of bytes to send.
socketFlags SocketFlags A bitwise combination of the values.
return int

Send() public method

Sends data to a connected SecureSocket, starting at the indicated location in the data.
is a null reference (Nothing in Visual Basic). An operating system error occurs while accessing the SecureSocket. The offset or size parameter exceeds the size of buffer. The specified size is zero. The SecureSocket has been closed. Unable to encrypt the data.
public Send ( byte buffer, int offset, int size, SocketFlags socketFlags ) : int
buffer byte The data to be sent.
offset int The position in the data buffer to begin sending data.
size int The number of bytes to send.
socketFlags SocketFlags A bitwise combination of the values.
return int

Shutdown() public method

Shuts down the secure connection.
SecureSocket has been closed. An operating system error occurs while accessing the SecureSocket. An error occurs while shutting the secure connection down.
public Shutdown ( SocketShutdown how ) : void
how SocketShutdown
return void