Ejemplo n.º 1
0
        public void DbxDownloadCommand(Context ctx)
        {
            var uuid = ctx.QueryUUID;

            Authenticate.Authenticate(ctx, AuthenticateType.Password);
            EncryptResponse(ctx);

            string dbxName = $"{ctx.Userprofile.Path}/dbx/{uuid}.dbx";

            if (!File.Exists(dbxName))
            {
                throw new FileNotFoundException($"Database '{uuid}' not found");
            }

            var data = File.ReadAllBytes(dbxName);

            var response = new ResponseMessage();

            response.Header["data"] = "OK";
            response.Header["md5"]  = Hash.MD5(data);
            ctx.Channel.WriteObject(response);
            ctx.Channel.Write(data);

            Logger.Info($"IP:{ctx.ClientIP} Download dbx '{uuid}' for user '{ctx.Username}'");
        }
Ejemplo n.º 2
0
        public void DbxUploadCommand(Context ctx)
        {
            var uuid         = ctx.QueryUUID;
            var md5          = ctx.QueryParam("md5");
            var lastModified = ctx.QueryDateTimeParam("last-modified");

            Authenticate.Authenticate(ctx, AuthenticateType.Password);
            EncryptResponse(ctx);

            var data = ctx.Channel.Read();

            if (Hash.MD5(data) != md5)
            {
                throw new BadRequestException("Bad MD5");
            }

            string dbxName = $"{ctx.Userprofile.Path}/dbx/{uuid}.dbx";

            if (File.Exists(dbxName))
            {
                FileCreateBackup(dbxName);
            }

            if (!Directory.Exists($"{ctx.Userprofile.Path}/dbx"))
            {
                Directory.CreateDirectory($"{ctx.Userprofile.Path}/dbx");
            }

            //Logger.Info($"Db LastModified: {lastModified}");

            File.WriteAllBytes(dbxName, data);
            var dbxInfo1 = new FileInfo(dbxName);

            dbxInfo1.CreationTime   = lastModified;
            dbxInfo1.LastWriteTime  = lastModified;
            dbxInfo1.LastAccessTime = lastModified;

            var response = new ResponseMessage();

            response.Header["data"] = "OK";
            ctx.Channel.WriteObject(response);

            Logger.Info($"IP:{ctx.ClientIP} Upload dbx '{uuid}' for user '{ctx.Username}'");
        }
Ejemplo n.º 3
0
        public void DbxSetKeyCommand(Context ctx)
        {
            var uuid  = ctx.QueryUUID;
            var value = ctx.QueryParam("value");

            Authenticate.Authenticate(ctx, AuthenticateType.OneTimeToken);
            EncryptResponse(ctx);

            var vault = new ConfigFile($"{ctx.Userprofile.Path}/vault.conf");

            vault.SetValue(uuid, value);
            vault.Export($"{ctx.Userprofile.Path}/vault.conf");

            var response = new ResponseMessage();

            response.Header["data"] = "OK";
            ctx.Channel.WriteObject(response);
            Logger.Info($"IP:{ctx.ClientIP} Set new Dbx key '{uuid}' for user '{ctx.Username}'");
        }
Ejemplo n.º 4
0
        public void DbxGetKeyCommand(Context ctx)
        {
            var uuid = ctx.QueryUUID;

            Authenticate.Authenticate(ctx, AuthenticateType.OneTimeToken);
            EncryptResponse(ctx);

            var vaultConf = new ConfigFile($"{ctx.Userprofile.Path}/vault.conf");
            var value     = vaultConf.GetValue(uuid, () => throw new BadRequestException("VaultKey not Found"));

            var response = new ResponseMessage();

            response.Header["data"] = value;
            ctx.Channel.WriteObject(response);
            Logger.Info($"IP:{ctx.ClientIP} requested key '{uuid}' for user '{ctx.Username}'");

            #pragma warning disable 4014
            if (!IsHomeNetwork(ctx.ClientIP))
            {
                Notification.SendAsync(ctx, NotificationType.GrantAccess);
            }
            #pragma warning restore 4014
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ctx"></param>
        public void DbxGetLastModifiedCommand(Context ctx)
        {
            var uuid = ctx.QueryUUID;

            Authenticate.Authenticate(ctx, AuthenticateType.Password);
            EncryptResponse(ctx);

            string dbxName = $"{ctx.Userprofile.Path}/dbx/{uuid}.dbx";

            if (!File.Exists(dbxName))
            {
                throw new FileNotFoundException($"Database '{uuid}' not found");
            }

            var dbxInfo = new FileInfo(dbxName);

            var response = new ResponseMessage();

            response.Header["data"] = dbxInfo.LastWriteTimeUtc.ToString("u");
            ctx.Channel.WriteObject(response);

            Logger.Info($"IP:{ctx.ClientIP} GetLastModified() for dbx '{uuid}' for user '{ctx.Username}'");
        }