/// <summary> /// Processes a chunk by decrypting and decompressing it. /// </summary> /// <param name="chunk">The chunk to process.</param> /// <param name="depotkey">The AES encryption key to use when decrypting the chunk.</param> /// <returns>The processed chunk.</returns> public static byte[] ProcessChunk(byte[] chunk, byte[] depotkey) { byte[] decrypted_chunk = CryptoHelper.SymmetricDecrypt(chunk, depotkey); byte[] decompressed_chunk = ZipUtil.Decompress(decrypted_chunk); return(decompressed_chunk); }
/// <summary> /// Processes the specified depot key by decrypting the data with the given depot encryption key, and then by decompressing the data. /// If the chunk has already been processed, this function does nothing. /// </summary> /// <param name="depotKey">The depot decryption key.</param> /// <exception cref="System.IO.InvalidDataException">Thrown if the processed data does not match the expected checksum given in it's chunk information.</exception> public void Process(byte[] depotKey) { if (depotKey == null) { throw new ArgumentNullException(nameof(depotKey)); } if (IsProcessed) { return; } byte[] processedData = CryptoHelper.SymmetricDecrypt(Data, depotKey); if (processedData.Length > 1 && processedData[0] == 'V' && processedData[1] == 'Z') { processedData = VZipUtil.Decompress(processedData); } else { processedData = ZipUtil.Decompress(processedData); } byte[] dataCrc = CryptoHelper.AdlerHash(processedData); if (!dataCrc.SequenceEqual(ChunkInfo.Checksum)) { throw new InvalidDataException("Processed data checksum is incorrect! Downloaded depot chunk is corrupt or invalid/wrong depot key?"); } Data = processedData; IsProcessed = true; }
/// <summary> /// Downloads the depot manifest for the given depot and manifest. /// </summary> /// <param name="depotid">The depotid.</param> /// <param name="manifestid">The manifestid.</param> /// <returns>A <see cref="DepotManifest"/> instance on success; otherwise, <c>null</c>.</returns> public DepotManifest DownloadDepotManifest(int depotid, ulong manifestid) { Uri manifestURI = new Uri(BuildCommand(endPoint, "depot"), String.Format("{0}/manifest/{1}", depotid, manifestid)); PrepareAuthHeader(ref webClient, manifestURI); byte[] compressedManifest; byte[] manifest; try { compressedManifest = webClient.DownloadData(manifestURI); } catch (WebException) { return(null); } try { manifest = ZipUtil.Decompress(compressedManifest); } catch (Exception) { return(null); } return(new DepotManifest(manifest)); }
/// <summary> /// Downloads the depot manifest specified by the given manifest ID, and optionally decrypts the manifest's filenames if the depot decryption key has been provided. /// </summary> /// <param name="manifestId">The unique identifier of the manifest to be downloaded.</param> /// <returns>A <see cref="DepotManifest"/> instance that contains information about the files present within a depot.</returns> public DepotManifest DownloadManifest(ulong manifestId) { byte[] compressedManifest = DoRawCommand(connectedServer, "depot", doAuth: true, args: string.Format("{0}/manifest/{1}", depotId, manifestId)); byte[] manifestData = ZipUtil.Decompress(compressedManifest); var depotManifest = new DepotManifest(manifestData); if (depotKey != null) { // if we have the depot key, decrypt the manifest filenames depotManifest.DecryptFilenames(depotKey); } return(depotManifest); }
async Task <DepotManifest> DownloadManifestCoreAsync(uint depotId, ulong manifestId, Server server, string cdnAuthToken, byte[] depotKey) { var manifestData = await DoRawCommandAsync(server, HttpMethod.Get, "depot", doAuth : true, args : string.Format("{0}/manifest/{1}/5", depotId, manifestId), authtoken : cdnAuthToken).ConfigureAwait(false); manifestData = ZipUtil.Decompress(manifestData); var depotManifest = new DepotManifest(manifestData); if (depotKey != null) { // if we have the depot key, decrypt the manifest filenames depotManifest.DecryptFilenames(depotKey); } return(depotManifest); }
DepotManifest DownloadManifestCore(uint depotId, ulong manifestId, Server server, string cdnAuthToken, byte[] depotKey) { byte[] manifestData = DoRawCommand(server, "depot", doAuth: true, args: string.Format("{0}/manifest/{1}/5", depotId, manifestId), authtoken: cdnAuthToken); manifestData = ZipUtil.Decompress(manifestData); var depotManifest = new DepotManifest(manifestData); if (depotKey != null) { // if we have the depot key, decrypt the manifest filenames depotManifest.DecryptFilenames(depotKey); } return(depotManifest); }
/// <summary> /// Processes the specified depot key by decrypting the data with the given depot encryption key, and then by decompressing the data. /// If the chunk has already been processed, this function does nothing. /// </summary> /// <param name="depotKey">The depot decryption key.</param> /// <exception cref="System.IO.InvalidDataException">Thrown if the processed data does not match the expected checksum given in it's chunk information.</exception> public void Process(byte[] depotKey) { if (IsProcessed) { return; } byte[] processedData = CryptoHelper.SymmetricDecrypt(Data, depotKey); processedData = ZipUtil.Decompress(processedData); byte[] dataCrc = CryptoHelper.AdlerHash(processedData); if (!dataCrc.SequenceEqual(ChunkInfo.Checksum)) { throw new InvalidDataException("Processed data checksum is incorrect! Downloaded depot chunk is corrupt or invalid/wrong depot key?"); } Data = processedData; IsProcessed = true; }
/// <summary> /// Downloads the depot manifest specified by the given manifest ID, and optionally decrypts the manifest's filenames if the depot decryption key has been provided. /// </summary> /// <param name="depotId">The id of the depot being accessed.</param> /// <param name="manifestId">The unique identifier of the manifest to be downloaded.</param> /// <param name="server">The content server to connect to.</param> /// <param name="cdnAuthToken">CDN auth token for CDN content server endpoints.</param> /// <param name="depotKey"> /// The depot decryption key for the depot that will be downloaded. /// This is used for decrypting filenames (if needed) in depot manifests, and processing depot chunks. /// </param> /// <param name="proxyServer">Optional content server marked as UseAsProxy which transforms the request.</param> /// <returns>A <see cref="DepotManifest"/> instance that contains information about the files present within a depot.</returns> /// <exception cref="System.ArgumentNullException"><see ref="server"/> was null.</exception> /// <exception cref="HttpRequestException">An network error occurred when performing the request.</exception> /// <exception cref="SteamKitWebRequestException">A network error occurred when performing the request.</exception> public async Task <DepotManifest> DownloadManifestAsync(uint depotId, ulong manifestId, Server server, string?cdnAuthToken, byte[]?depotKey, Server?proxyServer = null) { if (server == null) { throw new ArgumentNullException(nameof(server)); } var manifestData = await DoRawCommandAsync(server, string.Format("depot/{0}/manifest/{1}/5", depotId, manifestId), cdnAuthToken, proxyServer).ConfigureAwait(false); manifestData = ZipUtil.Decompress(manifestData); var depotManifest = new DepotManifest(manifestData); if (depotKey != null) { // if we have the depot key, decrypt the manifest filenames depotManifest.DecryptFilenames(depotKey); } return(depotManifest); }
/// <summary> /// Downloads the depot manifest specified by the given manifest ID, and optionally decrypts the manifest's filenames if the depot decryption key has been provided. /// </summary> /// <param name="depotId">The id of the depot being accessed.</param> /// <param name="manifestId">The unique identifier of the manifest to be downloaded.</param> /// <returns>A <see cref="DepotManifest"/> instance that contains information about the files present within a depot.</returns> public DepotManifest DownloadManifest(uint depotId, ulong manifestId) { string cdnToken = null; depotCdnAuthKeys.TryGetValue(depotId, out cdnToken); byte[] compressedManifest = DoRawCommand(connectedServer, "depot", doAuth: true, args: string.Format("{0}/manifest/{1}/5", depotId, manifestId), authtoken: cdnToken); byte[] manifestData = ZipUtil.Decompress(compressedManifest); var depotManifest = new DepotManifest(manifestData); byte[] depotKey; if (depotKeys.TryGetValue(depotId, out depotKey)) { // if we have the depot key, decrypt the manifest filenames depotManifest.DecryptFilenames(depotKey); } return(depotManifest); }
/// <summary> /// Processes the specified depot key by decrypting the data with the given depot encryption key, and then by decompressing the data. /// If the chunk has already been processed, this function does nothing. /// </summary> /// <param name="depotKey">The depot decryption key.</param> /// <exception cref="System.IO.InvalidDataException">Thrown if the processed data does not match the expected checksum given in it's chunk information.</exception> public void Process(byte[] depotKey) { if (depotKey == null) { throw new ArgumentNullException(nameof(depotKey)); } if (IsProcessed) { return; } if (Data != null) { byte[] processedData = CryptoHelper.SymmetricDecrypt(Data, depotKey); if (processedData.Length > 1 && processedData[0] == 'V' && processedData[1] == 'Z') { processedData = VZipUtil.Decompress(processedData); } else { processedData = ZipUtil.Decompress(processedData); } byte[] dataCrc = CryptoHelper.AdlerHash(processedData); if (!dataCrc.SequenceEqual(ChunkInfo.Checksum)) { throw new InvalidDataException("Processed data checksum is incorrect! Downloaded depot chunk is corrupt or invalid/wrong depot key?"); } Data = processedData; IsProcessed = true; } if (DataStream != null) { Stream reProcessedData; using (Stream processedData = CryptoHelper.SymmetricDecrypt(DataStream, depotKey)) { int firstByte = processedData.ReadByte(); int secondByte = processedData.ReadByte(); processedData.Position = 0; if (firstByte == 86 && secondByte == 90) { reProcessedData = VZipUtil.Decompress(processedData); } else { reProcessedData = ZipUtil.Decompress(processedData); } } byte[] dataCrc = CryptoHelper.AdlerHash(reProcessedData); if (!dataCrc.SequenceEqual(ChunkInfo.Checksum)) { throw new InvalidDataException("Processed data checksum is incorrect! Downloaded depot chunk is corrupt or invalid/wrong depot key?"); } DataStream = reProcessedData; IsProcessed = true; } }