From 9d9cf68e0aa20eac14b8060de8eae8d748fdedb4 Mon Sep 17 00:00:00 2001 From: Rebecca Wallander Date: Sat, 16 Jan 2021 18:57:14 +0100 Subject: [PATCH] Move decryption option to Settings + formatting fixes --- Aaru.Core/Devices/Dumping/Dump.cs | 13 ++++------ Aaru.Core/Devices/Dumping/MMC.cs | 24 +++++-------------- Aaru.Core/Devices/Dumping/Sbc/Data.cs | 17 ++++--------- Aaru.Core/Devices/Dumping/Sbc/Dump.cs | 14 ++++++----- Aaru.Core/Devices/Dumping/Sbc/Error.cs | 2 ++ .../ViewModels/Windows/MediaDumpViewModel.cs | 2 +- Aaru.Settings/Settings.cs | 13 ++++++++++ Aaru/Commands/Media/Dump.cs | 4 ++-- Aaru/Main.cs | 7 ------ 9 files changed, 42 insertions(+), 54 deletions(-) diff --git a/Aaru.Core/Devices/Dumping/Dump.cs b/Aaru.Core/Devices/Dumping/Dump.cs index 112b8612f..1e96fb9c8 100644 --- a/Aaru.Core/Devices/Dumping/Dump.cs +++ b/Aaru.Core/Devices/Dumping/Dump.cs @@ -96,9 +96,8 @@ namespace Aaru.Core.Devices.Dumping int _speed; int _speedMultiplier; bool _supportsPlextorD8; - bool _decryption; - bool _storeEncrypted; - bool _titleKeys; + readonly bool _storeEncrypted; + readonly bool _titleKeys; /// Initializes dumpers /// Should resume? @@ -135,12 +134,11 @@ namespace Aaru.Core.Devices.Dumping /// Generate missing subchannels /// Number of maximum blocks to be read at once (can be overriden by database) /// - /// If decryption should be used. - /// Store encrypted data as is - /// Dump DVD CSS title keys /// If MMC/SD does not support CMD23, use OS buffered reads instead of multiple single block /// commands /// + /// Store encrypted data as is + /// Dump DVD CSS title keys public Dump(bool doResume, Device dev, string devicePath, IWritableImage outputPlugin, ushort retryPasses, bool force, bool dumpRaw, bool persistent, bool stopOnError, Resume resume, DumpLog dumpLog, Encoding encoding, string outputPrefix, string outputPath, Dictionary formatOptions, @@ -148,7 +146,7 @@ namespace Aaru.Core.Devices.Dumping bool fixOffset, bool debug, DumpSubchannel subchannel, int speed, bool @private, bool fixSubchannelPosition, bool retrySubchannel, bool fixSubchannel, bool fixSubchannelCrc, bool skipCdireadyHole, ErrorLog errorLog, bool generateSubchannels, uint maximumReadable, - bool useBufferedReads, bool decryption, bool storeEncrypted, bool titleKeys) + bool useBufferedReads, bool storeEncrypted, bool titleKeys) { _doResume = doResume; _dev = dev; @@ -186,7 +184,6 @@ namespace Aaru.Core.Devices.Dumping _errorLog = errorLog; _generateSubchannels = generateSubchannels; _useBufferedReads = useBufferedReads; - _decryption = decryption; _storeEncrypted = storeEncrypted; _titleKeys = titleKeys; } diff --git a/Aaru.Core/Devices/Dumping/MMC.cs b/Aaru.Core/Devices/Dumping/MMC.cs index c3ac453ac..ca595d5e0 100644 --- a/Aaru.Core/Devices/Dumping/MMC.cs +++ b/Aaru.Core/Devices/Dumping/MMC.cs @@ -514,16 +514,12 @@ namespace Aaru.Core.Devices.Dumping CSS_CPRM.LeadInCopyright? cmi = CSS_CPRM.DecodeLeadInCopyright(cmdBuf); if(cmi!.Value.CopyrightType == CopyrightType.NoProtection) - { UpdateStatus?.Invoke("Drive reports no copy protection on disc."); - } else { - if(!_decryption) - { + if(!Settings.Settings.Current.EnableDecryption) UpdateStatus?.Invoke("Drive reports the disc uses copy protection. " + - "The dump might be incorrect unless decryption is enabled."); - } + "The dump will be incorrect unless decryption is enabled."); else { if(cmi!.Value.CopyrightType == CopyrightType.CSS) @@ -568,15 +564,9 @@ namespace Aaru.Core.Devices.Dumping if(rpc.HasValue) { - if(CSS.CheckRegion(rpc.Value, cmi.Value)) - { - UpdateStatus?.Invoke("Disc and drive regions match."); - } - else - { - UpdateStatus?. - Invoke("Disc and drive regions do not match. The dump might be incorrect"); - } + UpdateStatus?.Invoke(CSS.CheckRegion(rpc.Value, cmi.Value) + ? "Disc and drive regions match." + : "Disc and drive regions do not match. The dump will be incorrect"); } } @@ -596,9 +586,7 @@ namespace Aaru.Core.Devices.Dumping mediaTags.Add(MediaTagType.DVD_DiscKey_Decrypted, discKey); } else - { UpdateStatus?.Invoke("Decryption of disc key failed."); - } } } } @@ -609,7 +597,7 @@ namespace Aaru.Core.Devices.Dumping { UpdateStatus?. Invoke($"Drive reports disc uses {CSS_CPRM.DecodeLeadInCopyright(cmdBuf)!.Value.CopyrightType.ToString()} copy protection. " + - "This is not yet supported and the dump might be incorrect."); + "This is not yet supported and the dump will be incorrect."); } } } diff --git a/Aaru.Core/Devices/Dumping/Sbc/Data.cs b/Aaru.Core/Devices/Dumping/Sbc/Data.cs index 4c2b84cdf..e1474a87d 100644 --- a/Aaru.Core/Devices/Dumping/Sbc/Data.cs +++ b/Aaru.Core/Devices/Dumping/Sbc/Data.cs @@ -105,22 +105,18 @@ namespace Aaru.Core.Devices.Dumping if(!sense && !_dev.Error) { - if(_decryption) + if(Settings.Settings.Current.EnableDecryption) { if(_titleKeys && discKey != null) { for(ulong j = 0; j < blocksToRead; j++) { if(_aborted) - { break; - } if(!_resume.MissingTitleKeys.Contains(i + j)) - { // Key is already dumped. continue; - } byte[] tmpBuf; @@ -133,15 +129,14 @@ namespace Aaru.Core.Devices.Dumping CSS_CPRM.TitleKey? titleKey = CSS.DecodeTitleKey(tmpBuf, dvdDecrypt.BusKey); if(titleKey.HasValue) - { _outputPlugin.WriteSectorTag(new[] { titleKey.Value.CMI }, i + j, SectorTagType.DvdCmi); - } else continue; + // If the CMI bit is 1, the sector is using copy protection, else it is not if((titleKey.Value.CMI & 0x80) >> 7 == 0) { // The CMI indicates this sector is not encrypted. @@ -159,11 +154,11 @@ namespace Aaru.Core.Devices.Dumping continue; } - + + // According to libdvdcss, if the key is all zeroes, the sector is actually + // not encrypted even if the CMI says it is. if(titleKey.Value.Key.All(k => k == 0)) { - // According to libdvdcss, if the key is all zeroes, the sector is actually - // not encrypted even if the CMI says it is. _outputPlugin.WriteSectorTag(new byte[] { 0, 0, 0, 0, 0 @@ -189,14 +184,12 @@ namespace Aaru.Core.Devices.Dumping } if(!_storeEncrypted && _titleKeys) - { // Todo: Flag in the _outputPlugin that a sector has been decrypted buffer = CSS.DecryptSector(buffer, _outputPlugin.ReadSectorsTag(i, blocksToRead, SectorTagType.DvdCmi), _outputPlugin.ReadSectorsTag(i, blocksToRead, SectorTagType.DvdTitleKeyDecrypted), blocksToRead, blockSize); - } } mhddLog.Write(i, cmdDuration); diff --git a/Aaru.Core/Devices/Dumping/Sbc/Dump.cs b/Aaru.Core/Devices/Dumping/Sbc/Dump.cs index 50aa5705d..11f47c660 100644 --- a/Aaru.Core/Devices/Dumping/Sbc/Dump.cs +++ b/Aaru.Core/Devices/Dumping/Sbc/Dump.cs @@ -668,7 +668,7 @@ namespace Aaru.Core.Devices.Dumping bool newTrim = false; - if(_decryption && _titleKeys) + if(Settings.Settings.Current.EnableDecryption && _titleKeys) { UpdateStatus?.Invoke("Title keys dumping is enabled. This will be very slow."); _resume.MissingTitleKeys ??= new List(Enumerable.Range(0, (int)blocks).Select(n => (ulong)n)); @@ -681,7 +681,9 @@ namespace Aaru.Core.Devices.Dumping else ReadSbcData(blocks, blocksToRead, blockSize, currentTry, extents, ref currentSpeed, ref minSpeed, ref maxSpeed, ref totalDuration, scsiReader, mhddLog, ibgLog, ref imageWriteDuration, - ref newTrim, ref dvdDecrypt, mediaTags[MediaTagType.DVD_DiscKey_Decrypted]); + ref newTrim, ref dvdDecrypt, + mediaTags.ContainsKey(MediaTagType.DVD_DiscKey_Decrypted) + ? mediaTags[MediaTagType.DVD_DiscKey_Decrypted] : null); end = DateTime.UtcNow; mhddLog.Close(); @@ -732,10 +734,10 @@ namespace Aaru.Core.Devices.Dumping _retryPasses > 0) RetrySbcData(scsiReader, currentTry, extents, ref totalDuration, blankExtents); - if(_resume.MissingTitleKeys.Count > 0 && - !_aborted && - _retryPasses > 0 && - _decryption && + if(_resume.MissingTitleKeys.Count > 0 && + !_aborted && + _retryPasses > 0 && + Settings.Settings.Current.EnableDecryption && _titleKeys) RetryTitleKeys(dvdDecrypt, mediaTags[MediaTagType.DVD_DiscKey_Decrypted], ref totalDuration); #endregion Error handling diff --git a/Aaru.Core/Devices/Dumping/Sbc/Error.cs b/Aaru.Core/Devices/Dumping/Sbc/Error.cs index 2864bd530..7b4cd87ec 100644 --- a/Aaru.Core/Devices/Dumping/Sbc/Error.cs +++ b/Aaru.Core/Devices/Dumping/Sbc/Error.cs @@ -359,6 +359,8 @@ namespace Aaru.Core.Devices.Dumping titleKey.Value.CMI }, missingKey, SectorTagType.DvdCmi); + // If the CMI bit is 1, the sector is using copy protection, else it is not + // If the decoded title key is zeroed, there should be no copy protection if((titleKey.Value.CMI & 0x80) >> 7 == 0 || titleKey.Value.Key.All(k => k == 0)) { diff --git a/Aaru.Gui/ViewModels/Windows/MediaDumpViewModel.cs b/Aaru.Gui/ViewModels/Windows/MediaDumpViewModel.cs index 6803fb14f..668d34f05 100644 --- a/Aaru.Gui/ViewModels/Windows/MediaDumpViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/MediaDumpViewModel.cs @@ -810,7 +810,7 @@ namespace Aaru.Gui.ViewModels.Windows Persistent, StopOnError, _resume, dumpLog, encoding, _outputPrefix, Destination, parsedOptions, _sidecar, (uint)Skipped, ExistingMetadata == false, Trim == false, Track1Pregap, true, false, DumpSubchannel.Any, 0, false, false, false, false, false, - true, errorLog, false, 64, true, false, true, false); + true, errorLog, false, 64, true, true, false); new Thread(DoWork).Start(); } diff --git a/Aaru.Settings/Settings.cs b/Aaru.Settings/Settings.cs index 0d826182f..3bedef9c0 100644 --- a/Aaru.Settings/Settings.cs +++ b/Aaru.Settings/Settings.cs @@ -28,6 +28,7 @@ // // ---------------------------------------------------------------------------- // Copyright © 2011-2021 Natalia Portillo +// Copyright © 2021 Rebecca Wallander // ****************************************************************************/ using System; @@ -55,6 +56,8 @@ namespace Aaru.Settings public bool SaveReportsGlobally; /// If set to true, reports will be sent to Aaru.Server public bool ShareReports; + /// If set to true, enables the ability to decrypt encrypted data + public bool EnableDecryption; /// Statistics public StatsSettings Stats; } @@ -299,6 +302,9 @@ namespace Aaru.Settings Current.ShareReports = parsedPreferences.TryGetValue("ShareReports", out obj) && ((NSNumber)obj).ToBool(); + Current.EnableDecryption = parsedPreferences.TryGetValue("EnableDecryption", out obj) && + ((NSNumber)obj).ToBool(); + if(parsedPreferences.TryGetValue("Stats", out obj)) { var stats = (NSDictionary)obj; @@ -375,6 +381,7 @@ namespace Aaru.Settings Current.SaveReportsGlobally = Convert.ToBoolean(dicKey.GetValue("SaveReportsGlobally")); Current.ShareReports = Convert.ToBoolean(dicKey.GetValue("ShareReports")); Current.GdprCompliance = Convert.ToUInt64(dicKey.GetValue("GdprCompliance")); + Current.EnableDecryption = Convert.ToBoolean(dicKey.GetValue("EnableDecryption")); stats = Convert.ToBoolean(dicKey.GetValue("Statistics")); @@ -411,6 +418,7 @@ namespace Aaru.Settings Current.SaveReportsGlobally = Convert.ToBoolean(key.GetValue("SaveReportsGlobally")); Current.ShareReports = Convert.ToBoolean(key.GetValue("ShareReports")); Current.GdprCompliance = Convert.ToUInt64(key.GetValue("GdprCompliance")); + Current.EnableDecryption = Convert.ToBoolean(key.GetValue("EnableDecryption")); stats = Convert.ToBoolean(key.GetValue("Statistics")); @@ -509,6 +517,9 @@ namespace Aaru.Settings }, { "GdprCompliance", Current.GdprCompliance + }, + { + "EnableDecryption", Current.EnableDecryption } }; @@ -582,6 +593,7 @@ namespace Aaru.Settings key.SetValue("SaveReportsGlobally", Current.SaveReportsGlobally); key.SetValue("ShareReports", Current.ShareReports); key.SetValue("GdprCompliance", Current.GdprCompliance); + key.SetValue("EnableDecryption", Current.EnableDecryption); if(Current.Stats != null) { @@ -654,6 +666,7 @@ namespace Aaru.Settings SaveReportsGlobally = true, ShareReports = true, GdprCompliance = 0, + EnableDecryption = true, Stats = new StatsSettings { CommandStats = true, diff --git a/Aaru/Commands/Media/Dump.cs b/Aaru/Commands/Media/Dump.cs index b23df6d03..36c7bd9bc 100644 --- a/Aaru/Commands/Media/Dump.cs +++ b/Aaru/Commands/Media/Dump.cs @@ -317,7 +317,7 @@ namespace Aaru.Commands.Media uint skip, byte speed, bool stopOnError, string format, string subchannel, bool @private, bool fixSubchannelPosition, bool retrySubchannel, bool fixSubchannel, bool fixSubchannelCrc, bool generateSubchannels, bool skipCdiReadyHole, bool eject, - uint maxBlocks, bool useBufferedReads, bool decryption, bool storeEncrypted, + uint maxBlocks, bool useBufferedReads, bool storeEncrypted, bool titleKeys) { MainClass.PrintCopyright(); @@ -658,7 +658,7 @@ namespace Aaru.Commands.Media firstPregap, fixOffset, debug, wantedSubchannel, speed, @private, fixSubchannelPosition, retrySubchannel, fixSubchannel, fixSubchannelCrc, skipCdiReadyHole, errorLog, generateSubchannels, maxBlocks, useBufferedReads, - decryption, storeEncrypted, titleKeys); + storeEncrypted, titleKeys); dumper.UpdateStatus += Progress.UpdateStatus; dumper.ErrorMessage += Progress.ErrorMessage; diff --git a/Aaru/Main.cs b/Aaru/Main.cs index 5885148e6..a8c48f47b 100644 --- a/Aaru/Main.cs +++ b/Aaru/Main.cs @@ -175,13 +175,6 @@ namespace Aaru { Argument = new Argument(() => false) }, - new Option(new[] - { - "--decryption" - }, "Enables the ability to decrypt encrypted data.") - { - Argument = new Argument(() => true) - } }; rootCommand.Description =