mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
feat: replace OpenSSL with native Blowfish decryption and add library rescan
- Replace OpenSSL subprocess with BouncyCastle native Blowfish CBC decryption - Add automatic Subsonic library scan trigger after downloads (with 30s debounce) - Improve error handling in DeezerMetadataService search methods - Add comprehensive tests for download service, metadata service, and library service - Increase test coverage from 13 to 32 tests
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Org.BouncyCastle.Crypto.Engines;
|
||||
using Org.BouncyCastle.Crypto.Modes;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using octo_fiesta.Models;
|
||||
|
||||
namespace octo_fiesta.Services;
|
||||
@@ -135,6 +138,9 @@ public class DeezerDownloadService : IDownloadService
|
||||
song.LocalPath = localPath;
|
||||
await _localLibraryService.RegisterDownloadedSongAsync(song, localPath);
|
||||
|
||||
// Déclencher un rescan de la bibliothèque Subsonic (avec debounce)
|
||||
_ = _localLibraryService.TriggerLibraryScanAsync();
|
||||
|
||||
_logger.LogInformation("Download completed: {Path}", localPath);
|
||||
return localPath;
|
||||
}
|
||||
@@ -459,38 +465,20 @@ public class DeezerDownloadService : IDownloadService
|
||||
|
||||
private byte[] DecryptBlowfishCbc(byte[] data, byte[] key, byte[] iv)
|
||||
{
|
||||
// Note: .NET ne supporte pas nativement Blowfish
|
||||
// On utilise BouncyCastle ou une implémentation custom
|
||||
// Pour l'instant, on utilise un appel à OpenSSL via Process (comme le JS)
|
||||
// Use BouncyCastle for native Blowfish CBC decryption
|
||||
var engine = new BlowfishEngine();
|
||||
var cipher = new CbcBlockCipher(engine);
|
||||
cipher.Init(false, new ParametersWithIV(new KeyParameter(key), iv));
|
||||
|
||||
using var process = new System.Diagnostics.Process();
|
||||
process.StartInfo.FileName = "openssl";
|
||||
process.StartInfo.Arguments = $"enc -d -bf-cbc -K {Convert.ToHexString(key).ToLower()} -iv {Convert.ToHexString(iv).ToLower()} -nopad -provider legacy -provider default";
|
||||
process.StartInfo.RedirectStandardInput = true;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
process.StartInfo.RedirectStandardError = true;
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
|
||||
process.Start();
|
||||
var output = new byte[data.Length];
|
||||
var blockSize = cipher.GetBlockSize(); // 8 bytes for Blowfish
|
||||
|
||||
using var stdin = process.StandardInput.BaseStream;
|
||||
stdin.Write(data, 0, data.Length);
|
||||
stdin.Close();
|
||||
|
||||
using var stdout = process.StandardOutput.BaseStream;
|
||||
using var ms = new MemoryStream();
|
||||
stdout.CopyTo(ms);
|
||||
|
||||
process.WaitForExit();
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
for (int offset = 0; offset < data.Length; offset += blockSize)
|
||||
{
|
||||
var error = process.StandardError.ReadToEnd();
|
||||
throw new Exception($"OpenSSL decryption failed: {error}");
|
||||
cipher.ProcessBlock(data, offset, output, offset);
|
||||
}
|
||||
|
||||
return ms.ToArray();
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user