Classic ASP
Classic ASP
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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
set socket = Server.CreateObject("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"
set cert = Server.CreateObject("Chilkat.Cert")
success = cert.LoadPfxFile("qa_data/server.pfx",pfxPassword)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
Response.End
End If
success = socket.InitSslServer(cert)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( socket.LastErrorText) & "</pre>"
Response.End
End If
success = socket.BindAndListen(5000,25)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( socket.LastErrorText) & "</pre>"
Response.End
End If
' Accept a client connection. The accepted connection carries any client certificate presented
' during the TLS handshake.
set connectedSock = Server.CreateObject("Chilkat.Socket")
success = socket.AcceptNext(20000,connectedSock)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( socket.LastErrorText) & "</pre>"
Response.End
End If
' Copy each received client certificate and inspect it.
numClientCerts = connectedSock.NumReceivedClientCerts
set clientCert = Server.CreateObject("Chilkat.Cert")
For i = 0 To numClientCerts - 1
success = connectedSock.GetRcvdClientCert(i,clientCert)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( connectedSock.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Client certificate subject: " & clientCert.SubjectCN) & "</pre>"
Next
%>
</body>
</html>