DataFlex
DataFlex
Initiate an SSH Key Re-Exchange
See more SSH Examples
Demonstrates the Chilkat Ssh.ReKey method, which initiates an SSH key re-exchange and waits for it to complete. It takes no arguments. Either the client or the server may trigger rekeying at any time.
Background: Rekeying periodically replaces the session keys to limit how much data is protected by any single key. RFC 4253 recommends it after roughly one gigabyte of transfer or one hour, whichever comes first. In practice servers initiate this automatically and Chilkat handles it transparently, so calling
ReKey explicitly is rarely necessary.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSsh
Integer iSshPort
String sPassword
String sTemp1
Move False To iSuccess
// Demonstrates the Ssh.ReKey method, which initiates an SSH key re-exchange and waits for it to
// complete. It takes no arguments. In normal use the server initiates rekeying as needed and
// Chilkat handles it transparently.
Get Create (RefClass(cComChilkatSsh)) To hoSsh
If (Not(IsComObjectCreated(hoSsh))) Begin
Send CreateComObject of hoSsh
End
// Connect to the SSH server. Port 22 is the usual SSH port.
Move 22 To iSshPort
Get ComConnect Of hoSsh "ssh.example.com" iSshPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
Move "mySshPassword" To sPassword
Get ComAuthenticatePw Of hoSsh "mySshLogin" sPassword To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// Explicitly initiate a key re-exchange on the live connection.
Get ComReKey Of hoSsh To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Key re-exchange complete."
Send ComDisconnect To hoSsh
End_Procedure