Beispiel #1
0
        public override void Execute(object parameter)
        {
            _currentAccount = parameter as TimeServerAccount;
            if (_currentAccount == null)
            {
                return;
            }

            _usedInProfilesList = _profiles.Where(p => p.PdfSettings.Signature.TimeServerAccountId.Equals(_currentAccount.AccountId)).ToList();

            var title = Translation.RemoveTimeServerAccount;

            var messageSb = new StringBuilder();

            messageSb.AppendLine(_currentAccount.AccountInfo);
            messageSb.AppendLine(Translation.SureYouWantToDeleteAccount);

            if (_usedInProfilesList.Count > 0)
            {
                messageSb.AppendLine();
                messageSb.AppendLine(Translation.GetAccountIsUsedInFollowingMessage(_usedInProfilesList.Count));
                messageSb.AppendLine();
                foreach (var profile in _usedInProfilesList)
                {
                    messageSb.AppendLine(profile.Name);
                }
                messageSb.AppendLine();
                messageSb.AppendLine(Translation.GetTimeServerGetsDisabledMessage(_usedInProfilesList.Count));
            }
            var message     = messageSb.ToString();
            var icon        = _usedInProfilesList.Count > 0 ? MessageIcon.Warning : MessageIcon.Question;
            var interaction = new MessageInteraction(message, title, MessageOptions.YesNo, icon);

            _interactionRequest.Raise(interaction, DeleteAccountCallback);
        }
Beispiel #2
0
        public void SetUp()
        {
            _accounts = new Accounts();
            _profile  = new ConversionProfile();

            _existingFtpAccount           = new FtpAccount();
            _existingFtpAccount.AccountId = "ftpAccountID";

            _existingSmtpAccount           = new SmtpAccount();
            _existingSmtpAccount.AccountId = "smtpAccountID";

            _existingHttpAccount           = new HttpAccount();
            _existingHttpAccount.AccountId = "httpAccountID";

            _existingDropboxAccount           = new DropboxAccount();
            _existingDropboxAccount.AccountId = "dropboxAccountID";

            _existingTimeServerAccount           = new TimeServerAccount();
            _existingTimeServerAccount.AccountId = "timeserverAccountID";

            _accounts.FtpAccounts.Add(_existingFtpAccount);
            _accounts.SmtpAccounts.Add(_existingSmtpAccount);
            _accounts.HttpAccounts.Add(_existingHttpAccount);
            _accounts.DropboxAccounts.Add(_existingDropboxAccount);
            _accounts.TimeServerAccounts.Add(_existingTimeServerAccount);
        }
        public void SetUp()
        {
            var bootstrapper = new IntegrationTestBootstrapper();
            var container    = bootstrapper.ConfigureContainer();

            //override PasswordProvider, because tests write to job.passwords directly and the provider would replace those values with empty strings from the profile
            container.Options.AllowOverridingRegistrations = true;
            RegisterPdfProcessor(container);

            _pdfProcessor = container.GetInstance <IPdfProcessor>();

            _th = container.GetInstance <TestHelper>();
            _th.InitTempFolder("PdfProcessing PerformanceTest");

            var timeServerAccount = new TimeServerAccount();

            timeServerAccount.AccountId = "TestTimerserverID";
            var accounts = new Accounts();

            accounts.TimeServerAccounts.Add(timeServerAccount);
            _th.SetAccounts(accounts);

            _th.Profile.PdfSettings.Signature.TimeServerAccountId = timeServerAccount.AccountId;

            _th.Profile.PdfSettings.Signature.CertificateFile = _th.GenerateTestFile(TestFile.CertificationFileP12);
            _th.Profile.BackgroundPage.File = _th.GenerateTestFile(TestFile.Background3PagesPDF);
        }
Beispiel #4
0
        private void GenerateGsJob_WithSettedOutput(TestFile tf)
        {
            _th.GenerateGsJob_WithSetOutput(tf);

            var accounts          = new Accounts();
            var timeServerAccount = new TimeServerAccount();

            timeServerAccount.AccountId = "ExistingTimerServerAccountId";
            accounts.TimeServerAccounts.Add(timeServerAccount);
            _th.Job.Accounts = accounts;
            _th.Job.Profile.PdfSettings.Signature.TimeServerAccountId = timeServerAccount.AccountId;

            _th.Job.Profile.BackgroundPage.File = _th.GenerateTestFile(TestFile.Background3PagesPDF);
            _th.Job.Profile.PdfSettings.Signature.CertificateFile = _th.GenerateTestFile(TestFile.CertificationFileP12);

            _th.Job.Passwords.PdfUserPassword      = "******";
            _th.Job.Passwords.PdfOwnerPassword     = "******";
            _th.Job.Passwords.PdfSignaturePassword = "******";

            //Settings of the previously created outputfile
            _th.Job.JobInfo.Metadata.Title    = "Test Title";
            _th.Job.JobInfo.Metadata.Subject  = "Test Subject";
            _th.Job.JobInfo.Metadata.Keywords = "Test Keywords";
            _th.Job.JobInfo.Metadata.Author   = "Test Author";
        }
 private void AssertTimeServersAreEqual(TimeServerAccount first, TimeServerAccount second)
 {
     Assert.AreEqual(first.IsSecured, second.IsSecured);
     Assert.AreEqual(first.UserName, second.UserName);
     Assert.AreEqual(first.Password, second.Password);
     Assert.AreEqual(first.Url, second.Url);
 }
        public void EditAccount_AccountsViewIsSorted()
        {
            var account1 = new TimeServerAccount()
            {
                Url = "1"
            };
            var editAccount = new TimeServerAccount()
            {
                Url = "0"
            };                                                       //for editing
            var account3 = new TimeServerAccount()
            {
                Url = "3"
            };

            _timeServerAccounts.Add(account3);
            _timeServerAccounts.Add(editAccount);
            _timeServerAccounts.Add(account1);
            _timeServerEditCommand.Execute(Arg.Do <object>(o =>
            {
                var editAccountAsParameter = o as TimeServerAccount;
                editAccountAsParameter.Url = "2";
            }));

            _viewModel.EditTimeServerAccountCommand.Execute(editAccount);

            _viewModel.TimeServerAccountsView.MoveCurrentToPosition(0);
            Assert.AreSame(account1, _viewModel.TimeServerAccountsView.CurrentItem);
            _viewModel.TimeServerAccountsView.MoveCurrentToPosition(1);
            Assert.AreSame(editAccount, _viewModel.TimeServerAccountsView.CurrentItem);
            _viewModel.TimeServerAccountsView.MoveCurrentToPosition(2);
            Assert.AreSame(account3, _viewModel.TimeServerAccountsView.CurrentItem);
        }
        public void AddAccount_AccountsListisSorted()
        {
            var account1 = new TimeServerAccount()
            {
                Url = "1"
            };
            var account2 = new TimeServerAccount()
            {
                Url = "2"
            };
            var account3 = new TimeServerAccount()
            {
                Url = "3"
            };

            _timeServerAccounts.Add(account3);
            _timeServerAccounts.Add(account1);
            _timeServerAddCommand.Execute(Arg.Do <object>(o => _timeServerAccounts.Add(account2)));

            _viewModel.AddTimeServerAccountCommand.Execute(null);

            _viewModel.TimeServerAccountsView.MoveCurrentToPosition(0);
            Assert.AreSame(account1, _viewModel.TimeServerAccountsView.CurrentItem);
            _viewModel.TimeServerAccountsView.MoveCurrentToPosition(1);
            Assert.AreSame(account2, _viewModel.TimeServerAccountsView.CurrentItem);
            _viewModel.TimeServerAccountsView.MoveCurrentToPosition(2);
            Assert.AreSame(account3, _viewModel.TimeServerAccountsView.CurrentItem);
        }
        public void WithTimeServer_ExtractsTimeserverAccount()
        {
            var account = new TimeServerAccount
            {
                IsSecured = true,
                UserName  = "******",
                Password  = "******",
                Url       = "http://mytimeserver.local",
            };

            var data = CreateV6Storage();

            StoreTimeServerAccount(data, 0, account);

            var upgrader = new CreatorSettingsUpgrader(data);

            upgrader.Upgrade(7);

            var settings = CreateSettings(data);

            Assert.IsNotEmpty(settings.ApplicationSettings.Accounts.TimeServerAccounts);
            Assert.IsNotNull(settings.ConversionProfiles[0].PdfSettings.Signature.TimeServerAccountId);
            Assert.IsNotEmpty(settings.ConversionProfiles[0].PdfSettings.Signature.TimeServerAccountId);

            var storedAccount = settings.ApplicationSettings.Accounts.TimeServerAccounts.First(a => a.Url == account.Url);

            AssertTimeServersAreEqual(account, storedAccount);
        }
        public void WithSameTimeServerTwice_ExtractsSingleTimeserverAccount()
        {
            var account = new TimeServerAccount
            {
                IsSecured = true,
                UserName  = "******",
                Password  = "******",
                Url       = "http://mytimeserver.local",
            };
            var data = CreateV6Storage();

            data.SetValue(@"ConversionProfiles\numClasses", "2");
            StoreTimeServerAccount(data, 0, account);
            StoreTimeServerAccount(data, 1, account);

            var upgrader = new CreatorSettingsUpgrader(data);

            upgrader.Upgrade(7);

            var settings = CreateSettings(data);
            var expectedNumberofProfiles = NumDefaultServers + 1;

            Assert.AreEqual(expectedNumberofProfiles, settings.ApplicationSettings.Accounts.TimeServerAccounts.Count);
            Assert.IsNotNull(settings.ConversionProfiles[0].PdfSettings.Signature.TimeServerAccountId);
            Assert.IsNotEmpty(settings.ConversionProfiles[0].PdfSettings.Signature.TimeServerAccountId);

            Assert.IsNotNull(settings.ConversionProfiles[1].PdfSettings.Signature.TimeServerAccountId);
            Assert.IsNotEmpty(settings.ConversionProfiles[1].PdfSettings.Signature.TimeServerAccountId);
        }
Beispiel #10
0
        private void ApplySignatureSettings()
        {
            _th.Job.Profile.PdfSettings.Signature.Enabled = true;

            _th.Job.Profile.PdfSettings.Signature.CertificateFile = _th.GenerateTestFile(TestFile.CertificationFileP12);
            _th.Job.Passwords.PdfSignaturePassword = "******";

            _th.Job.Profile.PdfSettings.Signature.DisplaySignatureInDocument = true;
            _th.Job.Profile.PdfSettings.Signature.SignaturePage       = SignaturePage.FirstPage;
            _th.Job.Profile.PdfSettings.Signature.SignatureCustomPage = 1;
            _th.Job.Profile.PdfSettings.Signature.LeftX        = 50;
            _th.Job.Profile.PdfSettings.Signature.LeftY        = 50;
            _th.Job.Profile.PdfSettings.Signature.RightX       = 300;
            _th.Job.Profile.PdfSettings.Signature.RightY       = 150;
            _th.Job.Profile.PdfSettings.Signature.SignContact  = "Mr.Test";
            _th.Job.Profile.PdfSettings.Signature.SignLocation = "Testland";
            _th.Job.Profile.PdfSettings.Signature.SignReason   = "The Reason is Testing";

            var timeServerAccount = new TimeServerAccount();

            timeServerAccount.AccountId = "TestAccountId";
            timeServerAccount.Url       = "http://timestamp.digicert.com";
            timeServerAccount.IsSecured = false;
            _th.Job.Accounts.TimeServerAccounts.Add(timeServerAccount);

            _th.Job.Profile.PdfSettings.Signature.TimeServerAccountId = timeServerAccount.AccountId;
        }
 private void StoreTimeServerAccount(Data data, int profileId, TimeServerAccount account)
 {
     data.SetValue(@"ConversionProfiles\numClasses", (profileId + 1).ToString());
     data.SetValue($@"ConversionProfiles\{profileId}\PdfSettings\Signature\Enabled", "True");
     data.SetValue($@"ConversionProfiles\{profileId}\PdfSettings\Signature\TimeServerIsSecured", account.IsSecured.ToString());
     data.SetValue($@"ConversionProfiles\{profileId}\PdfSettings\Signature\TimeServerLoginName", account.UserName);
     data.SetValue($@"ConversionProfiles\{profileId}\PdfSettings\Signature\TimeServerPassword", Data.Encrypt(account.Password));
     data.SetValue($@"ConversionProfiles\{profileId}\PdfSettings\Signature\TimeServerUrl", account.Url);
 }
Beispiel #12
0
        public override void Execute(object parameter)
        {
            var newAccount = new TimeServerAccount();

            newAccount.AccountId = Guid.NewGuid().ToString();

            var interaction = new TimeServerAccountInteraction(newAccount, Translation.AddTimeServerAccount);

            _interactionRequest.Raise(interaction, AddTimeServerAccountCallback);
        }
        protected override void HandleInteractionObjectChanged()
        {
            _timeServerAccount = Interaction.TimeServerAccount;

            RaisePropertyChanged(nameof(Url));
            RaisePropertyChanged(nameof(Username));
            RaisePropertyChanged(nameof(Password));
            RaisePropertyChanged(nameof(IsSecured));
            SaveCommand.RaiseCanExecuteChanged();
        }
Beispiel #14
0
        protected void ExtractTimeServerAccounts(string sourceProfilePath, string targetAccountsPath)
        {
            var accounts = new Dictionary <TimeServerAccount, List <int> >();

            accounts[new TimeServerAccount {
                         Url = "https://freetsa.org/tsr"
                     }] = new List <int>();
            accounts[new TimeServerAccount {
                         Url = "http://timestamp.digicert.com"
                     }] = new List <int>();
            accounts[new TimeServerAccount {
                         Url = "http://timestamp.globalsign.com/scripts/timstamp.dll"
                     }] = new List <int>();

            ForAllProfiles((profilePath, profileIndex) =>
            {
                var path = profilePath + @"PdfSettings\Signature\";
                if (GetBool(Data.GetValue(path + "Enabled")) != true)
                {
                    return;
                }

                var account       = new TimeServerAccount();
                account.IsSecured = GetBool(Data.GetValue(path + "TimeServerIsSecured")) == true;
                account.UserName  = Data.GetValue(path + "TimeServerLoginName");
                account.Password  = Data.Decrypt(Data.GetValue(path + "TimeServerPassword"));
                account.Url       = Data.GetValue(path + "TimeServerUrl");

                var existingAccount = accounts.Keys.FirstOrDefault(a => a.Equals(account));
                if (existingAccount != null)
                {
                    accounts[existingAccount].Add(profileIndex);
                }
                else
                {
                    accounts[account] = new List <int>();
                    accounts[account].Add(profileIndex);
                }
            }, sourceProfilePath);

            for (var i = 0; i < accounts.Count; i++)
            {
                var account = accounts.Keys.ToArray()[i];
                account.AccountId = Guid.NewGuid().ToString();

                account.StoreValues(Data, $@"{targetAccountsPath}\Accounts\TimeServerAccounts\{i}\");

                foreach (var profileId in accounts[account])
                {
                    Data.SetValue($@"{sourceProfilePath}\{profileId}\PdfSettings\Signature\TimeServerAccountId", account.AccountId);
                }
            }
            Data.SetValue($@"{targetAccountsPath}\Accounts\TimeServerAccounts\numClasses", accounts.Keys.Count.ToString());
        }
Beispiel #15
0
        private ITSAClient BuildTimeServerClient(TimeServerAccount timeServerAccount)
        {
            if (string.IsNullOrWhiteSpace(timeServerAccount.Url))
            {
                return(null);
            }

            return(timeServerAccount.IsSecured
                ? new TSAClientBouncyCastle(timeServerAccount.Url, timeServerAccount.UserName, timeServerAccount.Password)
                : new TSAClientBouncyCastle(timeServerAccount.Url));
        }
        private void V7ExtractTimeServerAccounts()
        {
            var accounts = new Dictionary <TimeServerAccount, List <int> >();

            accounts[new TimeServerAccount {
                         Url = "https://freetsa.org/tsr"
                     }] = new List <int>();
            accounts[new TimeServerAccount {
                         Url = "http://timestamp.digicert.com"
                     }] = new List <int>();
            accounts[new TimeServerAccount {
                         Url = "http://timestamp.globalsign.com/scripts/timstamp.dll"
                     }] = new List <int>();

            ForAllProfiles((s, i) =>
            {
                var path = s + @"PdfSettings\Signature\";
                if (GetBool(Data.GetValue(path + "Enabled")) != true)
                {
                    return;
                }

                var account       = new TimeServerAccount();
                account.IsSecured = GetBool(Data.GetValue(path + "TimeServerIsSecured")) == true;
                account.UserName  = Data.GetValue(path + "TimeServerLoginName");
                account.Password  = Data.Decrypt(Data.GetValue(path + "TimeServerPassword"));
                account.Url       = Data.GetValue(path + "TimeServerUrl");

                var existingAccount = accounts.Keys.FirstOrDefault(a => a.Equals(account));
                if (existingAccount != null)
                {
                    accounts[existingAccount].Add(i);
                }
                else
                {
                    accounts[account] = new List <int>();
                    accounts[account].Add(i);
                }
            });

            for (var i = 0; i < accounts.Count; i++)
            {
                var account = accounts.Keys.ToArray()[i];
                account.AccountId = Guid.NewGuid().ToString();

                account.StoreValues(Data, $"ApplicationSettings\\Accounts\\TimeServerAccounts\\{i}\\");

                foreach (var profileId in accounts[account])
                {
                    Data.SetValue($"ConversionProfiles\\{profileId}\\PdfSettings\\Signature\\TimeServerAccountId", account.AccountId);
                }
            }
            Data.SetValue(@"ApplicationSettings\Accounts\TimeServerAccounts\numClasses", accounts.Keys.Count.ToString());
        }
        public void AddAccount_LatestAccountIsCurrentItemInView()
        {
            _timeServerAccounts.Add(new TimeServerAccount());

            var latestAccount = new TimeServerAccount();

            _timeServerAddCommand.Execute(Arg.Do <object>(o => _timeServerAccounts.Add(latestAccount)));

            _viewModel.AddTimeServerAccountCommand.Execute(null);

            Assert.AreSame(latestAccount, _viewModel.TimeServerAccountsView.CurrentItem, "Latest Account is not selected Item");
        }
Beispiel #18
0
        public void GetTimeServerAccount_TimeServerAccountIsNotEmpty_CallGetTimeServerAccountWithEmptyString_ReturnsNull()
        {
            var timeServerAccountWithEmptyId = new TimeServerAccount();

            timeServerAccountWithEmptyId.AccountId = "";
            _accounts.TimeServerAccounts.Add(timeServerAccountWithEmptyId);
            _profile.PdfSettings.Signature.TimeServerAccountId = "";

            var fetchedTimeServerAccount = _accounts.GetTimeServerAccount(_profile);

            Assert.IsNull(fetchedTimeServerAccount);
        }
Beispiel #19
0
        public void ChangeTimeServerAccountsCollection_TriggersRaiseCanExecuteChanged()
        {
            var newAccount = new TimeServerAccount();

            _timeServerAccounts.Add(newAccount);
            var wasRaised = false;

            _timeServerAccountRemoveCommand.CanExecuteChanged += (sender, args) => wasRaised = true;

            _timeServerAccounts.Remove(newAccount);

            Assert.IsTrue(wasRaised);
        }
        public void EditAccount_EditedAccountRemainsCurrentItemInView()
        {
            _timeServerAccounts.Add(new TimeServerAccount());
            var editAccount = new TimeServerAccount();

            _timeServerAccounts.Add(editAccount);
            _viewModel.TimeServerAccountsView.MoveCurrentTo(editAccount);
            _timeServerEditCommand.Execute(Arg.Do <object>(o => editAccount.UserName = "******"));

            _viewModel.EditTimeServerAccountCommand.Execute(null);

            Assert.AreSame(editAccount, _viewModel.TimeServerAccountsView.CurrentItem, "Latest Account is not selected Item");
        }
Beispiel #21
0
        public override void Execute(object parameter)
        {
            _currentAccount = parameter as TimeServerAccount;
            if (_currentAccount == null)
            {
                return;
            }
            if (!TimeServerAccounts.Contains(_currentAccount))
            {
                return;
            }

            var interaction = new TimeServerAccountInteraction(_currentAccount.Copy(), Translation.EditTimeServerAccount);

            _interactionRequest.Raise(interaction, UpdateTimeServerAccountsCallback);
        }
        public void SetUp()
        {
            _interactionRequest = new UnitTestInteractionRequest();
            _translation        = new TimeServerTranslation();
            _profilesProvider   = Substitute.For <ICurrentSettings <ObservableCollection <ConversionProfile> > >();
            _timeServerAccounts = new ObservableCollection <TimeServerAccount>();

            _usedAccount           = new TimeServerAccount();
            _usedAccount.AccountId = nameof(_usedAccount);
            _usedAccount.UserName  = "******";
            _usedAccount.Url       = "Url1";
            _timeServerAccounts.Add(_usedAccount);

            _unusedAccount           = new TimeServerAccount();
            _unusedAccount.AccountId = nameof(_unusedAccount);
            _unusedAccount.UserName  = "******";
            _unusedAccount.Url       = "Url2";
            _timeServerAccounts.Add(_unusedAccount);

            _profiles = new ObservableCollection <ConversionProfile>();

            _profileWithTimeServerAccountEnabled      = new ConversionProfile();
            _profileWithTimeServerAccountEnabled.Name = nameof(_profileWithTimeServerAccountEnabled);
            _profileWithTimeServerAccountEnabled.PdfSettings.Signature.Enabled             = true;
            _profileWithTimeServerAccountEnabled.PdfSettings.Signature.TimeServerAccountId = _usedAccount.AccountId;
            _profiles.Add(_profileWithTimeServerAccountEnabled);

            _profileWithTimeServerAccountDisabled      = new ConversionProfile();
            _profileWithTimeServerAccountDisabled.Name = nameof(_profileWithTimeServerAccountDisabled);
            _profileWithTimeServerAccountDisabled.PdfSettings.Signature.Enabled             = false;
            _profileWithTimeServerAccountDisabled.PdfSettings.Signature.TimeServerAccountId = _usedAccount.AccountId;
            _profiles.Add(_profileWithTimeServerAccountDisabled);

            var settings = new PdfCreatorSettings();

            settings.ApplicationSettings.Accounts.TimeServerAccounts = _timeServerAccounts;
            settings.ConversionProfiles = _profiles;

            _accountsProvider = Substitute.For <ICurrentSettings <Accounts> >();
            _accountsProvider.Settings.Returns(settings.ApplicationSettings.Accounts);
            _profilesProvider.Settings.Returns(_profiles);

            var translationUpdater = new TranslationUpdater(new TranslationFactory(), new ThreadManager());

            _timeServerAccountRemoveCommand = new TimeServerAccountRemoveCommand(_interactionRequest, _profilesProvider, _accountsProvider, translationUpdater);
        }
        public void SetUp()
        {
            var translationUpdater = new TranslationUpdater(new TranslationFactory(null), new ThreadManager());

            _timeServerAccount = new TimeServerAccount
            {
                AccountId = new Guid().ToString(),
                Url       = "www.randometimeserver.org",
                UserName  = "******",
                Password  = "******",
                IsSecured = true
            };

            _timeServerAccountInteraction = new TimeServerAccountInteraction(_timeServerAccount, "TimeServerAccountTestTitle");

            _viewModel = new TimeServerAccountViewModel(translationUpdater);
        }
Beispiel #24
0
        public void SetUp()
        {
            PdfProcessor = BuildPdfProcessor();

            var bootstrapper = new IntegrationTestBootstrapper();
            var container    = bootstrapper.ConfigureContainer();

            _accounts          = new Accounts();
            _timeServerAccount = new TimeServerAccount();
            _accounts.TimeServerAccounts.Add(_timeServerAccount);

            TestHelper = container.GetInstance <TestHelper>();
            TestHelper.InitTempFolder($"PDFProcessing_{PdfProcessor.GetType().Name}_Signing");

            TestHelper.GenerateGsJob_WithSetOutput(TestFile.ThreePDFCreatorTestpagesPDF);
            TestHelper.Job.Profile.PdfSettings.Signature.AllowMultiSigning = true;

            ApplySignatureSettings();
        }
Beispiel #25
0
        public void SetUp()
        {
            _interactionRequest       = new UnitTestInteractionRequest();
            _translation              = new TimeServerTranslation();
            _currentTimeServerAccount = new TimeServerAccount {
                UserName = "******"
            };

            _timeServerAccounts = new ObservableCollection <TimeServerAccount>();
            _timeServerAccounts.Add(_currentTimeServerAccount);

            var settings = new PdfCreatorSettings();

            settings.ApplicationSettings.Accounts.TimeServerAccounts = _timeServerAccounts;
            _accountsProvider = Substitute.For <ICurrentSettings <Accounts> >();
            _accountsProvider.Settings.Returns(settings.ApplicationSettings.Accounts);

            var translationUpdater = new TranslationUpdater(new TranslationFactory(), new ThreadManager());

            _timeServerAccountEditCommand = new TimeServerAccountEditCommand(_interactionRequest, _accountsProvider, translationUpdater);
        }
        public void WithTwoTimeServers_ExtractsBothTimeserverAccount()
        {
            var firstAccount = new TimeServerAccount
            {
                IsSecured = true,
                UserName  = "******",
                Password  = "******",
                Url       = "http://mytimeserver1.local",
            };
            var secondAccount = new TimeServerAccount
            {
                IsSecured = true,
                UserName  = "******",
                Password  = "******",
                Url       = "http://mytimeserver2.local",
            };

            var data = CreateV6Storage();

            data.SetValue(@"ConversionProfiles\numClasses", "2");
            StoreTimeServerAccount(data, 0, firstAccount);
            StoreTimeServerAccount(data, 1, secondAccount);

            var upgrader = new CreatorSettingsUpgrader(data);

            upgrader.Upgrade(7);

            var settings = CreateSettings(data);
            var expectedNumberofProfiles = NumDefaultServers + 2;

            Assert.AreEqual(expectedNumberofProfiles, settings.ApplicationSettings.Accounts.TimeServerAccounts.Count);
            Assert.IsNotNull(settings.ConversionProfiles[0].PdfSettings.Signature.TimeServerAccountId);
            Assert.IsNotEmpty(settings.ConversionProfiles[0].PdfSettings.Signature.TimeServerAccountId);

            Assert.IsNotNull(settings.ConversionProfiles[1].PdfSettings.Signature.TimeServerAccountId);
            Assert.IsNotEmpty(settings.ConversionProfiles[1].PdfSettings.Signature.TimeServerAccountId);

            AssertTimeServersAreEqual(firstAccount, settings.ApplicationSettings.Accounts.TimeServerAccounts.First(a => a.Url == firstAccount.Url));
            AssertTimeServersAreEqual(secondAccount, settings.ApplicationSettings.Accounts.TimeServerAccounts.First(a => a.Url == secondAccount.Url));
        }
        public void SetUp()
        {
            _profile         = new ConversionProfile();
            _file            = Substitute.For <IFile>();
            _actionCheckList = new List <ICheckable>();
            _actionCheckList.Add(Substitute.For <ICheckable>());
            _actionCheckList.Add(Substitute.For <ICheckable>());
            _actionCheckList.Add(Substitute.For <ICheckable>());

            _accounts                    = new Accounts();
            _timeServerAccount           = new TimeServerAccount();
            _timeServerAccount.AccountId = "TimeServerTestId";
            _profile.PdfSettings.Signature.TimeServerAccountId = _timeServerAccount.AccountId;
            _accounts.TimeServerAccounts.Add(_timeServerAccount);

            for (var i = 0; i < _actionCheckList.Count; i++)
            {
                _actionCheckList[i].Check(_profile, _accounts).Returns(new ActionResult());
            }

            _profileChecker = new ProfileChecker(_file, _actionCheckList);
        }
Beispiel #28
0
        private void DoSignPdfFile(PdfStamper stamper, Signature signing, JobPasswords jobPasswords, TimeServerAccount timeServerAccount)
        {
            Pkcs12Store store            = GetCertificateStore(signing.CertificateFile, jobPasswords.PdfSignaturePassword);
            var         certificateAlias = GetCertificateAlias(store);
            var         pk = GetPrivateKey(store, certificateAlias);

            var appearance = BuildSignatureAppearance(stamper, signing);

            // Creating the signature
            IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA512);
            var chain      = GetCertificateChain(store, certificateAlias);
            var ocspClient = BuildOcspClient();
            var tsaClient  = BuildTimeServerClient(timeServerAccount);

            var cryptoStandard = CryptoStandard.CADES;

            MakeSignature.SignDetached(appearance, pks, chain, null, ocspClient, tsaClient, 0, cryptoStandard);
        }
Beispiel #29
0
        private void DoSignPdfFile(PdfStamper stamper, Signature signing, JobPasswords jobPasswords, TimeServerAccount timeServerAccount)
        {
            var    fsCert = new FileStream(signing.CertificateFile, FileMode.Open, FileAccess.Read);
            var    ks     = new Pkcs12Store(fsCert, jobPasswords.PdfSignaturePassword.ToCharArray());
            string alias  = null;

            foreach (string al in ks.Aliases)
            {
                if (ks.IsKeyEntry(al) && ks.GetKey(al).Key.IsPrivate)
                {
                    alias = al;
                    break;
                }
            }
            fsCert.Close();
            ICipherParameters pk = ks.GetKey(alias).Key;
            var x     = ks.GetCertificateChain(alias);
            var chain = new X509Certificate[x.Length];

            for (var k = 0; k < x.Length; ++k)
            {
                chain[k] = x[k].Certificate;
            }

            ITSAClient tsc = null;

            if (!string.IsNullOrWhiteSpace(timeServerAccount.Url))
            {
                if (!timeServerAccount.IsSecured)
                {
                    tsc = new TSAClientBouncyCastle(timeServerAccount.Url);
                }
                else
                {
                    tsc = new TSAClientBouncyCastle(timeServerAccount.Url, timeServerAccount.UserName, timeServerAccount.Password);
                }
            }

            var psa = stamper.SignatureAppearance;

            if (tsc == null)
            {
                psa.SetCrypto(pk, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
            }
            else
            {
                psa.SetCrypto(null, chain, null, PdfSignatureAppearance.SELF_SIGNED);
            }

            if (!signing.AllowMultiSigning)
            {
                //Lock PDF, except for form filling (irrelevant for PDFCreator)
                psa.CertificationLevel = PdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS;
            }

            psa.Reason   = signing.SignReason;
            psa.Contact  = signing.SignContact;
            psa.Location = signing.SignLocation;

            if (signing.DisplaySignatureInDocument)
            {
                var signPage = SignPageNr(stamper, signing);

                psa.SetVisibleSignature(new Rectangle(signing.LeftX, signing.LeftY, signing.RightX, signing.RightY),
                                        signPage, null);
            }

            var dic = new PdfSignature(PdfName.ADOBE_PPKLITE, new PdfName("adbe.pkcs7.detached"));

            dic.Reason           = psa.Reason;
            dic.Location         = psa.Location;
            dic.Contact          = psa.Contact;
            dic.Date             = new PdfDate(psa.SignDate);
            psa.CryptoDictionary = dic;

            const int contentEstimated = 15000;
            // Preallocate excluded byte-range for the signature content (hex encoded)
            var exc = new Dictionary <PdfName, int>();

            exc[PdfName.CONTENTS] = contentEstimated * 2 + 2;
            psa.PreClose(exc);
            const string hashAlgorithm = "SHA1"; //Always use HashAlgorithm "SHA1"
            var          sgn           = new PdfPKCS7(pk, chain, null, hashAlgorithm, false);
            var          messageDigest = DigestUtilities.GetDigest(hashAlgorithm);
            var          data          = psa.GetRangeStream();
            var          buf           = new byte[8192];
            int          n;

            while ((n = data.Read(buf, 0, buf.Length)) > 0)
            {
                messageDigest.BlockUpdate(buf, 0, n);
            }
            var hash = new byte[messageDigest.GetDigestSize()];

            messageDigest.DoFinal(hash, 0);
            byte[] ocsp = null;
            if (chain.Length >= 2)
            {
                var url = PdfPKCS7.GetOCSPURL(chain[0]);
                if (!string.IsNullOrEmpty(url))
                {
                    ocsp = new OcspClientBouncyCastle().GetEncoded(chain[0], chain[1], url);
                }
            }
            var cal = psa.SignDate;
            var sh  = sgn.GetAuthenticatedAttributeBytes(hash, cal, ocsp);

            sgn.Update(sh, 0, sh.Length);

            var paddedSig = new byte[contentEstimated];

            if (tsc != null)
            {
                byte[] encodedSigTsa = null;
                try
                {
                    encodedSigTsa = sgn.GetEncodedPKCS7(hash, cal, tsc, ocsp);
                    Array.Copy(encodedSigTsa, 0, paddedSig, 0, encodedSigTsa.Length);
                }
                catch (Exception ex)
                {
                    throw new ProcessingException(
                              ex.GetType() + " while connecting to timeserver (can't connect to timeserver): " + ex.Message, ErrorCode.Signature_NoTimeServerConnection);
                }
                if (contentEstimated + 2 < encodedSigTsa.Length)
                {
                    throw new ProcessingException(
                              "Not enough space for signature", ErrorCode.Signature_NotEnoughSpaceForSignature);
                }
            }
            else
            {
                var encodedSig = sgn.GetEncodedPKCS7(hash, cal);
                Array.Copy(encodedSig, 0, paddedSig, 0, encodedSig.Length);
                if (contentEstimated + 2 < encodedSig.Length)
                {
                    throw new ProcessingException("Not enough space for signature", ErrorCode.Signature_ProfileCheck_NotEnoughSpaceForSignature);
                }
            }

            var dic2 = new PdfDictionary();

            dic2.Put(PdfName.CONTENTS, new PdfString(paddedSig).SetHexWriting(true));
            psa.Close(dic2);
        }
Beispiel #30
0
        private bool DoSignPdfFile(Secure pdf, ConversionProfile profile, X509Certificate2 certificate, TimeServerAccount timeServerAccount)
        {
            var signatureSettings = profile.PdfSettings.Signature;

            if (!certificate.HasPrivateKey)
            {
                _logger.Error("Canceled signing. The certificate '" + signatureSettings.CertificateFile + "' has no private key.");
                throw new ProcessingException(
                          "Canceled signing. The certificate '" + signatureSettings.CertificateFile + "' has no private key.", ErrorCode.Signature_NoPrivateKey);
            }

            using (var signature = new Pdftools.PdfSecure.Signature())
            {
                signature.Provider             = ""; //"Microsoft Base Cryptographic Provider v1.0;123456";
                signature.Name                 = certificate.GetNameInfo(X509NameType.SimpleName, false);
                signature.Store                = "MY";
                signature.StoreLocation        = 1; // 0 = Local Machine; 1 = Current User
                signature.SignerFingerprintStr = certificate.Thumbprint;

                signature.ContactInfo = signatureSettings.SignContact;
                signature.Location    = signatureSettings.SignLocation;
                signature.Reason      = signatureSettings.SignReason;

                signature.PageNo = GetSignaturePageNumber(signatureSettings);
                signature.Rect   = GetSignatureRect(signatureSettings);

                var timeServerUri = new UriBuilder(timeServerAccount.Url);

                if (timeServerAccount.IsSecured)
                {
                    timeServerUri.UserName = Uri.EscapeDataString(timeServerAccount.UserName);
                    timeServerUri.Password = Uri.EscapeDataString(timeServerAccount.Password);
                }

                signature.TimeStampURL = timeServerUri.ToString();

                signature.FillColor   = 16777215; //White
                signature.StrokeColor = 13158600; //Grey

                if (!signatureSettings.AllowMultiSigning &&
                    profile.OutputFormat != OutputFormat.PdfA1B)
                {
                    return(pdf.AddDocMDPSignature(signature, 1));
                }

                return(pdf.AddSignature(signature));
            }
        }