Search Results for

    Show / Hide Table of Contents

    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.

    Inheritance
    object
    MarshalByRefObject
    Stream
    NetworkStream
    SslStream
    Implements
    IDisposable
    Inherited Members
    NetworkStream._socketType
    NetworkStream._remoteEndPoint
    NetworkStream._disposed
    NetworkStream.Close(int)
    NetworkStream.Flush()
    NetworkStream.Seek(long, SeekOrigin)
    NetworkStream.SetLength(long)
    NetworkStream.Read(SpanByte)
    NetworkStream.CanRead
    NetworkStream.CanSeek
    NetworkStream.CanTimeout
    NetworkStream.CanWrite
    NetworkStream.ReadTimeout
    NetworkStream.WriteTimeout
    NetworkStream.Position
    Stream.Close()
    Stream.CopyTo(Stream)
    Stream.Dispose()
    Stream.ReadByte()
    Stream.WriteByte(byte)
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: System.Net.Security
    Assembly: System.Net.dll
    Syntax
    public class SslStream : NetworkStream, IDisposable

    Constructors

    SslStream(Socket)

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

    Declaration
    public SslStream(Socket socket)
    Parameters
    Type Name Description
    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.)

    Declaration
    public override bool DataAvailable { get; }
    Property Value
    Type Description
    bool
    Overrides
    NetworkStream.DataAvailable

    IsServer

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

    Declaration
    public bool IsServer { get; }
    Property Value
    Type Description
    bool

    Length

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

    Declaration
    public override long Length { get; }
    Property Value
    Type Description
    long
    Overrides
    NetworkStream.Length

    SslVerification

    Option for SSL verification. The default behaviour is CertificateRequired.

    Declaration
    public SslVerification SslVerification { get; set; }
    Property Value
    Type Description
    SslVerification

    UseStoredDeviceCertificate

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

    Declaration
    public bool UseStoredDeviceCertificate { get; set; }
    Property Value
    Type Description
    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.

    Declaration
    public void AuthenticateAsClient(string targetHost, SslProtocols enabledSslProtocols)
    Parameters
    Type Name Description
    string targetHost

    The name of the server that will share this SslStream.

    SslProtocols enabledSslProtocols

    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.

    Declaration
    public void AuthenticateAsClient(string targetHost, X509Certificate clientCertificate, SslProtocols enabledSslProtocols)
    Parameters
    Type Name Description
    string targetHost

    The name of the server that will share this SslStream.

    X509Certificate clientCertificate

    The client certificate.

    SslProtocols enabledSslProtocols

    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.

    Declaration
    public void AuthenticateAsClient(string targetHost, X509Certificate clientCertificate, X509Certificate ca, SslProtocols enabledSslProtocols)
    Parameters
    Type Name Description
    string targetHost

    The name of the server that will share this SslStream.

    X509Certificate clientCertificate

    The client certificate.

    X509Certificate ca

    Certificate Authority certificate to use for authentication with the server.

    SslProtocols enabledSslProtocols

    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.

    Declaration
    public void AuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols)
    Parameters
    Type Name Description
    X509Certificate serverCertificate

    The X509Certificate used to authenticate the server.

    bool clientCertificateRequired

    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.

    SslProtocols enabledSslProtocols

    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.

    Declaration
    public void AuthenticateAsServer(X509Certificate serverCertificate, SslProtocols enabledSslProtocols)
    Parameters
    Type Name Description
    X509Certificate serverCertificate

    The certificate used to authenticate the server.

    SslProtocols enabledSslProtocols

    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.

    Declaration
    protected override void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

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

    Overrides
    NetworkStream.Dispose(bool)

    Finalize()

    Declaration
    protected override void Finalize()
    Overrides
    Stream.Finalize()

    Read(byte[], int, int)

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

    Declaration
    public override int Read(byte[] buffer, int offset, int size)
    Parameters
    Type Name Description
    byte[] buffer

    An array that receives the bytes read from this stream.

    int offset

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

    int size

    The maximum number of bytes to read from this stream.

    Returns
    Type Description
    int
    Overrides
    NetworkStream.Read(byte[], int, int)

    Write(byte[], int, int)

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

    Declaration
    public override void Write(byte[] buffer, int offset, int size)
    Parameters
    Type Name Description
    byte[] buffer

    An array that supplies the bytes written to the stream.

    int offset

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

    int size

    The number of bytes to read from buffer.

    Overrides
    NetworkStream.Write(byte[], int, int)

    Implements

    IDisposable

    Extension Methods

    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    LogDispatcher.GetCurrentClassLogger(object)
    In This Article
    Back to top Copyright © 2023 nanoFramework Contributors
    Generated by DocFX