Visual FoxPro
Visual FoxPro
SSH Authentication using an SSH Certificate
See more SSH Examples
Demonstrates how to authenticate using an SSH certificate.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loSbSshCert
LOCAL loSbPrivKey
LOCAL loKey
LOCAL loSsh
LOCAL lcHostname
LOCAL lnPort
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loSbSshCert = CreateObject('Chilkat.StringBuilder')
lnSuccess = loSbSshCert.LoadFile("qa_data/sshCert/user_ecdsa_key-cert.pub","utf-8")
IF (lnSuccess = 0) THEN
? "Failed to load user_ecdsa_key-cert.pub"
RELEASE loSbSshCert
CANCEL
ENDIF
loSbPrivKey = CreateObject('Chilkat.StringBuilder')
lnSuccess = loSbPrivKey.LoadFile("qa_data/sshKeys/user_ecdsa_key","utf-8")
IF (lnSuccess = 0) THEN
? "Failed to load user_ecdsa_key"
RELEASE loSbSshCert
RELEASE loSbPrivKey
CANCEL
ENDIF
loKey = CreateObject('Chilkat.SshKey')
* Provide the password if the user_ecdsa_key is stored in an encrypted format.
loKey.Password = "secret"
lnSuccess = loKey.FromOpenSshPrivateKey(loSbPrivKey.GetAsString())
IF (lnSuccess = 0) THEN
? loKey.LastErrorText
RELEASE loSbSshCert
RELEASE loSbPrivKey
RELEASE loKey
CANCEL
ENDIF
* Indicate that the SSH certificate is to be used for authentication.
* The UseSshCertificate method was added in Chilkat v11.0.0
loKey.UseSshCertificate(loSbSshCert.GetAsString())
loSsh = CreateObject('Chilkat.Ssh')
lcHostname = "ssh.example.com"
lnPort = 22
lnSuccess = loSsh.Connect(lcHostname,lnPort)
IF (lnSuccess <> 1) THEN
? loSsh.LastErrorText
RELEASE loSbSshCert
RELEASE loSbPrivKey
RELEASE loKey
RELEASE loSsh
CANCEL
ENDIF
lnSuccess = loSsh.AuthenticatePk("myLogin",loKey)
IF (lnSuccess <> 1) THEN
? loSsh.LastErrorText
RELEASE loSbSshCert
RELEASE loSbPrivKey
RELEASE loKey
RELEASE loSsh
CANCEL
ENDIF
? "Public-Key Authentication using an SSH Certificate was Successful!"
RELEASE loSbSshCert
RELEASE loSbPrivKey
RELEASE loKey
RELEASE loSsh