Skip to content

Commit 1390f91

Browse files
committed
CustomBuildTool: Add SSL policy override winsiderss#563
1 parent 7ea9d2d commit 1390f91

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

tools/CustomBuildTool/Build.cs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,23 +1326,41 @@ public static bool BuildDeployUploadArtifacts()
13261326
{
13271327
string fileName = Path.GetFileName(sourceFile);
13281328

1329-
using (HttpClient client = new HttpClient())
1330-
using (FileStream fileStream = File.OpenRead(sourceFile))
1331-
using (StreamContent streamContent = new StreamContent(fileStream))
1332-
using (MultipartFormDataContent content = new MultipartFormDataContent())
1329+
using (HttpClientHandler httpClientHandler = new HttpClientHandler())
13331330
{
1334-
client.DefaultRequestHeaders.Add("X-ApiKey", buildBuildUrlKey);
1335-
streamContent.Headers.Add("Content-Type", "application/octet-stream");
1336-
streamContent.Headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"" + fileName + "\"");
1337-
content.Add(streamContent, "file", fileName);
1331+
httpClientHandler.AutomaticDecompression = DecompressionMethods.All;
1332+
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) =>
1333+
{
1334+
// Allow this client to communicate with authenticated servers.
1335+
if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.None)
1336+
return true;
13381337

1339-
var httpTask = client.PostAsync(buildBuildUrl, content);
1340-
httpTask.Wait();
1338+
// Temporarily ignore wj32.org expired certificate.
1339+
if (string.Equals(cert.GetCertHashString(), "b60cb3b6aac5f59075689fc3c7dfd561750ce100", StringComparison.OrdinalIgnoreCase))
1340+
return true;
13411341

1342-
if (!httpTask.Result.IsSuccessStatusCode)
1343-
{
1344-
Program.PrintColorMessage("[HttpClient PostAsync] " + httpTask.Result, ConsoleColor.Red);
1342+
// Do not allow this client to communicate with unauthenticated servers.
13451343
return false;
1344+
};
1345+
1346+
using (HttpClient client = new HttpClient(httpClientHandler))
1347+
using (FileStream fileStream = File.OpenRead(sourceFile))
1348+
using (StreamContent streamContent = new StreamContent(fileStream))
1349+
using (MultipartFormDataContent content = new MultipartFormDataContent())
1350+
{
1351+
client.DefaultRequestHeaders.Add("X-ApiKey", buildBuildUrlKey);
1352+
streamContent.Headers.Add("Content-Type", "application/octet-stream");
1353+
streamContent.Headers.Add("Content-Disposition", "form-data; name=\"file\"; filename=\"" + fileName + "\"");
1354+
content.Add(streamContent, "file", fileName);
1355+
1356+
var httpTask = client.PostAsync(buildBuildUrl, content);
1357+
httpTask.Wait();
1358+
1359+
if (!httpTask.Result.IsSuccessStatusCode)
1360+
{
1361+
Program.PrintColorMessage("[HttpClient PostAsync] " + httpTask.Result, ConsoleColor.Red);
1362+
return false;
1363+
}
13461364
}
13471365
}
13481366
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)