1 //
2 // CertificateViewer.cs: Certificate Viewer for System.Windows.Forms
3 //
4 // Author:
5 //	Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9 
10 using System;
11 using System.Drawing;
12 using System.Collections;
13 using System.ComponentModel;
14 using System.IO;
15 using System.Reflection;
16 using System.Text;
17 using System.Windows.Forms;
18 
19 using Mono.Security.X509;
20 
21 [assembly: AssemblyTitle("Mono Certificate Viewer")]
22 [assembly: AssemblyDescription("X.509 Certificate Viewer for SWF")]
23 
24 namespace Mono.Tools.CertView {
25 
26 	public class CertificateViewer : System.Windows.Forms.Form {
27 
28 		private System.Windows.Forms.TabControl tabControl1;
29 		private System.Windows.Forms.TabPage tabPage1;
30 		private System.Windows.Forms.TabPage tabPage2;
31 		private System.Windows.Forms.TabPage tabPage3;
32 		private System.Windows.Forms.Panel panel1;
33 		private System.Windows.Forms.Label label1;
34 		private System.Windows.Forms.Label label2;
35 		private System.Windows.Forms.Label label3;
36 		private System.Windows.Forms.Label label4;
37 		private System.Windows.Forms.Label label6;
38 		private System.Windows.Forms.Label label8;
39 		private System.Windows.Forms.Label label9;
40 		private System.Windows.Forms.Panel panel2;
41 		private System.Windows.Forms.Panel panel3;
42 		private System.Windows.Forms.Button issuerStatementButton;
43 		private System.Windows.Forms.Label privateKeyLabel;
44 		private System.Windows.Forms.RichTextBox keyUsageRichTextBox;
45 		private System.Windows.Forms.Label notAfterLabel;
46 		private System.Windows.Forms.Label notBeforeLabel;
47 		private System.Windows.Forms.ComboBox showComboBox;
48 		private System.Windows.Forms.TextBox detailsTextBox;
49 		private System.Windows.Forms.ListView fieldListView;
50 		private System.Windows.Forms.TextBox certStatusTextBox;
51 		private System.Windows.Forms.TreeView certPathTreeView;
52 		private System.Windows.Forms.Button okButton;
53 		private System.Windows.Forms.Panel panel4;
54 		private System.Windows.Forms.Panel panel5;
55 		private System.Windows.Forms.LinkLabel issuedByLinkLabel;
56 		private System.Windows.Forms.TextBox issuedToTextBox;
57 		private System.Windows.Forms.Label certificateLabel;
58 		private System.Windows.Forms.TextBox issuedByTextBox;
59 		private System.Windows.Forms.ColumnHeader fieldColumnHeader;
60 		private System.Windows.Forms.ColumnHeader valueColumnHeader;
61 		private System.Windows.Forms.ImageList fieldsImageList;
62 		private System.Windows.Forms.HelpProvider helpProvider;
63 		private System.Windows.Forms.ToolTip toolTip;
64 		private System.Windows.Forms.LinkLabel subjectAltNameLinkLabel;
65 		private System.Windows.Forms.ImageList iconImageList;
66 		private System.Windows.Forms.PictureBox goodPictureBox;
67 		private System.Windows.Forms.PictureBox badPictureBox;
68 		private System.ComponentModel.IContainer components;
69 
CertificateViewer(string filename)70 		public CertificateViewer (string filename)
71 		{
72 			//
73 			// Required for Windows Form Designer support
74 			//
75 			InitializeComponent();
76 
77 			//
78 			// TODO: Add any constructor code after InitializeComponent call
79 			//
80 			LoadCertificate (filename);
81 			helpProvider.SetHelpString (issuedToTextBox, CertificateFormatter.Help.IssuedTo);
82 			helpProvider.SetHelpString (issuedByTextBox, CertificateFormatter.Help.IssuedBy);
83 			helpProvider.SetHelpString (notBeforeLabel, CertificateFormatter.Help.ValidFrom);
84 			helpProvider.SetHelpString (notAfterLabel, CertificateFormatter.Help.ValidUntil);
85 		}
86 
87 		/// <summary>
88 		/// Clean up any resources being used.
89 		/// </summary>
Dispose( bool disposing )90 		protected override void Dispose( bool disposing )
91 		{
92 			if( disposing )
93 			{
94 				if (components != null)
95 				{
96 					components.Dispose();
97 				}
98 			}
99 			base.Dispose( disposing );
100 		}
101 
102 		#region Windows Form Designer generated code
103 		/// <summary>
104 		/// Required method for Designer support - do not modify
105 		/// the contents of this method with the code editor.
106 		/// </summary>
InitializeComponent()107 		private void InitializeComponent()
108 		{
109 			this.components = new System.ComponentModel.Container();
110 			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CertificateViewer));
111 			this.tabControl1 = new System.Windows.Forms.TabControl();
112 			this.tabPage1 = new System.Windows.Forms.TabPage();
113 			this.issuerStatementButton = new System.Windows.Forms.Button();
114 			this.panel1 = new System.Windows.Forms.Panel();
115 			this.badPictureBox = new System.Windows.Forms.PictureBox();
116 			this.goodPictureBox = new System.Windows.Forms.PictureBox();
117 			this.label1 = new System.Windows.Forms.Label();
118 			this.subjectAltNameLinkLabel = new System.Windows.Forms.LinkLabel();
119 			this.keyUsageRichTextBox = new System.Windows.Forms.RichTextBox();
120 			this.issuedByTextBox = new System.Windows.Forms.TextBox();
121 			this.issuedToTextBox = new System.Windows.Forms.TextBox();
122 			this.issuedByLinkLabel = new System.Windows.Forms.LinkLabel();
123 			this.panel4 = new System.Windows.Forms.Panel();
124 			this.panel5 = new System.Windows.Forms.Panel();
125 			this.panel2 = new System.Windows.Forms.Panel();
126 			this.panel3 = new System.Windows.Forms.Panel();
127 			this.privateKeyLabel = new System.Windows.Forms.Label();
128 			this.notAfterLabel = new System.Windows.Forms.Label();
129 			this.label6 = new System.Windows.Forms.Label();
130 			this.notBeforeLabel = new System.Windows.Forms.Label();
131 			this.label4 = new System.Windows.Forms.Label();
132 			this.label3 = new System.Windows.Forms.Label();
133 			this.label2 = new System.Windows.Forms.Label();
134 			this.certificateLabel = new System.Windows.Forms.Label();
135 			this.tabPage2 = new System.Windows.Forms.TabPage();
136 			this.label8 = new System.Windows.Forms.Label();
137 			this.showComboBox = new System.Windows.Forms.ComboBox();
138 			this.detailsTextBox = new System.Windows.Forms.TextBox();
139 			this.fieldListView = new System.Windows.Forms.ListView();
140 			this.fieldColumnHeader = new System.Windows.Forms.ColumnHeader();
141 			this.valueColumnHeader = new System.Windows.Forms.ColumnHeader();
142 			this.fieldsImageList = new System.Windows.Forms.ImageList(this.components);
143 			this.tabPage3 = new System.Windows.Forms.TabPage();
144 			this.label9 = new System.Windows.Forms.Label();
145 			this.certStatusTextBox = new System.Windows.Forms.TextBox();
146 			this.certPathTreeView = new System.Windows.Forms.TreeView();
147 			this.okButton = new System.Windows.Forms.Button();
148 			this.toolTip = new System.Windows.Forms.ToolTip(this.components);
149 			this.helpProvider = new System.Windows.Forms.HelpProvider();
150 			this.iconImageList = new System.Windows.Forms.ImageList(this.components);
151 			this.tabControl1.SuspendLayout();
152 			this.tabPage1.SuspendLayout();
153 			this.panel1.SuspendLayout();
154 			this.panel4.SuspendLayout();
155 			this.panel2.SuspendLayout();
156 			this.tabPage2.SuspendLayout();
157 			this.tabPage3.SuspendLayout();
158 			this.SuspendLayout();
159 			//
160 			// tabControl1
161 			//
162 			this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
163 												      this.tabPage1,
164 												      this.tabPage2,
165 												      this.tabPage3});
166 			this.tabControl1.Location = new System.Drawing.Point(8, 8);
167 			this.tabControl1.Name = "tabControl1";
168 			this.tabControl1.SelectedIndex = 0;
169 			this.tabControl1.Size = new System.Drawing.Size(384, 408);
170 			this.tabControl1.TabIndex = 0;
171 			//
172 			// tabPage1
173 			//
174 			this.tabPage1.Controls.AddRange(new System.Windows.Forms.Control[] {
175 												   this.issuerStatementButton,
176 												   this.panel1});
177 			this.tabPage1.Location = new System.Drawing.Point(4, 22);
178 			this.tabPage1.Name = "tabPage1";
179 			this.tabPage1.Size = new System.Drawing.Size(376, 382);
180 			this.tabPage1.TabIndex = 0;
181 			this.tabPage1.Text = "General";
182 			//
183 			// issuerStatementButton
184 			//
185 			this.issuerStatementButton.Enabled = false;
186 			this.issuerStatementButton.Location = new System.Drawing.Point(264, 344);
187 			this.issuerStatementButton.Name = "issuerStatementButton";
188 			this.issuerStatementButton.Size = new System.Drawing.Size(104, 23);
189 			this.issuerStatementButton.TabIndex = 2;
190 			this.issuerStatementButton.Text = "Issuer Statement";
191 			//
192 			// panel1
193 			//
194 			this.panel1.BackColor = System.Drawing.SystemColors.Window;
195 			this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
196 			this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
197 												 this.badPictureBox,
198 												 this.goodPictureBox,
199 												 this.label1,
200 												 this.subjectAltNameLinkLabel,
201 												 this.keyUsageRichTextBox,
202 												 this.issuedByTextBox,
203 												 this.issuedToTextBox,
204 												 this.issuedByLinkLabel,
205 												 this.panel4,
206 												 this.panel2,
207 												 this.privateKeyLabel,
208 												 this.notAfterLabel,
209 												 this.label6,
210 												 this.notBeforeLabel,
211 												 this.label4,
212 												 this.label3,
213 												 this.label2,
214 												 this.certificateLabel});
215 			this.panel1.Location = new System.Drawing.Point(8, 8);
216 			this.panel1.Name = "panel1";
217 			this.panel1.Size = new System.Drawing.Size(360, 328);
218 			this.panel1.TabIndex = 0;
219 			//
220 			// badPictureBox
221 			//
222 			this.badPictureBox.Image = ((System.Drawing.Bitmap)(resources.GetObject("badPictureBox.Image")));
223 			this.badPictureBox.Name = "badPictureBox";
224 			this.badPictureBox.Size = new System.Drawing.Size(64, 64);
225 			this.badPictureBox.TabIndex = 21;
226 			this.badPictureBox.TabStop = false;
227 			//
228 			// goodPictureBox
229 			//
230 			this.goodPictureBox.Image = ((System.Drawing.Bitmap)(resources.GetObject("goodPictureBox.Image")));
231 			this.goodPictureBox.Name = "goodPictureBox";
232 			this.goodPictureBox.Size = new System.Drawing.Size(64, 64);
233 			this.goodPictureBox.TabIndex = 20;
234 			this.goodPictureBox.TabStop = false;
235 			this.goodPictureBox.Visible = false;
236 			//
237 			// label1
238 			//
239 			this.label1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
240 			this.label1.Location = new System.Drawing.Point(64, 8);
241 			this.label1.Name = "label1";
242 			this.label1.Size = new System.Drawing.Size(288, 56);
243 			this.label1.TabIndex = 0;
244 			this.label1.Text = "Certificate Information";
245 			//
246 			// subjectAltNameLinkLabel
247 			//
248 			this.helpProvider.SetHelpString(this.subjectAltNameLinkLabel, "Subject Alternative Name (e.g. email)");
249 			this.subjectAltNameLinkLabel.Location = new System.Drawing.Point(73, 208);
250 			this.subjectAltNameLinkLabel.Name = "subjectAltNameLinkLabel";
251 			this.helpProvider.SetShowHelp(this.subjectAltNameLinkLabel, true);
252 			this.subjectAltNameLinkLabel.Size = new System.Drawing.Size(272, 16);
253 			this.subjectAltNameLinkLabel.TabIndex = 19;
254 			this.subjectAltNameLinkLabel.TabStop = true;
255 			this.subjectAltNameLinkLabel.Text = "mailto:spouliot@motus.com";
256 			this.subjectAltNameLinkLabel.Visible = false;
257 			this.subjectAltNameLinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.subjectAltNameLinkLabel_LinkClicked);
258 			//
259 			// keyUsageRichTextBox
260 			//
261 			this.keyUsageRichTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
262 			this.keyUsageRichTextBox.Location = new System.Drawing.Point(16, 96);
263 			this.keyUsageRichTextBox.Name = "keyUsageRichTextBox";
264 			this.keyUsageRichTextBox.Size = new System.Drawing.Size(328, 88);
265 			this.keyUsageRichTextBox.TabIndex = 9;
266 			this.keyUsageRichTextBox.TabStop = false;
267 			this.keyUsageRichTextBox.Text = "";
268 			//
269 			// issuedByTextBox
270 			//
271 			this.issuedByTextBox.AcceptsReturn = true;
272 			this.issuedByTextBox.BackColor = System.Drawing.SystemColors.Window;
273 			this.issuedByTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
274 			this.issuedByTextBox.Location = new System.Drawing.Point(75, 232);
275 			this.issuedByTextBox.Name = "issuedByTextBox";
276 			this.issuedByTextBox.ReadOnly = true;
277 			this.issuedByTextBox.Size = new System.Drawing.Size(269, 14);
278 			this.issuedByTextBox.TabIndex = 18;
279 			this.issuedByTextBox.TabStop = false;
280 			this.issuedByTextBox.Text = "issued by";
281 			//
282 			// issuedToTextBox
283 			//
284 			this.issuedToTextBox.AcceptsReturn = true;
285 			this.issuedToTextBox.BackColor = System.Drawing.SystemColors.Window;
286 			this.issuedToTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
287 			this.issuedToTextBox.Location = new System.Drawing.Point(75, 192);
288 			this.issuedToTextBox.Name = "issuedToTextBox";
289 			this.issuedToTextBox.ReadOnly = true;
290 			this.issuedToTextBox.Size = new System.Drawing.Size(269, 14);
291 			this.issuedToTextBox.TabIndex = 17;
292 			this.issuedToTextBox.TabStop = false;
293 			this.issuedToTextBox.Text = "issued to";
294 			//
295 			// issuedByLinkLabel
296 			//
297 			this.issuedByLinkLabel.Location = new System.Drawing.Point(72, 248);
298 			this.issuedByLinkLabel.Name = "issuedByLinkLabel";
299 			this.issuedByLinkLabel.Size = new System.Drawing.Size(272, 16);
300 			this.issuedByLinkLabel.TabIndex = 15;
301 			this.issuedByLinkLabel.TabStop = true;
302 			this.issuedByLinkLabel.Text = "http://www.go-mono.com/";
303 			this.issuedByLinkLabel.Visible = false;
304 			//
305 			// panel4
306 			//
307 			this.panel4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
308 			this.panel4.Controls.AddRange(new System.Windows.Forms.Control[] {
309 												 this.panel5});
310 			this.panel4.Location = new System.Drawing.Point(8, 64);
311 			this.panel4.Name = "panel4";
312 			this.panel4.Size = new System.Drawing.Size(336, 1);
313 			this.panel4.TabIndex = 13;
314 			//
315 			// panel5
316 			//
317 			this.panel5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
318 			this.panel5.Location = new System.Drawing.Point(-1, 0);
319 			this.panel5.Name = "panel5";
320 			this.panel5.Size = new System.Drawing.Size(344, 1);
321 			this.panel5.TabIndex = 13;
322 			//
323 			// panel2
324 			//
325 			this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
326 			this.panel2.Controls.AddRange(new System.Windows.Forms.Control[] {
327 												 this.panel3});
328 			this.panel2.Location = new System.Drawing.Point(8, 184);
329 			this.panel2.Name = "panel2";
330 			this.panel2.Size = new System.Drawing.Size(336, 1);
331 			this.panel2.TabIndex = 12;
332 			//
333 			// panel3
334 			//
335 			this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
336 			this.panel3.Location = new System.Drawing.Point(-1, 0);
337 			this.panel3.Name = "panel3";
338 			this.panel3.Size = new System.Drawing.Size(344, 1);
339 			this.panel3.TabIndex = 13;
340 			//
341 			// privateKeyLabel
342 			//
343 			this.privateKeyLabel.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
344 			this.privateKeyLabel.Location = new System.Drawing.Point(32, 298);
345 			this.privateKeyLabel.Name = "privateKeyLabel";
346 			this.privateKeyLabel.Size = new System.Drawing.Size(312, 16);
347 			this.privateKeyLabel.TabIndex = 11;
348 			this.privateKeyLabel.Text = "You have a private key that match this certificate";
349 			this.privateKeyLabel.Visible = false;
350 			//
351 			// notAfterLabel
352 			//
353 			this.notAfterLabel.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
354 			this.notAfterLabel.Location = new System.Drawing.Point(156, 272);
355 			this.notAfterLabel.Name = "notAfterLabel";
356 			this.notAfterLabel.Size = new System.Drawing.Size(64, 16);
357 			this.notAfterLabel.TabIndex = 8;
358 			this.notAfterLabel.Text = "9999-99-99";
359 			//
360 			// label6
361 			//
362 			this.label6.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
363 			this.label6.Location = new System.Drawing.Point(136, 272);
364 			this.label6.Name = "label6";
365 			this.label6.Size = new System.Drawing.Size(16, 16);
366 			this.label6.TabIndex = 7;
367 			this.label6.Text = "to";
368 			//
369 			// notBeforeLabel
370 			//
371 			this.notBeforeLabel.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
372 			this.notBeforeLabel.Location = new System.Drawing.Point(72, 272);
373 			this.notBeforeLabel.Name = "notBeforeLabel";
374 			this.notBeforeLabel.Size = new System.Drawing.Size(64, 16);
375 			this.notBeforeLabel.TabIndex = 6;
376 			this.notBeforeLabel.Text = "9999-99-99";
377 			//
378 			// label4
379 			//
380 			this.label4.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
381 			this.label4.Location = new System.Drawing.Point(8, 232);
382 			this.label4.Name = "label4";
383 			this.label4.Size = new System.Drawing.Size(64, 16);
384 			this.label4.TabIndex = 3;
385 			this.label4.Text = "Issued by:";
386 			//
387 			// label3
388 			//
389 			this.label3.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
390 			this.label3.Location = new System.Drawing.Point(8, 192);
391 			this.label3.Name = "label3";
392 			this.label3.Size = new System.Drawing.Size(64, 16);
393 			this.label3.TabIndex = 2;
394 			this.label3.Text = "Issued to:";
395 			//
396 			// label2
397 			//
398 			this.label2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
399 			this.label2.Location = new System.Drawing.Point(8, 272);
400 			this.label2.Name = "label2";
401 			this.label2.Size = new System.Drawing.Size(64, 16);
402 			this.label2.TabIndex = 1;
403 			this.label2.Text = "Valid from";
404 			//
405 			// certificateLabel
406 			//
407 			this.certificateLabel.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
408 			this.certificateLabel.Location = new System.Drawing.Point(8, 72);
409 			this.certificateLabel.Name = "certificateLabel";
410 			this.certificateLabel.Size = new System.Drawing.Size(344, 112);
411 			this.certificateLabel.TabIndex = 10;
412 			this.certificateLabel.Text = "This certificate is intended to:";
413 			//
414 			// tabPage2
415 			//
416 			this.tabPage2.Controls.AddRange(new System.Windows.Forms.Control[] {
417 												   this.label8,
418 												   this.showComboBox,
419 												   this.detailsTextBox,
420 												   this.fieldListView});
421 			this.tabPage2.Location = new System.Drawing.Point(4, 22);
422 			this.tabPage2.Name = "tabPage2";
423 			this.tabPage2.Size = new System.Drawing.Size(376, 382);
424 			this.tabPage2.TabIndex = 1;
425 			this.tabPage2.Text = "Details";
426 			//
427 			// label8
428 			//
429 			this.label8.Location = new System.Drawing.Point(8, 12);
430 			this.label8.Name = "label8";
431 			this.label8.Size = new System.Drawing.Size(40, 16);
432 			this.label8.TabIndex = 3;
433 			this.label8.Text = "Show:";
434 			//
435 			// showComboBox
436 			//
437 			this.showComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
438 			this.showComboBox.Items.AddRange(new object[] {
439 									      "<All>",
440 									      "Version 1 Fields Only",
441 									      "Extensions Only",
442 									      "Critical Extensions Only",
443 									      "Properties Only"});
444 			this.showComboBox.Location = new System.Drawing.Point(48, 8);
445 			this.showComboBox.MaxDropDownItems = 5;
446 			this.showComboBox.Name = "showComboBox";
447 			this.showComboBox.Size = new System.Drawing.Size(320, 21);
448 			this.showComboBox.TabIndex = 2;
449 			this.showComboBox.SelectedIndexChanged += new System.EventHandler(this.showComboBox_SelectedIndexChanged);
450 			//
451 			// detailsTextBox
452 			//
453 			this.detailsTextBox.AcceptsReturn = true;
454 			this.detailsTextBox.BackColor = System.Drawing.SystemColors.Window;
455 			this.detailsTextBox.Location = new System.Drawing.Point(8, 216);
456 			this.detailsTextBox.Multiline = true;
457 			this.detailsTextBox.Name = "detailsTextBox";
458 			this.detailsTextBox.ReadOnly = true;
459 			this.detailsTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
460 			this.detailsTextBox.Size = new System.Drawing.Size(360, 120);
461 			this.detailsTextBox.TabIndex = 1;
462 			this.detailsTextBox.Text = "";
463 			//
464 			// fieldListView
465 			//
466 			this.fieldListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
467 													    this.fieldColumnHeader,
468 													    this.valueColumnHeader});
469 			this.fieldListView.FullRowSelect = true;
470 			this.fieldListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
471 			this.fieldListView.HideSelection = false;
472 			this.fieldListView.Location = new System.Drawing.Point(8, 40);
473 			this.fieldListView.MultiSelect = false;
474 			this.fieldListView.Name = "fieldListView";
475 			this.fieldListView.Size = new System.Drawing.Size(360, 168);
476 			this.fieldListView.SmallImageList = this.fieldsImageList;
477 			this.fieldListView.TabIndex = 0;
478 			this.fieldListView.View = System.Windows.Forms.View.Details;
479 			this.fieldListView.SelectedIndexChanged += new System.EventHandler(this.fieldListView_SelectedIndexChanged);
480 			//
481 			// fieldColumnHeader
482 			//
483 			this.fieldColumnHeader.Text = "Field";
484 			this.fieldColumnHeader.Width = 140;
485 			//
486 			// valueColumnHeader
487 			//
488 			this.valueColumnHeader.Text = "Value";
489 			this.valueColumnHeader.Width = 200;
490 			//
491 			// fieldsImageList
492 			//
493 			this.fieldsImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
494 			this.fieldsImageList.ImageSize = new System.Drawing.Size(16, 16);
495 			this.fieldsImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("fieldsImageList.ImageStream")));
496 			this.fieldsImageList.TransparentColor = System.Drawing.Color.Transparent;
497 			//
498 			// tabPage3
499 			//
500 			this.tabPage3.Controls.AddRange(new System.Windows.Forms.Control[] {
501 												   this.label9,
502 												   this.certStatusTextBox,
503 												   this.certPathTreeView});
504 			this.tabPage3.Location = new System.Drawing.Point(4, 22);
505 			this.tabPage3.Name = "tabPage3";
506 			this.tabPage3.Size = new System.Drawing.Size(376, 382);
507 			this.tabPage3.TabIndex = 2;
508 			this.tabPage3.Text = "Certificate Path";
509 			//
510 			// label9
511 			//
512 			this.label9.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
513 			this.label9.Location = new System.Drawing.Point(8, 296);
514 			this.label9.Name = "label9";
515 			this.label9.Size = new System.Drawing.Size(96, 16);
516 			this.label9.TabIndex = 7;
517 			this.label9.Text = "Certificate Status";
518 			//
519 			// certStatusTextBox
520 			//
521 			this.certStatusTextBox.AcceptsReturn = true;
522 			this.certStatusTextBox.BackColor = System.Drawing.SystemColors.Window;
523 			this.certStatusTextBox.ForeColor = System.Drawing.SystemColors.WindowText;
524 			this.certStatusTextBox.Location = new System.Drawing.Point(8, 312);
525 			this.certStatusTextBox.Multiline = true;
526 			this.certStatusTextBox.Name = "certStatusTextBox";
527 			this.certStatusTextBox.ReadOnly = true;
528 			this.certStatusTextBox.Size = new System.Drawing.Size(360, 56);
529 			this.certStatusTextBox.TabIndex = 2;
530 			this.certStatusTextBox.Text = "This certificate is OK.";
531 			//
532 			// certPathTreeView
533 			//
534 			this.certPathTreeView.ImageIndex = -1;
535 			this.certPathTreeView.Location = new System.Drawing.Point(8, 8);
536 			this.certPathTreeView.Name = "certPathTreeView";
537 			this.certPathTreeView.SelectedImageIndex = -1;
538 			this.certPathTreeView.Size = new System.Drawing.Size(360, 280);
539 			this.certPathTreeView.TabIndex = 0;
540 			//
541 			// okButton
542 			//
543 			this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
544 			this.okButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
545 			this.okButton.Location = new System.Drawing.Point(317, 424);
546 			this.okButton.Name = "okButton";
547 			this.okButton.TabIndex = 1;
548 			this.okButton.Text = "OK";
549 			this.okButton.Click += new System.EventHandler(this.okButton_Click);
550 			//
551 			// iconImageList
552 			//
553 			this.iconImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
554 			this.iconImageList.ImageSize = new System.Drawing.Size(64, 64);
555 			this.iconImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("iconImageList.ImageStream")));
556 			this.iconImageList.TransparentColor = System.Drawing.Color.Black;
557 			//
558 			// CertificateViewer
559 			//
560 			this.AcceptButton = this.okButton;
561 			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
562 			this.CancelButton = this.okButton;
563 			this.ClientSize = new System.Drawing.Size(400, 453);
564 			this.Controls.AddRange(new System.Windows.Forms.Control[] {
565 											  this.okButton,
566 											  this.tabControl1});
567 			this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
568 			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
569 			this.HelpButton = true;
570 			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
571 			this.MaximizeBox = false;
572 			this.MinimizeBox = false;
573 			this.Name = "CertificateViewer";
574 			this.Text = "Mono Certificate Viewer";
575 			this.tabControl1.ResumeLayout(false);
576 			this.tabPage1.ResumeLayout(false);
577 			this.panel1.ResumeLayout(false);
578 			this.panel4.ResumeLayout(false);
579 			this.panel2.ResumeLayout(false);
580 			this.tabPage2.ResumeLayout(false);
581 			this.tabPage3.ResumeLayout(false);
582 			this.ResumeLayout(false);
583 
584 		}
585 		#endregion
586 
587 		private CertificateFormatter cf;
588 		private Font genericFont;
589 		private Font monospaceFont;
590 
591 		private ListViewItem itemVersion;
592 		private ListViewItem itemSerial;
593 		private ListViewItem itemSignatureAlgorithm;
594 		private ListViewItem itemIssuer;
595 		private ListViewItem itemValidFrom;
596 		private ListViewItem itemValidUntil;
597 		private ListViewItem itemSubject;
598 		private ListViewItem itemPublicKey;
599 		private ListViewItem[] itemExtensions;
600 		private ListViewItem itemThumbprintAlgorithm;
601 		private ListViewItem itemThumbprint;
602 
LoadCertificate(string filename)603 		public void LoadCertificate (string filename)
604 		{
605 			cf = new CertificateFormatter (filename);
606 
607 			genericFont = detailsTextBox.Font;
608 			monospaceFont = new Font (FontFamily.GenericMonospace, 10);
609 
610 			issuedToTextBox.Text = cf.Subject (false);
611 			toolTip.SetToolTip (issuedToTextBox, issuedToTextBox.Text);
612 
613 			subjectAltNameLinkLabel.Text = cf.SubjectAltName (false);
614 			subjectAltNameLinkLabel.Visible = (subjectAltNameLinkLabel.Text != String.Empty);
615 
616 			issuedByTextBox.Text = cf.Issuer (false);
617 			toolTip.SetToolTip (issuedByTextBox, issuedByTextBox.Text);
618 
619 			notBeforeLabel.Text = cf.Certificate.ValidFrom.ToString ("yyyy-MM-dd");
620 			notAfterLabel.Text = cf.Certificate.ValidUntil.ToString ("yyyy-MM-dd");
621 
622 			if (cf.Certificate.Version == 1) {
623 				// not in certificate so it's a property
624 				itemVersion = new ListViewItem (CertificateFormatter.FieldNames.Version, 0);
625 				itemVersion.ForeColor = Color.Blue;
626 			}
627 			else
628 				itemVersion = new ListViewItem (CertificateFormatter.FieldNames.Version, 2);
629 			itemVersion.SubItems.Add (cf.Version (false));
630 			itemVersion.SubItems.Add (cf.Version (true));
631 
632 			itemSerial = new ListViewItem (CertificateFormatter.FieldNames.SerialNumber, 1);
633 			itemSerial.SubItems.Add (cf.SerialNumber (false));
634 			itemSerial.SubItems.Add (cf.SerialNumber (true));
635 			itemSerial.Tag = monospaceFont;
636 
637 			itemSignatureAlgorithm = new ListViewItem (CertificateFormatter.FieldNames.SignatureAlgorithm, 1);
638 			itemSignatureAlgorithm.SubItems.Add (cf.SignatureAlgorithm (false));
639 			itemSignatureAlgorithm.SubItems.Add (cf.SignatureAlgorithm (true));
640 
641 			itemIssuer = new ListViewItem (CertificateFormatter.FieldNames.Issuer, 1);
642 			itemIssuer.SubItems.Add (cf.Issuer (false));
643 			itemIssuer.SubItems.Add (cf.Issuer (true));
644 
645 			itemValidFrom = new ListViewItem (CertificateFormatter.FieldNames.ValidFrom, 1);
646 			itemValidFrom.SubItems.Add (cf.ValidFrom (false));
647 			itemValidFrom.SubItems.Add (cf.ValidFrom (true));
648 
649 			itemValidUntil = new ListViewItem (CertificateFormatter.FieldNames.ValidUntil,1);
650 			itemValidUntil.SubItems.Add (cf.ValidUntil (false));
651 			itemValidUntil.SubItems.Add (cf.ValidUntil (true));
652 
653 			itemSubject = new ListViewItem (CertificateFormatter.FieldNames.Subject, 1);
654 			itemSubject.SubItems.Add (cf.Subject (false));
655 			itemSubject.SubItems.Add (cf.Subject (true));
656 
657 			itemPublicKey = new ListViewItem (CertificateFormatter.FieldNames.PublicKey, 1);
658 			itemPublicKey.SubItems.Add (cf.PublicKey (false));
659 			itemPublicKey.SubItems.Add (cf.PublicKey (true));
660 			itemPublicKey.Tag = monospaceFont;
661 
662 			itemExtensions = new ListViewItem [cf.Certificate.Extensions.Count];
663 			for (int i=0; i < cf.Certificate.Extensions.Count; i++) {
664 				X509Extension xe = cf.GetExtension (i);
665 				int critical = (xe.Critical ? 4 : 3);
666 				string name = xe.Name;
667 				object tag = null;
668 				if (name == xe.Oid)
669 					tag = monospaceFont;
670 				ListViewItem lvi = new ListViewItem (name, critical);
671 				lvi.Tag = tag;
672 				if (critical == 4)
673 					lvi.ForeColor = Color.Red;
674 				string exts = xe.ToString ();
675 				if (xe.Name == xe.Oid)
676 					lvi.SubItems.Add (cf.Extension (i, false));
677 				else
678 					lvi.SubItems.Add (CertificateFormatter.OneLine (exts));
679 				lvi.SubItems.Add (exts);
680 				itemExtensions [i] = lvi;
681 			}
682 
683 			// properties (calculated)
684 			itemThumbprintAlgorithm = new ListViewItem (CertificateFormatter.PropertyNames.ThumbprintAlgorithm, 0);
685 			itemThumbprintAlgorithm.SubItems.Add (cf.ThumbprintAlgorithm);
686 			itemThumbprintAlgorithm.SubItems.Add (cf.ThumbprintAlgorithm);
687 			itemThumbprintAlgorithm.ForeColor = Color.Blue;
688 
689 			itemThumbprint = new ListViewItem (CertificateFormatter.PropertyNames.Thumbprint, 0);
690 			string tb = CertificateFormatter.Array2Word (cf.Thumbprint);
691 			itemThumbprint.SubItems.Add (tb);
692 			itemThumbprint.SubItems.Add (tb);
693 			itemThumbprint.Tag = monospaceFont;
694 			itemThumbprint.ForeColor = Color.Blue;
695 
696 			showComboBox.SelectedIndex = 0;
697 
698 			if (cf.Status != null) {
699 				badPictureBox.Visible = true;
700 				keyUsageRichTextBox.Visible = false;
701 				certificateLabel.Text = cf.Status;
702 				certificateLabel.ForeColor = Color.Red;
703 				certStatusTextBox.Text = cf.Status;
704 				certStatusTextBox.ForeColor = Color.Red;
705 			}
706 			else
707 				badPictureBox.Visible = false;
708 			goodPictureBox.Visible = !badPictureBox.Visible;
709 
710 			keyUsageRichTextBox.SelectionBullet = true;
711 			keyUsageRichTextBox.Text = "No restrictions";
712 		}
713 
714 		/// <summary>
715 		/// The main entry point for the application.
716 		/// </summary>
717 		[STAThread]
Main(string[] args)718 		static void Main (string[] args)
719 		{
720 			string filename = ((args.Length > 0) ? args[0] : null);
721 			if ((filename != null) && (File.Exists (filename)))
722 				Application.Run (new CertificateViewer (filename));
723 		}
724 
okButton_Click(object sender, System.EventArgs e)725 		private void okButton_Click (object sender, System.EventArgs e)
726 		{
727 			Application.Exit ();
728 		}
729 
fieldListView_SelectedIndexChanged(object sender, System.EventArgs e)730 		private void fieldListView_SelectedIndexChanged (object sender, System.EventArgs e)
731 		{
732 			if (sender is ListView) {
733 				ListView lv = (sender as ListView);
734 				if (lv.SelectedItems.Count > 0) {
735 					ListViewItem lvi = lv.SelectedItems [0];
736 					if (lvi.Tag is Font)
737 						detailsTextBox.Font = (lvi.Tag as Font);
738 					else
739 						detailsTextBox.Font = genericFont;
740 					detailsTextBox.Text = lvi.SubItems [2].Text;
741 				}
742 			}
743 		}
744 
UpdateListView(int filter)745 		private void UpdateListView (int filter)
746 		{
747 			fieldListView.Items.Clear ();
748 
749 			if ((filter == 0) || ((filter == 4) && (itemVersion.ImageIndex == 0)))
750 				fieldListView.Items.Add (itemVersion);
751 
752 			if (filter < 2)
753 				fieldListView.Items.AddRange (new ListViewItem[] {itemSerial, itemSignatureAlgorithm, itemIssuer, itemValidFrom, itemValidUntil, itemSubject, itemPublicKey });
754 
755 			if ((filter != 1) && (filter != 4)) {
756 				for (int i=0; i < itemExtensions.Length; i++) {
757 					if ((filter != 3) || ((filter == 3) && (cf.Certificate.Extensions [i].Critical))) {
758 						fieldListView.Items.Add (itemExtensions [i]);
759 					}
760 				}
761 			}
762 
763 			if ((filter == 0) || (filter == 4)) {
764 				fieldListView.Items.Add (itemThumbprintAlgorithm);
765 				fieldListView.Items.Add (itemThumbprint);
766 			}
767 
768 			detailsTextBox.Text = "";
769 		}
770 
showComboBox_SelectedIndexChanged(object sender, System.EventArgs e)771 		private void showComboBox_SelectedIndexChanged (object sender, System.EventArgs e)
772 		{
773 			UpdateListView ((sender as ComboBox).SelectedIndex);
774 		}
775 
subjectAltNameLinkLabel_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)776 		private void subjectAltNameLinkLabel_LinkClicked (object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
777 		{
778 			System.Diagnostics.Process.Start ((sender as LinkLabel).Text);
779 		}
780 	}
781 }
782