Exemplo n.º 1
0
 private void MassSignDialog_Load(object sender, EventArgs e)
 {
     comboBoxSecretKey.Items.Add("");
     foreach (var secretKey in OpenPgp.Signing().ListSecretKeys())
     {
         comboBoxSecretKey.Items.Add(secretKey);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a <see cref="Catalog"/> from an XML file and identifies the signature (if any).
        /// </summary>
        /// <param name="path">The file to load from.</param>
        /// <returns>The loaded <see cref="SignedCatalog"/>.</returns>
        /// <exception cref="IOException">A problem occurred while reading the file.</exception>
        /// <exception cref="UnauthorizedAccessException">Read access to the file is not permitted.</exception>
        /// <exception cref="InvalidDataException">A problem occurred while deserializing the XML data.</exception>
        public static SignedCatalog Load(string path)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            #endregion

            var openPgp = OpenPgp.Signing();
            return(new SignedCatalog(XmlStorage.LoadXml <Catalog>(path), FeedUtils.GetKey(path, openPgp), openPgp));
        }
Exemplo 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       = OpenPgp.Signing();
                var signedCatalog = new SignedCatalog(catalog, openPgp.GetSecretKey(_key));

                PromptPassphrase(
                    () => signedCatalog.Save(_catalogFile !, _openPgpPassphrase),
                    signedCatalog.SecretKey);
            }
            else
            {
                catalog.SaveXml(_catalogFile !);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Saves a feed.
        /// </summary>
        /// <exception cref="IOException">A file could not be read or written or the GnuPG could not be launched or the feed file could not be read or written.</exception>
        /// <exception cref="UnauthorizedAccessException">Read or write access to a feed file is not permitted.</exception>
        /// <exception cref="KeyNotFoundException">An OpenPGP key could not be found.</exception>
        private void SaveFeed(FeedEditing feedEditing)
        {
            if (!feedEditing.Path !.EndsWith(".xml.template") &&
                !feedEditing.IsValid(out string problem))
            {
                Log.Warn(problem);
            }

            if (_unsign)
            {
                // Remove any existing signatures
                feedEditing.SignedFeed.SecretKey = null;
            }
            else
            {
                var openPgp = OpenPgp.Signing();
                if (_xmlSign)
                {     // Signing explicitly requested
                    if (feedEditing.SignedFeed.SecretKey == null)
                    { // No previous signature
                        // Use user-specified key or default key
                        feedEditing.SignedFeed.SecretKey = openPgp.GetSecretKey(_key);
                    }
                    else
                    {                                    // Existing signature
                        if (!string.IsNullOrEmpty(_key)) // Use new user-specified key
                        {
                            feedEditing.SignedFeed.SecretKey = openPgp.GetSecretKey(_key);
                        }
                        //else resign implied
                    }
                }
                //else resign implied
            }

            // If no signing or unsigning was explicitly requested and the content did not change
            // there is no need to overwrite (and potential resign) the file
            if (!_xmlSign && !_unsign && !feedEditing.UnsavedChanges)
            {
                return;
            }

            PromptPassphrase(
                () => feedEditing.SignedFeed.Save(feedEditing.Path !, _openPgpPassphrase),
                feedEditing.SignedFeed.SecretKey);
        }
Exemplo n.º 5
0
        [STAThread] // Required for WinForms
        private static void Main(string[] args)
        {
            ProcessUtils.SanitizeEnvironmentVariables();
            NetUtils.ApplyProxy();

            WindowsUtils.SetCurrentProcessAppID("ZeroInstall.Publishing");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ErrorReportForm.SetupMonitoring(new Uri("https://0install.de/error-report/"));

            var openPgp = OpenPgp.Signing();

            if (args.Length == 0)
            {
                Application.Run(new WelcomeForm(openPgp));
            }
            else
            {
                try
                {
                    var files = Paths.ResolveFiles(args, "*.xml");
                    if (files.Count == 1)
                    {
                        string path = files.First().FullName;
                        Application.Run(new MainForm(FeedEditing.Load(path), openPgp));
                    }
                    else
                    {
                        MassSignForm.Show(files);
                    }
                }
                #region Error handling
                catch (Exception ex) when(ex is ArgumentException or IOException or InvalidDataException)
                {
                    Msg.Inform(null, ex.GetMessageWithInner(), MsgSeverity.Warn);
                }
                catch (Exception ex) when(ex is UnauthorizedAccessException)
                {
                    Msg.Inform(null, ex.Message, MsgSeverity.Error);
                }
                #endregion
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new signed catalog.
 /// </summary>
 /// <param name="catalog">The wrapped <see cref="Catalog"/>.</param>
 /// <param name="secretKey">The secret key used to sign the <see cref="Catalog"/>; <c>null</c> for no signature.</param>
 /// <param name="openPgp">The OpenPGP-compatible system used to create the signatures; <c>null</c> for default.</param>
 public SignedCatalog(Catalog catalog, OpenPgpSecretKey?secretKey, IOpenPgp?openPgp = null)
 {
     Catalog   = catalog ?? throw new ArgumentNullException(nameof(catalog));
     SecretKey = secretKey;
     _openPgp  = openPgp ?? OpenPgp.Signing();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new signed feed.
 /// </summary>
 /// <param name="feed">The wrapped <see cref="Feed"/>.</param>
 /// <param name="secretKey">The secret key used to sign the <see cref="Feed"/>; <c>null</c> for no signature.</param>
 /// <param name="openPgp">The OpenPGP-compatible system used to create the signatures; <c>null</c> for default.</param>
 public SignedFeed(Feed feed, OpenPgpSecretKey?secretKey = null, IOpenPgp?openPgp = null)
 {
     Feed      = feed ?? throw new ArgumentNullException(nameof(feed));
     SecretKey = secretKey;
     _openPgp  = openPgp ?? OpenPgp.Signing();
 }