2 // System.Web.HttpClientCertificate class
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005-2009 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections.Specialized;
30 using System.Globalization;
31 using System.Security.Permissions;
32 using System.Web.Util;
37 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 public class HttpClientCertificate : NameValueCollection
41 HttpWorkerRequest hwr;
46 internal HttpClientCertificate (HttpWorkerRequest hwr)
48 // we don't check hwr for null so we end up throwing a
49 // NullReferenceException just like MS implementation
50 // if the public ctor for HttpRequest is used
52 flags = GetIntNoPresense ("CERT_FLAGS");
54 from = hwr.GetClientCertificateValidFrom ();
55 until = hwr.GetClientCertificateValidUntil ();
62 public byte[] BinaryIssuer {
63 get { return hwr.GetClientCertificateBinaryIssuer (); }
66 public int CertEncoding {
67 get { return hwr.GetClientCertificateEncoding (); }
70 public byte[] Certificate {
71 get { return hwr.GetClientCertificate (); }
74 public string Cookie {
75 get { return GetString ("CERT_COOKIE"); }
82 public bool IsPresent {
83 get { return ((flags & 0x01) == 0x01); }
86 public string Issuer {
87 get { return GetString ("CERT_ISSUER"); }
93 return true; // lame but true
95 return ((flags & 0x02) == 0x00);
100 get { return GetInt ("CERT_KEYSIZE"); }
103 public byte[] PublicKey {
104 get { return hwr.GetClientCertificatePublicKey (); }
107 public int SecretKeySize {
108 get { return GetInt ("CERT_SECRETKEYSIZE"); }
111 public string SerialNumber {
112 get { return GetString ("CERT_SERIALNUMBER"); }
115 public string ServerIssuer {
116 get { return GetString ("CERT_SERVER_ISSUER"); }
119 public string ServerSubject {
120 get { return GetString ("CERT_SERVER_SUBJECT"); }
123 public string Subject {
124 get { return GetString ("CERT_SUBJECT"); }
127 public DateTime ValidFrom {
131 public DateTime ValidUntil {
132 get { return until; }
136 // LAMESPEC: this doesn't return values added with Add(string,string)
137 public override string Get (string field)
146 int GetInt (string variable)
151 return GetIntNoPresense (variable);
154 int GetIntNoPresense (string variable)
156 string s = hwr.GetServerVariable (variable);
161 return Int32.Parse (s, Helpers.InvariantCulture);
168 string GetString (string variable)
173 string s = hwr.GetServerVariable (variable);
174 return (s == null) ? String.Empty : s;