1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
//
// Oid.cs - System.Security.Cryptography.Oid
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2005 Novell Inc. (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0 && SECURITY_DEP
using System.Security.Cryptography.X509Certificates;
namespace System.Security.Cryptography {
public sealed class Oid {
private string _value;
private string _name;
// constructors
public Oid ()
{
}
public Oid (string oid)
{
if (oid == null)
throw new ArgumentNullException ("oid");
_value = oid;
_name = GetName (oid);
}
public Oid (string value, string friendlyName)
{
_value = value;
_name = friendlyName;
}
public Oid (Oid oid)
{
if (oid == null)
throw new ArgumentNullException ("oid");
_value = oid.Value;
_name = oid.FriendlyName;
}
// properties
public string FriendlyName {
get { return _name; }
set {
_name = value;
_value = GetValue (_name);
}
}
public string Value {
get { return _value; }
set {
_value = value;
_name = GetName (_value);
}
}
// internal stuff
// Known OID/Names not defined anywhere else (by OID order)
internal const string oidRSA = "1.2.840.113549.1.1.1";
internal const string nameRSA = "RSA";
internal const string oidPkcs7Data = "1.2.840.113549.1.7.1";
internal const string namePkcs7Data = "PKCS 7 Data";
internal const string oidPkcs9ContentType = "1.2.840.113549.1.9.3";
internal const string namePkcs9ContentType = "Content Type";
internal const string oidPkcs9MessageDigest = "1.2.840.113549.1.9.4";
internal const string namePkcs9MessageDigest = "Message Digest";
internal const string oidPkcs9SigningTime = "1.2.840.113549.1.9.5";
internal const string namePkcs9SigningTime = "Signing Time";
internal const string oidMd5 = "1.2.840.113549.2.5";
internal const string nameMd5 = "md5";
internal const string oid3Des = "1.2.840.113549.3.7";
internal const string name3Des = "3des";
internal const string oidSha1 = "1.3.14.3.2.26";
internal const string nameSha1 = "sha1";
internal const string oidSubjectAltName = "2.5.29.17";
internal const string nameSubjectAltName = "Subject Alternative Name";
internal const string oidNetscapeCertType = "2.16.840.1.113730.1.1";
internal const string nameNetscapeCertType = "Netscape Cert Type";
// TODO - find the complete list
private string GetName (string oid)
{
switch (oid) {
case oidRSA:
return nameRSA;
case oidPkcs7Data:
return namePkcs7Data;
case oidPkcs9ContentType:
return namePkcs9ContentType;
case oidPkcs9MessageDigest:
return namePkcs9MessageDigest;
case oidPkcs9SigningTime:
return namePkcs9SigningTime;
case oid3Des:
return name3Des;
case X509BasicConstraintsExtension.oid:
return X509BasicConstraintsExtension.friendlyName;
case X509KeyUsageExtension.oid:
return X509KeyUsageExtension.friendlyName;
case X509EnhancedKeyUsageExtension.oid:
return X509EnhancedKeyUsageExtension.friendlyName;
case X509SubjectKeyIdentifierExtension.oid:
return X509SubjectKeyIdentifierExtension.friendlyName;
case oidSubjectAltName:
return nameSubjectAltName;
case oidNetscapeCertType:
return nameNetscapeCertType;
case oidMd5:
return nameMd5;
case oidSha1:
return nameSha1;
default:
return _name;
}
}
// TODO - find the complete list
private string GetValue (string name)
{
switch (name) {
case nameRSA:
return oidRSA;
case namePkcs7Data:
return oidPkcs7Data;
case namePkcs9ContentType:
return oidPkcs9ContentType;
case namePkcs9MessageDigest:
return oidPkcs9MessageDigest;
case namePkcs9SigningTime:
return oidPkcs9SigningTime;
case name3Des:
return oid3Des;
case X509BasicConstraintsExtension.friendlyName:
return X509BasicConstraintsExtension.oid;
case X509KeyUsageExtension.friendlyName:
return X509KeyUsageExtension.oid;
case X509EnhancedKeyUsageExtension.friendlyName:
return X509EnhancedKeyUsageExtension.oid;
case X509SubjectKeyIdentifierExtension.friendlyName:
return X509SubjectKeyIdentifierExtension.oid;
case nameSubjectAltName:
return oidSubjectAltName;
case nameNetscapeCertType:
return oidNetscapeCertType;
case nameMd5:
return oidMd5;
case nameSha1:
return oidSha1;
default:
return _value;
}
}
}
}
#endif
|