PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Tunnel
integer li_SshPort
string ls_Password
integer li_ListenPort
integer li_WaitForThreadExit
li_Success = 0
// Demonstrates the SshTunnel.EnableSecrets property, which enables automatic resolution of
// credentials from the operating system's secure storage.
loo_Tunnel = create oleobject
li_rc = loo_Tunnel.ConnectToNewObject("Chilkat.SshTunnel")
if li_rc < 0 then
destroy loo_Tunnel
MessageBox("Error","Connecting to COM object failed")
return
end if
// When EnableSecrets is 1, 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.).
loo_Tunnel.EnableSecrets = 1
loo_Tunnel.DestHostname = "db.internal.example.com"
loo_Tunnel.DestPort = 5432
li_SshPort = 22
li_Success = loo_Tunnel.Connect("ssh.example.com",li_SshPort)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
// 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.
ls_Password = "!!my_ssh_password_secret"
li_Success = loo_Tunnel.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
li_ListenPort = 1080
li_Success = loo_Tunnel.BeginAccepting(li_ListenPort)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
Write-Debug "Authenticated using a secret from OS secure storage."
li_WaitForThreadExit = 1
li_Success = loo_Tunnel.CloseTunnel(li_WaitForThreadExit)
if li_Success = 0 then
Write-Debug loo_Tunnel.LastErrorText
destroy loo_Tunnel
return
end if
destroy loo_Tunnel