Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CheckCertificateRevocation to be set on connection string #1591

Merged
merged 4 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ The `ConfigurationOptions` object has a wide range of properties, all of which a
| abortConnect={bool} | `AbortOnConnectFail` | `true` (`false` on Azure) | If true, `Connect` will not create a connection while no servers are available |
| allowAdmin={bool} | `AllowAdmin` | `false` | Enables a range of commands that are considered risky |
| channelPrefix={string} | `ChannelPrefix` | `null` | Optional channel prefix for all pub/sub operations |
| checkCertificateRevocation={bool} | `CheckCertificateRevocation` | `true` | A Boolean value that specifies whether the certificate revocation list is checked during authentication. |
| connectRetry={int} | `ConnectRetry` | `3` | The number of times to repeat connect attempts during initial `Connect` |
| connectTimeout={int} | `ConnectTimeout` | `5000` | Timeout (ms) for connect operations |
| configChannel={string} | `ConfigurationChannel` | `__Booksleeve_MasterChanged` | Broadcast channel name for communicating configuration changes |
Expand Down
12 changes: 9 additions & 3 deletions src/StackExchange.Redis/ConfigurationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ internal const string
SyncTimeout = "syncTimeout",
TieBreaker = "tiebreaker",
Version = "version",
WriteBuffer = "writeBuffer";
WriteBuffer = "writeBuffer",
CheckCertificateRevocation = "checkCertificateRevocation";


private static readonly Dictionary<string, string> normalizedOptions = new[]
{
Expand Down Expand Up @@ -118,6 +120,7 @@ internal const string
TieBreaker,
Version,
WriteBuffer,
CheckCertificateRevocation
}.ToDictionary(x => x, StringComparer.OrdinalIgnoreCase);

public static string TryNormalize(string value)
Expand Down Expand Up @@ -189,7 +192,7 @@ public static string TryNormalize(string value)
/// <summary>
/// A Boolean value that specifies whether the certificate revocation list is checked during authentication.
/// </summary>
public bool CheckCertificateRevocation {get { return checkCertificateRevocation ?? true; } set { checkCertificateRevocation = value; }}
public bool CheckCertificateRevocation { get { return checkCertificateRevocation ?? true; } set { checkCertificateRevocation = value; } }

/// <summary>
/// Create a certificate validation check that checks against the supplied issuer even if not known by the machine
Expand Down Expand Up @@ -619,7 +622,7 @@ private static void Append(StringBuilder sb, string prefix, object value)

private void Clear()
{
ClientName = ServiceName = User =Password = tieBreaker = sslHost = configChannel = null;
ClientName = ServiceName = User = Password = tieBreaker = sslHost = configChannel = null;
keepAlive = syncTimeout = asyncTimeout = connectTimeout = writeBuffer = connectRetry = configCheckSeconds = DefaultDatabase = null;
allowAdmin = abortOnConnectFail = highPrioritySocketThreads = resolveDns = ssl = null;
SslProtocols = null;
Expand Down Expand Up @@ -667,6 +670,9 @@ private void DoParse(string configuration, bool ignoreUnknown)

switch (OptionKeys.TryNormalize(key))
{
case OptionKeys.CheckCertificateRevocation:
CheckCertificateRevocation = OptionKeys.ParseBoolean(key, value);
break;
case OptionKeys.SyncTimeout:
SyncTimeout = OptionKeys.ParseInt32(key, value, minValue: 1);
break;
Expand Down
10 changes: 10 additions & 0 deletions tests/StackExchange.Redis.Tests/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public void SslProtocols_MultipleValues()
Assert.Equal(SslProtocols.Tls11 | SslProtocols.Tls12, options.SslProtocols.GetValueOrDefault());
}

[Theory]
[InlineData("host,checkCertificateRevocation=false", false)]
[InlineData("host,checkCertificateRevocation=true", true)]
[InlineData("host", true)]
public void ConfigurationOption_CheckCertificateRevocation(string conString, bool expectedValue)
{
var options = ConfigurationOptions.Parse(conString);
Assert.Equal(expectedValue, options.CheckCertificateRevocation);
}

[Fact]
public void SslProtocols_UsingIntegerValue()
{
Expand Down