-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/7.0] Fix server-side OCSP stapling on Linux (#96808)
* Recover from failed OCSP download. (#96448) * Recover from failed OCSP check. * Add 5s back-off after failed OCSP querry * Do not OCSP staple invalid OCSP responses * Add entire issuer chain to trusted X509_STORE when validating OCSP_Response Code review feedback More code review feedback Update src/libraries/System.Net.Security/src/System/Net/Security/SslStreamCertificateContext.Linux.cs Co-authored-by: Jeremy Barton <jbarton@microsoft.com> Fix compilation Always include root certificate * Fix compilation * Don't shorten OCSP expriation on failed server OCSP fetch (#96972) * Don't shorten OCSP expriation on failed server OCSP fetch * Code review feedback --------- Co-authored-by: Kevin Jones <kevin@vcsjones.com> Co-authored-by: Carlos Sánchez López <1175054+carlossanlop@users.noreply.github.com>
- Loading branch information
1 parent
a314c5b
commit 7a97ad4
Showing
8 changed files
with
162 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamCertificateContextTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Reflection; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Security.Cryptography.X509Certificates.Tests.Common; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace System.Net.Security.Tests | ||
{ | ||
public static class SslStreamCertificateContextTests | ||
{ | ||
[Fact] | ||
[OuterLoop("Subject to resource contention and load.")] | ||
[PlatformSpecific(TestPlatforms.Linux)] | ||
public static async Task Create_OcspDoesNotReturnOrCacheInvalidStapleData() | ||
{ | ||
string serverName = $"{nameof(Create_OcspDoesNotReturnOrCacheInvalidStapleData)}.example"; | ||
|
||
CertificateAuthority.BuildPrivatePki( | ||
PkiOptions.EndEntityRevocationViaOcsp | PkiOptions.CrlEverywhere, | ||
out RevocationResponder responder, | ||
out CertificateAuthority rootAuthority, | ||
out CertificateAuthority[] intermediateAuthorities, | ||
out X509Certificate2 serverCert, | ||
intermediateAuthorityCount: 1, | ||
subjectName: serverName, | ||
keySize: 2048, | ||
extensions: TestHelper.BuildTlsServerCertExtensions(serverName)); | ||
|
||
using (responder) | ||
using (rootAuthority) | ||
using (CertificateAuthority intermediateAuthority = intermediateAuthorities[0]) | ||
using (serverCert) | ||
using (X509Certificate2 rootCert = rootAuthority.CloneIssuerCert()) | ||
using (X509Certificate2 issuerCert = intermediateAuthority.CloneIssuerCert()) | ||
{ | ||
responder.RespondKind = RespondKind.Invalid; | ||
|
||
SslStreamCertificateContext context = SslStreamCertificateContext.Create( | ||
serverCert, | ||
additionalCertificates: new X509Certificate2Collection { issuerCert }, | ||
offline: false); | ||
|
||
MethodInfo fetchOcspAsyncMethod = typeof(SslStreamCertificateContext).GetMethod( | ||
"DownloadOcspAsync", | ||
BindingFlags.Instance | BindingFlags.NonPublic); | ||
FieldInfo ocspResponseField = typeof(SslStreamCertificateContext).GetField( | ||
"_ocspResponse", | ||
BindingFlags.Instance | BindingFlags.NonPublic); | ||
|
||
Assert.NotNull(fetchOcspAsyncMethod); | ||
Assert.NotNull(ocspResponseField); | ||
|
||
byte[] ocspFetch = await (ValueTask<byte[]>)fetchOcspAsyncMethod.Invoke(context, Array.Empty<object>()); | ||
Assert.Null(ocspFetch); | ||
|
||
byte[] ocspResponseValue = (byte[])ocspResponseField.GetValue(context); | ||
Assert.Null(ocspResponseValue); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters