2 // SubjectAltNameExtension.cs: Handles X.509 SubjectAltName extensions.
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2005 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 System.Collections;
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
59 * OtherName ::= SEQUENCE {
60 * type-id OBJECT IDENTIFIER,
61 * value [0] EXPLICIT ANY DEFINED BY type-id
64 * EDIPartyName ::= SEQUENCE {
65 * nameAssigner [0] DirectoryString OPTIONAL,
66 * partyName [1] DirectoryString
70 // TODO - incomplete (only rfc822Name, dNSName are supported)
71 public class SubjectAltNameExtension : X509Extension {
73 private GeneralNames _names;
75 public SubjectAltNameExtension ()
77 extnOid = "2.5.29.17";
78 _names = new GeneralNames ();
81 public SubjectAltNameExtension (ASN1 asn1)
86 public SubjectAltNameExtension (X509Extension extension)
91 protected override void Decode ()
93 ASN1 sequence = new ASN1 (extnValue.Value);
94 if (sequence.Tag != 0x30)
95 throw new ArgumentException ("Invalid SubjectAltName extension");
96 _names = new GeneralNames (sequence);
99 public override string Name {
100 get { return "Subject Alternative Name"; }
103 public string[] RFC822 {
104 get { return _names.RFC822; }
107 public string[] DNSNames {
108 get { return _names.DNSNames; }
111 // Incomplete support
112 public string[] IPAddresses {
113 get { return _names.IPAddresses; }
116 public override string ToString ()
118 return _names.ToString ();