Sample code for 30+ languages & platforms
PowerShell

Get a Received Client Certificate (Server Side)

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetRcvdClientCert, which copies a client certificate presented during the TLS handshake of an accepted server-side connection into a Cert object.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. Use NumReceivedClientCerts to determine the valid index range. Client certificates are supplied only when the server requests them for mutual TLS.

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

$socket = New-Object Chilkat.Socket

#  The file path is relative to the application's current working directory.  An absolute path
#  may also be used.  Supply the path appropriate to your own environment.
#  The PFX password should come from a secure source rather than being hard-coded.
$pfxPassword = "myPfxPassword"
$cert = New-Object Chilkat.Cert
$success = $cert.LoadPfxFile("qa_data/server.pfx",$pfxPassword)
if ($success -eq $false) {
    $($cert.LastErrorText)
    exit
}

$success = $socket.InitSslServer($cert)
if ($success -eq $false) {
    $($socket.LastErrorText)
    exit
}

$success = $socket.BindAndListen(5000,25)
if ($success -eq $false) {
    $($socket.LastErrorText)
    exit
}

#  Accept a client connection.  The accepted connection carries any client certificate presented
#  during the TLS handshake.
$connectedSock = New-Object Chilkat.Socket
$success = $socket.AcceptNext(20000,$connectedSock)
if ($success -eq $false) {
    $($socket.LastErrorText)
    exit
}

#  Copy each received client certificate and inspect it.
$numClientCerts = $connectedSock.NumReceivedClientCerts
$clientCert = New-Object Chilkat.Cert

for ($i = 0; $i -le $numClientCerts - 1; $i++) {
    $success = $connectedSock.GetRcvdClientCert($i,$clientCert)
    if ($success -eq $false) {
        $($connectedSock.LastErrorText)
        exit
    }

    $("Client certificate subject: " + $clientCert.SubjectCN)
}