blob: 50de6a06ea490b260ed92eb2e683d100f4498ad1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Net.Test.Common;
using System.Security.Authentication;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
namespace System.Net.Http.Functional.Tests
{
using Configuration = System.Net.Test.Common.Configuration;
[SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "dotnet/corefx #20010")]
public class SchSendAuxRecordHttpTest
{
readonly ITestOutputHelper _output;
public SchSendAuxRecordHttpTest(ITestOutputHelper output)
{
_output = output;
}
[OuterLoop] // TODO: Issue #11345
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
public async Task HttpClient_ClientUsesAuxRecord_Ok()
{
var options = new HttpsTestServer.Options();
options.AllowedProtocols = SslProtocols.Tls;
using (var server = new HttpsTestServer(options))
using (var handler = new HttpClientHandler() { ServerCertificateCustomValidationCallback = LoopbackServer.AllowAllCertificates })
using (var client = new HttpClient(handler))
{
server.Start();
var tasks = new Task[2];
bool serverAuxRecordDetected = false;
bool serverAuxRecordDetectedInconclusive = false;
int serverTotalBytesReceived = 0;
int serverChunks = 0;
tasks[0] = server.AcceptHttpsClientAsync((requestString) =>
{
serverTotalBytesReceived += requestString.Length;
if (serverTotalBytesReceived == 1 && serverChunks == 0)
{
serverAuxRecordDetected = true;
}
serverChunks++;
// Test is inconclusive if any non-CBC cipher is used:
if (server.Stream.CipherAlgorithm == CipherAlgorithmType.None ||
server.Stream.CipherAlgorithm == CipherAlgorithmType.Null ||
server.Stream.CipherAlgorithm == CipherAlgorithmType.Rc4)
{
serverAuxRecordDetectedInconclusive = true;
}
if (serverTotalBytesReceived < 5)
{
return Task.FromResult<string>(null);
}
else
{
return Task.FromResult(HttpsTestServer.Options.DefaultResponseString);
}
});
string requestUriString = "https://localhost:" + server.Port.ToString();
tasks[1] = client.GetStringAsync(requestUriString);
await Task.WhenAll(tasks).TimeoutAfter(15 * 1000);
if (serverAuxRecordDetectedInconclusive)
{
_output.WriteLine("Test inconclusive: The Operating system preferred a non-CBC or Null cipher.");
}
else
{
Assert.True(serverAuxRecordDetected, "Server reports: Client auxiliary record not detected.");
}
}
}
}
}
|