Merge pull request #3622 from rolfbjarne/remove-stray-file
[mono.git] / mcs / class / System.Web / System.Web / HttpClientCertificate.cs
index 003b70ecebd3a68dac949dda0b9741ea7bff4c5f..40bb542582c7e1d8c68cb0a7b64e3474bc2e8042 100644 (file)
@@ -4,7 +4,7 @@
 // Author:
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2009 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
 
 using System.Collections.Specialized;
 using System.Globalization;
-
-namespace System.Web {
-
-       public class HttpClientCertificate : NameValueCollection {
-
-               private HttpWorkerRequest hwr;
-               private bool present;
-               private string issuer;
-               private DateTime from;
-               private DateTime until;
-
+using System.Security.Permissions;
+using System.Web.Util;
+
+namespace System.Web
+{
+       // CAS
+       [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       public class HttpClientCertificate : NameValueCollection
+       {
+               HttpWorkerRequest hwr;
+               int flags;
+               DateTime from;
+               DateTime until;
 
                internal HttpClientCertificate (HttpWorkerRequest hwr)
                {
-#if NET_2_0
                        // we don't check hwr for null so we end up throwing a 
                        // NullReferenceException just like MS implementation
                        // if the public ctor for HttpRequest is used
-#else
-                       if (hwr == null)
-                               throw new ArgumentNullException ("hwr");
-#endif
                        this.hwr = hwr;
-                       issuer = hwr.GetServerVariable ("CERT_ISSUER");
-                       if (issuer == null) {
-                               issuer = String.Empty;
-                               present = false;
-                       } else {
-                               present = (issuer.Length > 0);
-                       }
-
-                       if (present) {
+                       flags = GetIntNoPresense ("CERT_FLAGS");
+                       if (IsPresent) {
                                from = hwr.GetClientCertificateValidFrom ();
                                until = hwr.GetClientCertificateValidUntil ();
                        } else {
@@ -68,7 +59,6 @@ namespace System.Web {
                        }
                }
 
-
                public byte[] BinaryIssuer {
                        get { return hwr.GetClientCertificateBinaryIssuer (); }
                }
@@ -86,24 +76,23 @@ namespace System.Web {
                }
 
                public int Flags {
-                       get { return GetInt ("CERT_FLAGS"); }
+                       get { return flags; }
                }
 
                public bool IsPresent {
-                       get { return present; }
+                       get { return ((flags & 0x01) == 0x01); }
                }
 
                public string Issuer {
-                       get { return issuer; }
+                       get { return GetString ("CERT_ISSUER"); }
                }
 
-               [MonoTODO ("validate certificate")]
                public bool IsValid {
                        get {
-                               if (!present)
-                                       return true;
-                               // TODO - more complex stuff here
-                               return false;
+                               if (!IsPresent)
+                                       return true; // lame but true
+                               // low on details
+                               return ((flags & 0x02) == 0x00);
                        }
                }
 
@@ -153,27 +142,32 @@ namespace System.Web {
                        }
                }
 
-               // private stuff
-               private int GetInt (string variable)
+               // stuff
+               int GetInt (string variable)
                {
-                       if (!present)
+                       if (!IsPresent)
                                return 0;
 
+                       return GetIntNoPresense (variable);
+               }
+
+               int GetIntNoPresense (string variable)
+               {
                        string s = hwr.GetServerVariable (variable);
                        if (s == null)
                                return 0;
 
                        try {
-                               return Int32.Parse (s, CultureInfo.InvariantCulture);
+                               return Int32.Parse (s, Helpers.InvariantCulture);
                        }
                        catch {
                                return 0;
                        }
                }
 
-               private string GetString (string variable)
+               string GetString (string variable)
                {
-                       if (!present)
+                       if (!IsPresent)
                                return String.Empty;
 
                        string s = hwr.GetServerVariable (variable);