Skip to content

Commit 7609e10

Browse files
committed
fix: remove duplicate ValidateHasSigningExtension() call from AiaOcspService, negate DoesSupportNonce condition to fix debug log in SubjectCertificateNotRevokedValidator
WE2-416 Signed-off-by: Mart Somermaa <[email protected]>
1 parent 3a545f2 commit 7609e10

File tree

4 files changed

+3
-28
lines changed

4 files changed

+3
-28
lines changed

src/WebEid.Security/Validator/AuthTokenParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static void ValidateTokenSignature(string authToken,
9494
X509Certificate certificate,
9595
TimeSpan allowedClockSkew)
9696
{
97-
using (var certificate2 = new X509Certificate2(certificate))
97+
try
9898
{
9999
var certificate2 = new X509Certificate2(certificate);
100100
// Don't dispose the key, see: https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/1433

src/WebEid.Security/Validator/Ocsp/Service/AiaOcspService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public AiaOcspService(AiaOcspServiceConfiguration configuration,
3232
private Uri GetOcspAiaUrlFromCertificate(Org.BouncyCastle.X509.X509Certificate certificate)
3333
{
3434
if (certificate == null) { throw new ArgumentNullException(nameof(certificate)); }
35-
35+
3636
return certificate.GetOcspUri() ??
3737
throw new UserCertificateRevocationCheckFailedException(
3838
"Getting the AIA OCSP responder field from the certificate failed");
@@ -43,7 +43,6 @@ public void ValidateResponderCertificate(Org.BouncyCastle.X509.X509Certificate r
4343
try
4444
{
4545
responderCertificate.ValidateCertificateExpiry(producedAt, "AIA OCSP responder");
46-
OcspResponseValidator.ValidateHasSigningExtension(responderCertificate);
4746
// Trusted certificates validity has been already verified in ValidateCertificateExpiry().
4847
OcspResponseValidator.ValidateHasSigningExtension(responderCertificate);
4948
new X509Certificate2(DotNetUtilities.ToX509Certificate(responderCertificate))

src/WebEid.Security/Validator/Validators/AuthTokenValidatorDataExtensions.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,6 @@ namespace WebEid.Security.Validator.Validators
99

1010
internal static class AuthTokenValidatorDataExtensions
1111
{
12-
using (var cert2 = new X509Certificate2(actualTokenData.SubjectCertificate))
13-
{
14-
// Use JJWT Clock interface so that the date can be mocked in tests.
15-
if (cert2.NotAfter <= DateTime.Now)
16-
{
17-
throw new UserCertificateExpiredException();
18-
}
19-
if (cert2.NotBefore > DateTime.Now)
20-
{
21-
throw new UserCertificateNotYetValidException();
22-
}
23-
}
24-
using (var cert2 = new X509Certificate2(actualTokenData.SubjectCertificate))
25-
{
26-
var usages = cert2.Extensions.OfType<X509EnhancedKeyUsageExtension>().ToArray();
27-
if (!usages.Any())
28-
{
29-
throw new UserCertificateMissingPurposeException();
30-
}
31-
if (usages.SelectMany(oid => oid.EnhancedKeyUsages.OfType<Oid>())
32-
.All(oid => oid.Value != ExtendedKeyUsageClientAuthentication))
33-
{
34-
throw new UserCertificateWrongPurposeException();
35-
}
3612

3713
}
3814
}

src/WebEid.Security/Validator/Validators/SubjectCertificateNotRevokedValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async Task Validate(AuthTokenValidatorData actualTokenData)
4545
var certificate = DotNetUtilities.FromX509Certificate(actualTokenData.SubjectCertificate);
4646
var ocspService = this.ocspServiceProvider.GetService(certificate);
4747

48-
if (ocspService.DoesSupportNonce)
48+
if (!ocspService.DoesSupportNonce)
4949
{
5050
this.logger?.LogDebug("Disabling OCSP nonce extension");
5151
}

0 commit comments

Comments
 (0)