You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SshConnectionException: MAC Error when using only hmac-sha2-512 with .NET 8 and SSH.NET 2024.1.0 #1660
When connecting to a Cisco switch that only allows the hmac-sha2-512 MAC algorithm, the SSH.NET client throws a SshConnectionException with the message MAC Error.
This happens only when hmac-sha2-512 is the sole allowed MAC on the server. If we include hmac-sha2-256 in the server config, the connection succeeds.
Environment:
SSH.NET version: 2024.1.0
.NET version: .NET 8
Platform: Linux and Windows (tested on both)
SSH server: Cisco switch with the following settings:
ip ssh server algorithm mac hmac-sha2-512
Server-Side SSH Debug Output (Cisco):
Jun 25 10:31:45.083: kex: client->server enc:aes128-ctr mac:hmac-sha2-512
Jun 25 10:31:45.083: kex: server->client enc:aes128-ctr mac:hmac-sha2-512
Jun 25 10:31:47.932: SSH2 1: SSH2_MSG_NEWKEYS received
Jun 25 10:31:48.760: SSH1: Session disconnected - error 0x00
Client Stack Trace:
Renci.SshNet.Common.SshConnectionException: MAC Error
at Renci.SshNet.Session.ReceiveMessage(Socket socket)
at Renci.SshNet.Session.MessageListener()
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.CreateAndConnectSession()
at Renci.SshNet.BaseClient.Connect()
What Works:
When we change the server to:
ip ssh server algorithm mac hmac-sha2-512 hmac-sha2-256
Then the client connects successfully, negotiating hmac-sha2-256.
Expected Behavior:
SSH.NET should be able to successfully connect using hmac-sha2-512 as the MAC algorithm.
Notes:
This looks like a bug in the hmac-sha2-512 MAC handling implementation in SSH.NET.
Possibly related to incorrect handling of the MAC size (512 bits = 64 bytes) or key derivation.
Repro Steps (Pseudocode):
KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(_user);
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(_user, _password);
//kauth.AuthenticationPrompt += new EventHandler<Renci.SshNet.Common.AuthenticationPromptEventArgs>(HandleKeyEvent);
kauth.AuthenticationPrompt += (a, b) => HandleKeyEvent(a, b, _password);
// Setup Credentials and Server Information
ConnectionInfo ConnNfo = new ConnectionInfo(_ipAddress, 22, _user,
[kauth, pauth]
);
ConnNfo.Timeout = TimeSpan.FromSeconds(30);
_sshClient = new SshClient(ConnNfo);
_sshClient.TrustKeyReceived();
_sshClient.Connect(); // throws SshConnectionException: MAC Error
Jun 25 08:46:04.650: SSH2_MSG_NEWKEYS sent
Jun 25 08:46:04.690: SSH2_MSG_NEWKEYS received
Jun 25 08:46:04.691: Next packet from client received
Jun 25 08:46:04.691: partial packet length(block size)16 bytes, needed 32 bytes, maclen 64
Jun 25 08:46:04.691: computed MAC for sequence no.#4 type 1
Jun 25 08:46:04.692: computed MAC for sequence no.#5 type 1
Jun 25 08:46:04.789: **Session disconnected - error 0x07 (MAC verification failed)**
I could connect using sshpass or Mobaxtream with HmacSha512
and with powershell using:
ssh user@host -o KexAlgorithms=diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1 -o MACs=hmac-sha2-512 -o HostKeyAlgorithms=+ssh-rsa
This is the exception we get when trying to connect:
This exception was originally thrown at this call stack: [External Code] NetPoller.session.SshClientWrapper.Connect() in ISshClient.cs NetPoller.session.SepioSshClient.Connect() in SepioSshClient.cs Sepio.Shared.Netpoller.session.SshSession.ReadAllAsync(int, Sepio.Prime.Core.Controller.Resources.Net.SwitchConnectionResource, System.Collections.Generic.IReadOnlyDictionary<string, string>, bool, Serilog.ILogger) in SshSession.cs Renci.SshNet.Common.SshConnectionException: 'MAC error'
hard to say, maybe something to do with padding. Are you also connecting to a cisco box? Does it happen every time?
Anybody's device publicly accessible?
It happens every time . Im connecting to this switch:
Cisco IOS Software, C3560CX Software (C3560CX-UNIVERSALK9-M), Version 15.2(7)E9, RELEASE SOFTWARE (fc1)
Activity
giladsepio commentedon Jun 25, 2025
Happens also in version 2025.0.0
giladsepio commentedon Jun 25, 2025
in the switch ssh logs we see:
scott-xu commentedon Jun 25, 2025
Can PuTTY or other SSH client connect to it with HmacSha512?
giladsepio commentedon Jul 7, 2025
some of the tools worked and some not.
YaelHerman123 commentedon Jul 13, 2025
I could connect using sshpass or Mobaxtream with HmacSha512
and with powershell using:
ssh user@host -o KexAlgorithms=diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1 -o MACs=hmac-sha2-512 -o HostKeyAlgorithms=+ssh-rsa
YaelHerman123 commentedon Jul 13, 2025
This is the exception we get when trying to connect:
This exception was originally thrown at this call stack: [External Code] NetPoller.session.SshClientWrapper.Connect() in ISshClient.cs NetPoller.session.SepioSshClient.Connect() in SepioSshClient.cs Sepio.Shared.Netpoller.session.SshSession.ReadAllAsync(int, Sepio.Prime.Core.Controller.Resources.Net.SwitchConnectionResource, System.Collections.Generic.IReadOnlyDictionary<string, string>, bool, Serilog.ILogger) in SshSession.cs Renci.SshNet.Common.SshConnectionException: 'MAC error'
YaelHerman123 commentedon Aug 6, 2025
@Rob-Hague maybe you can help?
Rob-Hague commentedon Aug 7, 2025
hard to say, maybe something to do with padding. Are you also connecting to a cisco box? Does it happen every time?
Anybody's device publicly accessible?
YaelHerman123 commentedon Aug 7, 2025
It happens every time . Im connecting to this switch:
Cisco IOS Software, C3560CX Software (C3560CX-UNIVERSALK9-M), Version 15.2(7)E9, RELEASE SOFTWARE (fc1)
YaelHerman123 commentedon Aug 10, 2025
@Rob-Hague Let me know when you can take a look, and we’ll arrange access for you to the switch.
can you share your email address?
Rob-Hague commentedon Aug 10, 2025
It's in the commit message here 03ae6bf
Fix key material extension during key exchange
Fix key material extension during key exchange (sshnet#1689)