Allow compiling SSL/TLS and NTLM support directly into System.dll to avoid a dependen...
[mono-project.git] / mcs / class / Mono.Security / Mono.Security.X509.Extensions / SubjectAltNameExtension.cs
blob23d12c5ab09ae2dc33301144fb454437cf7d69da
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.
30 using System;
31 using System.Net;
32 using System.Collections;
33 using System.Text;
35 using Mono.Security;
36 using Mono.Security.X509;
38 namespace Mono.Security.X509.Extensions {
41 * id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 }
43 * SubjectAltName ::= GeneralNames
45 * GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName
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 * }
59 * OtherName ::= SEQUENCE {
60 * type-id OBJECT IDENTIFIER,
61 * value [0] EXPLICIT ANY DEFINED BY type-id
62 * }
64 * EDIPartyName ::= SEQUENCE {
65 * nameAssigner [0] DirectoryString OPTIONAL,
66 * partyName [1] DirectoryString
67 * }
70 // TODO: Directories not supported
71 #if INSIDE_SYSTEM
72 internal
73 #else
74 public
75 #endif
76 class SubjectAltNameExtension : X509Extension {
78 private GeneralNames _names;
80 public SubjectAltNameExtension ()
82 extnOid = "2.5.29.17";
83 _names = new GeneralNames ();
86 public SubjectAltNameExtension (ASN1 asn1)
87 : base (asn1)
91 public SubjectAltNameExtension (X509Extension extension)
92 : base (extension)
96 public SubjectAltNameExtension (string[] rfc822, string[] dnsNames,
97 string[] ipAddresses, string[] uris)
99 _names = new GeneralNames(rfc822, dnsNames, ipAddresses, uris);
100 // 0x04 for string decoding and then the General Names!
101 extnValue = new ASN1 (0x04, _names.GetBytes());
102 extnOid = "2.5.29.17";
103 // extnCritical = true;
106 protected override void Decode ()
108 ASN1 sequence = new ASN1 (extnValue.Value);
109 if (sequence.Tag != 0x30)
110 throw new ArgumentException ("Invalid SubjectAltName extension");
111 _names = new GeneralNames (sequence);
114 public override string Name {
115 get { return "Subject Alternative Name"; }
118 public string[] RFC822 {
119 get { return _names.RFC822; }
122 public string[] DNSNames {
123 get { return _names.DNSNames; }
126 public string[] IPAddresses {
127 get { return _names.IPAddresses; }
130 public string[] UniformResourceIdentifiers {
131 get { return _names.UniformResourceIdentifiers; }
134 public override string ToString ()
136 return _names.ToString ();