Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <summary>
        ///     инициализация визарда
        /// </summary>
        /// <param name="id"></param>
        /// <param name="cryptxService"></param>
        /// <param name="authService"></param>
        /// <param name="token"></param>
        public WizardModel(Guid id, CryptxServiceClient cryptxService, AuthorizeServiceClient authService, Guid token)
        {
            ProfileSelect            = new ProfileSelect();
            CanBack                  = true;
            CanNext                  = true;
            CanmakeOperation         = false;
            ProfileSelect.UseDefault = false;
            ProfileResponse userDefaultResponse = cryptxService.GetDefaultProfile(token);

            if (userDefaultResponse.Exception == null)
            {
                if (userDefaultResponse.Settings.Id == Guid.Empty)
                {
                    ProfileResponse response = cryptxService.GetBlankProfile();
                    if (response.Exception == null)
                    {
                        ProfileSelect.UseDefault = true;
                        Settings = response.Settings;
                    }
                    else
                    {
                        throw new Exception("Ошибка при получении настроек по умолчанию");
                    }
                }
                else
                {
                    Settings = userDefaultResponse.Settings;
                }
            }
            else
            {
                throw new Exception("Ошибка при получении ваших настроек по умолчанию");
            }
            //зануляем пароли
            Settings._SignatureSettings.KeysetPassword  = "";
            Settings._DecryptionSettings.KeysetPassword = "";

            //Settings = _cryptxService.GetDefaultProfile();// SettingInitializer.InitializeSettings();
            UserInfo = new UserInfoW();
            UserInfoResponse userInfo = authService.GetUserData(token);

            DownloadedFiles        = new List <DownloadedFile>();
            UserInfo.WebDavRootDir = userInfo.WebDavRootDir;
            UserInfo.User          = userInfo.User;
            Id           = id;
            CreationTime = DateTime.Now;
        }
Esempio n. 3
0
        /// <summary>
        ///     запросить пин-код?
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static bool RequestPin(ref WizardModel model, Guid token)
        {
            if (model.SigningOptions.WrongPIN || model.DecryptionOptions.WrongPIN)
            {
                return(true);
            }
            var client = new CryptxServiceClient();

            if (model.Settings.Id == Guid.Empty)
            {
                return(true);
            }
            ProfileResponse profileResponse = client.GetProfile(model.Settings.Id, Guid.Empty, token);

            //произошла ошибка в получении профиля
            //запросим пинкод
            if (profileResponse.Exception != null)
            {
                return(true);
            }

            if (model.Type == OperationType.Decrypt)
            {
                if (model.DecryptionOptions.DecryptCertificate ==
                    profileResponse.Settings._DecryptionSettings.DecryptCertificate &&
                    !string.IsNullOrEmpty(profileResponse.Settings._DecryptionSettings.KeysetPassword))
                {
                    model.Settings._DecryptionSettings.KeysetPassword =
                        profileResponse.Settings._DecryptionSettings.KeysetPassword;
                    return(false);
                }
            }
            if (model.Type == OperationType.Sign)
            {
                if (model.SigningOptions.SignerCertificate1 ==
                    profileResponse.Settings._SignatureSettings.SignerCertificate1 &&
                    !string.IsNullOrEmpty(profileResponse.Settings._SignatureSettings.KeysetPassword))
                {
                    model.Settings._SignatureSettings.KeysetPassword =
                        profileResponse.Settings._SignatureSettings.KeysetPassword;
                    return(false);
                }
            }


            return(true);
        }
Esempio n. 4
0
        public MasterInitModel(Guid token, CryptxServiceClient cryptx, AuthorizeServiceClient authorize, string files,
                               OperationType?type)
        {
            UserInfoResponse curUser = authorize.GetUserData(token);

            ProfileResponse      blankProfileResponse = cryptx.GetBlankProfile();
            UserProfilesResponse response             = cryptx.GetUserProfiles(Guid.Empty, token);

            OperationType    = (type == null) ? 0 : (OperationType)type;
            FilesJSON        = string.IsNullOrEmpty(files) ? "[]" : files;
            BlankProfileJSON = JsonConvert.SerializeObject(blankProfileResponse.Settings, Formatting.Indented);

            if (response.UserProfileList.Count == 0)
            {
                response.UserProfileList.Add(new UserProfileListElement
                {
                    Name = "Стандартные"
                });
            }

            SettingsJSON = JsonConvert.SerializeObject(response.UserProfileList, Formatting.Indented);
            UserInfo     = curUser.User;
        }