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}'"); }
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}'"); }
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}'"); }
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 }
/// <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}'"); }