2 // X509ChainElement.cs - System.Security.Cryptography.X509Certificates.X509ChainElement
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2005-2006 Novell Inc. (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using Mono.Security.X509;
34 namespace System.Security.Cryptography.X509Certificates {
36 public class X509ChainElement {
38 private X509Certificate2 certificate;
39 private X509ChainStatus[] status;
41 private X509ChainStatusFlags compressed_status_flags;
45 // only accessible from X509Chain.ChainElements
46 internal X509ChainElement (X509Certificate2 certificate)
48 this.certificate = certificate;
49 // so far String.Empty is the only thing I've seen.
50 // The interesting stuff is inside X509ChainStatus.Information
56 public X509Certificate2 Certificate {
57 get { return certificate; }
60 public X509ChainStatus[] ChainElementStatus {
61 get { return status; }
64 public string Information {
70 internal X509ChainStatusFlags StatusFlags {
71 get { return compressed_status_flags; }
72 set { compressed_status_flags = value; }
75 private int Count (X509ChainStatusFlags flags)
89 private void Set (X509ChainStatus[] status, ref int position, X509ChainStatusFlags flags, X509ChainStatusFlags mask)
91 if ((flags & mask) != 0) {
92 status [position].Status = mask;
93 status [position].StatusInformation = X509ChainStatus.GetInformation (mask);
98 internal void UncompressFlags ()
100 if (compressed_status_flags == X509ChainStatusFlags.NoError) {
101 status = new X509ChainStatus [0];
103 int size = Count (compressed_status_flags);
104 status = new X509ChainStatus [size];
107 // process every possible error
108 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.UntrustedRoot);
109 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.NotTimeValid);
110 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.NotTimeNested);
111 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.Revoked);
112 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.NotSignatureValid);
113 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.NotValidForUsage);
114 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.RevocationStatusUnknown);
115 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.Cyclic);
116 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.InvalidExtension);
117 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.InvalidPolicyConstraints);
118 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.InvalidBasicConstraints);
119 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.InvalidNameConstraints);
120 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.HasNotSupportedNameConstraint);
121 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.HasNotDefinedNameConstraint);
122 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.HasNotPermittedNameConstraint);
123 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.HasExcludedNameConstraint);
124 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.PartialChain);
125 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.CtlNotTimeValid);
126 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.CtlNotSignatureValid);
127 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.CtlNotValidForUsage);
128 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.OfflineRevocation);
129 Set (status, ref n, compressed_status_flags, X509ChainStatusFlags.NoIssuanceChainPolicy);