Ejemplo n.º 1
0
        public static async Task Main(string[] args)
        {
            var webHost = CreateWebHostBuilder(args).Build();

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                //await Task.Run(() => NGDP.LoadAllIndexes());
                //Console.WriteLine("Loaded indexes");

                var keys = await KeyService.LoadKeys();

                Console.WriteLine("Loaded " + keys.Count + " keys");
            }

            await webHost.RunAsync();
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                NGDP.LoadAllIndexes();
            }

            KeyService.LoadKeys();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseResponseCompression();

            app.UseCors("AllowSpecificOrigin");

            app.UseMvc();
        }
Ejemplo n.º 3
0
        private static byte[] Decrypt(byte[] data, int index)
        {
            byte keyNameSize = data[1];

            if (keyNameSize == 0 || keyNameSize != 8)
            {
                throw new Exception("keyNameSize == 0 || keyNameSize != 8");
            }

            byte[] keyNameBytes = new byte[keyNameSize];
            Array.Copy(data, 2, keyNameBytes, 0, keyNameSize);

            ulong keyName = BitConverter.ToUInt64(keyNameBytes, 0);

            byte IVSize = data[keyNameSize + 2];

            if (IVSize != 4 || IVSize > 0x10)
            {
                throw new Exception("IVSize != 4 || IVSize > 0x10");
            }

            byte[] IVpart = new byte[IVSize];
            Array.Copy(data, keyNameSize + 3, IVpart, 0, IVSize);

            if (data.Length < IVSize + keyNameSize + 4)
            {
                throw new Exception("data.Length < IVSize + keyNameSize + 4");
            }

            int dataOffset = keyNameSize + IVSize + 3;

            byte encType = data[dataOffset];

            if (encType != 'S' && encType != 'A') // 'S' or 'A'
            {
                throw new Exception("encType != ENCRYPTION_SALSA20 && encType != ENCRYPTION_ARC4");
            }

            dataOffset++;

            // expand to 8 bytes
            byte[] IV = new byte[8];
            Array.Copy(IVpart, IV, IVpart.Length);

            // magic
            for (int shift = 0, i = 0; i < sizeof(int); shift += 8, i++)
            {
                IV[i] ^= (byte)((index >> shift) & 0xFF);
            }

            byte[] key = KeyService.GetKey(keyName);

            if (key == null)
            {
                throw new KeyNotFoundException("Unknown keyname " + keyName.ToString("X16"));
            }

            if (encType == 'S')
            {
                ICryptoTransform decryptor = KeyService.SalsaInstance.CreateDecryptor(key, IV);

                return(decryptor.TransformFinalBlock(data, dataOffset, data.Length - dataOffset));
            }
            else
            {
                // ARC4 ?
                throw new Exception("encType ENCRYPTION_ARC4 not implemented");
            }
        }