Class SslStream
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
SocketA 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
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
Length
Gets the length of the stream. (Overrides NetworkStream. . :: . .Length.)
public override long Length { get; }
Property Value
SslVerification
Option for SSL verification. The default behaviour is CertificateRequired.
public SslVerification SslVerification { get; set; }
Property Value
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
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
stringThe name of the server that will share this SslStream.
enabledSslProtocols
SslProtocolsThe 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
stringThe name of the server that will share this SslStream.
clientCertificate
X509CertificateThe client certificate.
enabledSslProtocols
SslProtocolsThe 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
stringThe name of the server that will share this SslStream.
clientCertificate
X509CertificateThe client certificate.
ca
X509CertificateCertificate Authority certificate to use for authentication with the server.
enabledSslProtocols
SslProtocolsThe 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
X509CertificateThe X509Certificate used to authenticate the server.
clientCertificateRequired
boolA 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
SslProtocolsThe 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
X509CertificateThe certificate used to authenticate the server.
enabledSslProtocols
SslProtocolsThe 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
booltrue 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
intAn integer that contains the zero-based location in buffer at which to begin storing the data read from this stream.
size
intThe maximum number of bytes to read from this stream.
Returns
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)