Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
tunnel: HCkSshTunnel;
sshPort: Integer;
infoRequestXml: PWideChar;
waitForThreadExit: Boolean;
begin
success := False;
// 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.
tunnel := CkSshTunnel_Create();
// The tunnel forwards accepted local connections to this destination through the SSH server.
CkSshTunnel_putDestHostname(tunnel,'db.internal.example.com');
CkSshTunnel_putDestPort(tunnel,5432);
// Connect to the SSH server. This performs the TCP/proxy connection and SSH handshake, but
// does not authenticate yet.
sshPort := 22;
success := CkSshTunnel_Connect(tunnel,'ssh.example.com',sshPort);
if (success = False) then
begin
Memo1.Lines.Add(CkSshTunnel__lastErrorText(tunnel));
Exit;
end;
// Begin keyboard-interactive authentication. The returned XML describes the server's prompts.
infoRequestXml := CkSshTunnel__startKeyboardAuth(tunnel,'mySshLogin');
if (CkSshTunnel_getLastMethodSuccess(tunnel) = False) then
begin
Memo1.Lines.Add(CkSshTunnel__lastErrorText(tunnel));
Exit;
end;
Memo1.Lines.Add(infoRequestXml);
// Answer the prompt(s) with ContinueKeyboardAuth, then call BeginAccepting.
waitForThreadExit := True;
success := CkSshTunnel_CloseTunnel(tunnel,waitForThreadExit);
if (success = False) then
begin
Memo1.Lines.Add(CkSshTunnel__lastErrorText(tunnel));
Exit;
end;
CkSshTunnel_Dispose(tunnel);