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

Verify that OCSP and CRL checks fall back. #43586

Merged
merged 1 commit into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ internal void HandleRequest()

if (context != null)
{
HandleRequest(context);
ThreadPool.QueueUserWorkItem(
state => HandleRequest(state),
context,
true);
}
}

Expand All @@ -108,7 +111,10 @@ internal async Task HandleRequestAsync()

if (context != null)
{
HandleRequest(context);
ThreadPool.QueueUserWorkItem(
state => HandleRequest(state),
context,
true);
}
}

Expand Down Expand Up @@ -375,14 +381,14 @@ private static void Trace(string trace)
Console.WriteLine(trace);
}
}
}

internal enum DelayedActionsFlag : byte
{
None = 0,
Ocsp = 0b1,
Crl = 0b10,
Aia = 0b100,
All = 0b11111111
}
public enum DelayedActionsFlag : byte
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needed to be changed to public for test method parameters; enclosing type is internal so move it out.

{
None = 0,
Ocsp = 0b1,
Crl = 0b10,
Aia = 0b100,
All = 0b11111111
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void RevocationCheckingDelayed(PkiOptions pkiOptions)

X509Chain chain = holder.Chain;
responder.ResponseDelay = delay;
responder.DelayedActions = RevocationResponder.DelayedActionsFlag.All;
responder.DelayedActions = DelayedActionsFlag.All;

// This needs to be greater than delay, but less than 2x delay to ensure
// that the time is a timeout for individual fetches, not a running total.
Expand Down Expand Up @@ -90,7 +90,7 @@ public static void RevocationCheckingTimeout(PkiOptions pkiOptions)

X509Chain chain = holder.Chain;
responder.ResponseDelay = delay;
responder.DelayedActions = RevocationResponder.DelayedActionsFlag.All;
responder.DelayedActions = DelayedActionsFlag.All;

chain.ChainPolicy.UrlRetrievalTimeout = TimeSpan.FromSeconds(1);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
Expand Down Expand Up @@ -148,7 +148,7 @@ public static void RevocationCheckingMaximum(PkiOptions pkiOptions)

X509Chain chain = holder.Chain;
responder.ResponseDelay = delay;
responder.DelayedActions = RevocationResponder.DelayedActionsFlag.All;
responder.DelayedActions = DelayedActionsFlag.All;

chain.ChainPolicy.UrlRetrievalTimeout = TimeSpan.FromMinutes(2);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
Expand Down Expand Up @@ -200,7 +200,7 @@ public static void RevocationCheckingNegativeTimeout(PkiOptions pkiOptions)

X509Chain chain = holder.Chain;
responder.ResponseDelay = delay;
responder.DelayedActions = RevocationResponder.DelayedActionsFlag.All;
responder.DelayedActions = DelayedActionsFlag.All;

chain.ChainPolicy.UrlRetrievalTimeout = TimeSpan.FromMinutes(-1);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
Expand All @@ -216,6 +216,47 @@ public static void RevocationCheckingNegativeTimeout(PkiOptions pkiOptions)
});
}

[Theory]
[InlineData(DelayedActionsFlag.Ocsp)]
[InlineData(DelayedActionsFlag.Crl)]
[PlatformSpecific(TestPlatforms.Windows | TestPlatforms.Linux)]
public static void RevocationCheckingTimeoutFallbackToOther(DelayedActionsFlag delayFlags)
{
RetryHelper.Execute(() => {
CertificateAuthority.BuildPrivatePki(
PkiOptions.AllRevocation,
out RevocationResponder responder,
out CertificateAuthority rootAuthority,
out CertificateAuthority intermediateAuthority,
out X509Certificate2 endEntityCert,
nameof(RevocationCheckingTimeoutFallbackToOther));

using (responder)
using (rootAuthority)
using (intermediateAuthority)
using (endEntityCert)
using (ChainHolder holder = new ChainHolder())
using (X509Certificate2 rootCert = rootAuthority.CloneIssuerCert())
using (X509Certificate2 intermediateCert = intermediateAuthority.CloneIssuerCert())
{
X509Chain chain = holder.Chain;
responder.ResponseDelay = TimeSpan.FromSeconds(8);
responder.DelayedActions = delayFlags;

chain.ChainPolicy.UrlRetrievalTimeout = TimeSpan.FromSeconds(4);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
chain.ChainPolicy.CustomTrustStore.Add(rootCert);
chain.ChainPolicy.ExtraStore.Add(intermediateCert);
chain.ChainPolicy.RevocationMode = X509RevocationMode.Online;
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EndCertificateOnly;

chain.ChainPolicy.DisableCertificateDownloads = true;

Assert.True(chain.Build(endEntityCert), $"chain.Build; Chain status: {chain.AllStatusFlags()}");
}
});
}

[Fact]
[PlatformSpecific(TestPlatforms.Linux)]
public static void AiaFetchDelayed()
Expand All @@ -241,7 +282,7 @@ public static void AiaFetchDelayed()

X509Chain chain = holder.Chain;
responder.ResponseDelay = delay;
responder.DelayedActions = RevocationResponder.DelayedActionsFlag.All;
responder.DelayedActions = DelayedActionsFlag.All;

chain.ChainPolicy.UrlRetrievalTimeout = TimeSpan.FromSeconds(15);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
Expand Down Expand Up @@ -281,7 +322,7 @@ public static void AiaFetchTimeout()

X509Chain chain = holder.Chain;
responder.ResponseDelay = delay;
responder.DelayedActions = RevocationResponder.DelayedActionsFlag.All;
responder.DelayedActions = DelayedActionsFlag.All;

chain.ChainPolicy.UrlRetrievalTimeout = TimeSpan.FromSeconds(2);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
Expand Down