示例#1
0
        private static void FindProviders(CMFApplication app)
        {
            Providers[app] = new Dictionary <uint, ICMFProvider>();
            Assembly asm = typeof(ICMFProvider).Assembly;

            AddProviders(asm);
        }
示例#2
0
        public static KeyValuePair <byte[], byte[]> GenerateKeyIV(string name, CMFHeaderCommon header, CMFApplication app)
        {
            if (!Providers.ContainsKey(app))
            {
                FindProviders(app);
            }

            byte[] digest = CreateDigest(name);

            ICMFProvider provider;

            if (Providers[app].ContainsKey(header.BuildVersion))
            {
                TankLib.Helpers.Logger.Info("CASC", $"Using CMF procedure {header.BuildVersion}");
                provider = Providers[app][header.BuildVersion];
            }
            else
            {
                TankLib.Helpers.Logger.Warn("CASC", $"No CMF procedure for build {header.BuildVersion}, trying closest version");
                try {
                    KeyValuePair <uint, ICMFProvider> pair = Providers[app].Where(it => it.Key < header.BuildVersion).OrderByDescending(it => it.Key).First();
                    TankLib.Helpers.Logger.Info("CASC", $"Using CMF procedure {pair.Key}");
                    provider = pair.Value;
                } catch {
                    throw new CryptographicException("Missing CMF generators");
                }
            }

            byte[] key = provider.Key(header, name, digest, 32);
            byte[] iv  = provider.IV(header, name, digest, 16);

            name = Path.GetFileNameWithoutExtension(name);
            TankLib.Helpers.Logger.Debug("CMF", $"{name}: key={string.Join(" ", key.Select(x => x.ToString("X2")))}");
            TankLib.Helpers.Logger.Debug("CMF", $"{name}: iv={string.Join(" ", iv.Select(x => x.ToString("X2")))}");
            return(new KeyValuePair <byte[], byte[]>(key, iv));
        }