2 // X520.cs: X.520 related stuff (attributes, RDN)
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 // (C) 2004 Novell (http://www.novell.com)
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 namespace Mono
.Security
.X509
{
42 // 1. Information technology - Open Systems Interconnection - The Directory: Selected attribute types
43 // http://www.itu.int/rec/recommendation.asp?type=folders&lang=e&parent=T-REC-X.520
44 // 2. Internet X.509 Public Key Infrastructure Certificate and CRL Profile
45 // http://www.ietf.org/rfc/rfc3280.txt
48 * AttributeTypeAndValue ::= SEQUENCE {
50 * value AttributeValue
53 * AttributeType ::= OBJECT IDENTIFIER
55 * AttributeValue ::= ANY DEFINED BY AttributeType
64 public abstract class AttributeTypeAndValue
{
66 private string attrValue
;
67 private int upperBound
;
68 private byte encoding
;
70 protected AttributeTypeAndValue (string oid
, int upperBound
)
73 this.upperBound
= upperBound
;
77 protected AttributeTypeAndValue (string oid
, int upperBound
, byte encoding
)
80 this.upperBound
= upperBound
;
81 this.encoding
= encoding
;
85 get { return attrValue; }
86 set { attrValue = value; }
90 get { return GetASN1 (); }
93 internal ASN1
GetASN1 (byte encoding
)
95 byte encode
= encoding
;
97 encode
= SelectBestEncoding ();
99 ASN1 asn1
= new ASN1 (0x30);
100 asn1
.Add (ASN1Convert
.FromOid (oid
));
104 asn1
.Add (new ASN1 (0x13, Encoding
.ASCII
.GetBytes (attrValue
)));
108 asn1
.Add (new ASN1 (0x1E, Encoding
.BigEndianUnicode
.GetBytes (attrValue
)));
114 internal ASN1
GetASN1 ()
116 return GetASN1 (encoding
);
119 public byte[] GetBytes (byte encoding
)
121 return GetASN1 (encoding
) .GetBytes ();
124 public byte[] GetBytes ()
126 return GetASN1 () .GetBytes ();
129 private byte SelectBestEncoding ()
131 char[] notPrintableString
= { '@', '_' }
;
132 if (attrValue
.IndexOfAny (notPrintableString
) != -1)
133 return 0x1E; // BMPSTRING
135 return 0x13; // PRINTABLESTRING
139 public class Name
: AttributeTypeAndValue
{
141 public Name () : base ("2.5.4.41", 32768)
146 public class CommonName
: AttributeTypeAndValue
{
148 public CommonName () : base ("2.5.4.3", 64)
153 public class LocalityName
: AttributeTypeAndValue
{
155 public LocalityName () : base ("2.5.4.7", 128)
160 public class StateOrProvinceName
: AttributeTypeAndValue
{
162 public StateOrProvinceName () : base ("2.5.4.8", 128)
167 public class OrganizationName
: AttributeTypeAndValue
{
169 public OrganizationName () : base ("2.5.4.10", 64)
174 public class OrganizationalUnitName
: AttributeTypeAndValue
{
176 public OrganizationalUnitName () : base ("2.5.4.11", 64)
181 /* -- Naming attributes of type X520Title
182 * id-at-title AttributeType ::= { id-at 12 }
184 * X520Title ::= CHOICE {
185 * teletexString TeletexString (SIZE (1..ub-title)),
186 * printableString PrintableString (SIZE (1..ub-title)),
187 * universalString UniversalString (SIZE (1..ub-title)),
188 * utf8String UTF8String (SIZE (1..ub-title)),
189 * bmpString BMPString (SIZE (1..ub-title))
192 public class Title
: AttributeTypeAndValue
{
194 public Title () : base ("2.5.4.12", 64) {}
197 public class CountryName
: AttributeTypeAndValue
{
199 // (0x13) PRINTABLESTRING
200 public CountryName () : base ("2.5.4.6", 2, 0x13)
207 * -- specifications of Upper Bounds MUST be regarded as mandatory
208 * -- from Annex B of ITU-T X.411 Reference Definition of MTS Parameter
212 * ub-name INTEGER ::= 32768
213 * ub-common-name INTEGER ::= 64
214 * ub-locality-name INTEGER ::= 128
215 * ub-state-name INTEGER ::= 128
216 * ub-organization-name INTEGER ::= 64
217 * ub-organizational-unit-name INTEGER ::= 64
218 * ub-title INTEGER ::= 64
219 * ub-serial-number INTEGER ::= 64
220 * ub-match INTEGER ::= 128
221 * ub-emailaddress-length INTEGER ::= 128
222 * ub-common-name-length INTEGER ::= 64
223 * ub-country-name-alpha-length INTEGER ::= 2
224 * ub-country-name-numeric-length INTEGER ::= 3
225 * ub-domain-defined-attributes INTEGER ::= 4
226 * ub-domain-defined-attribute-type-length INTEGER ::= 8
227 * ub-domain-defined-attribute-value-length INTEGER ::= 128
228 * ub-domain-name-length INTEGER ::= 16
229 * ub-extension-attributes INTEGER ::= 256
230 * ub-e163-4-number-length INTEGER ::= 15
231 * ub-e163-4-sub-address-length INTEGER ::= 40
232 * ub-generation-qualifier-length INTEGER ::= 3
233 * ub-given-name-length INTEGER ::= 16
234 * ub-initials-length INTEGER ::= 5
235 * ub-integer-options INTEGER ::= 256
236 * ub-numeric-user-id-length INTEGER ::= 32
237 * ub-organization-name-length INTEGER ::= 64
238 * ub-organizational-unit-name-length INTEGER ::= 32
239 * ub-organizational-units INTEGER ::= 4
240 * ub-pds-name-length INTEGER ::= 16
241 * ub-pds-parameter-length INTEGER ::= 30
242 * ub-pds-physical-address-lines INTEGER ::= 6
243 * ub-postal-code-length INTEGER ::= 16
244 * ub-pseudonym INTEGER ::= 128
245 * ub-surname-length INTEGER ::= 40
246 * ub-terminal-id-length INTEGER ::= 24
247 * ub-unformatted-address-length INTEGER ::= 180
248 * ub-x121-address-length INTEGER ::= 16
250 * -- Note - upper bounds on string types, such as TeletexString, are
251 * -- measured in characters. Excepting PrintableString or IA5String, a
252 * -- significantly greater number of octets will be required to hold
253 * -- such a value. As a minimum, 16 octets, or twice the specified
254 * -- upper bound, whichever is the larger, should be allowed for
255 * -- TeletexString. For UTF8String or UniversalString at least four
256 * -- times the upper bound should be allowed.