Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

//  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.

loTunnel = createobject("CkSshTunnel")

//  The tunnel forwards accepted local connections to this destination through the SSH server.
loTunnel.DestHostname = "db.internal.example.com"
loTunnel.DestPort = 5432

//  Connect to the SSH server.  This performs the TCP/proxy connection and SSH handshake, but
//  does not authenticate yet.
lnSshPort = 22
llSuccess = loTunnel.Connect("ssh.example.com",lnSshPort)
if (llSuccess = .F.) then
    ? loTunnel.LastErrorText
    release loTunnel
    return
endif

//  Begin keyboard-interactive authentication.  The returned XML describes the server's prompts.
lcInfoRequestXml = loTunnel.StartKeyboardAuth("mySshLogin")
if (loTunnel.LastMethodSuccess = .F.) then
    ? loTunnel.LastErrorText
    release loTunnel
    return
endif

? lcInfoRequestXml

//  Answer the prompt(s) with ContinueKeyboardAuth, then call BeginAccepting.

llWaitForThreadExit = .T.
llSuccess = loTunnel.CloseTunnel(llWaitForThreadExit)
if (llSuccess = .F.) then
    ? loTunnel.LastErrorText
    release loTunnel
    return
endif



release loTunnel