Merge branch 'master' of http://github.com/mono/mono
[mono.git] / mcs / class / System / Test / System.Security.Cryptography.X509Certificates / pkits / x509build.cs
1 using System;\r
2 using System.Security.Cryptography.X509Certificates;\r
3 \r
4 class Program {\r
5 \r
6         static int Main (string[] args)\r
7         {\r
8                 if (args.Length == 0) {\r
9                         Console.WriteLine ("Usage: mono x509build.exe filename");\r
10                         return 2;\r
11                 }\r
12                 string filename = args [0];\r
13 \r
14                 X509Certificate2 cert = new X509Certificate2 (filename);\r
15                 // using X509Chain.Create will use the X509Chain defined in machine.config\r
16                 X509Chain chain = X509Chain.Create ();\r
17                 bool result = chain.Build (cert);\r
18                 Console.WriteLine ("Build: {0}", result);\r
19                 Console.WriteLine ();\r
20 \r
21                 Console.WriteLine ("ChainStatus:");\r
22                 if (chain.ChainStatus.Length > 0) {\r
23                         foreach (X509ChainStatus st in chain.ChainStatus) {\r
24                                 Console.WriteLine ("\t{0}", st.Status);\r
25                         }\r
26                 } else {\r
27                         Console.WriteLine ("\t{0}", X509ChainStatusFlags.NoError);\r
28                 }\r
29                 Console.WriteLine ();\r
30 \r
31                 int n = 1;\r
32                 Console.WriteLine ("ChainElements:");\r
33                 foreach (X509ChainElement ce in chain.ChainElements) {\r
34                         Console.WriteLine ("{0}. Certificate: {1}", n++, ce.Certificate);\r
35                         Console.WriteLine ("\tChainStatus:");\r
36                         if (ce.ChainElementStatus.Length > 0) {\r
37                                 foreach (X509ChainStatus st in ce.ChainElementStatus) {\r
38                                         Console.WriteLine ("\t\t{0}", st.Status);\r
39                                 }\r
40                         } else {\r
41                                 Console.WriteLine ("\t\t{0}", X509ChainStatusFlags.NoError);\r
42                         }\r
43                         Console.WriteLine ();\r
44                 }\r
45 \r
46                 return result ? 0 : 1;\r
47         }\r
48 }\r