See Also

SslStream Class  | SslStream Members

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

See Also Languages PowerTCP SSL Sockets for .NET

Certificate Property

Dart.PowerTCP.SslSockets Namespace > SslStream Class : Certificate Property (SslStream)

Returns the Certificate object used by this Stream.

[Visual Basic]
Public Property Certificate As Certificate
[C#]
public Certificate Certificate {get; set;}
[C++]
public: __property Certificate* get_Certificate(); public: __property void set_Certificate(    Certificate* value );
[C++/CLI]
public: property Certificate^ Certificate {    Certificate^ get();    void set (Certificate^ value); }

Remarks

A digital certificate is a common credential that provides authentication. This property returns the Certificate representing the digital certificate providing authentication for this SSL transaction.

When creating a secure server: Set Certificate to the certificate you wish to use before starting the server by using Listen. Any child that connected will be sent the certificate. If a child connects successfully, the Child.Stream property will return a SegmentedStream initialized with an SslStream, so communication with the child can occur securely.

When creating a secure client: This property typically does not need to be set because clients don't often have to identify themselves. If the server does request a certificate from the client however, the CertificateRequested event will be raised. Set the Tcp control's underlying SslStream.Certificate property to a valid certificate within this event.

Example

The following example demonstrates creating a simple secure client.

[Visual Basic] 

Private Sub SecureTest()

    'Allow component to negotiate best security option
    Tcp1.SecureProtocol = SecureProtocol.Auto

    ' Connect to a secure echo server.
    Tcp1.Connect("mysecureserver", 7)

    ' Send secure data
    Tcp1.Send("Test")

    ' Receive and display secure data
    System.Diagnostics.Debug.WriteLine(Tcp1.Receive().ToString())

    ' Close the connection
    Tcp1.Close()
End Sub

Private Sub Tcp1_CertificateRequested(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tcp1.CertificateRequested
    'The server has requested client authentication
    'Allow the user to select a certificate
    Dim certform As New CertificateListForm(True, True)
    If (certform.ShowDialog(Me) = DialogResult.OK) Then
        Tcp1.Certificate = certform.SelectedCertificate
    End If
End Sub

Private Sub Tcp1_CertificateReceived(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.CertificateReceivedEventArgs) Handles Tcp1.CertificateReceived
    'If the server's certificate is invalid for any reason,
    'the user can decide whether to proceed
    Dim msg As String = "The certificate was invalid for the following reason(s)" + vbLf

    ' Check to see if the certificate is from a trusted root.
    If (Not e.TrustedRoot) Then
        msg += "This certificate is not from a trusted root" + vbLf
    End If

    ' Check to see if the certificate has a valid date.
    If (Not e.ValidDate) Then
        msg += "This certificate does not have a valid date" + vbLf
    End If

    ' Check to see if the certificate has a valid name.
    If (Not e.ValidName) Then
        msg += "This certificate does not have a valid name" + vbLf
    End If

    If (Not e.Accept) Then
        msg += "Would you like to accept this certificate anyway?"
        If (MessageBox.Show(msg, "Invalid Cert Received", MessageBoxButtons.YesNo) = DialogResult.Yes) Then
            e.Accept = True
        End If
    End If
End Sub

[C#] 


private void SecureTest()
{
   
//Allow component to negotiate best security option
   
tcp1.SecureProtocol = SecureProtocol.Auto;

   
// Connect to a secure echo server.
   
tcp1.Connect("mysecureserver", 7);

   
// Send secure data
   
tcp1.Send("Test");

   
// Receive and display secure data
   
System.Diagnostics.Debug.WriteLine(tcp1.Receive().ToString());

   
// Close the connection
   
tcp1.Close();
}        

private void tcp1_CertificateRequested(object sender, System.EventArgs e)
{
   
//The server has requested client authentication
   
//Allow the user to select a certificate
   
CertificateListForm certform = new CertificateListForm(true, true);
   
if(certform.ShowDialog(this) == DialogResult.OK)
       tcp1.Certificate = certform.SelectedCertificate;
}

private void tcp1_CertificateReceived(object sender, CertificateReceivedEventArgs e)
{
   
//If the server's certificate is invalid for any reason,
   
//the user can decide whether to proceed
   
string msg = "The certificate was invalid for the following reason(s)\n";

   
// Check to see if the certificate is from a trusted root.
   
if(!e.TrustedRoot)
       msg+=
"This certificate is not from a trusted root\n";

   
// Check to see if the certificate has a valid date.
   
if(!e.ValidDate)
       msg+=
"This certificate does not have a valid date\n";

   
// Check to see if the certificate has a valid name.
   
if(!e.ValidName)
       msg+=
"This certificate does not have a valid name\n";

   
if(!e.Accept)
   {
       msg +=
"Would you like to accept this certificate anyway?";
       
if(MessageBox.Show(msg, "Invalid Cert Received", MessageBoxButtons.YesNo) == DialogResult.Yes)
           e.Accept = true;
   }
}
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

SslStream Class  | SslStream Members


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.