public ActionResult DevEditPost(DevEditViewModel editVm) { var repo = new Repository(); var original = GetDevEditViewModel(editVm.Id); original.Message = editVm.Message; var asc = new WebClient().DownloadData(repo.GetASCLink(editVm.Id)); string extracted; if(!CryptoHelper.VerifySig(asc, editVm.Message, out extracted)) { ModelState.AddModelError("Message", "Incorrectly signed"); } else { byte[] hash = null; using(SHA256 sha = new SHA256Managed()) { hash = sha.ComputeHash(Encoding.UTF8.GetBytes(extracted)); } if(repo.SaveHash(hash)) { repo.UpdateDevViewModel(original); return RedirectToAction("Dev", "Main", new { devId = editVm.Id }); } else { ModelState.AddModelError("Message", "You can't replay an old message"); } } return View("DevEdit", original); }
private static DevEditViewModel GetDevEditViewModel(string devId) { var repo = new Repository(); var vm = repo.GetDevViewModel(devId); var editVm = new DevEditViewModel(); editVm.Id = vm.Id; editVm.FriendlyName = vm.FriendlyName; editVm.MessageLink = vm.MessageLink; editVm.ASCLink = vm.ASCLink; if(vm.Message != null) editVm.Message = repo.GetSig(editVm.Id); editVm.SignatureSample = repo.GetSigLink("zsample"); editVm.ResultSample = "/Opinion/zsample"; return editVm; }
public void UpdateDevViewModel(DevEditViewModel dev) { var bytes = Encoding.UTF8.GetBytes(dev.Message); var sigBlob = GetSigBlob(dev.Id); //hashBlob.Properties.ContentEncoding = "text/html; charset=UTF-8"; sigBlob.UploadFromByteArray(bytes, 0, bytes.Length); }