public JsonResult Add(IEnumerable <string> targets) { var response = new AddRecipientResponse(); var fileNames = GetFileNamesFromTargets(targets); foreach (var target in targets) { FullPath fullPath = ParsePath(target); service.AddRecipientCertificate(File.ReadAllBytes(fullPath.File.Name), string.Empty, Guid.Empty, token); } }
public ActionResult AddRecipientCertificate(HttpPostedFile file) { Guid token = CheckSessionAuthState(CurrentUser, _authService); if (token == Guid.Empty) { return(Json(new { status = "Error", errorCode = "401", errorMessage = "" }, JsonRequestBehavior.AllowGet)); } Stream tmpStream1 = Request.Files[0].InputStream; var fileBytes = new byte[tmpStream1.Length]; tmpStream1.Read(fileBytes, 0, (int)tmpStream1.Length); AddRecipientResponse response = _cryptxService.AddRecipientCertificate(fileBytes, "", Guid.Empty, token); if (response.Exception != null) { return(Json(new { status = "Error", errorCode = "", errorMessage = response.Exception.Message }, JsonRequestBehavior.AllowGet)); } return(Json(new { status = "ok", response.AddedCertificate }, JsonRequestBehavior.AllowGet)); }
public ActionResult AddRecipientCertificateToUser(Guid?userId) { Guid token = CheckSessionAuthState(CurrentUser, _authService); if (token == Guid.Empty) { return(Json(new { Status = "logoff" })); //return RedirectToAction("LogOff", "Account"); } string fileName = Request.Headers["X-File-Name"]; string fileType = Request.Headers["X-File-Type"]; int fileSize = Convert.ToInt32(Request.Headers["X-File-Size"]); Stream fileContent = Request.InputStream; var buf = new byte[fileSize]; fileContent.Read(buf, 0, fileSize); try { var x509Certificate2 = new X509Certificate2(buf); if (!x509Certificate2.SignatureAlgorithm.FriendlyName.ToLower().Contains("гост")) { return (Json( new { Status = "Файл не соответствует требованиям к сертификатам, используемым в Cryptogramm. Загрузка невозможна." })); } } catch (Exception) { return (Json( new { Status = "Файл не соответствует требованиям к сертификатам, используемым в Cryptogramm. Загрузка невозможна." })); } AddRecipientResponse response = _cryptxService.AddRecipientCertificate(buf, "", (userId == null ? Guid.Empty : (Guid)userId), token); if (response.Exception == null) { string status = ""; if (response.Status == AddRecipientResponse.StatusTypes.CertInDB) { status = "refresh"; } if (response.Status == AddRecipientResponse.StatusTypes.CertAdded) { status = "refresh"; } if (response.Status == AddRecipientResponse.StatusTypes.CertHasRelation) { status = "Выбранный сертификат уже присутствует в списке"; } return(Json(new { Status = status })); } return(Json(new { ErrorMessage = response.Exception.Message })); }