Skip to content

Commit

Permalink
Added SslKeyExchangeAlgorithm/Strength accessors to clients
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed May 26, 2021
1 parent 72c7ef0 commit 8e0ff20
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 0 deletions.
18 changes: 18 additions & 0 deletions MailKit/IMailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,24 @@ public CipherSuitesPolicy SslCipherSuitesPolicy {
/// <value>The negotiated SSL or TLS hash algorithm strength.</value>
int? SslHashStrength { get; }

/// <summary>
/// Get the negotiated SSL or TLS key exchange algorithm.
/// </summary>
/// <remarks>
/// Gets the negotiated SSL or TLS key exchange algorithm once an SSL or TLS connection has been made.
/// </remarks>
/// <value>The negotiated SSL or TLS key exchange algorithm.</value>
ExchangeAlgorithmType? SslKeyExchangeAlgorithm { get; }

/// <summary>
/// Get the negotiated SSL or TLS key exchange algorithm strength.
/// </summary>
/// <remarks>
/// Gets the negotiated SSL or TLS key exchange algorithm strength once an SSL or TLS connection has been made.
/// </remarks>
/// <value>The negotiated SSL or TLS key exchange algorithm strength.</value>
int? SslKeyExchangeStrength { get; }

/// <summary>
/// Get or set the timeout for network streaming operations, in milliseconds.
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions MailKit/MailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,28 @@ public abstract int? SslHashStrength {
get;
}

/// <summary>
/// Get the negotiated SSL or TLS key exchange algorithm.
/// </summary>
/// <remarks>
/// Gets the negotiated SSL or TLS key exchange algorithm once an SSL or TLS connection has been made.
/// </remarks>
/// <value>The negotiated SSL or TLS key exchange algorithm.</value>
public abstract ExchangeAlgorithmType? SslKeyExchangeAlgorithm {
get;
}

/// <summary>
/// Get the negotiated SSL or TLS key exchange algorithm strength.
/// </summary>
/// <remarks>
/// Gets the negotiated SSL or TLS key exchange algorithm strength once an SSL or TLS connection has been made.
/// </remarks>
/// <value>The negotiated SSL or TLS key exchange algorithm strength.</value>
public abstract int? SslKeyExchangeStrength {
get;
}

/// <summary>
/// Get whether or not the client is currently authenticated with the mail server.
/// </summary>
Expand Down
32 changes: 32 additions & 0 deletions MailKit/Net/Imap/ImapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,38 @@ public override int? SslHashStrength {
}
}

/// <summary>
/// Get the negotiated SSL or TLS key exchange algorithm.
/// </summary>
/// <remarks>
/// Gets the negotiated SSL or TLS key exchange algorithm once an SSL or TLS connection has been made.
/// </remarks>
/// <value>The negotiated SSL or TLS key exchange algorithm.</value>
public override ExchangeAlgorithmType? SslKeyExchangeAlgorithm {
get {
if (IsSecure && (engine.Stream.Stream is SslStream sslStream))
return sslStream.KeyExchangeAlgorithm;

return null;
}
}

/// <summary>
/// Get the negotiated SSL or TLS key exchange algorithm strength.
/// </summary>
/// <remarks>
/// Gets the negotiated SSL or TLS key exchange algorithm strength once an SSL or TLS connection has been made.
/// </remarks>
/// <value>The negotiated SSL or TLS key exchange algorithm strength.</value>
public override int? SslKeyExchangeStrength {
get {
if (IsSecure && (engine.Stream.Stream is SslStream sslStream))
return sslStream.KeyExchangeStrength;

return null;
}
}

/// <summary>
/// Get whether or not the client is currently authenticated with the IMAP server.
/// </summary>
Expand Down
32 changes: 32 additions & 0 deletions MailKit/Net/Pop3/Pop3Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,38 @@ public override int? SslHashStrength {
}
}

/// <summary>
/// Get the negotiated SSL or TLS key exchange algorithm.
/// </summary>
/// <remarks>
/// Gets the negotiated SSL or TLS key exchange algorithm once an SSL or TLS connection has been made.
/// </remarks>
/// <value>The negotiated SSL or TLS key exchange algorithm.</value>
public override ExchangeAlgorithmType? SslKeyExchangeAlgorithm {
get {
if (IsSecure && (engine.Stream.Stream is SslStream sslStream))
return sslStream.KeyExchangeAlgorithm;

return null;
}
}

/// <summary>
/// Get the negotiated SSL or TLS key exchange algorithm strength.
/// </summary>
/// <remarks>
/// Gets the negotiated SSL or TLS key exchange algorithm strength once an SSL or TLS connection has been made.
/// </remarks>
/// <value>The negotiated SSL or TLS key exchange algorithm strength.</value>
public override int? SslKeyExchangeStrength {
get {
if (IsSecure && (engine.Stream.Stream is SslStream sslStream))
return sslStream.KeyExchangeStrength;

return null;
}
}

/// <summary>
/// Get whether or not the client is currently authenticated with the POP3 server.
/// </summary>
Expand Down
32 changes: 32 additions & 0 deletions MailKit/Net/Smtp/SmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,38 @@ public override int? SslHashStrength {
}
}

/// <summary>
/// Get the negotiated SSL or TLS key exchange algorithm.
/// </summary>
/// <remarks>
/// Gets the negotiated SSL or TLS key exchange algorithm once an SSL or TLS connection has been made.
/// </remarks>
/// <value>The negotiated SSL or TLS key exchange algorithm.</value>
public override ExchangeAlgorithmType? SslKeyExchangeAlgorithm {
get {
if (IsSecure && (Stream.Stream is SslStream sslStream))
return sslStream.KeyExchangeAlgorithm;

return null;
}
}

/// <summary>
/// Get the negotiated SSL or TLS key exchange algorithm strength.
/// </summary>
/// <remarks>
/// Gets the negotiated SSL or TLS key exchange algorithm strength once an SSL or TLS connection has been made.
/// </remarks>
/// <value>The negotiated SSL or TLS key exchange algorithm strength.</value>
public override int? SslKeyExchangeStrength {
get {
if (IsSecure && (Stream.Stream is SslStream sslStream))
return sslStream.KeyExchangeStrength;

return null;
}
}

/// <summary>
/// Get whether or not the client is currently authenticated with the SMTP server.
/// </summary>
Expand Down
42 changes: 42 additions & 0 deletions UnitTests/Net/Imap/ImapClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ public class ImapClientTests
const CipherAlgorithmType GMailCipherAlgorithm = CipherAlgorithmType.Aes128;
const int GMailCipherStrength = 128;
const HashAlgorithmType GMailHashAlgorithm = HashAlgorithmType.Sha256;
const ExchangeAlgorithmType GMailKeyExchangeAlgorithm = (ExchangeAlgorithmType) 44550;
const CipherAlgorithmType GmxDeCipherAlgorithm = CipherAlgorithmType.Aes256;
const int GmxDeCipherStrength = 256;
const HashAlgorithmType GmxDeHashAlgorithm = HashAlgorithmType.Sha384;
const ExchangeAlgorithmType GmxDeKeyExchangeAlgorithm = (ExchangeAlgorithmType) 44550;

static FolderAttributes GetSpecialFolderAttribute (SpecialFolder special)
{
Expand Down Expand Up @@ -384,6 +386,8 @@ public void TestConnectGMail ()
Assert.AreEqual (GMailCipherStrength, client.SslCipherStrength);
Assert.AreEqual (GMailHashAlgorithm, client.SslHashAlgorithm);
Assert.AreEqual (0, client.SslHashStrength);
Assert.AreEqual (GMailKeyExchangeAlgorithm, client.SslKeyExchangeAlgorithm);
Assert.AreEqual (255, client.SslKeyExchangeStrength);
Assert.IsFalse (client.IsAuthenticated, "Expected the client to not be authenticated");
Assert.AreEqual (1, connected, "ConnectedEvent");

Expand All @@ -399,6 +403,8 @@ public void TestConnectGMail ()
Assert.IsNull (client.SslCipherStrength, "Expected SslCipherStrength to be null after disconnecting");
Assert.IsNull (client.SslHashAlgorithm, "Expected SslHashAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslHashStrength, "Expected SslHashStrength to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeAlgorithm, "Expected SslKeyExchangeAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeStrength, "Expected SslKeyExchangeStrength to be null after disconnecting");
Assert.AreEqual (1, disconnected, "DisconnectedEvent");
}
}
Expand Down Expand Up @@ -438,6 +444,8 @@ public async Task TestConnectGMailAsync ()
Assert.AreEqual (GMailCipherStrength, client.SslCipherStrength);
Assert.AreEqual (GMailHashAlgorithm, client.SslHashAlgorithm);
Assert.AreEqual (0, client.SslHashStrength);
Assert.AreEqual (GMailKeyExchangeAlgorithm, client.SslKeyExchangeAlgorithm);
Assert.AreEqual (255, client.SslKeyExchangeStrength);
Assert.IsFalse (client.IsAuthenticated, "Expected the client to not be authenticated");
Assert.AreEqual (1, connected, "ConnectedEvent");

Expand All @@ -453,6 +461,8 @@ public async Task TestConnectGMailAsync ()
Assert.IsNull (client.SslCipherStrength, "Expected SslCipherStrength to be null after disconnecting");
Assert.IsNull (client.SslHashAlgorithm, "Expected SslHashAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslHashStrength, "Expected SslHashStrength to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeAlgorithm, "Expected SslKeyExchangeAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeStrength, "Expected SslKeyExchangeStrength to be null after disconnecting");
Assert.AreEqual (1, disconnected, "DisconnectedEvent");
}
}
Expand Down Expand Up @@ -508,6 +518,8 @@ public void TestConnectGMailViaProxy ()
Assert.AreEqual (GMailCipherStrength, client.SslCipherStrength);
Assert.AreEqual (GMailHashAlgorithm, client.SslHashAlgorithm);
Assert.AreEqual (0, client.SslHashStrength);
Assert.AreEqual (GMailKeyExchangeAlgorithm, client.SslKeyExchangeAlgorithm);
Assert.AreEqual (255, client.SslKeyExchangeStrength);
Assert.IsFalse (client.IsAuthenticated, "Expected the client to not be authenticated");
Assert.AreEqual (1, connected, "ConnectedEvent");

Expand All @@ -523,6 +535,8 @@ public void TestConnectGMailViaProxy ()
Assert.IsNull (client.SslCipherStrength, "Expected SslCipherStrength to be null after disconnecting");
Assert.IsNull (client.SslHashAlgorithm, "Expected SslHashAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslHashStrength, "Expected SslHashStrength to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeAlgorithm, "Expected SslKeyExchangeAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeStrength, "Expected SslKeyExchangeStrength to be null after disconnecting");
Assert.AreEqual (1, disconnected, "DisconnectedEvent");
}
}
Expand Down Expand Up @@ -580,6 +594,8 @@ public async Task TestConnectGMailViaProxyAsync ()
Assert.AreEqual (GMailCipherStrength, client.SslCipherStrength);
Assert.AreEqual (GMailHashAlgorithm, client.SslHashAlgorithm);
Assert.AreEqual (0, client.SslHashStrength);
Assert.AreEqual (GMailKeyExchangeAlgorithm, client.SslKeyExchangeAlgorithm);
Assert.AreEqual (255, client.SslKeyExchangeStrength);
Assert.IsFalse (client.IsAuthenticated, "Expected the client to not be authenticated");
Assert.AreEqual (1, connected, "ConnectedEvent");

Expand All @@ -595,6 +611,8 @@ public async Task TestConnectGMailViaProxyAsync ()
Assert.IsNull (client.SslCipherStrength, "Expected SslCipherStrength to be null after disconnecting");
Assert.IsNull (client.SslHashAlgorithm, "Expected SslHashAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslHashStrength, "Expected SslHashStrength to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeAlgorithm, "Expected SslKeyExchangeAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeStrength, "Expected SslKeyExchangeStrength to be null after disconnecting");
Assert.AreEqual (1, disconnected, "DisconnectedEvent");
}
}
Expand Down Expand Up @@ -641,6 +659,8 @@ public void TestConnectGMailSocket ()
Assert.AreEqual (GMailCipherStrength, client.SslCipherStrength);
Assert.AreEqual (GMailHashAlgorithm, client.SslHashAlgorithm);
Assert.AreEqual (0, client.SslHashStrength);
Assert.AreEqual (GMailKeyExchangeAlgorithm, client.SslKeyExchangeAlgorithm);
Assert.AreEqual (255, client.SslKeyExchangeStrength);
Assert.IsFalse (client.IsAuthenticated, "Expected the client to not be authenticated");
Assert.AreEqual (1, connected, "ConnectedEvent");

Expand All @@ -656,6 +676,8 @@ public void TestConnectGMailSocket ()
Assert.IsNull (client.SslCipherStrength, "Expected SslCipherStrength to be null after disconnecting");
Assert.IsNull (client.SslHashAlgorithm, "Expected SslHashAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslHashStrength, "Expected SslHashStrength to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeAlgorithm, "Expected SslKeyExchangeAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeStrength, "Expected SslKeyExchangeStrength to be null after disconnecting");
Assert.AreEqual (1, disconnected, "DisconnectedEvent");
}
}
Expand Down Expand Up @@ -701,6 +723,8 @@ public async Task TestConnectGMailSocketAsync ()
Assert.AreEqual (GMailCipherStrength, client.SslCipherStrength);
Assert.AreEqual (GMailHashAlgorithm, client.SslHashAlgorithm);
Assert.AreEqual (0, client.SslHashStrength);
Assert.AreEqual (GMailKeyExchangeAlgorithm, client.SslKeyExchangeAlgorithm);
Assert.AreEqual (255, client.SslKeyExchangeStrength);
Assert.IsFalse (client.IsAuthenticated, "Expected the client to not be authenticated");
Assert.AreEqual (1, connected, "ConnectedEvent");

Expand All @@ -716,6 +740,8 @@ public async Task TestConnectGMailSocketAsync ()
Assert.IsNull (client.SslCipherStrength, "Expected SslCipherStrength to be null after disconnecting");
Assert.IsNull (client.SslHashAlgorithm, "Expected SslHashAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslHashStrength, "Expected SslHashStrength to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeAlgorithm, "Expected SslKeyExchangeAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeStrength, "Expected SslKeyExchangeStrength to be null after disconnecting");
Assert.AreEqual (1, disconnected, "DisconnectedEvent");
}
}
Expand Down Expand Up @@ -757,6 +783,8 @@ public void TestConnectGmxDe ()
Assert.AreEqual (GmxDeCipherStrength, client.SslCipherStrength);
Assert.AreEqual (GmxDeHashAlgorithm, client.SslHashAlgorithm);
Assert.AreEqual (0, client.SslHashStrength);
Assert.AreEqual (GmxDeKeyExchangeAlgorithm, client.SslKeyExchangeAlgorithm);
Assert.AreEqual (255, client.SslKeyExchangeStrength);
Assert.IsFalse (client.IsAuthenticated, "Expected the client to not be authenticated");
Assert.AreEqual (1, connected, "ConnectedEvent");

Expand All @@ -770,6 +798,8 @@ public void TestConnectGmxDe ()
Assert.IsNull (client.SslCipherStrength, "Expected SslCipherStrength to be null after disconnecting");
Assert.IsNull (client.SslHashAlgorithm, "Expected SslHashAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslHashStrength, "Expected SslHashStrength to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeAlgorithm, "Expected SslKeyExchangeAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeStrength, "Expected SslKeyExchangeStrength to be null after disconnecting");
Assert.AreEqual (1, disconnected, "DisconnectedEvent");
}
}
Expand Down Expand Up @@ -812,6 +842,8 @@ public async Task TestConnectGmxDeAsync ()
Assert.AreEqual (GmxDeCipherStrength, client.SslCipherStrength);
Assert.AreEqual (GmxDeHashAlgorithm, client.SslHashAlgorithm);
Assert.AreEqual (0, client.SslHashStrength);
Assert.AreEqual (GmxDeKeyExchangeAlgorithm, client.SslKeyExchangeAlgorithm);
Assert.AreEqual (255, client.SslKeyExchangeStrength);
Assert.IsFalse (client.IsAuthenticated, "Expected the client to not be authenticated");
Assert.AreEqual (1, connected, "ConnectedEvent");

Expand All @@ -825,6 +857,8 @@ public async Task TestConnectGmxDeAsync ()
Assert.IsNull (client.SslCipherStrength, "Expected SslCipherStrength to be null after disconnecting");
Assert.IsNull (client.SslHashAlgorithm, "Expected SslHashAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslHashStrength, "Expected SslHashStrength to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeAlgorithm, "Expected SslKeyExchangeAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeStrength, "Expected SslKeyExchangeStrength to be null after disconnecting");
Assert.AreEqual (1, disconnected, "DisconnectedEvent");
}
}
Expand Down Expand Up @@ -867,6 +901,8 @@ public void TestConnectGmxDeSocket ()
Assert.AreEqual (GmxDeCipherStrength, client.SslCipherStrength);
Assert.AreEqual (GmxDeHashAlgorithm, client.SslHashAlgorithm);
Assert.AreEqual (0, client.SslHashStrength);
Assert.AreEqual (GmxDeKeyExchangeAlgorithm, client.SslKeyExchangeAlgorithm);
Assert.AreEqual (255, client.SslKeyExchangeStrength);
Assert.IsFalse (client.IsAuthenticated, "Expected the client to not be authenticated");
Assert.AreEqual (1, connected, "ConnectedEvent");

Expand All @@ -880,6 +916,8 @@ public void TestConnectGmxDeSocket ()
Assert.IsNull (client.SslCipherStrength, "Expected SslCipherStrength to be null after disconnecting");
Assert.IsNull (client.SslHashAlgorithm, "Expected SslHashAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslHashStrength, "Expected SslHashStrength to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeAlgorithm, "Expected SslKeyExchangeAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeStrength, "Expected SslKeyExchangeStrength to be null after disconnecting");
Assert.AreEqual (1, disconnected, "DisconnectedEvent");
}
}
Expand Down Expand Up @@ -922,6 +960,8 @@ public async Task TestConnectGmxDeSocketAsync ()
Assert.AreEqual (GmxDeCipherStrength, client.SslCipherStrength);
Assert.AreEqual (GmxDeHashAlgorithm, client.SslHashAlgorithm);
Assert.AreEqual (0, client.SslHashStrength);
Assert.AreEqual (GmxDeKeyExchangeAlgorithm, client.SslKeyExchangeAlgorithm);
Assert.AreEqual (255, client.SslKeyExchangeStrength);
Assert.IsFalse (client.IsAuthenticated, "Expected the client to not be authenticated");
Assert.AreEqual (1, connected, "ConnectedEvent");

Expand All @@ -935,6 +975,8 @@ public async Task TestConnectGmxDeSocketAsync ()
Assert.IsNull (client.SslCipherStrength, "Expected SslCipherStrength to be null after disconnecting");
Assert.IsNull (client.SslHashAlgorithm, "Expected SslHashAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslHashStrength, "Expected SslHashStrength to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeAlgorithm, "Expected SslKeyExchangeAlgorithm to be null after disconnecting");
Assert.IsNull (client.SslKeyExchangeStrength, "Expected SslKeyExchangeStrength to be null after disconnecting");
Assert.AreEqual (1, disconnected, "DisconnectedEvent");
}
}
Expand Down
Loading

0 comments on commit 8e0ff20

Please sign in to comment.