Esempio n. 1
0
        /// <summary>
        /// Saves a catalog.
        /// </summary>
        /// <param name="catalog">The catalog to save.</param>
        /// <exception cref="IOException">A file could not be read or written or the GnuPG could not be launched or the catalog file could not be written.</exception>
        /// <exception cref="UnauthorizedAccessException">Read or write access to a catalog file is not permitted.</exception>
        /// <exception cref="KeyNotFoundException">An OpenPGP key could not be found.</exception>
        private void SaveCatalog(Catalog catalog)
        {
            if (_xmlSign)
            {
                var openPgp       = OpenPgpFactory.CreateDefault();
                var signedCatalog = new SignedCatalog(catalog, openPgp.GetSecretKey(_key));

                while (true)
                {
                    try
                    {
                        signedCatalog.Save(_catalogFile, _openPgpPassphrase);
                        break; // Exit loop if passphrase is correct
                    }
                    catch (WrongPassphraseException ex)
                    {
                        // Continue loop if passhrase is incorrect
                        if (!string.IsNullOrEmpty(_openPgpPassphrase))
                        {
                            Log.Error(ex);
                        }
                    }

                    // Ask for passphrase to unlock secret key if we were unable to save without it
                    _openPgpPassphrase = CliUtils.ReadPassword(string.Format(Resources.AskForPassphrase, signedCatalog.SecretKey));
                }
            }
            else
            {
                catalog.SaveXml(_catalogFile);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Saves a catalog.
        /// </summary>
        /// <param name="catalog">The catalog to save.</param>
        /// <exception cref="IOException">A file could not be read or written or the GnuPG could not be launched or the catalog file could not be written.</exception>
        /// <exception cref="UnauthorizedAccessException">Read or write access to a catalog file is not permitted.</exception>
        /// <exception cref="KeyNotFoundException">An OpenPGP key could not be found.</exception>
        private void SaveCatalog(Catalog catalog)
        {
            if (_xmlSign)
            {
                var openPgp       = OpenPgp.Signing();
                var signedCatalog = new SignedCatalog(catalog, openPgp.GetSecretKey(_key));

                PromptPassphrase(
                    () => signedCatalog.Save(_catalogFile !, _openPgpPassphrase),
                    signedCatalog.SecretKey);
            }
            else
            {
                catalog.SaveXml(_catalogFile !);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Saves a catalog.
        /// </summary>
        /// <param name="catalog">The catalog to save.</param>
        /// <exception cref="IOException">A file could not be read or written or the GnuPG could not be launched or the catalog file could not be written.</exception>
        /// <exception cref="UnauthorizedAccessException">Read or write access to a catalog file is not permitted.</exception>
        /// <exception cref="KeyNotFoundException">An OpenPGP key could not be found.</exception>
        private void SaveCatalog(Catalog catalog)
        {
            if (_xmlSign)
            {
                var openPgp = OpenPgpFactory.CreateDefault();
                var signedCatalog = new SignedCatalog(catalog, openPgp.GetSecretKey(_key));

                while (true)
                {
                    try
                    {
                        signedCatalog.Save(_catalogFile, _openPgpPassphrase);
                        break; // Exit loop if passphrase is correct
                    }
                    catch (WrongPassphraseException ex)
                    {
                        // Continue loop if passhrase is incorrect
                        if (!string.IsNullOrEmpty(_openPgpPassphrase)) Log.Error(ex);
                    }

                    // Ask for passphrase to unlock secret key if we were unable to save without it
                    _openPgpPassphrase = CliUtils.ReadPassword(string.Format(Resources.AskForPassphrase, signedCatalog.SecretKey));
                }
            }
            else catalog.SaveXml(_catalogFile);
        }