static void CheckExpiringCertificates() { var certUtils = new CertificateUtils { DaysBeforeEnd = DaysToExpire }; X509Certificate2Collection expiringCerts = certUtils.Check(); if (expiringCerts.Count == 0) return; var popupNotifier = Helper.PopupFactory(); ContextMenuStrip ContextMenu = new System.Windows.Forms.ContextMenuStrip(new System.ComponentModel.Container()); ContextMenu.Items.AddRange( new System.Windows.Forms.ToolStripItem[] { new System.Windows.Forms.ToolStripMenuItem("Details", Properties.Resources.details, (o, e)=> X509Certificate2UI.SelectFromCollection(expiringCerts, "Expiring certificates", "Selecting certificate will do nothing.", X509SelectionFlag.MultiSelection, handle)) }); popupNotifier.OptionsMenu = ContextMenu; popupNotifier.TitleText = "Some certificates are going to expire!"; popupNotifier.ContentText = String.Format("{0} certificates are going to expire in less than {1} days", expiringCerts.Count, DaysToExpire); popupNotifier.Popup(); }
static void CheckEncryptionCerts() { var certUtils = new CertificateUtils(); var myself = UserPrincipal.Current; DateTime notAfterDefault = new DateTime(1900, 1, 1); if (myself.Certificates.Count > 0) { var lastADCert = myself.Certificates.FindLast(); notAfterDefault = lastADCert.NotAfter; } var localEncryptionCerts = certUtils.GetEncryptionCerts(notAfterDefault); if (localEncryptionCerts.Count == 0) return; var popupNotifier = Helper.PopupFactory(); ContextMenuStrip ContextMenu = new System.Windows.Forms.ContextMenuStrip(new System.ComponentModel.Container()); ContextMenu.Items.AddRange( new System.Windows.Forms.ToolStripItem[] { new System.Windows.Forms.ToolStripMenuItem("Details", Properties.Resources.details, (o, e)=> { var certs = X509Certificate2UI.SelectFromCollection(localEncryptionCerts, "Certificates mising in AD", "Select encryption certificate(s) to add to AD.", X509SelectionFlag.MultiSelection, handle); if (certs.Count > 0) { myself.Certificates.AddRange(localEncryptionCerts); myself.Save(); } }) }); popupNotifier.OptionsMenu = ContextMenu; popupNotifier.TitleText = "Some certificates are not in AD!"; popupNotifier.ContentText = String.Format("{0} certificates are not in AD. People may not be able to send you encrypted mail.", localEncryptionCerts.Count); popupNotifier.Popup(); }