Table of Contents

Class SslStream

Namespace
System.Net.Security
Assembly
System.Net.dll

Provides a stream used for client-server communication that uses the Secure Socket Layer (SSL) security protocol to authenticate the server and optionally the client.

public class SslStream : NetworkStream, IDisposable
Inheritance
SslStream
Implements
Inherited Members
Extension Methods

Constructors

SslStream(Socket)

Initializes a new instance of the SslStream class using the specified Socket.

public SslStream(Socket socket)

Parameters

socket Socket

A valid socket that currently has a TCP connection.

Remarks

The SslStream maintains the lifetime of the socket. When the SslStream object is disposed, the underlying TCP socket will be closed.

Properties

DataAvailable

Gets a value the indicates whether data is available in the stream. (Overrides NetworkStream. . :: . .DataAvailable.)

public override bool DataAvailable { get; }

Property Value

bool

IsServer

Gets a value that indicates whether the local side of the connection used by this SslStream was authenticated as the server.

public bool IsServer { get; }

Property Value

bool

Length

Gets the length of the stream. (Overrides NetworkStream. . :: . .Length.)

public override long Length { get; }

Property Value

long

SslVerification

Option for SSL verification. The default behaviour is CertificateRequired.

public SslVerification SslVerification { get; set; }

Property Value

SslVerification

UseStoredDeviceCertificate

Option to use the certificate stored in the device as client or server certificate. The default option is false.

public bool UseStoredDeviceCertificate { get; set; }

Property Value

bool

Remarks

This property is exclusive of .NET nanoFramework. In case there is no device certificate stored, the authentication will use whatever is provided (or not) in the parameter of the method being called.

Methods

AuthenticateAsClient(string, SslProtocols)

Called by clients to authenticate the server and optionally the client in a client-server connection. The authentication process uses the specified SSL protocols.

public void AuthenticateAsClient(string targetHost, SslProtocols enabledSslProtocols)

Parameters

targetHost string

The name of the server that will share this SslStream.

enabledSslProtocols SslProtocols

The SslProtocols value that represents the protocol used for authentication.

AuthenticateAsClient(string, X509Certificate, SslProtocols)

Called by clients to authenticate the server and optionally the client in a client-server connection. The authentication process uses the specified certificate collections and SSL protocols.

public void AuthenticateAsClient(string targetHost, X509Certificate clientCertificate, SslProtocols enabledSslProtocols)

Parameters

targetHost string

The name of the server that will share this SslStream.

clientCertificate X509Certificate

The client certificate.

enabledSslProtocols SslProtocols

The SslProtocols value that represents the protocol used for authentication.

Remarks

Instead of providing the client certificate in the clientCertificate parameter the UseStoredDeviceCertificate property can be used to use the certificate stored in the device.

AuthenticateAsClient(string, X509Certificate, X509Certificate, SslProtocols)

Called by clients to authenticate the server and optionally the client in a client-server connection. The authentication process uses the specified certificate collections and SSL protocols.

public void AuthenticateAsClient(string targetHost, X509Certificate clientCertificate, X509Certificate ca, SslProtocols enabledSslProtocols)

Parameters

targetHost string

The name of the server that will share this SslStream.

clientCertificate X509Certificate

The client certificate.

ca X509Certificate

Certificate Authority certificate to use for authentication with the server.

enabledSslProtocols SslProtocols

The SslProtocols value that represents the protocol used for authentication.

Remarks

Instead of providing the client certificate in the clientCertificate parameter the UseStoredDeviceCertificate property can be used to use the certificate stored in the device.

AuthenticateAsServer(X509Certificate, bool, SslProtocols)

Called by servers to authenticate the server and optionally the client in a client-server connection using the specified certificates, requirements and security protocol.

public void AuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols)

Parameters

serverCertificate X509Certificate

The X509Certificate used to authenticate the server.

clientCertificateRequired bool

A bool value that specifies whether the client is asked for a certificate for authentication. Note that this is only a request, if no certificate is provided, the server still accepts the connection request.

enabledSslProtocols SslProtocols

The protocols that may be used for authentication.

Remarks

Instead of providing the server certificate in the serverCertificate parameter the UseStoredDeviceCertificate property can be used to use the certificate stored in the device.

AuthenticateAsServer(X509Certificate, SslProtocols)

Called by servers to authenticate the server and optionally the client in a client-server connection using the specified certificate, verification requirements and security protocol.

public void AuthenticateAsServer(X509Certificate serverCertificate, SslProtocols enabledSslProtocols)

Parameters

serverCertificate X509Certificate

The certificate used to authenticate the server.

enabledSslProtocols SslProtocols

The protocols that may be used for authentication.

Remarks

Instead of providing the server certificate in the serverCertificate parameter the UseStoredDeviceCertificate property can be used to use the certificate stored in the device.

Dispose(bool)

Releases the unmanaged resources used by the SslStream and optionally releases the managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Finalize()

protected override void Finalize()

Read(byte[], int, int)

Reads data from this stream and stores it in the specified array.

public override int Read(byte[] buffer, int offset, int size)

Parameters

buffer byte[]

An array that receives the bytes read from this stream.

offset int

An integer that contains the zero-based location in buffer at which to begin storing the data read from this stream.

size int

The maximum number of bytes to read from this stream.

Returns

int

Write(byte[], int, int)

Write the specified number of bytes to the underlying stream using the specified buffer and offset.

public override void Write(byte[] buffer, int offset, int size)

Parameters

buffer byte[]

An array that supplies the bytes written to the stream.

offset int

he zero-based location in buffer at which to begin reading bytes to be written to the stream.

size int

The number of bytes to read from buffer.