SQL Server
SQL Server
Start SSH Tunnel Keyboard-Interactive Authentication
See more SSH Tunnel Examples
Demonstrates the Chilkat SshTunnel.StartKeyboardAuth method, which begins keyboard-interactive authentication. The only argument is the login name. It returns XML describing the server's prompts, which are answered with ContinueKeyboardAuth.
Background: Keyboard-interactive is the prompt-driven authentication method: the server sends one or more questions — a password, a one-time code, a security question — and the client answers each. This is how a tunnel supports two-factor and other challenge-response schemes. The returned XML says exactly what to ask and whether to mask the input.
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
-- Demonstrates the SshTunnel.StartKeyboardAuth method, which begins keyboard-interactive
-- authentication. The only argument is the login name. It returns XML describing the server's
-- prompts, which are answered with ContinueKeyboardAuth.
DECLARE @tunnel int
EXEC @hr = sp_OACreate 'Chilkat.SshTunnel', @tunnel OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- The tunnel forwards accepted local connections to this destination through the SSH server.
EXEC sp_OASetProperty @tunnel, 'DestHostname', 'db.internal.example.com'
EXEC sp_OASetProperty @tunnel, 'DestPort', 5432
-- Connect to the SSH server. This performs the TCP/proxy connection and SSH handshake, but
-- does not authenticate yet.
DECLARE @sshPort int
SELECT @sshPort = 22
EXEC sp_OAMethod @tunnel, 'Connect', @success OUT, 'ssh.example.com', @sshPort
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @tunnel, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @tunnel
RETURN
END
-- Begin keyboard-interactive authentication. The returned XML describes the server's prompts.
DECLARE @infoRequestXml nvarchar(4000)
EXEC sp_OAMethod @tunnel, 'StartKeyboardAuth', @infoRequestXml OUT, 'mySshLogin'
EXEC sp_OAGetProperty @tunnel, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @tunnel, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @tunnel
RETURN
END
PRINT @infoRequestXml
-- Answer the prompt(s) with ContinueKeyboardAuth, then call BeginAccepting.
DECLARE @waitForThreadExit int
SELECT @waitForThreadExit = 1
EXEC sp_OAMethod @tunnel, 'CloseTunnel', @success OUT, @waitForThreadExit
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @tunnel, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @tunnel
RETURN
END
EXEC @hr = sp_OADestroy @tunnel
END
GO