SQL Server
SQL Server
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 SQL Server Downloads
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- 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.
DECLARE @tunnel int
EXEC @hr = sp_OACreate 'Chilkat.SshTunnel', @tunnel OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- List the allowed algorithms for each category, in order of preference.
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'kex', 'curve25519-sha256@libssh.org,ecdh-sha2-nistp256'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'hostKey', 'ssh-ed25519,ecdsa-sha2-nistp256'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'cipher', 'chacha20-poly1305@openssh.com,aes256-ctr'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'mac', 'hmac-sha2-256,hmac-sha2-512'
-- Apply the allow-list before connecting.
EXEC sp_OAMethod @tunnel, 'SetAllowedAlgorithms', @success OUT, @json
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @tunnel, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @tunnel
EXEC @hr = sp_OADestroy @json
RETURN
END
EXEC sp_OASetProperty @tunnel, 'DestHostname', 'db.internal.example.com'
EXEC sp_OASetProperty @tunnel, 'DestPort', 5432
DECLARE @sshPort int
SELECT @sshPort = 22
EXEC sp_OAMethod @tunnel, 'Connect', @success OUT, 'ssh.example.com', @sshPort
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @tunnel, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @tunnel
EXEC @hr = sp_OADestroy @json
RETURN
END
PRINT 'Connected.'
DECLARE @waitForThreadExit int
SELECT @waitForThreadExit = 1
EXEC sp_OAMethod @tunnel, 'CloseTunnel', @success OUT, @waitForThreadExit
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @tunnel, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @tunnel
EXEC @hr = sp_OADestroy @json
RETURN
END
EXEC @hr = sp_OADestroy @tunnel
EXEC @hr = sp_OADestroy @json
END
GO