DataFlex
DataFlex
SSH Tunnel Set Allowed SSH Algorithms
See more SSH Tunnel Examples
Demonstrates the Chilkat SshTunnel.SetAllowedAlgorithms method, which restricts the SSH connection to a specific set of algorithms. A JsonObject supplies comma-separated allow-lists for the kex, hostKey, cipher, and mac categories. It must be called before Connect.
Important: You typically should not set allowed algorithms explicitly. By default Chilkat orders algorithms according to best practices and accounts for known vulnerabilities.
Background: SSH negotiates a mutually supported algorithm from each category at connection time, and pinning that choice makes an application brittle: if the server later drops a weak algorithm, the two sides may fail to agree and the tunnel stops working. The legitimate reasons to override are a security policy mandating specific algorithms or a compatibility problem with an old server; otherwise let the library's defaults evolve with current guidance.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoTunnel
Variant vJson
Handle hoJson
Integer iSshPort
Boolean iWaitForThreadExit
String sTemp1
Move False To iSuccess
// Demonstrates the SshTunnel.SetAllowedAlgorithms method, which restricts the SSH connection to a
// specific set of algorithms. The only argument is a JsonObject. It must be called before
// Connect.
//
// Note: You typically should NOT set allowed algorithms explicitly. By default Chilkat orders
// algorithms according to best practices and accounts for known vulnerabilities. Hard-coding
// them can make an application brittle if a server later changes its allowed algorithms.
Get Create (RefClass(cComChilkatSshTunnel)) To hoTunnel
If (Not(IsComObjectCreated(hoTunnel))) Begin
Send CreateComObject of hoTunnel
End
// List the allowed algorithms for each category, in order of preference.
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "kex" "curve25519-sha256@libssh.org,ecdh-sha2-nistp256" To iSuccess
Get ComUpdateString Of hoJson "hostKey" "ssh-ed25519,ecdsa-sha2-nistp256" To iSuccess
Get ComUpdateString Of hoJson "cipher" "chacha20-poly1305@openssh.com,aes256-ctr" To iSuccess
Get ComUpdateString Of hoJson "mac" "hmac-sha2-256,hmac-sha2-512" To iSuccess
// Apply the allow-list before connecting.
Get pvComObject of hoJson to vJson
Get ComSetAllowedAlgorithms Of hoTunnel vJson To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
Set ComDestHostname Of hoTunnel To "db.internal.example.com"
Set ComDestPort Of hoTunnel To 5432
Move 22 To iSshPort
Get ComConnect Of hoTunnel "ssh.example.com" iSshPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Connected."
Move True To iWaitForThreadExit
Get ComCloseTunnel Of hoTunnel iWaitForThreadExit To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoTunnel To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure