Skip to content

Commit dded7eb

Browse files
committed
fix: apply Ocsp request timeout from configuration
WE2-1109 Signed-off-by: Sven Mitt <[email protected]>
1 parent 2c24ca6 commit dded7eb

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright © 2020-2025 Estonian Information System Authority
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
namespace WebEid.Security.Tests.Validator
23+
{
24+
using System;
25+
using System.Threading.Tasks;
26+
using NUnit.Framework;
27+
using WebEid.Security.Exceptions;
28+
using WebEid.Security.Tests.TestUtils;
29+
using WebEid.Security.Util;
30+
31+
public class AuthTokenValidatonOcspTest : AbstractTestWithValidator
32+
{
33+
34+
[Test]
35+
public void WhenOcspRequestTimeoutIsReachedThenValidationFails()
36+
{
37+
using var _ = DateTimeProvider.OverrideUtcNow(new DateTime(2023, 10, 21));
38+
var authTokenValidator = AuthTokenValidators
39+
.GetDefaultAuthTokenValidatorBuilder()
40+
.WithOcspRequestTimeout(TimeSpan.FromMilliseconds(1))
41+
.Build();
42+
43+
var exception = Assert.ThrowsAsync<UserCertificateOcspCheckFailedException>(() => authTokenValidator.Validate(authTokenValidator.Parse(ValidAuthTokenStr), ValidChallengeNonce));
44+
Assert.That(exception.InnerException, Is.TypeOf<TaskCanceledException>());
45+
Assert.That(exception.InnerException.Message, Does.Match("The request was canceled due to the configured HttpClient.Timeout of 0,[0-9]* seconds elapsing."));
46+
47+
}
48+
49+
[Test]
50+
public async Task WhenCertificateIsNotRevokedThenOcspCheckIsSuccessful()
51+
{
52+
using var _ = DateTimeProvider.OverrideUtcNow(new DateTime(2023, 10, 21));
53+
var authTokenValidator = AuthTokenValidators
54+
.GetDefaultAuthTokenValidatorBuilder()
55+
.WithAllowedOcspResponseTimeSkew(TimeSpan.FromDays(365 * 20))
56+
.Build();
57+
58+
var certificate = await authTokenValidator.Validate(authTokenValidator.Parse(ValidAuthTokenStr), ValidChallengeNonce);
59+
Assert.That(certificate, Is.Not.Null);
60+
}
61+
}
62+
}

src/WebEid.Security/Validator/AuthTokenValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public AuthTokenValidator(AuthTokenValidationConfiguration configuration, ILogge
7171

7272
if (configuration.IsUserCertificateRevocationCheckWithOcspEnabled)
7373
{
74-
this.ocspClient = new OcspClient(TimeSpan.FromSeconds(5), this.logger);
74+
this.ocspClient = new OcspClient(configuration.OcspRequestTimeout, this.logger);
7575
this.ocspServiceProvider =
7676
new OcspServiceProvider(configuration.DesignatedOcspServiceConfiguration,
7777
new AiaOcspServiceConfiguration(configuration.NonceDisabledOcspUrls,

0 commit comments

Comments
 (0)