# < Summary

Information

Class: | Renci.SshNet.Security.KeyExchangeDiffieHellmanGroupExchangeShaBase
Assembly: | Renci.SshNet
File(s): | \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\KeyExchangeDiffieHellmanGroupExchangeShaBase.cs

Line coverage
100%

Covered lines: | 48
Uncovered lines: | 0
Coverable lines: | 48
Total lines: | 115
Line coverage: | 100%

Branch coverage
N/A

Covered branches: | 0
Total branches: | 0
Branch coverage: | N/A

Method coverage

Feature is only available for sponsors

Upgrade to PRO version

# Metrics

Method | Branch coverage | Cyclomatic complexity | Line coverage
--- | --- | --- | ---
CalculateHash() | 100% | 1 | 100%
Start(...) | 100% | 1 | 100%
Finish() | 100% | 1 | 100%
Session_KeyExchangeDhGroupExchangeGroupReceived(...) | 100% | 1 | 100%
Session_KeyExchangeDhGroupExchangeReplyReceived(...) | 100% | 1 | 100%

# File(s)

## \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\KeyExchangeDiffieHellmanGroupExchangeShaBase.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using Renci.SshNet.Messages.Transport;`
|  | `2` |  | ``
|  | `3` |  | `namespace Renci.SshNet.Security`
|  | `4` |  | `{`
|  | `5` |  | `/// <summary>`
|  | `6` |  | `/// Base class for "diffie-hellman-group-exchange" algorithms.`
|  | `7` |  | `/// </summary>`
|  | `8` |  | `internal abstract class KeyExchangeDiffieHellmanGroupExchangeShaBase : KeyExchangeDiffieHellman`
|  | `9` |  | `{`
|  | `10` |  | `private const int MinimumGroupSize = 1024;`
|  | `11` |  | `private const int PreferredGroupSize = 1024;`
|  | `12` |  | `private const int MaximumProupSize = 8192;`
|  | `13` |  | ``
|  | `14` |  | `/// <summary>`
|  | `15` |  | `/// Calculates key exchange hash value.`
|  | `16` |  | `/// </summary>`
|  | `17` |  | `/// <returns>`
|  | `18` |  | `/// Key exchange hash.`
|  | `19` |  | `/// </returns>`
|  | `20` |  | `protected override byte[] CalculateHash()`
| 12 | `21` |  | `{`
| 12 | `22` |  | `var groupExchangeHashData = new GroupExchangeHashData`
| 12 | `23` |  | `{`
| 12 | `24` |  | `ClientVersion = Session.ClientVersion,`
| 12 | `25` |  | `ServerVersion = Session.ServerVersion,`
| 12 | `26` |  | `ClientPayload = _clientPayload,`
| 12 | `27` |  | `ServerPayload = _serverPayload,`
| 12 | `28` |  | `HostKey = _hostKey,`
| 12 | `29` |  | `MinimumGroupSize = MinimumGroupSize,`
| 12 | `30` |  | `PreferredGroupSize = PreferredGroupSize,`
| 12 | `31` |  | `MaximumGroupSize = MaximumProupSize,`
| 12 | `32` |  | `Prime = _prime,`
| 12 | `33` |  | `SubGroup = _group,`
| 12 | `34` |  | `ClientExchangeValue = _clientExchangeValue,`
| 12 | `35` |  | `ServerExchangeValue = _serverExchangeValue,`
| 12 | `36` |  | `SharedKey = SharedKey,`
| 12 | `37` |  | `};`
|  | `38` |  | ``
| 12 | `39` |  | `return Hash(groupExchangeHashData.GetBytes());`
| 12 | `40` |  | `}`
|  | `41` |  | ``
|  | `42` |  | `/// <summary>`
|  | `43` |  | `/// Starts key exchange algorithm.`
|  | `44` |  | `/// </summary>`
|  | `45` |  | `/// <param name="session">The session.</param>`
|  | `46` |  | `/// <param name="message">Key exchange init message.</param>`
|  | `47` |  | `public override void Start(Session session, KeyExchangeInitMessage message)`
| 6 | `48` |  | `{`
| 6 | `49` |  | `base.Start(session, message);`
|  | `50` |  | ``
|  | `51` |  | `// Register SSH_MSG_KEX_DH_GEX_GROUP message`
| 6 | `52` |  | `Session.RegisterMessage("SSH_MSG_KEX_DH_GEX_GROUP");`
|  | `53` |  | ``
|  | `54` |  | `// Subscribe to KeyExchangeDhGroupExchangeGroupReceived events`
| 6 | `55` |  | `Session.KeyExchangeDhGroupExchangeGroupReceived += Session_KeyExchangeDhGroupExchangeGroupReceived;`
|  | `56` |  | ``
|  | `57` |  | `// 1. client sends SSH_MSG_KEY_DH_GEX_REQUEST`
| 6 | `58` |  | `SendMessage(new KeyExchangeDhGroupExchangeRequest(MinimumGroupSize, PreferredGroupSize, MaximumProupSize));`
| 6 | `59` |  | `}`
|  | `60` |  | ``
|  | `61` |  | `/// <summary>`
|  | `62` |  | `/// Finishes key exchange algorithm.`
|  | `63` |  | `/// </summary>`
|  | `64` |  | `public override void Finish()`
| 6 | `65` |  | `{`
| 6 | `66` |  | `base.Finish();`
|  | `67` |  | ``
| 6 | `68` |  | `Session.KeyExchangeDhGroupExchangeGroupReceived -= Session_KeyExchangeDhGroupExchangeGroupReceived;`
| 6 | `69` |  | `Session.KeyExchangeDhGroupExchangeReplyReceived -= Session_KeyExchangeDhGroupExchangeReplyReceived;`
| 6 | `70` |  | `}`
|  | `71` |  | ``
|  | `72` |  | `private void Session_KeyExchangeDhGroupExchangeGroupReceived(object sender, MessageEventArgs<KeyExchangeDhGroupE`
| 6 | `73` |  | `{`
|  | `74` |  | `// 2. server sends SSH_MSG_KEX_DH_GEX_GROUP`
| 6 | `75` |  | `var groupMessage = e.Message;`
|  | `76` |  | ``
|  | `77` |  | `// Unregister SSH_MSG_KEX_DH_GEX_GROUP message once received`
| 6 | `78` |  | `Session.UnRegisterMessage("SSH_MSG_KEX_DH_GEX_GROUP");`
|  | `79` |  | ``
|  | `80` |  | `// Unsubscribe from KeyExchangeDhGroupExchangeGroupReceived events`
| 6 | `81` |  | `Session.KeyExchangeDhGroupExchangeGroupReceived -= Session_KeyExchangeDhGroupExchangeGroupReceived;`
|  | `82` |  | ``
|  | `83` |  | `// Register in order to be able to receive SSH_MSG_KEX_DH_GEX_REPLY message`
| 6 | `84` |  | `Session.RegisterMessage("SSH_MSG_KEX_DH_GEX_REPLY");`
|  | `85` |  | ``
|  | `86` |  | `// Subscribe to KeyExchangeDhGroupExchangeReplyReceived events`
| 6 | `87` |  | `Session.KeyExchangeDhGroupExchangeReplyReceived += Session_KeyExchangeDhGroupExchangeReplyReceived;`
|  | `88` |  | ``
| 6 | `89` |  | `_prime = groupMessage.SafePrime;`
| 6 | `90` |  | `_group = groupMessage.SubGroup;`
|  | `91` |  | ``
| 6 | `92` |  | `PopulateClientExchangeValue();`
|  | `93` |  | ``
|  | `94` |  | `// 3. client sends SSH_MSG_KEX_DH_GEX_INIT`
| 6 | `95` |  | `SendMessage(new KeyExchangeDhGroupExchangeInit(_clientExchangeValue));`
| 6 | `96` |  | `}`
|  | `97` |  | ``
|  | `98` |  | `private void Session_KeyExchangeDhGroupExchangeReplyReceived(object sender, MessageEventArgs<KeyExchangeDhGroupE`
| 6 | `99` |  | `{`
|  | `100` |  | `// 4. server sends SSH_MSG_KEX_DH_GEX_REPLY`
| 6 | `101` |  | `var replyMessage = e.Message;`
|  | `102` |  | ``
|  | `103` |  | `// Unregister SSH_MSG_KEX_DH_GEX_REPLY message once received`
| 6 | `104` |  | `Session.UnRegisterMessage("SSH_MSG_KEX_DH_GEX_REPLY");`
|  | `105` |  | ``
|  | `106` |  | `// Unsubscribe from KeyExchangeDhGroupExchangeReplyReceived events`
| 6 | `107` |  | `Session.KeyExchangeDhGroupExchangeReplyReceived -= Session_KeyExchangeDhGroupExchangeReplyReceived;`
|  | `108` |  | ``
| 6 | `109` |  | `HandleServerDhReply(replyMessage.HostKey, replyMessage.F, replyMessage.Signature);`
|  | `110` |  | ``
|  | `111` |  | `// When SSH_MSG_KEX_DH_GEX_REPLY received key exchange is completed`
| 6 | `112` |  | `Finish();`
| 6 | `113` |  | `}`
|  | `114` |  | `}`
|  | `115` |  | `}`

# Methods/Properties

CalculateHash()
Start(Renci.SshNet.Session,Renci.SshNet.Messages.Transport.KeyExchangeInitMessage)
Finish()
Session_KeyExchangeDhGroupExchangeGroupReceived(System.Object,Renci.SshNet.MessageEventArgs`1<Renci.SshNet.Messages.Transport.KeyExchangeDhGroupExchangeGroup>)
Session_KeyExchangeDhGroupExchangeReplyReceived(System.Object,Renci.SshNet.MessageEventArgs`1<Renci.SshNet.Messages.Transport.KeyExchangeDhGroupExchangeReply>)