/// <summary> /// Получение списка личных сертификатов /// </summary> /// <returns></returns> public ActionResult GetMyCertificates() { Guid token = CheckSessionAuthState(CurrentUser, _authService); if (token == Guid.Empty) { return(Json(new { status = "Error", errorCode = "401", errorMessage = "" }, JsonRequestBehavior.AllowGet)); } //bool isActiveCur = isActive ?? false; var model = new List <CertificateInfoContactAdd>(); CertificatesResponse response = _cryptxService.GetMyCertificates(Guid.Empty, token); if (response.Exception == null) { foreach (CertificateInfo certificateInfo in response.Certificates) { var curCert = new CertificateInfoContactAdd(); curCert.CertificateId = certificateInfo.CertificateId; curCert.SubjectName = certificateInfo.SubjectName; curCert.IssureName = certificateInfo.IssureName; curCert.Thumbprint = certificateInfo.Thumbprint; curCert.Organization = certificateInfo.Organization; curCert.IsTest = certificateInfo.IsTest; if (DateTime.Now < certificateInfo.NotBefore) { curCert.TimeMessage = "Недействителен до " + certificateInfo.NotBefore.Date.ToShortDateString().Replace("/", "."); } if (DateTime.Now > certificateInfo.NotBefore && DateTime.Now < certificateInfo.NotAfter) { curCert.TimeMessage = "Действителен до " + certificateInfo.NotAfter.Date.ToShortDateString().Replace("/", "."); } else { curCert.TimeMessage = "Недействителен с " + certificateInfo.NotAfter.Date.ToShortDateString().Replace("/", "."); } model.Add(curCert); } } else { return(Json(new { status = "Error", errorCode = "", errorMessage = response.Exception.Message }, JsonRequestBehavior.AllowGet)); } return(Json(new { model, status = "ok" }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Обрабатываем все файлы(загрузка и из ссылки) /// </summary> /// <param name="files"></param> /// <param name="_cryptxService"></param> /// <param name="token"></param> /// <returns></returns> public static DecryptCertificateResult GetDecryptCertificates(List <DownloadedFile> files, CryptxServiceClient _cryptxService, Guid token) { var result = new DecryptCertificateResult(); List <CertificateInfo> prevCertlist = null; var prevDownloadedFiles = new List <DownloadedFile>(); foreach (DownloadedFile downloadedFile in files) { CertificatesResponse response = _cryptxService.DAVGetDecryptCertificates(downloadedFile.Uri, token); if (response.Exception != null) { downloadedFile.Exception = new Exception("Ошибка при нахождении доступных сертификатов для расшифровки", response.Exception); //throw new Exception("Ошибка при нахождении доступных сертификатов для расшифровки",response.Exception); downloadedFile.Exception = response.Exception; if (prevCertlist == null) { prevCertlist = new List <CertificateInfo>(); } prevDownloadedFiles.Add(downloadedFile); } else { List <CertificateInfo> myCertifcatesInFile = response.Certificates.Where(x => x.MyCertificate != null).ToList(); downloadedFile.DecryptCertificatesNames = myCertifcatesInFile.Select(x => x.SubjectName).ToList(); downloadedFile.DecryptCertificatesThumbprints = myCertifcatesInFile.Select(x => x.Thumbprint).ToList(); prevDownloadedFiles.Add(downloadedFile); if (prevCertlist == null) { prevCertlist = myCertifcatesInFile; } else { prevCertlist = prevCertlist.Union(myCertifcatesInFile, new CertificateInfoEqualityComparer()).ToList(); } } } result.CertificateInfos = prevCertlist; result.DownloadedFiles = prevDownloadedFiles; return(result); }
public AddressBookModel(CertificatesResponse data) { Certificates = new Certificates(); Certificates.UserCertificates = new List <ContactCertificateRelationship>(); foreach (CertificateInfo certificateInfo in data.Certificates) { var relationship = new ContactCertificateRelationship(); relationship.CertificateInfo = certificateInfo; relationship.CertificateID = certificateInfo.CertificateId; relationship.FriendlyName = certificateInfo.RecipientCertificate.FriendlyName; Certificates.UserCertificates.Add(relationship); } Certificates.Filter = CertificateFilter.Active; }
public ActionResult MyCertificates(Guid?userId) { Guid token = CheckSessionAuthState(CurrentUser, _authService); if (token == Guid.Empty) { return(RedirectToAction("LogOff", "Account")); } CertificatesResponse response = _cryptxService.GetMyCertificates((userId == null ? Guid.Empty : (Guid)userId), token); if (response.Exception != null) { throw response.Exception; } var model = new List <CertificateInfoContactAdd>(); foreach (CertificateInfo certificateInfo in response.Certificates) { var curCert = new CertificateInfoContactAdd(); curCert.CertificateId = certificateInfo.CertificateId; curCert.SubjectName = certificateInfo.SubjectName; curCert.IssureName = certificateInfo.IssureName; curCert.Thumbprint = certificateInfo.Thumbprint; curCert.Organization = certificateInfo.Organization; curCert.IsTest = certificateInfo.IsTest; if (DateTime.Now < certificateInfo.NotBefore) { curCert.TimeMessage = "Недействителен до " + certificateInfo.NotBefore.Date.ToShortDateString().Replace("/", "."); } if (DateTime.Now > certificateInfo.NotBefore && DateTime.Now < certificateInfo.NotAfter) { curCert.TimeMessage = "Действителен до " + certificateInfo.NotAfter.Date.ToShortDateString().Replace("/", "."); } else { curCert.TimeMessage = "Недействителен с " + certificateInfo.NotAfter.Date.ToShortDateString().Replace("/", "."); } model.Add(curCert); } return(View(model)); }
public ActionResult CertificateList(Guid?userId) { string status = ""; Guid token = CheckSessionAuthState(CurrentUser, _authService); AddressBookModel model; if (token == Guid.Empty) { status = "logoff"; model = new AddressBookModel(); model.Status = status; return(View(model)); //return RedirectToAction("LogOff", "Account"); } try { CertificatesResponse response = _cryptxService.GetUserCertificates("", CertificateSort.FriendlyNameASC, CertificateFilter.Active, (userId == null ? Guid.Empty : (Guid)userId), token, 0); model = new AddressBookModel(response); } catch (Exception exception) { throw; } var navigation = new MyNavigation(); if (userId != null && userId != Guid.Empty) { navigation.Navigations.Add(new NavElement { Depth = 1, Name = "Администрирование", Action = "Index", Controller = "Administration", IsUrl = true }); UserInfoResponse responseUser = _authService.GetUserDataByID((Guid)userId); navigation.Navigations.Add(new NavElement { Depth = 3, Name = responseUser.User.Name, IsUrl = false }); navigation.Navigations.Add(new NavElement { Depth = 4, Name = "Список сертификатов", IsUrl = false }); } else { navigation.Navigations.Add(new NavElement { Depth = 1, Name = "Адресная книга", Action = "Index", Controller = "AddressBook", IsUrl = false }); } navigation.Navigations = navigation.Navigations.OrderBy(x => x.Depth).ToList(); ViewBag.nav = Helper.HtmlNavElement(navigation, Request.RequestContext); ViewBag.UserId = (userId == null ? Guid.Empty : (Guid)userId); model.Status = status; return(View(model)); }
public ActionResult CertificateList(Certificates certificates, string que, string save, string deletingCerts, string toContactList, Guid?userId) { var js = new JavaScriptSerializer(); var delCerts = (List <string>)js.Deserialize(deletingCerts, typeof(List <string>)); string status = ""; Guid token = CheckSessionAuthState(CurrentUser, _authService); AddressBookModel model; if (token == Guid.Empty) { status = "logoff"; model = new AddressBookModel(); model.Status = status; return(View(model)); } //удаление сертов if (delCerts != null && delCerts.Count > 0 && que == null) { foreach (string delCert in delCerts) { _cryptxService.DeleteRecipientRelation(delCert, (userId == null ? Guid.Empty : (Guid)userId), token); } } try { CertificatesResponse response = _cryptxService.GetUserCertificates(certificates.SearchString, certificates.Sort, certificates.Filter, (userId == null ? Guid.Empty : (Guid)userId), token, 0); model = new AddressBookModel(response); } catch (Exception exception) { model = new AddressBookModel(); status = "logoff"; } var navigation = new MyNavigation(); if (userId != null && userId != Guid.Empty) { navigation.Navigations.Add(new NavElement { Depth = 1, Name = "Администрирование", Action = "Index", Controller = "Administration", IsUrl = true }); UserInfoResponse responseUser = _authService.GetUserDataByID((Guid)userId); navigation.Navigations.Add(new NavElement { Depth = 3, Name = responseUser.User.Name, IsUrl = false }); navigation.Navigations.Add(new NavElement { Depth = 4, Name = "Список сертификатов", IsUrl = false }); } else { navigation.Navigations.Add(new NavElement { Depth = 1, Name = "Адресная книга", Action = "Index", Controller = "AddressBook", IsUrl = false }); } navigation.Navigations = navigation.Navigations.OrderBy(x => x.Depth).ToList(); ViewBag.nav = Helper.HtmlNavElement(navigation, Request.RequestContext); model.Status = status; ViewBag.UserId = (userId == null ? Guid.Empty : (Guid)userId); return(View(model)); }