SQL Server
SQL Server
Enumerate Server-Advertised Acceptable Client CAs
See more Socket/SSL/TLS Examples
Demonstrates Socket.GetSslAcceptableClientCaDn, which returns a certificate-authority distinguished name advertised by a TLS server when it requests a client certificate.
Background. Valid indexes range from 0 through
NumSslAcceptableClientCAs minus one. A client can use these names to select an appropriate client certificate.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @socket int
EXEC @hr = sp_OACreate 'Chilkat.Socket', @socket OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Connect to the server using TLS.
DECLARE @bTls int
SELECT @bTls = 1
DECLARE @maxWaitMs int
SELECT @maxWaitMs = 5000
EXEC sp_OAMethod @socket, 'Connect', @success OUT, 'example.com', 5000, @bTls, @maxWaitMs
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @socket, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @socket
RETURN
END
-- After connecting to a server that requests a client certificate, enumerate the certificate-
-- authority distinguished names the server advertised as acceptable.
DECLARE @numCAs int
EXEC sp_OAGetProperty @socket, 'NumSslAcceptableClientCAs', @numCAs OUT
DECLARE @i int
SELECT @i = 0
WHILE @i <= @numCAs - 1
BEGIN
DECLARE @caDn nvarchar(4000)
EXEC sp_OAMethod @socket, 'GetSslAcceptableClientCaDn', @caDn OUT, @i
EXEC sp_OAGetProperty @socket, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @socket, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @socket
RETURN
END
PRINT @caDn
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @socket
END
GO