Dart.PowerTCP.SslSockets Namespace > Server Class : AuthenticateClient Property |
Gets or sets a value that determines if a client must authenticate themselves to the server.
[Visual Basic]
<DefaultValueAttribute()>
<BrowsableAttribute(False)>
<DescriptionAttribute("Gets or sets a value that determines if a client must authenticate themselves to the server.")>
Public Property AuthenticateClient As Boolean
[C#]
[DefaultValueAttribute()]
[BrowsableAttribute(false)]
[DescriptionAttribute("Gets or sets a value that determines if a client must authenticate themselves to the server.")]
public bool AuthenticateClient {get; set;}
[C++]
[DefaultValueAttribute()]
[BrowsableAttribute(false)]
[DescriptionAttribute("Gets or sets a value that determines if a client must authenticate themselves to the server.")]
public: __property bool get_AuthenticateClient();
public: __property void set_AuthenticateClient(
bool value
);
[C++/CLI]
[DefaultValueAttribute()]
[BrowsableAttribute(false)]
[DescriptionAttribute("Gets or sets a value that determines if a client must authenticate themselves to the server.")]
public:
property bool AuthenticateClient {
bool get();
void set (bool value);
}
A boolean indicating if remote clients must authenticate to the server upon connecting.
Only use this property is you are creating a secure server application.
Set this to true to force the remote client to authenticate (send a digital certificate) to the server before they can communicate.
The following example demonstrates creating a simple secure server that requires client authentication.
[Visual Basic]
Private Sub StartSecureServer()
' Require ClientAuthentication
Server1.AuthenticateClient = True
' Create a new CertificateStore object for "MY" certificate store.
Dim store As New CertificateStore(CertificateStoreLocation.LocalMachine, CertificateStoreName.My)
' Set the certificate to the default certificate.
Server1.Certificate = store(0)
' Begin listening for connections.
Server1.Listen(443)
End Sub
Private Sub Server1_Connection(ByVal sender As Object, ByVal e As ConnectionEventArgs) Handles Server1.Connection
Try
' Keep reading and echoing until the client closes the connection.
Dim s As String = e.Tcp.Receive().ToString()
While e.Tcp.Connected
e.Tcp.Send(s)
s = e.Tcp.Receive().ToString()
End While
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub
Private Sub Server1_CertificateReceived(ByVal sender As Object, ByRef e As CertificateReceivedEventArgs) Handles Server1.CertificateReceived
Dim msg As String = "The certificate was invalid for the following reason(s)" + vbCrLf
' 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" + vbCrLf
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" + vbCrLf
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" + vbCrLf
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 StartSecureServer()
{
// Require ClientAuthentication
server1.AuthenticateClient = true;
// Create a new CertificateStore object for "MY" certificate store.
CertificateStore store = new CertificateStore(CertificateStoreLocation.LocalMachine, CertificateStoreName.My);
// Set the certificate to the default certificate.
server1.Certificate = store[0];
// Begin listening for connections.
server1.Listen(443);
}
private void server1_Connection(object
sender, ConnectionEventArgs e)
{
try
{
// Keep reading and echoing until the client closes the connection.
string s = e.Tcp.Receive().ToString();
while (e.Tcp.Connected)
{
e.Tcp.Send(s);
s = e.Tcp.Receive().ToString();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
private void server1_CertificateReceived(object sender, CertificateReceivedEventArgs e)
{
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;
}
}
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.