Skip to content

Commit ff73bdf

Browse files
committed
Switch to HTTPS for CDN downloads
1 parent 2f3d123 commit ff73bdf

File tree

2 files changed

+104
-11
lines changed

2 files changed

+104
-11
lines changed

TACTSharp/CDN.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,26 +237,26 @@ public async Task<string> GetPatchServiceFile(string product, string file = "ver
237237

238238
for (var i = 0; i < CDNServers.Count; i++)
239239
{
240-
var url = $"http://{CDNServers[i]}/{ProductDirectory}/{type}/{hash[0]}{hash[1]}/{hash[2]}{hash[3]}/{hash}";
240+
var url = $"https://{CDNServers[i]}/{ProductDirectory}/{type}/{hash[0]}{hash[1]}/{hash[2]}{hash[3]}/{hash}";
241241

242242
Console.WriteLine("Downloading " + url);
243243

244244
var request = new HttpRequestMessage(HttpMethod.Get, url);
245245

246-
var response = Client.Send(request, token);
247-
248-
if (!response.IsSuccessStatusCode)
249-
{
250-
Console.WriteLine("Encountered HTTP " + response.StatusCode + " downloading " + hash + " from " + CDNServers[i]);
251-
continue;
252-
}
253-
254246
lock (FileLocks[cachePath])
255247
{
256248
Directory.CreateDirectory(Path.GetDirectoryName(cachePath)!);
257249

258250
try
259251
{
252+
var response = Client.Send(request, token);
253+
254+
if (!response.IsSuccessStatusCode)
255+
{
256+
Console.WriteLine("Encountered HTTP " + response.StatusCode + " downloading " + hash + " from " + CDNServers[i]);
257+
continue;
258+
}
259+
260260
using (var fileStream = new FileStream(cachePath, FileMode.Create, FileAccess.Write))
261261
{
262262
if (string.IsNullOrEmpty(ArmadilloKeyName))
@@ -420,7 +420,7 @@ public unsafe bool TryGetLocalFile(string eKey, out ReadOnlySpan<byte> data)
420420

421421
for (var i = 0; i < CDNServers.Count; i++)
422422
{
423-
var url = $"http://{CDNServers[i]}/{ProductDirectory}/data/{archive[0]}{archive[1]}/{archive[2]}{archive[3]}/{archive}";
423+
var url = $"https://{CDNServers[i]}/{ProductDirectory}/data/{archive[0]}{archive[1]}/{archive[2]}{archive[3]}/{archive}";
424424

425425
Console.WriteLine("Downloading file " + eKey + " from archive " + archive + " at offset " + offset + " with size " + size + " from " + CDNServers[i]);
426426

@@ -560,7 +560,7 @@ public unsafe bool TryGetLocalFile(string eKey, out ReadOnlySpan<byte> data)
560560

561561
for (var i = 0; i < CDNServers.Count; i++)
562562
{
563-
var url = $"http://{CDNServers[i]}/tpr/configs/data/{hash[0]}{hash[1]}/{hash[2]}{hash[3]}/{hash}";
563+
var url = $"https://{CDNServers[i]}/tpr/configs/data/{hash[0]}{hash[1]}/{hash[2]}{hash[3]}/{hash}";
564564

565565
Console.WriteLine("Downloading " + url);
566566

TACTTool/RunModes/Verify.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Security.Cryptography;
4+
using System.Text;
5+
using TACTSharp;
6+
7+
namespace TACTTool.RunModes
8+
{
9+
public static class Verify
10+
{
11+
public static void Run(BuildInstance buildInstance)
12+
{
13+
Console.WriteLine("Starting TACT CDN directory verification...");
14+
Console.WriteLine("!!!");
15+
Console.WriteLine("NOTE: This is currently a very basic implementation that only checks archive/loose file existence & sizes.");
16+
Console.WriteLine("!!!");
17+
18+
if (buildInstance.Settings.CDNConfig is null)
19+
{
20+
Console.WriteLine("!!! Warning, no CDN config given so will check entire directory. This may take a long time and may fail on SMB mounted shares.");
21+
Console.WriteLine("Also, this is not yet implemented.");
22+
throw new NotImplementedException();
23+
}
24+
else
25+
{
26+
var config = new TACTSharp.Config(buildInstance.cdn, buildInstance.Settings.CDNConfig, false);
27+
28+
var archiveCount = config.Values["archives"].Length;
29+
for (var i = 0; i < archiveCount; i++)
30+
{
31+
var archiveIndex = config.Values["archives"][i];
32+
33+
var indexPath = Path.Combine(buildInstance.Settings.CDNDir, "tpr", "wow", "data", archiveIndex[0..2], archiveIndex[2..4], archiveIndex + ".index");
34+
if (!File.Exists(indexPath))
35+
throw new FileNotFoundException(indexPath);
36+
37+
var index = new IndexInstance(indexPath);
38+
39+
var allFiles = index.GetAllEntries();
40+
var highestOffset = allFiles.Select(x => x.offset + x.size).Max();
41+
42+
var archiveFileInfo = new FileInfo(indexPath.Replace(".index", ""));
43+
if (!archiveFileInfo.Exists)
44+
throw new FileNotFoundException(archiveFileInfo.FullName);
45+
var archiveLength = archiveFileInfo.Length;
46+
47+
if (highestOffset != archiveLength)
48+
{
49+
Console.WriteLine($"!!! Archive {archiveIndex} has wrong size! Expected {highestOffset} bytes but only found {archiveLength} bytes.");
50+
}
51+
52+
Console.Write("Checking archives.. " + (i + 1) + "/" + archiveCount + "\r");
53+
}
54+
55+
Console.WriteLine();
56+
57+
if (config.Values.TryGetValue("file-index", out string[]? fileIndexName))
58+
{
59+
var fileIndexPath = Path.Combine(buildInstance.Settings.CDNDir, "tpr", "wow", "data", fileIndexName[0][0..2], fileIndexName[0][2..4], fileIndexName[0] + ".index");
60+
var fileIndex = new IndexInstance(fileIndexPath);
61+
var allFiles = fileIndex.GetAllEntries();
62+
var looseFileCount = allFiles.Count;
63+
for(var i = 0; i < looseFileCount; i++)
64+
{
65+
Console.Write("Checking loose files.. " + (i + 1) + "/" + looseFileCount + "\r");
66+
var looseFile = allFiles[i];
67+
var looseFileName = Convert.ToHexStringLower(looseFile.eKey);
68+
var looseFilePath = Path.Combine(buildInstance.Settings.CDNDir, "tpr", "wow", "data", looseFileName[0..2], looseFileName[2..4], looseFileName);
69+
var looseFileInfo = new FileInfo(looseFilePath);
70+
if (!looseFileInfo.Exists)
71+
throw new FileNotFoundException(looseFilePath);
72+
73+
var looseFileSize = looseFileInfo.Length;
74+
var looseFileSupposedSize = looseFile.size;
75+
76+
//var looseFileMD5 = Convert.ToHexStringLower(MD5.HashData(File.ReadAllBytes(looseFilePath)));
77+
//if(looseFileMD5 != looseFileName)
78+
//{
79+
// Console.WriteLine($"!!! MD5 for file {looseFileName} is incorrect ({looseFileName} != {looseFileMD5}!");
80+
//}
81+
82+
if (looseFileSize != looseFileSupposedSize)
83+
{
84+
Console.WriteLine($"!!! Loose file {looseFileName} has wrong size! Expected {looseFileSupposedSize} bytes but only found {looseFileSize} bytes.");
85+
}
86+
}
87+
}
88+
89+
Console.WriteLine();
90+
}
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)