Lianja
Lianja
SSH Tunnel Credentials from OS Secure Storage
See more SSH Tunnel Examples
Demonstrates the EnableSecrets property, which enables automatic resolution of credentials from the operating system's secure storage. When enabled, password properties and methods may receive a "secret specification string" beginning with !! instead of a literal password.
Background: This is a cleaner alternative to reading a secret yourself and passing it in: with
EnableSecrets on, you hand Chilkat a reference like !!my_secret_name and it fetches the actual value from the platform's secure store — Windows Credential Manager, Apple Keychain, and so on. The literal password never appears in your source or configuration, which is exactly the practice recommended throughout these examples.Chilkat Lianja Downloads
llSuccess = .F.
// Demonstrates the SshTunnel.EnableSecrets property, which enables automatic resolution of
// credentials from the operating system's secure storage.
loTunnel = createobject("CkSshTunnel")
// When EnableSecrets is .T., supported password properties and methods may receive a "secret
// specification string" beginning with "!!" instead of a literal password. Chilkat resolves the
// secret from the OS secure store (Windows Credential Manager, Apple Keychain, etc.).
loTunnel.EnableSecrets = .T.
loTunnel.DestHostname = "db.internal.example.com"
loTunnel.DestPort = 5432
lnSshPort = 22
llSuccess = loTunnel.Connect("ssh.example.com",lnSshPort)
if (llSuccess = .F.) then
? loTunnel.LastErrorText
release loTunnel
return
endif
// Pass a secret specification instead of a literal password. Chilkat looks up the named secret
// in the OS secure store rather than using this text directly.
lcPassword = "!!my_ssh_password_secret"
llSuccess = loTunnel.AuthenticatePw("mySshLogin",lcPassword)
if (llSuccess = .F.) then
? loTunnel.LastErrorText
release loTunnel
return
endif
lnListenPort = 1080
llSuccess = loTunnel.BeginAccepting(lnListenPort)
if (llSuccess = .F.) then
? loTunnel.LastErrorText
release loTunnel
return
endif
? "Authenticated using a secret from OS secure storage."
llWaitForThreadExit = .T.
llSuccess = loTunnel.CloseTunnel(llWaitForThreadExit)
if (llSuccess = .F.) then
? loTunnel.LastErrorText
release loTunnel
return
endif
release loTunnel