// 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 {
}
}
-
public byte[] BinaryIssuer {
get { return hwr.GetClientCertificateBinaryIssuer (); }
}
}
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);
}
}
}
}
- // 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);