示例#1
0
        public void LoadCertificate(string filename)
        {
            cf = new CertificateFormatter(filename);

            genericFont   = detailsTextBox.Font;
            monospaceFont = new Font(FontFamily.GenericMonospace, 10);

            issuedToTextBox.Text = cf.Subject(false);
            toolTip.SetToolTip(issuedToTextBox, issuedToTextBox.Text);

            subjectAltNameLinkLabel.Text    = cf.SubjectAltName(false);
            subjectAltNameLinkLabel.Visible = (subjectAltNameLinkLabel.Text != String.Empty);

            issuedByTextBox.Text = cf.Issuer(false);
            toolTip.SetToolTip(issuedByTextBox, issuedByTextBox.Text);

            notBeforeLabel.Text = cf.Certificate.ValidFrom.ToString("yyyy-MM-dd");
            notAfterLabel.Text  = cf.Certificate.ValidUntil.ToString("yyyy-MM-dd");

            if (cf.Certificate.Version == 1)
            {
                // not in certificate so it's a property
                itemVersion           = new ListViewItem(CertificateFormatter.FieldNames.Version, 0);
                itemVersion.ForeColor = Color.Blue;
            }
            else
            {
                itemVersion = new ListViewItem(CertificateFormatter.FieldNames.Version, 2);
            }
            itemVersion.SubItems.Add(cf.Version(false));
            itemVersion.SubItems.Add(cf.Version(true));

            itemSerial = new ListViewItem(CertificateFormatter.FieldNames.SerialNumber, 1);
            itemSerial.SubItems.Add(cf.SerialNumber(false));
            itemSerial.SubItems.Add(cf.SerialNumber(true));
            itemSerial.Tag = monospaceFont;

            itemSignatureAlgorithm = new ListViewItem(CertificateFormatter.FieldNames.SignatureAlgorithm, 1);
            itemSignatureAlgorithm.SubItems.Add(cf.SignatureAlgorithm(false));
            itemSignatureAlgorithm.SubItems.Add(cf.SignatureAlgorithm(true));

            itemIssuer = new ListViewItem(CertificateFormatter.FieldNames.Issuer, 1);
            itemIssuer.SubItems.Add(cf.Issuer(false));
            itemIssuer.SubItems.Add(cf.Issuer(true));

            itemValidFrom = new ListViewItem(CertificateFormatter.FieldNames.ValidFrom, 1);
            itemValidFrom.SubItems.Add(cf.ValidFrom(false));
            itemValidFrom.SubItems.Add(cf.ValidFrom(true));

            itemValidUntil = new ListViewItem(CertificateFormatter.FieldNames.ValidUntil, 1);
            itemValidUntil.SubItems.Add(cf.ValidUntil(false));
            itemValidUntil.SubItems.Add(cf.ValidUntil(true));

            itemSubject = new ListViewItem(CertificateFormatter.FieldNames.Subject, 1);
            itemSubject.SubItems.Add(cf.Subject(false));
            itemSubject.SubItems.Add(cf.Subject(true));

            itemPublicKey = new ListViewItem(CertificateFormatter.FieldNames.PublicKey, 1);
            itemPublicKey.SubItems.Add(cf.PublicKey(false));
            itemPublicKey.SubItems.Add(cf.PublicKey(true));
            itemPublicKey.Tag = monospaceFont;

            itemExtensions = new ListViewItem [cf.Certificate.Extensions.Count];
            for (int i = 0; i < cf.Certificate.Extensions.Count; i++)
            {
                X509Extension xe       = cf.GetExtension(i);
                int           critical = (xe.Critical ? 4 : 3);
                string        name     = xe.Name;
                object        tag      = null;
                if (name == xe.Oid)
                {
                    tag = monospaceFont;
                }
                ListViewItem lvi = new ListViewItem(name, critical);
                lvi.Tag = tag;
                if (critical == 4)
                {
                    lvi.ForeColor = Color.Red;
                }
                string exts = xe.ToString();
                if (xe.Name == xe.Oid)
                {
                    lvi.SubItems.Add(cf.Extension(i, false));
                }
                else
                {
                    lvi.SubItems.Add(CertificateFormatter.OneLine(exts));
                }
                lvi.SubItems.Add(exts);
                itemExtensions [i] = lvi;
            }

            // properties (calculated)
            itemThumbprintAlgorithm = new ListViewItem(CertificateFormatter.PropertyNames.ThumbprintAlgorithm, 0);
            itemThumbprintAlgorithm.SubItems.Add(cf.ThumbprintAlgorithm);
            itemThumbprintAlgorithm.SubItems.Add(cf.ThumbprintAlgorithm);
            itemThumbprintAlgorithm.ForeColor = Color.Blue;

            itemThumbprint = new ListViewItem(CertificateFormatter.PropertyNames.Thumbprint, 0);
            string tb = CertificateFormatter.Array2Word(cf.Thumbprint);

            itemThumbprint.SubItems.Add(tb);
            itemThumbprint.SubItems.Add(tb);
            itemThumbprint.Tag       = monospaceFont;
            itemThumbprint.ForeColor = Color.Blue;

            showComboBox.SelectedIndex = 0;

            if (cf.Status != null)
            {
                badPictureBox.Visible       = true;
                keyUsageRichTextBox.Visible = false;
                certificateLabel.Text       = cf.Status;
                certificateLabel.ForeColor  = Color.Red;
                certStatusTextBox.Text      = cf.Status;
                certStatusTextBox.ForeColor = Color.Red;
            }
            else
            {
                badPictureBox.Visible = false;
            }
            goodPictureBox.Visible = !badPictureBox.Visible;

            keyUsageRichTextBox.SelectionBullet = true;
            keyUsageRichTextBox.Text            = "No restrictions";
        }
示例#2
0
文件: gcertview.cs 项目: nobled/mono
		public GtkCertificateViewer (string filename) 
		{
			Application.Init();

			Glade.XML gxml = new Glade.XML (null, "certview.glade", "CertificateViewer", null);
			gxml.Autoconnect (this);

			cf = new CertificateFormatter (filename);

			// init UI
			brokenSealImage.Pixbuf = new Pixbuf (null, "wax-seal-broken.png");
			sealImage.Pixbuf = new Pixbuf (null, "wax-seal.png");

			Tooltips tt = new Tooltips ();
			issuedToEntry.Text = cf.Issuer (false);
			tt.SetTip (issuedToEntry, issuedToEntry.Text, issuedToEntry.Text);
			issuedByEntry.Text = cf.Subject (false);
			tt.SetTip (issuedByEntry, issuedByEntry.Text, issuedByEntry.Text);

			subjectAltNameLabel.Text = cf.SubjectAltName (false);
			subjectAltNameLabel.Visible = (subjectAltNameLabel.Text != null);

			notBeforeEntry.Text = cf.Certificate.ValidFrom.ToString ("yyyy-MM-dd");
			notAfterEntry.Text = cf.Certificate.ValidUntil.ToString ("yyyy-MM-dd");

			TextBuffer tb = new TextBuffer (null);
			if (cf.Status != null)
				tb.SetText (cf.Status);
			certStatusTextview.Buffer = tb;
			if (cf.Status != null) {
				certInfoTextview.Buffer = tb;
				certInfoTextview.ModifyText (StateType.Normal, new Gdk.Color (0xff, 0x00, 0x00));
			}

			sealImage.Visible = (cf.Status == null);
			brokenSealImage.Visible = !sealImage.Visible;

			Type[] storeType = new Type [4] { typeof (string), typeof (string), typeof (string), typeof (int) };
			allStore = new ListStore (storeType);
			v1Store = new ListStore (storeType);
			extensionsStore = new ListStore (storeType);
			criticalStore = new ListStore (storeType);
			propertiesStore = new ListStore (storeType);
			emptyStore = new ListStore (storeType);

			AddToStores (CertificateFormatter.FieldNames.Version, cf.Version (false), cf.Version (true), 1);
			AddToStores (CertificateFormatter.FieldNames.SerialNumber, cf.SerialNumber (false), cf.SerialNumber (true), 0);
			AddToStores (CertificateFormatter.FieldNames.SignatureAlgorithm, cf.SignatureAlgorithm (false), cf.SignatureAlgorithm (true), 0);
			AddToStores (CertificateFormatter.FieldNames.Issuer, cf.Issuer (false), cf.Issuer (true), 0);
			AddToStores (CertificateFormatter.FieldNames.ValidFrom, cf.ValidFrom (false), cf.ValidFrom (true), 0);
			AddToStores (CertificateFormatter.FieldNames.ValidUntil, cf.ValidUntil (false), cf.ValidUntil (true), 0);
			AddToStores (CertificateFormatter.FieldNames.Subject, cf.Subject (false), cf.Subject (true), 0);
			AddToStores (CertificateFormatter.FieldNames.PublicKey, cf.PublicKey (false), cf.PublicKey (true), 0);
			for (int i=0; i < cf.Certificate.Extensions.Count; i++) {
				X509Extension xe = cf.GetExtension (i);
				string name = xe.Name;
				int icon = 2;
				if (xe.Critical)
					icon = 3;
				string exts = xe.ToString ();
				string details;
				if (xe.Name == xe.Oid) {
					exts = cf.Extension (i, false);
					details = cf.Extension (i, true);
				}
				else {
					details = xe.ToString ();
					exts = CertificateFormatter.OneLine (details);
				}

				AddToStores (name, exts, details, icon);
			}
			AddToStores (CertificateFormatter.PropertyNames.ThumbprintAlgorithm, cf.ThumbprintAlgorithm, cf.ThumbprintAlgorithm, 4);
			string ftb = CertificateFormatter.Array2Word (cf.Thumbprint);
			AddToStores (CertificateFormatter.PropertyNames.Thumbprint, ftb, ftb, 4);

			// select appropriate store to show
			OnShowComboChanged (null, null);

			TreeViewColumn fieldColumn = new TreeViewColumn ();
			CellRendererPixbuf pr = new CellRendererPixbuf ();
			CellRenderer fieldRenderer = new CellRendererText ();
			fieldColumn.PackStart (pr, false);
			fieldColumn.SetCellDataFunc (pr, CellDataFunc, IntPtr.Zero, null);
			fieldColumn.Title = "Field";
			fieldColumn.PackStart (fieldRenderer, false);
			fieldColumn.AddAttribute (fieldRenderer, "text", 0);
			detailsTreeview.AppendColumn (fieldColumn);

			TreeViewColumn valueColumn = new TreeViewColumn ();
			CellRenderer valueRenderer = new CellRendererText ();
			valueColumn.Title = "Value";
			valueColumn.PackStart (valueRenderer, true);
			valueColumn.AddAttribute (valueRenderer, "text", 1);
			detailsTreeview.AppendColumn (valueColumn);

//			detailsTreeview.ModifyText (StateType.Selected, new Gdk.Color (0x33, 0xff, 0x33));

			Application.Run();
		}
示例#3
0
		public void LoadCertificate (string filename) 
		{
			cf = new CertificateFormatter (filename);

			genericFont = detailsTextBox.Font;
			monospaceFont = new Font (FontFamily.GenericMonospace, 10);

			issuedToTextBox.Text = cf.Subject (false);
			toolTip.SetToolTip (issuedToTextBox, issuedToTextBox.Text);

			subjectAltNameLinkLabel.Text = cf.SubjectAltName (false);
			subjectAltNameLinkLabel.Visible = (subjectAltNameLinkLabel.Text != String.Empty);

			issuedByTextBox.Text = cf.Issuer (false);
			toolTip.SetToolTip (issuedByTextBox, issuedByTextBox.Text);

			notBeforeLabel.Text = cf.Certificate.ValidFrom.ToString ("yyyy-MM-dd");
			notAfterLabel.Text = cf.Certificate.ValidUntil.ToString ("yyyy-MM-dd");

			if (cf.Certificate.Version == 1) {
				// not in certificate so it's a property
				itemVersion = new ListViewItem (CertificateFormatter.FieldNames.Version, 0);
				itemVersion.ForeColor = Color.Blue;
			}
			else
				itemVersion = new ListViewItem (CertificateFormatter.FieldNames.Version, 2);
			itemVersion.SubItems.Add (cf.Version (false));
			itemVersion.SubItems.Add (cf.Version (true));

			itemSerial = new ListViewItem (CertificateFormatter.FieldNames.SerialNumber, 1);
			itemSerial.SubItems.Add (cf.SerialNumber (false));
			itemSerial.SubItems.Add (cf.SerialNumber (true));
			itemSerial.Tag = monospaceFont;

			itemSignatureAlgorithm = new ListViewItem (CertificateFormatter.FieldNames.SignatureAlgorithm, 1);
			itemSignatureAlgorithm.SubItems.Add (cf.SignatureAlgorithm (false));
			itemSignatureAlgorithm.SubItems.Add (cf.SignatureAlgorithm (true));

			itemIssuer = new ListViewItem (CertificateFormatter.FieldNames.Issuer, 1);
			itemIssuer.SubItems.Add (cf.Issuer (false));
			itemIssuer.SubItems.Add (cf.Issuer (true));

			itemValidFrom = new ListViewItem (CertificateFormatter.FieldNames.ValidFrom, 1);
			itemValidFrom.SubItems.Add (cf.ValidFrom (false));
			itemValidFrom.SubItems.Add (cf.ValidFrom (true));

			itemValidUntil = new ListViewItem (CertificateFormatter.FieldNames.ValidUntil,1);
			itemValidUntil.SubItems.Add (cf.ValidUntil (false));
			itemValidUntil.SubItems.Add (cf.ValidUntil (true));

			itemSubject = new ListViewItem (CertificateFormatter.FieldNames.Subject, 1);
			itemSubject.SubItems.Add (cf.Subject (false));
			itemSubject.SubItems.Add (cf.Subject (true));

			itemPublicKey = new ListViewItem (CertificateFormatter.FieldNames.PublicKey, 1);
			itemPublicKey.SubItems.Add (cf.PublicKey (false));
			itemPublicKey.SubItems.Add (cf.PublicKey (true));
			itemPublicKey.Tag = monospaceFont;

			itemExtensions = new ListViewItem [cf.Certificate.Extensions.Count];
			for (int i=0; i < cf.Certificate.Extensions.Count; i++) {
				X509Extension xe = cf.GetExtension (i);
				int critical = (xe.Critical ? 4 : 3);
				string name = xe.Name;
				object tag = null;
				if (name == xe.Oid)
					tag = monospaceFont;
				ListViewItem lvi = new ListViewItem (name, critical);
				lvi.Tag = tag;
				if (critical == 4)
					lvi.ForeColor = Color.Red;
				string exts = xe.ToString ();
				if (xe.Name == xe.Oid)
					lvi.SubItems.Add (cf.Extension (i, false));
				else 
					lvi.SubItems.Add (CertificateFormatter.OneLine (exts));
				lvi.SubItems.Add (exts);
				itemExtensions [i] = lvi;
			}

			// properties (calculated)
			itemThumbprintAlgorithm = new ListViewItem (CertificateFormatter.PropertyNames.ThumbprintAlgorithm, 0);
			itemThumbprintAlgorithm.SubItems.Add (cf.ThumbprintAlgorithm);
			itemThumbprintAlgorithm.SubItems.Add (cf.ThumbprintAlgorithm);
			itemThumbprintAlgorithm.ForeColor = Color.Blue;

			itemThumbprint = new ListViewItem (CertificateFormatter.PropertyNames.Thumbprint, 0);
			string tb = CertificateFormatter.Array2Word (cf.Thumbprint);
			itemThumbprint.SubItems.Add (tb);
			itemThumbprint.SubItems.Add (tb);
			itemThumbprint.Tag = monospaceFont;
			itemThumbprint.ForeColor = Color.Blue;

			showComboBox.SelectedIndex = 0;

			if (cf.Status != null) {
				badPictureBox.Visible = true;
				keyUsageRichTextBox.Visible = false;
				certificateLabel.Text = cf.Status;
				certificateLabel.ForeColor = Color.Red;
				certStatusTextBox.Text = cf.Status;
				certStatusTextBox.ForeColor = Color.Red;
			}
			else
				badPictureBox.Visible = false;
			goodPictureBox.Visible = !badPictureBox.Visible;

			keyUsageRichTextBox.SelectionBullet = true;
			keyUsageRichTextBox.Text = "No restrictions";
		}
示例#4
0
        public GtkCertificateViewer(string filename)
        {
            Application.Init();

            Glade.XML gxml = new Glade.XML(null, "certview.glade", "CertificateViewer", null);
            gxml.Autoconnect(this);

            cf = new CertificateFormatter(filename);

            // init UI
            brokenSealImage.Pixbuf = new Pixbuf(null, "wax-seal-broken.png");
            sealImage.Pixbuf       = new Pixbuf(null, "wax-seal.png");

            Tooltips tt = new Tooltips();

            issuedToEntry.Text = cf.Issuer(false);
            tt.SetTip(issuedToEntry, issuedToEntry.Text, issuedToEntry.Text);
            issuedByEntry.Text = cf.Subject(false);
            tt.SetTip(issuedByEntry, issuedByEntry.Text, issuedByEntry.Text);

            subjectAltNameLabel.Text    = cf.SubjectAltName(false);
            subjectAltNameLabel.Visible = (subjectAltNameLabel.Text != null);

            notBeforeEntry.Text = cf.Certificate.ValidFrom.ToString("yyyy-MM-dd");
            notAfterEntry.Text  = cf.Certificate.ValidUntil.ToString("yyyy-MM-dd");

            TextBuffer tb = new TextBuffer(null);

            if (cf.Status != null)
            {
                tb.SetText(cf.Status);
            }
            certStatusTextview.Buffer = tb;
            if (cf.Status != null)
            {
                certInfoTextview.Buffer = tb;
                certInfoTextview.ModifyText(StateType.Normal, new Gdk.Color(0xff, 0x00, 0x00));
            }

            sealImage.Visible       = (cf.Status == null);
            brokenSealImage.Visible = !sealImage.Visible;

            Type[] storeType = new Type [4] {
                typeof(string), typeof(string), typeof(string), typeof(int)
            };
            allStore        = new ListStore(storeType);
            v1Store         = new ListStore(storeType);
            extensionsStore = new ListStore(storeType);
            criticalStore   = new ListStore(storeType);
            propertiesStore = new ListStore(storeType);
            emptyStore      = new ListStore(storeType);

            AddToStores(CertificateFormatter.FieldNames.Version, cf.Version(false), cf.Version(true), 1);
            AddToStores(CertificateFormatter.FieldNames.SerialNumber, cf.SerialNumber(false), cf.SerialNumber(true), 0);
            AddToStores(CertificateFormatter.FieldNames.SignatureAlgorithm, cf.SignatureAlgorithm(false), cf.SignatureAlgorithm(true), 0);
            AddToStores(CertificateFormatter.FieldNames.Issuer, cf.Issuer(false), cf.Issuer(true), 0);
            AddToStores(CertificateFormatter.FieldNames.ValidFrom, cf.ValidFrom(false), cf.ValidFrom(true), 0);
            AddToStores(CertificateFormatter.FieldNames.ValidUntil, cf.ValidUntil(false), cf.ValidUntil(true), 0);
            AddToStores(CertificateFormatter.FieldNames.Subject, cf.Subject(false), cf.Subject(true), 0);
            AddToStores(CertificateFormatter.FieldNames.PublicKey, cf.PublicKey(false), cf.PublicKey(true), 0);
            for (int i = 0; i < cf.Certificate.Extensions.Count; i++)
            {
                X509Extension xe   = cf.GetExtension(i);
                string        name = xe.Name;
                int           icon = 2;
                if (xe.Critical)
                {
                    icon = 3;
                }
                string exts = xe.ToString();
                string details;
                if (xe.Name == xe.Oid)
                {
                    exts    = cf.Extension(i, false);
                    details = cf.Extension(i, true);
                }
                else
                {
                    details = xe.ToString();
                    exts    = CertificateFormatter.OneLine(details);
                }

                AddToStores(name, exts, details, icon);
            }
            AddToStores(CertificateFormatter.PropertyNames.ThumbprintAlgorithm, cf.ThumbprintAlgorithm, cf.ThumbprintAlgorithm, 4);
            string ftb = CertificateFormatter.Array2Word(cf.Thumbprint);

            AddToStores(CertificateFormatter.PropertyNames.Thumbprint, ftb, ftb, 4);

            // select appropriate store to show
            OnShowComboChanged(null, null);

            TreeViewColumn     fieldColumn   = new TreeViewColumn();
            CellRendererPixbuf pr            = new CellRendererPixbuf();
            CellRenderer       fieldRenderer = new CellRendererText();

            fieldColumn.PackStart(pr, false);
            fieldColumn.SetCellDataFunc(pr, CellDataFunc, IntPtr.Zero, null);
            fieldColumn.Title = "Field";
            fieldColumn.PackStart(fieldRenderer, false);
            fieldColumn.AddAttribute(fieldRenderer, "text", 0);
            detailsTreeview.AppendColumn(fieldColumn);

            TreeViewColumn valueColumn   = new TreeViewColumn();
            CellRenderer   valueRenderer = new CellRendererText();

            valueColumn.Title = "Value";
            valueColumn.PackStart(valueRenderer, true);
            valueColumn.AddAttribute(valueRenderer, "text", 1);
            detailsTreeview.AppendColumn(valueColumn);

//			detailsTreeview.ModifyText (StateType.Selected, new Gdk.Color (0x33, 0xff, 0x33));

            Application.Run();
        }