* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Mono.Security / Mono.Security.X509.Extensions / SubjectAltNameExtension.cs
1 //
2 // SubjectAltNameExtension.cs: Handles X.509 SubjectAltName extensions.
3 //
4 // Author:
5 //      Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 using System;
31 using System.Net;
32 using System.Collections;
33 using System.Text;
34
35 using Mono.Security;
36 using Mono.Security.X509;
37
38 namespace Mono.Security.X509.Extensions {
39
40         /*
41          * id-ce-subjectAltName OBJECT IDENTIFIER ::=  { id-ce 17 }
42          * 
43          * SubjectAltName ::= GeneralNames
44          * 
45          * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
46          * 
47          * GeneralName ::= CHOICE {
48          *    otherName                       [0]     OtherName,
49          *    rfc822Name                      [1]     IA5String,
50          *    dNSName                         [2]     IA5String,
51          *    x400Address                     [3]     ORAddress,
52          *    directoryName                   [4]     Name,
53          *    ediPartyName                    [5]     EDIPartyName,
54          *    uniformResourceIdentifier       [6]     IA5String,
55          *    iPAddress                       [7]     OCTET STRING,
56          *    registeredID                    [8]     OBJECT IDENTIFIER 
57          * }
58          * 
59          * OtherName ::= SEQUENCE {
60          *    type-id    OBJECT IDENTIFIER,
61          *    value      [0] EXPLICIT ANY DEFINED BY type-id 
62          * }
63          * 
64          * EDIPartyName ::= SEQUENCE {
65          *    nameAssigner            [0]     DirectoryString OPTIONAL,
66          *    partyName               [1]     DirectoryString 
67          * }
68          */
69
70         // TODO - incomplete (only rfc822Name, dNSName are supported)
71         public class SubjectAltNameExtension : X509Extension {
72                 
73                 private GeneralNames _names;
74
75                 public SubjectAltNameExtension ()
76                 {
77                         extnOid = "2.5.29.17";
78                         _names = new GeneralNames ();
79                 }
80
81                 public SubjectAltNameExtension (ASN1 asn1)
82                         : base (asn1)
83                 {
84                 }
85
86                 public SubjectAltNameExtension (X509Extension extension) 
87                         : base (extension) 
88                 {
89                 }
90
91                 protected override void Decode () 
92                 {
93                         ASN1 sequence = new ASN1 (extnValue.Value);
94                         if (sequence.Tag != 0x30)
95                                 throw new ArgumentException ("Invalid SubjectAltName extension");
96                         _names = new GeneralNames (sequence);
97                 }
98
99                 public override string Name {
100                         get { return "Subject Alternative Name"; }
101                 }
102
103                 public string[] RFC822 {
104                         get { return _names.RFC822; }
105                 }
106
107                 public string[] DNSNames {
108                         get { return _names.DNSNames; }
109                 }
110
111                 // Incomplete support
112                 public string[] IPAddresses {
113                         get { return _names.IPAddresses; }
114                 }
115
116                 public override string ToString () 
117                 {
118                         return _names.ToString ();
119                 }
120         }
121 }