[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Security/Policy UrlPar
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Security/Policy UrlParser.cs, NONE, 1.1 ApplicationDirectory.cs, 1.3, 1.4 ApplicationDirectoryMembershipCondition.cs, 1.2, 1.3 Hash.cs, 1.4, 1.5 HashMembershipCondition.cs, 1.3, 1.4 PermissionRequestEvidence.cs, 1.2, 1.3 PolicyStatement.cs, 1.2, 1.3 Publisher.cs, 1.3, 1.4 PublisherMembershipCondition.cs, 1.3, 1.4 Site.cs, 1.2, 1.3 SiteMembershipCondition.cs, 1.2, 1.3 StrongName.cs, 1.2, 1.3 StrongNameMembershipCondition.cs, 1.2, 1.3 Url.cs, 1.2, 1.3 UrlMembershipCondition.cs, 1.2, 1.3 ZoneMembershipCondition.cs, 1.2, 1.3 |
Date: |
Thu, 21 Aug 2003 01:37:39 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy
In directory subversions:/tmp/cvs-serv2842/runtime/System/Security/Policy
Modified Files:
ApplicationDirectory.cs
ApplicationDirectoryMembershipCondition.cs Hash.cs
HashMembershipCondition.cs PermissionRequestEvidence.cs
PolicyStatement.cs Publisher.cs
PublisherMembershipCondition.cs Site.cs
SiteMembershipCondition.cs StrongName.cs
StrongNameMembershipCondition.cs Url.cs
UrlMembershipCondition.cs ZoneMembershipCondition.cs
Added Files:
UrlParser.cs
Log Message:
Implement missing TODO's in "System.Security.Policy".
--- NEW FILE ---
/*
* UrlParser.cs - Implementation of the
* "System.Security.Policy.UrlParser" class.
*
* Copyright (C) 2003 Southern Storm Software, Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
namespace System.Security.Policy
{
#if CONFIG_POLICY_OBJECTS
internal sealed class UrlParser
{
// Internal state.
private String url;
private String scheme;
private String userInfo;
private String host;
private String port;
private String rest;
// Constructor.
public UrlParser(String url)
{
if(url == null)
{
throw new ArgumentNullException("url");
}
this.url = url;
if(!Parse(url))
{
throw new
ArgumentException(_("Arg_InvalidURL"));
}
}
// Parse a URL into its constituent components.
private bool Parse(String url)
{
int index, index2;
// Extract the scheme.
index = url.IndexOf(':');
if(index == -1)
{
return false;
}
scheme = url.Substring(0, index);
if(scheme.IndexOf('/') != -1)
{
return false;
}
// Split the URL between the "host" and "rest"
portions.
if((index + 2) < url.Length &&
url[index + 1] == '/' && url[index + 2] ==
'/')
{
url = url.Substring(index + 3);
index = url.IndexOf('/');
if(index != -1)
{
rest = url.Substring(index);
host = url.Substring(0, index);
}
else
{
host = url;
rest = "/";
}
}
else
{
// Probably something like "mailto:xxx".
host = String.Empty;
rest = url.Substring(index + 1);
}
// Pull out the port number and the user login
information.
index = host.LastIndexOf(':');
if(index != -1)
{
port = host.Substring(index + 1);
host = host.Substring(0, index);
}
else
{
port = String.Empty;
}
index = host.LastIndexOf('@');
if(index != -1)
{
userInfo = host.Substring(0, index);
host = host.Substring(index + 1);
}
else
{
userInfo = String.Empty;
}
return true;
}
// Get the URL components.
public String URL
{
get
{
return url;
}
}
public String Scheme
{
get
{
return scheme;
}
}
public String UserInfo
{
get
{
return userInfo;
}
}
public String Host
{
get
{
return host;
}
}
public String Port
{
get
{
return port;
}
}
public String Rest
{
get
{
return rest;
}
}
// Determine if we have a host subset match.
public static bool HostMatches(String pattern, String actual)
{
if(pattern.Length > actual.Length)
{
return false;
}
if(String.Compare(pattern, 0, actual,
actual.Length
- pattern.Length,
pattern.Length, true) != 0)
{
return false;
}
if(pattern.Length == actual.Length)
{
return true;
}
else
{
return (actual[actual.Length -
pattern.Length - 1] == '.');
}
}
// Determine if we have a URL subset match.
public bool Matches(UrlParser url)
{
// Compare the scheme and host information.
if(String.Compare(scheme, url.Scheme, true) !=
0)
{
return false;
}
if(String.Compare(userInfo, url.UserInfo, true)
!= 0)
{
return false;
}
if(!HostMatches(host, url.Host))
{
return false;
}
if(String.Compare(port, url.Port, true) != 0)
{
return false;
}
// Compare the "rest" fields.
if(rest.EndsWith("*"))
{
String r = rest.Substring(0,
rest.Length - 1);
String ur = url.Rest;
if(r.Length > ur.Length)
{
return false;
}
if(String.Compare(r, 0, ur, 0,
r.Length, true) != 0)
{
return false;
}
}
else
{
if(String.Compare(rest, url.Rest, true)
!= 0)
{
return false;
}
}
return true;
}
}; // class UrlParser
#endif // CONFIG_POLICY_OBJECTS
}; // namespace System.Security.Policy
Index: ApplicationDirectory.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/ApplicationDirectory.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** ApplicationDirectory.cs 29 May 2003 03:12:58 -0000 1.3
--- ApplicationDirectory.cs 21 Aug 2003 05:37:36 -0000 1.4
***************
*** 29,33 ****
{
// Internal state.
! private String name;
// Constructor.
--- 29,33 ----
{
// Internal state.
! internal UrlParser parser;
// Constructor.
***************
*** 38,42 ****
throw new ArgumentNullException("name");
}
! this.name = name;
}
--- 38,42 ----
throw new ArgumentNullException("name");
}
! parser = new UrlParser(name);
}
***************
*** 46,50 ****
get
{
! return name;
}
}
--- 46,50 ----
get
{
! return parser.URL;
}
}
***************
*** 53,57 ****
public Object Copy()
{
! return new ApplicationDirectory(name);
}
--- 53,57 ----
public Object Copy()
{
! return new ApplicationDirectory(parser.URL);
}
***************
*** 62,66 ****
if(other != null)
{
! return (other.name == name);
}
else
--- 62,66 ----
if(other != null)
{
! return (other.parser.URL == parser.URL);
}
else
***************
*** 73,77 ****
public override int GetHashCode()
{
! return name.GetHashCode();
}
--- 73,77 ----
public override int GetHashCode()
{
! return parser.URL.GetHashCode();
}
***************
*** 81,85 ****
return
"<System.Security.Policy.ApplicationDirectory>\n" +
" <Directory>" +
! SecurityElement.Escape(name) +
"</Directory>\n" +
"</System.Security.Policy.ApplicationDirectory>\n";
--- 81,85 ----
return
"<System.Security.Policy.ApplicationDirectory>\n" +
" <Directory>" +
! SecurityElement.Escape(parser.URL) +
"</Directory>\n" +
"</System.Security.Policy.ApplicationDirectory>\n";
Index: ApplicationDirectoryMembershipCondition.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/ApplicationDirectoryMembershipCondition.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ApplicationDirectoryMembershipCondition.cs 29 May 2003 03:12:58 -0000
1.2
--- ApplicationDirectoryMembershipCondition.cs 21 Aug 2003 05:37:36 -0000
1.3
***************
*** 25,28 ****
--- 25,30 ----
#if CONFIG_POLICY_OBJECTS
+ using System.Collections;
+
[Serializable]
public sealed class ApplicationDirectoryMembershipCondition
***************
*** 32,41 ****
public ApplicationDirectoryMembershipCondition() {}
// Implement the IMembership interface.
- [TODO]
public bool Check(Evidence evidence)
{
! // TODO
! return true;
}
public IMembershipCondition Copy()
--- 34,82 ----
public ApplicationDirectoryMembershipCondition() {}
+ // Determine if we have an application directory match.
+ private static bool Match(UrlParser url, String dir)
+ {
+ if(dir.EndsWith("/"))
+ {
+ dir = dir + "*";
+ }
+ else
+ {
+ dir = dir + "/*";
+ }
+ UrlParser parser = new UrlParser(dir);
+ return parser.Matches(url);
+ }
+
// Implement the IMembership interface.
public bool Check(Evidence evidence)
{
! if(evidence == null)
! {
! return false;
! }
! IEnumerator e = evidence.GetHostEnumerator();
! IEnumerator e2;
! while(e.MoveNext())
! {
! ApplicationDirectory appDir =
! (e.Current as
ApplicationDirectory);
! if(appDir != null)
! {
! e2 =
evidence.GetHostEnumerator();
! while(e2.MoveNext())
! {
! Url url = (e2.Current
as Url);
! if(url != null)
! {
!
if(Match(url.parser, appDir.Directory))
! {
! return
true;
! }
! }
! }
! }
! }
! return false;
}
public IMembershipCondition Copy()
Index: Hash.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/Hash.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** Hash.cs 29 May 2003 03:12:58 -0000 1.4
--- Hash.cs 21 Aug 2003 05:37:36 -0000 1.5
***************
*** 28,31 ****
--- 28,32 ----
using System.Runtime.Serialization;
using System.Security.Cryptography;
+ using System.Security.Permissions;
[Serializable]
***************
*** 51,58 ****
}
#if CONFIG_SERIALIZATION
- [TODO]
internal Hash(SerializationInfo info, StreamingContext context)
{
! // TODO
}
#endif
--- 52,62 ----
}
#if CONFIG_SERIALIZATION
internal Hash(SerializationInfo info, StreamingContext context)
{
! if(info == null)
! {
! throw new ArgumentNullException("info");
! }
! dataToHash = (byte[])info.GetValue("RawData",
typeof(byte[]));
}
#endif
***************
*** 84,89 ****
}
! // Generate the hash value for this assembly using a given algorith.
[TODO]
public byte[] GenerateHash(HashAlgorithm hashAlg)
{
--- 88,107 ----
}
! // Get the raw data to be hashed.
[TODO]
+ private byte[] RawData
+ {
+ get
+ {
+ if(dataToHash == null)
+ {
+ // TODO: get the data to be
hashed.
+ throw new
NotSupportedException();
+ }
+ return dataToHash;
+ }
+ }
+
+ // Generate the hash value for this assembly using a given algorith.
public byte[] GenerateHash(HashAlgorithm hashAlg)
{
***************
*** 92,101 ****
throw new
ArgumentNullException("hashAlg");
}
! if(dataToHash == null)
{
! // TODO: get the data to be hashed.
}
hashAlg.Initialize();
! return hashAlg.ComputeHash(dataToHash);
}
--- 110,120 ----
throw new
ArgumentNullException("hashAlg");
}
! byte[] rawData = RawData;
! if(rawData == null)
{
! return null;
}
hashAlg.Initialize();
! return hashAlg.ComputeHash(rawData);
}
***************
*** 103,110 ****
// Implement the ISerialization interface.
- [TODO]
public void GetObjectData(SerializationInfo info, StreamingContext
context)
{
! // TODO
}
--- 122,132 ----
// Implement the ISerialization interface.
public void GetObjectData(SerializationInfo info, StreamingContext
context)
{
! if(info == null)
! {
! throw new ArgumentNullException("info");
! }
! info.AddValue("RawData", RawData,
typeof(byte[]));
}
***************
*** 112,120 ****
// Convert this object into a string.
- [TODO]
public override String ToString()
{
! // TODO
! return null;
}
--- 134,149 ----
// Convert this object into a string.
public override String ToString()
{
! SecurityElement element;
! element = new
SecurityElement("System.Security.Policy.Hash");
! element.AddAttribute("version", "1");
! byte[] rawData = RawData;
! if(rawData != null && rawData.Length != 0)
! {
! element.AddChild(new SecurityElement
! ("RawData",
StrongNamePublicKeyBlob.ToHex(rawData)));
! }
! return element.ToString();
}
Index: HashMembershipCondition.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/HashMembershipCondition.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** HashMembershipCondition.cs 29 May 2003 03:12:58 -0000 1.3
--- HashMembershipCondition.cs 21 Aug 2003 05:37:36 -0000 1.4
***************
*** 25,28 ****
--- 25,30 ----
#if CONFIG_CRYPTO && CONFIG_POLICY_OBJECTS
+ using System.Text;
+ using System.Collections;
using System.Security.Permissions;
using System.Security.Cryptography;
***************
*** 84,92 ****
// Implement the IMembership interface.
- [TODO]
public bool Check(Evidence evidence)
{
! // TODO
! return true;
}
public IMembershipCondition Copy()
--- 86,121 ----
// Implement the IMembership interface.
public bool Check(Evidence evidence)
{
! if(evidence == null)
! {
! return false;
! }
! IEnumerator e = evidence.GetHostEnumerator();
! while(e.MoveNext())
! {
! Hash hash = (e.Current as Hash);
! if(hash != null)
! {
! byte[] computed =
hash.GenerateHash(hashAlg);
! if(computed == null ||
value.Length != computed.Length)
! {
! continue;
! }
! int posn;
! for(posn = 0; posn <
computed.Length; ++posn)
! {
! if(computed[posn] !=
value[posn])
! {
! break;
! }
! }
! if(posn >= computed.Length)
! {
! return true;
! }
! }
! }
! return false;
}
public IMembershipCondition Copy()
***************
*** 123,131 ****
}
}
- [TODO]
public override String ToString()
{
! // TODO
! return null;
}
--- 152,163 ----
}
}
public override String ToString()
{
! StringBuilder builder = new StringBuilder();
! builder.Append("Hash - ");
!
builder.Append(hashAlg.GetType().AssemblyQualifiedName);
! builder.Append(" = ");
!
builder.Append(StrongNamePublicKeyBlob.ToHex(value));
! return builder.ToString();
}
***************
*** 141,154 ****
// Implement the ISecurityPolicyEncodable interface.
- [TODO]
public void FromXml(SecurityElement et, PolicyLevel level)
{
! // TODO
}
- [TODO]
public SecurityElement ToXml(PolicyLevel level)
{
! // TODO
! return null;
}
--- 173,210 ----
// Implement the ISecurityPolicyEncodable interface.
public void FromXml(SecurityElement et, PolicyLevel level)
{
! if(et == null)
! {
! throw new ArgumentNullException("et");
! }
! if(et.Tag != "IMembershipCondition")
! {
! throw new
ArgumentException(_("Security_PolicyName"));
! }
! if(et.Attribute("version") != "1")
! {
! throw new
ArgumentException(_("Security_PolicyVersion"));
! }
! String val = et.Attribute("HashValue");
! value = StrongNamePublicKeyBlob.FromHex(val);
! val = et.Attribute("HashAlgorithm");
! hashAlg = HashAlgorithm.Create(val);
}
public SecurityElement ToXml(PolicyLevel level)
{
! SecurityElement element;
! element = new
SecurityElement("IMembershipCondition");
! element.AddAttribute
! ("class",
! SecurityElement.Escape
!
(typeof(HashMembershipCondition).
!
AssemblyQualifiedName));
! element.AddAttribute("version", "1");
! element.AddAttribute
! ("HashValue",
StrongNamePublicKeyBlob.ToHex(value));
! element.AddAttribute
! ("HashAlgorithm",
hashAlg.GetType().FullName);
! return element;
}
Index: PermissionRequestEvidence.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/PermissionRequestEvidence.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** PermissionRequestEvidence.cs 29 May 2003 03:12:58 -0000 1.2
--- PermissionRequestEvidence.cs 21 Aug 2003 05:37:36 -0000 1.3
***************
*** 74,82 ****
// Convert this object into a string.
- [TODO]
public override String ToString()
{
! // TODO
! return null;
}
--- 74,102 ----
// Convert this object into a string.
public override String ToString()
{
! SecurityElement element = new SecurityElement
!
("System.Security.Policy.PermissionRequestEvidence");
! SecurityElement child;
! element.AddAttribute("version", "1");
! if(request != null)
! {
! child = new SecurityElement("Request");
! child.AddChild(request.ToXml());
! element.AddChild(child);
! }
! if(optional != null)
! {
! child = new SecurityElement("Optional");
! child.AddChild(optional.ToXml());
! element.AddChild(child);
! }
! if(denied != null)
! {
! child = new SecurityElement("Denied");
! child.AddChild(denied.ToXml());
! element.AddChild(child);
! }
! return element.ToString();
}
Index: PolicyStatement.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/PolicyStatement.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** PolicyStatement.cs 29 May 2003 03:12:58 -0000 1.2
--- PolicyStatement.cs 21 Aug 2003 05:37:36 -0000 1.3
***************
*** 31,34 ****
--- 31,36 ----
#else // CONFIG_PERMISSIONS
+ using System.Security.Permissions;
+
[Serializable]
public sealed class PolicyStatement
***************
*** 66,71 ****
get
{
! // TODO
! return null;
}
}
--- 68,81 ----
get
{
! switch(attributes &
PolicyStatementAttribute.All)
! {
! case
PolicyStatementAttribute.Exclusive:
! return "Exclusive";
! case
PolicyStatementAttribute.LevelFinal:
! return "LevelFinal";
! case
PolicyStatementAttribute.All:
! return "Exclusive
LevelFinal";
! }
! return String.Empty;
}
}
***************
*** 115,119 ****
(_("Security_PolicyVersion"));
}
! // TODO
}
public SecurityElement ToXml(PolicyLevel level)
--- 125,183 ----
(_("Security_PolicyVersion"));
}
! String value = et.Attribute("Attributes");
! if(value != null)
! {
! attributes = (PolicyStatementAttribute)
!
Enum.Parse(typeof(PolicyStatementAttribute), value);
! }
! else
! {
! attributes =
PolicyStatementAttribute.Nothing;
! }
! permSet = null;
! if(level != null)
! {
! String name =
et.Attribute("PermissionSetName");
! if(name != null)
! {
! permSet =
level.GetNamedPermissionSet(value);
! if(permSet == null)
! {
! permSet = new
PermissionSet(PermissionState.None);
! }
! }
! }
! if(permSet == null)
! {
! SecurityElement child;
! child =
et.SearchForChildByTag("PermissionSet");
! if(child != null)
! {
! String permClass;
! permClass =
child.Attribute("class");
! if(permClass != null &&
!
permClass.IndexOf("NamedPermissionSet") != -1)
! {
! permSet = new
NamedPermissionSet
! ("DefaultName",
PermissionState.None);
! }
! else
! {
! permSet = new
PermissionSet(PermissionState.None);
! }
! try
! {
! permSet.FromXml(child);
! }
! catch(Exception)
! {
! // Ignore errors during
set loading.
! }
! }
! }
! if(permSet == null)
! {
! permSet = new
PermissionSet(PermissionState.None);
! }
}
public SecurityElement ToXml(PolicyLevel level)
***************
*** 126,130 ****
AssemblyQualifiedName));
element.AddAttribute("version", "1");
! // TODO
return element;
}
--- 190,219 ----
AssemblyQualifiedName));
element.AddAttribute("version", "1");
! if(attributes !=
PolicyStatementAttribute.Nothing)
! {
! element.AddAttribute("Attributes",
attributes.ToString());
! }
! if(permSet != null)
! {
! NamedPermissionSet namedSet;
! namedSet = (permSet as
NamedPermissionSet);
! if(namedSet != null)
! {
! if(level != null &&
!
level.GetNamedPermissionSet(namedSet.Name) != null)
! {
! element.AddAttribute
!
("PermissionSetName", namedSet.Name);
! }
! else
! {
!
element.AddChild(permSet.ToXml());
! }
! }
! else
! {
!
element.AddChild(permSet.ToXml());
! }
! }
return element;
}
Index: Publisher.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/Publisher.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** Publisher.cs 29 May 2003 03:12:58 -0000 1.3
--- Publisher.cs 21 Aug 2003 05:37:36 -0000 1.4
***************
*** 93,101 ****
// Convert this object into a string.
- [TODO]
public override String ToString()
{
! // TODO
! return cert.ToString();
}
--- 93,106 ----
// Convert this object into a string.
public override String ToString()
{
! SecurityElement element = new SecurityElement
! ("System.Security.Policy.Publisher");
! SecurityElement child;
! element.AddAttribute("version", "1");
! child = new SecurityElement
! ("X509v3Certificate",
cert.GetRawCertDataString());
! element.AddChild(child);
! return element.ToString();
}
Index: PublisherMembershipCondition.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/PublisherMembershipCondition.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** PublisherMembershipCondition.cs 29 May 2003 03:12:58 -0000 1.3
--- PublisherMembershipCondition.cs 21 Aug 2003 05:37:36 -0000 1.4
***************
*** 25,28 ****
--- 25,29 ----
#if CONFIG_X509_CERTIFICATES && CONFIG_POLICY_OBJECTS
+ using System.Collections;
using System.Security.Permissions;
using System.Security.Cryptography.X509Certificates;
***************
*** 63,71 ****
// Implement the IMembership interface.
- [TODO]
public bool Check(Evidence evidence)
{
! // TODO
! return true;
}
public IMembershipCondition Copy()
--- 64,84 ----
// Implement the IMembership interface.
public bool Check(Evidence evidence)
{
! if(evidence == null)
! {
! return false;
! }
! IEnumerator e = evidence.GetHostEnumerator();
! while(e.MoveNext())
! {
! Publisher publisher = (e.Current as
Publisher);
! if(publisher != null &&
!
publisher.Certificate.Equals(certificate))
! {
! return true;
! }
! }
! return false;
}
public IMembershipCondition Copy()
***************
*** 86,94 ****
}
}
- [TODO]
public override String ToString()
{
! // TODO
! return null;
}
--- 99,105 ----
}
}
public override String ToString()
{
! return "Publisher - " +
certificate.GetRawCertDataString();
}
***************
*** 104,117 ****
// Implement the ISecurityPolicyEncodable interface.
- [TODO]
public void FromXml(SecurityElement et, PolicyLevel level)
{
! // TODO
}
- [TODO]
public SecurityElement ToXml(PolicyLevel level)
{
! // TODO
! return null;
}
--- 115,149 ----
// Implement the ISecurityPolicyEncodable interface.
public void FromXml(SecurityElement et, PolicyLevel level)
{
! if(et == null)
! {
! throw new ArgumentNullException("et");
! }
! if(et.Tag != "IMembershipCondition")
! {
! throw new
ArgumentException(_("Security_PolicyName"));
! }
! if(et.Attribute("version") != "1")
! {
! throw new
ArgumentException(_("Security_PolicyVersion"));
! }
! String value = et.Attribute("X509Certificate");
! certificate = new X509Certificate
!
(StrongNamePublicKeyBlob.FromHex(value));
}
public SecurityElement ToXml(PolicyLevel level)
{
! SecurityElement element;
! element = new
SecurityElement("IMembershipCondition");
! element.AddAttribute
! ("class",
! SecurityElement.Escape
!
(typeof(PublisherMembershipCondition).
!
AssemblyQualifiedName));
! element.AddAttribute("version", "1");
! element.AddAttribute
! ("X509Certificate",
certificate.GetRawCertDataString());
! return element;
}
Index: Site.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/Site.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Site.cs 29 May 2003 03:12:58 -0000 1.2
--- Site.cs 21 Aug 2003 05:37:36 -0000 1.3
***************
*** 64,73 ****
public static Site CreateFromUrl(String url)
{
! if(url == null)
! {
! throw new ArgumentNullException("url");
! }
! // TODO
! return null;
}
--- 64,69 ----
public static Site CreateFromUrl(String url)
{
! UrlParser parser = new UrlParser(url);
! return new Site(parser.Host);
}
***************
*** 103,111 ****
// Convert this object into a string.
- [TODO]
public override String ToString()
{
! // TODO
! return name;
}
--- 99,111 ----
// Convert this object into a string.
public override String ToString()
{
! SecurityElement element = new SecurityElement
! ("System.Security.Policy.Site");
! SecurityElement child;
! element.AddAttribute("version", "1");
! child = new SecurityElement("Name", name);
! element.AddChild(child);
! return element.ToString();
}
Index: SiteMembershipCondition.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/SiteMembershipCondition.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** SiteMembershipCondition.cs 29 May 2003 03:12:58 -0000 1.2
--- SiteMembershipCondition.cs 21 Aug 2003 05:37:36 -0000 1.3
***************
*** 25,28 ****
--- 25,29 ----
#if CONFIG_POLICY_OBJECTS
+ using System.Collections;
using System.Security.Permissions;
***************
*** 62,70 ****
// Implement the IMembership interface.
- [TODO]
public bool Check(Evidence evidence)
{
! // TODO
! return true;
}
public IMembershipCondition Copy()
--- 63,85 ----
// Implement the IMembership interface.
public bool Check(Evidence evidence)
{
! if(evidence == null)
! {
! return false;
! }
! IEnumerator e = evidence.GetHostEnumerator();
! while(e.MoveNext())
! {
! Site s = (e.Current as Site);
! if(s != null)
! {
! if(UrlParser.HostMatches(site,
s.Name))
! {
! return true;
! }
! }
! }
! return false;
}
public IMembershipCondition Copy()
***************
*** 85,93 ****
}
}
- [TODO]
public override String ToString()
{
! // TODO
! return null;
}
--- 100,106 ----
}
}
public override String ToString()
{
! return "Site - " + site;
}
***************
*** 103,116 ****
// Implement the ISecurityPolicyEncodable interface.
- [TODO]
public void FromXml(SecurityElement et, PolicyLevel level)
{
! // TODO
}
- [TODO]
public SecurityElement ToXml(PolicyLevel level)
{
! // TODO
! return null;
}
--- 116,154 ----
// Implement the ISecurityPolicyEncodable interface.
public void FromXml(SecurityElement et, PolicyLevel level)
{
! if(et == null)
! {
! throw new ArgumentNullException("et");
! }
! if(et.Tag != "IMembershipCondition")
! {
! throw new
ArgumentException(_("Security_PolicyName"));
! }
! if(et.Attribute("version") != "1")
! {
! throw new
ArgumentException(_("Security_PolicyVersion"));
! }
! String value = et.Attribute("Site");
! if(value != null)
! {
! site = value;
! }
! else
! {
! throw new
ArgumentException(_("Arg_InvalidSite"));
! }
}
public SecurityElement ToXml(PolicyLevel level)
{
! SecurityElement element;
! element = new
SecurityElement("IMembershipCondition");
! element.AddAttribute
! ("class",
!
SecurityElement.Escape(typeof(SiteMembershipCondition).
!
AssemblyQualifiedName));
! element.AddAttribute("version", "1");
! element.AddAttribute("Site", site);
! return element;
}
Index: StrongName.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/StrongName.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** StrongName.cs 29 May 2003 03:12:58 -0000 1.2
--- StrongName.cs 21 Aug 2003 05:37:36 -0000 1.3
***************
*** 117,129 ****
public override int GetHashCode()
{
! return name.GetHashCode();
}
// Convert this object into a string.
- [TODO]
public override String ToString()
{
! // TODO
! return null;
}
--- 117,132 ----
public override int GetHashCode()
{
! return blob.GetHashCode();
}
// Convert this object into a string.
public override String ToString()
{
! SecurityElement element = new
SecurityElement("StrongName");
! element.AddAttribute("version", "1");
! element.AddAttribute("Key", blob.ToString());
! element.AddAttribute("Name", name);
! element.AddAttribute("Version",
version.ToString());
! return element.ToString();
}
Index: StrongNameMembershipCondition.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/StrongNameMembershipCondition.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** StrongNameMembershipCondition.cs 29 May 2003 03:12:58 -0000 1.2
--- StrongNameMembershipCondition.cs 21 Aug 2003 05:37:36 -0000 1.3
***************
*** 25,28 ****
--- 25,30 ----
#if CONFIG_POLICY_OBJECTS
+ using System.Text;
+ using System.Collections;
using System.Security.Permissions;
***************
*** 89,97 ****
// Implement the IMembership interface.
- [TODO]
public bool Check(Evidence evidence)
{
! // TODO
! return true;
}
public IMembershipCondition Copy()
--- 91,115 ----
// Implement the IMembership interface.
public bool Check(Evidence evidence)
{
! if(evidence == null)
! {
! return false;
! }
! IEnumerator e = evidence.GetHostEnumerator();
! while(e.MoveNext())
! {
! StrongName sn = (e.Current as
StrongName);
! if(sn != null)
! {
! if(sn.PublicKey.Equals(blob) &&
! sn.Name == name &&
! sn.Version.Equals(version))
! {
! return true;
! }
! }
! }
! return false;
}
public IMembershipCondition Copy()
***************
*** 105,111 ****
if(other != null)
{
! return (other.blob.Equals(blob) &&
! other.name == name &&
! other.version ==
version);
}
else
--- 123,141 ----
if(other != null)
{
! if(other.blob.Equals(blob) &&
other.name == name)
! {
! if(other.version == null)
! {
! return (version ==
null);
! }
! else
! {
! return
other.version.Equals(version);
! }
! }
! else
! {
! return false;
! }
}
else
***************
*** 114,122 ****
}
}
- [TODO]
public override String ToString()
{
! // TODO
! return null;
}
--- 144,163 ----
}
}
public override String ToString()
{
! StringBuilder builder = new StringBuilder();
! builder.Append("StrongName - ");
! builder.Append(blob.ToString());
! if(name != null)
! {
! builder.Append(" name = ");
! builder.Append(name);
! }
! if(version != null)
! {
! builder.Append(" version = ");
! builder.Append(version.ToString());
! }
! return builder.ToString();
}
***************
*** 132,145 ****
// Implement the ISecurityPolicyEncodable interface.
- [TODO]
public void FromXml(SecurityElement et, PolicyLevel level)
{
! // TODO
}
- [TODO]
public SecurityElement ToXml(PolicyLevel level)
{
! // TODO
! return null;
}
--- 173,230 ----
// Implement the ISecurityPolicyEncodable interface.
public void FromXml(SecurityElement et, PolicyLevel level)
{
! if(et == null)
! {
! throw new ArgumentNullException("et");
! }
! if(et.Tag != "IMembershipCondition")
! {
! throw new
ArgumentException(_("Security_PolicyName"));
! }
! if(et.Attribute("version") != "1")
! {
! throw new
ArgumentException(_("Security_PolicyVersion"));
! }
! String value = et.Attribute("PublicKey");
! if(value != null)
! {
! blob = new
StrongNamePublicKeyBlob(value);
! }
! else
! {
! throw new
ArgumentException(_("Arg_PublicKeyBlob"));
! }
! name = et.Attribute("Name");
! value = et.Attribute("AssemblyVersion");
! if(value != null)
! {
! version = new Version(value);
! }
! else
! {
! version = null;
! }
}
public SecurityElement ToXml(PolicyLevel level)
{
! SecurityElement element;
! element = new
SecurityElement("IMembershipCondition");
! element.AddAttribute
! ("class",
! SecurityElement.Escape
!
(typeof(StrongNameMembershipCondition).
!
AssemblyQualifiedName));
! element.AddAttribute("version", "1");
! element.AddAttribute("PublicKey",
blob.ToString());
! if(name != null)
! {
! element.AddAttribute("Name", name);
! }
! if(version != null)
! {
! element.AddAttribute("AssemblyVersion",
version.ToString());
! }
! return element;
}
Index: Url.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/Url.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** Url.cs 29 May 2003 03:12:58 -0000 1.2
--- Url.cs 21 Aug 2003 05:37:36 -0000 1.3
***************
*** 34,38 ****
{
// Internal state.
! private String name;
// Constructor.
--- 34,38 ----
{
// Internal state.
! internal UrlParser parser;
// Constructor.
***************
*** 43,47 ****
throw new ArgumentNullException("name");
}
! this.name = name;
}
--- 43,47 ----
throw new ArgumentNullException("name");
}
! parser = new UrlParser(name);
}
***************
*** 51,55 ****
get
{
! return name;
}
}
--- 51,55 ----
get
{
! return parser.URL;
}
}
***************
*** 58,62 ****
public Object Copy()
{
! return new Url(name);
}
--- 58,62 ----
public Object Copy()
{
! return new Url(parser.URL);
}
***************
*** 66,70 ****
public IPermission CreateIdentityPermission(Evidence evidence)
{
! return new UrlIdentityPermission(name);
}
--- 66,70 ----
public IPermission CreateIdentityPermission(Evidence evidence)
{
! return new UrlIdentityPermission(parser.URL);
}
***************
*** 77,81 ****
if(other != null)
{
! return (other.name == name);
}
else
--- 77,81 ----
if(other != null)
{
! return (other.parser.URL == parser.URL);
}
else
***************
*** 88,100 ****
public override int GetHashCode()
{
! return name.GetHashCode();
}
// Convert this object into a string.
- [TODO]
public override String ToString()
{
! // TODO
! return name;
}
--- 88,104 ----
public override int GetHashCode()
{
! return parser.URL.GetHashCode();
}
// Convert this object into a string.
public override String ToString()
{
! SecurityElement element = new SecurityElement
! ("System.Security.Policy.Url");
! SecurityElement child;
! element.AddAttribute("version", "1");
! child = new SecurityElement("Url", parser.URL);
! element.AddChild(child);
! return element.ToString();
}
Index: UrlMembershipCondition.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/UrlMembershipCondition.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** UrlMembershipCondition.cs 29 May 2003 03:12:58 -0000 1.2
--- UrlMembershipCondition.cs 21 Aug 2003 05:37:36 -0000 1.3
***************
*** 25,28 ****
--- 25,29 ----
#if CONFIG_POLICY_OBJECTS
+ using System.Collections;
using System.Security.Permissions;
***************
*** 32,36 ****
{
// Internal state.
! private String url;
// Constructor.
--- 33,37 ----
{
// Internal state.
! private UrlParser parser;
// Constructor.
***************
*** 41,45 ****
throw new ArgumentNullException("url");
}
! this.url = url;
}
--- 42,46 ----
throw new ArgumentNullException("url");
}
! parser = new UrlParser(url);
}
***************
*** 49,53 ****
get
{
! return url;
}
set
--- 50,54 ----
get
{
! return parser.URL;
}
set
***************
*** 57,74 ****
throw new
ArgumentNullException("value");
}
! url = value;
}
}
// Implement the IMembership interface.
- [TODO]
public bool Check(Evidence evidence)
{
! // TODO
! return true;
}
public IMembershipCondition Copy()
{
! return new UrlMembershipCondition(url);
}
public override bool Equals(Object obj)
--- 58,89 ----
throw new
ArgumentNullException("value");
}
! parser = new UrlParser(value);
}
}
// Implement the IMembership interface.
public bool Check(Evidence evidence)
{
! if(evidence == null)
! {
! return false;
! }
! IEnumerator e = evidence.GetHostEnumerator();
! while(e.MoveNext())
! {
! Url url = (e.Current as Url);
! if(url != null)
! {
! if(parser.Matches(url.parser))
! {
! return true;
! }
! }
! }
! return false;
}
public IMembershipCondition Copy()
{
! return new UrlMembershipCondition(parser.URL);
}
public override bool Equals(Object obj)
***************
*** 78,82 ****
if(other != null)
{
! return (other.url == url);
}
else
--- 93,97 ----
if(other != null)
{
! return (other.parser.URL == parser.URL);
}
else
***************
*** 85,93 ****
}
}
- [TODO]
public override String ToString()
{
! // TODO
! return null;
}
--- 100,106 ----
}
}
public override String ToString()
{
! return "Url - " + parser.URL;
}
***************
*** 103,116 ****
// Implement the ISecurityPolicyEncodable interface.
- [TODO]
public void FromXml(SecurityElement et, PolicyLevel level)
{
! // TODO
}
- [TODO]
public SecurityElement ToXml(PolicyLevel level)
{
! // TODO
! return null;
}
--- 116,154 ----
// Implement the ISecurityPolicyEncodable interface.
public void FromXml(SecurityElement et, PolicyLevel level)
{
! if(et == null)
! {
! throw new ArgumentNullException("et");
! }
! if(et.Tag != "IMembershipCondition")
! {
! throw new
ArgumentException(_("Security_PolicyName"));
! }
! if(et.Attribute("version") != "1")
! {
! throw new
ArgumentException(_("Security_PolicyVersion"));
! }
! String value = et.Attribute("Url");
! if(value != null)
! {
! parser = new UrlParser(value);
! }
! else
! {
! throw new
ArgumentException(_("Arg_InvalidURL"));
! }
}
public SecurityElement ToXml(PolicyLevel level)
{
! SecurityElement element;
! element = new
SecurityElement("IMembershipCondition");
! element.AddAttribute
! ("class",
!
SecurityElement.Escape(typeof(UrlMembershipCondition).
!
AssemblyQualifiedName));
! element.AddAttribute("version", "1");
! element.AddAttribute("Url", parser.URL);
! return element;
}
***************
*** 118,122 ****
public override int GetHashCode()
{
! return url.GetHashCode();
}
--- 156,160 ----
public override int GetHashCode()
{
! return parser.URL.GetHashCode();
}
Index: ZoneMembershipCondition.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Security/Policy/ZoneMembershipCondition.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ZoneMembershipCondition.cs 29 May 2003 03:12:58 -0000 1.2
--- ZoneMembershipCondition.cs 21 Aug 2003 05:37:36 -0000 1.3
***************
*** 25,28 ****
--- 25,29 ----
#if CONFIG_POLICY_OBJECTS
+ using System.Collections;
using System.Security.Permissions;
***************
*** 37,40 ****
--- 38,46 ----
public ZoneMembershipCondition(SecurityZone zone)
{
+ if(zone < SecurityZone.MyComputer ||
+ zone > SecurityZone.Untrusted)
+ {
+ throw new
ArgumentException(_("Arg_SecurityZone"));
+ }
this.zone = zone;
}
***************
*** 49,52 ****
--- 55,63 ----
set
{
+ if(zone < SecurityZone.MyComputer ||
+ zone > SecurityZone.Untrusted)
+ {
+ throw new
ArgumentException(_("Arg_SecurityZone"));
+ }
zone = value;
}
***************
*** 54,62 ****
// Implement the IMembership interface.
- [TODO]
public bool Check(Evidence evidence)
{
! // TODO
! return true;
}
public IMembershipCondition Copy()
--- 65,84 ----
// Implement the IMembership interface.
public bool Check(Evidence evidence)
{
! if(evidence == null)
! {
! return false;
! }
! IEnumerator e = evidence.GetHostEnumerator();
! while(e.MoveNext())
! {
! Zone z = (e.Current as Zone);
! if(z != null && z.SecurityZone == zone)
! {
! return true;
! }
! }
! return false;
}
public IMembershipCondition Copy()
***************
*** 77,85 ****
}
}
- [TODO]
public override String ToString()
{
! // TODO
! return null;
}
--- 99,105 ----
}
}
public override String ToString()
{
! return "Zone - " + zone.ToString();
}
***************
*** 95,108 ****
// Implement the ISecurityPolicyEncodable interface.
- [TODO]
public void FromXml(SecurityElement et, PolicyLevel level)
{
! // TODO
}
- [TODO]
public SecurityElement ToXml(PolicyLevel level)
{
! // TODO
! return null;
}
--- 115,154 ----
// Implement the ISecurityPolicyEncodable interface.
public void FromXml(SecurityElement et, PolicyLevel level)
{
! if(et == null)
! {
! throw new ArgumentNullException("et");
! }
! if(et.Tag != "IMembershipCondition")
! {
! throw new
ArgumentException(_("Security_PolicyName"));
! }
! if(et.Attribute("version") != "1")
! {
! throw new
ArgumentException(_("Security_PolicyVersion"));
! }
! String value = et.Attribute("Zone");
! if(value != null)
! {
! zone = (SecurityZone)
!
Enum.Parse(typeof(SecurityZone), value);
! }
! else
! {
! throw new
ArgumentException(_("Arg_SecurityZone"));
! }
}
public SecurityElement ToXml(PolicyLevel level)
{
! SecurityElement element;
! element = new
SecurityElement("IMembershipCondition");
! element.AddAttribute
! ("class",
!
SecurityElement.Escape(typeof(ZoneMembershipCondition).
!
AssemblyQualifiedName));
! element.AddAttribute("version", "1");
! element.AddAttribute("Zone", zone.ToString());
! return element;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Security/Policy UrlParser.cs, NONE, 1.1 ApplicationDirectory.cs, 1.3, 1.4 ApplicationDirectoryMembershipCondition.cs, 1.2, 1.3 Hash.cs, 1.4, 1.5 HashMembershipCondition.cs, 1.3, 1.4 PermissionRequestEvidence.cs, 1.2, 1.3 PolicyStatement.cs, 1.2, 1.3 Publisher.cs, 1.3, 1.4 PublisherMembershipCondition.cs, 1.3, 1.4 Site.cs, 1.2, 1.3 SiteMembershipCondition.cs, 1.2, 1.3 StrongName.cs, 1.2, 1.3 StrongNameMembershipCondition.cs, 1.2, 1.3 Url.cs, 1.2, 1.3 UrlMembershipCondition.cs, 1.2, 1.3 ZoneMembershipCondition.cs, 1.2, 1.3,
Rhys Weatherley <address@hidden> <=