本文整理汇总了C#中System.Security.Policy.Evidence.AddHostEvidence方法的典型用法代码示例。如果您正苦于以下问题:C# Evidence.AddHostEvidence方法的具体用法?C# Evidence.AddHostEvidence怎么用?C# Evidence.AddHostEvidence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Policy.Evidence
的用法示例。
在下文中一共展示了Evidence.AddHostEvidence方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateEvidenceForUrl
public static Evidence CreateEvidenceForUrl(string securityUrl) {
#if !DISABLE_CAS_USE
Evidence evidence = new Evidence();
if (securityUrl != null && securityUrl.Length > 0) {
evidence.AddHostEvidence(new Url(securityUrl));
evidence.AddHostEvidence(Zone.CreateFromUrl(securityUrl));
Uri uri = new Uri(securityUrl, UriKind.RelativeOrAbsolute);
if (uri.IsAbsoluteUri && !uri.IsFile) {
evidence.AddHostEvidence(Site.CreateFromUrl(securityUrl));
}
// Allow same directory access for UNCs (SQLBUDT 394535)
if (uri.IsAbsoluteUri && uri.IsUnc) {
string uncDir = System.IO.Path.GetDirectoryName(uri.LocalPath);
if (uncDir != null && uncDir.Length != 0) {
evidence.AddHostEvidence(new UncDirectory(uncDir));
}
}
}
return evidence;
#else
return null;
#endif
}
示例2: Arrange
protected override void Arrange()
{
base.Arrange();
var fullyTrustedAssemblies = this.GetFullyTrustedAssemblies().ToArray();
var unsignedAssemblies = fullyTrustedAssemblies.Where(sn => sn.PublicKey.ToString() == "");
if (unsignedAssemblies.Any())
{
Assert.Inconclusive("Full trust assemblies must be signed. This test will be ignored. Unsigned assemblies: " + unsignedAssemblies.Aggregate("", (a, sn) => a + sn.Name + " "));
}
var evidence = new Evidence();
evidence.AddHostEvidence(new Zone(SecurityZone.Intranet));
var set = SecurityManager.GetStandardSandbox(evidence);
this.AddPermissions(set);
this.appDomain =
AppDomain.CreateDomain(
"partial trust",
null,
AppDomain.CurrentDomain.SetupInformation,
set,
fullyTrustedAssemblies);
this.loggerProxy = ((LoggerProxy)this.appDomain.CreateInstanceAndUnwrap(typeof(LoggerProxy).Assembly.FullName, typeof(LoggerProxy).FullName));
this.loggerProxy.Setup();
}
示例3: SandboxCreator
public static AppDomain SandboxCreator()
{
CheckMono();
#if RAZOR4
Assert.Ignore("IsolatedRazorEngineServiceTestFixture is not tested with razor 4 as it is not signed!");
#endif
#if MONO
// Mono has no AddHostEvidence or GetHostEvidence.
// We do not run the tests anyway.
return null;
#else
Evidence ev = new Evidence();
ev.AddHostEvidence(new Zone(SecurityZone.Internet));
PermissionSet permSet = SecurityManager.GetStandardSandbox(ev);
// We have to load ourself with full trust
StrongName razorEngineAssembly = typeof(RazorEngineService).Assembly.Evidence.GetHostEvidence<StrongName>();
// We have to load Razor with full trust (so all methods are SecurityCritical)
// This is because we apply AllowPartiallyTrustedCallers to RazorEngine, because
// We need the untrusted (transparent) code to be able to inherit TemplateBase.
// Because in the normal environment/appdomain we run as full trust and the Razor assembly has no security attributes
// it will be completely SecurityCritical.
// This means we have to mark a lot of our members SecurityCritical (which is fine).
// However in the sandbox domain we have partial trust and because razor has no Security attributes that means the
// code will be transparent (this is where we get a lot of exceptions, because we now have different security attributes)
// To work around this we give Razor full trust in the sandbox as well.
StrongName razorAssembly = typeof(RazorTemplateEngine).Assembly.Evidence.GetHostEvidence<StrongName>();
// We trust ourself as well
StrongName testAssembly = typeof(IsolatedRazorEngineServiceTestFixture).Assembly.Evidence.GetHostEvidence<StrongName>();
AppDomainSetup adSetup = new AppDomainSetup();
adSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
AppDomain newDomain = AppDomain.CreateDomain("Sandbox", null, adSetup, permSet, razorEngineAssembly, razorAssembly, testAssembly);
return newDomain;
#endif
}
示例4: CreatePermissionSet
/*!*/
private static PermissionSet CreatePermissionSet()
{
#if CLR2
string name = "Internet";
bool foundName = false;
PermissionSet setIntersection = new PermissionSet(PermissionState.Unrestricted);
// iterate over each policy level
IEnumerator e = SecurityManager.PolicyHierarchy();
while (e.MoveNext()) {
PolicyLevel level = (PolicyLevel)e.Current;
PermissionSet levelSet = level.GetNamedPermissionSet(name);
if (levelSet != null) {
foundName = true;
setIntersection = setIntersection.Intersect(levelSet);
}
}
if (setIntersection == null || !foundName) {
setIntersection = new PermissionSet(PermissionState.None);
} else {
setIntersection = new NamedPermissionSet(name, setIntersection);
}
return setIntersection;
#else
// this functionality is not available on Mono (AddHostEvidence is undefined), use dynamic to resolve it at runtime
dynamic e = new Evidence();
e.AddHostEvidence(new Zone(SecurityZone.Internet));
return SecurityManager.GetStandardSandbox((Evidence)e);
#endif
}
示例5: LoadInAppDomain
protected void LoadInAppDomain(string fullTypeName, ASCOMClient ascomClient)
{
string[] tokens = fullTypeName.Split(new char[] { ',' }, 2);
m_AssemblyName = new AssemblyName(tokens[1]);
var appSetup = new AppDomainSetup()
{
ApplicationName = "OccuRec",
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
};
m_DomainName = string.Format("{0}{1}.v{2}", APP_DOMAIN_PREFIX, m_AssemblyName.Name, m_AssemblyName.Version != null ? m_AssemblyName.Version.ToString() : "XX");
var e = new Evidence();
e.AddHostEvidence(new Zone(SecurityZone.MyComputer));
PermissionSet pset = SecurityManager.GetStandardSandbox(e);
m_HostDomain = AppDomain.CreateDomain(m_DomainName, AppDomain.CurrentDomain.Evidence, appSetup, pset, null);
m_HostDomain.AssemblyResolve += m_HostDomain_AssemblyResolve;
m_HostDomain.ReflectionOnlyAssemblyResolve += m_HostDomain_AssemblyResolve;
m_HostDomain.UnhandledException += m_HostDomain_UnhandledException;
m_HostDomain.DomainUnload += m_HostDomain_DomainUnload;
object obj = m_HostDomain.CreateInstanceAndUnwrap(tokens[1], tokens[0]);
ascomClient.RegisterLifetimeService(obj as MarshalByRefObject);
m_Instance = (IIsolatedDevice)obj;
m_Instance.Initialise(new OccuRecHostDelegate(tokens[0], ascomClient));
}
示例6: AppDomainProxy
/// <summary>
/// Initializes a new instance of the <see cref="AppDomainProxy"/> class.
/// </summary>
AppDomainProxy()
{
var evidence = new Evidence ();
evidence.AddHostEvidence (new Zone (SecurityZone.MyComputer));
var setup = new AppDomainSetup ();
domain = AppDomain.CreateDomain (Guid.NewGuid ().ToString ("N"), evidence, setup);
domain.AssemblyResolve += ResolveAssembly;
}
示例7: CreateSandboxDomain
public AppDomain CreateSandboxDomain(string name, string path, SecurityZone zone)
{
var setup = new AppDomainSetup { ApplicationBase = Common.ApiPath, PrivateBinPath = Path.GetFullPath(path) };
var evidence = new Evidence();
evidence.AddHostEvidence(new Zone(zone));
var permissions = SecurityManager.GetStandardSandbox(evidence);
var strongName = typeof(ClientService).Assembly.Evidence.GetHostEvidence<StrongName>();
return AppDomain.CreateDomain(name, null, setup);
}
示例8: RunScenario
private static void RunScenario(SecurityZone zone, bool fullyTrustEventSource, bool grantUnmanagedCodePermission)
{
Console.Write("Running scenario for zone '{0}', fully trusted EventSource {1}, unmanaged permission {2}: ", zone, fullyTrustEventSource, grantUnmanagedCodePermission);
var evidence = new Evidence();
evidence.AddHostEvidence(new Zone(zone));
var permissionSet = SecurityManager.GetStandardSandbox(evidence);
if (!permissionSet.IsUnrestricted() && grantUnmanagedCodePermission)
{
permissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
}
var eventSourceAssemblyName = typeof(EventSource).Assembly.GetName();
var fullyTrustedAssemblies =
fullyTrustEventSource
? new StrongName[]
{
new StrongName(new StrongNamePublicKeyBlob(eventSourceAssemblyName.GetPublicKey()), eventSourceAssemblyName.Name, eventSourceAssemblyName.Version)
}
: new StrongName[0];
var info = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory };
info.ApplicationTrust = new ApplicationTrust(permissionSet, fullyTrustedAssemblies);
var appDomain =
AppDomain.CreateDomain(
"partial trust",
evidence,
info);
try
{
var tester = (LttADEventSourceTester)appDomain
.CreateInstanceAndUnwrap(
typeof(LttADEventSourceTester).Assembly.GetName().Name,
typeof(LttADEventSourceTester).FullName);
tester.IsEventSourceAssmFullyTrusted = fullyTrustEventSource;
tester.DoStuff(1);
tester.DoStuff(2);
tester.DoStuff(3);
Assert.IsTrue(tester.IsStateValid, "EventSource ConstructionException as expected");
Console.WriteLine("SUCCESS");
Console.WriteLine();
}
finally
{
AppDomain.Unload(appDomain);
}
Console.WriteLine("==================================================================");
Console.WriteLine();
}
示例9: GetRestrictedPermissions
public override void GetRestrictedPermissions(IInternalConfigRecord configRecord, out PermissionSet permissionSet, out bool isHostReady)
{
string streamName;
bool flag = this.IsFile(configRecord.StreamName);
if (flag)
{
streamName = UrlPath.ConvertFileNameToUrl(configRecord.StreamName);
}
else
{
streamName = configRecord.StreamName;
}
Evidence evidence = new Evidence();
evidence.AddHostEvidence<Url>(new Url(streamName));
evidence.AddHostEvidence<Zone>(Zone.CreateFromUrl(streamName));
if (!flag)
{
evidence.AddHostEvidence<Site>(Site.CreateFromUrl(streamName));
}
permissionSet = SecurityManager.GetStandardSandbox(evidence);
isHostReady = true;
}
示例10: CreateEvidenceForUrl
public static Evidence CreateEvidenceForUrl(string securityUrl)
{
Evidence evidence = new Evidence();
if ((securityUrl != null) && (securityUrl.Length > 0))
{
evidence.AddHostEvidence<Url>(new Url(securityUrl));
evidence.AddHostEvidence<Zone>(Zone.CreateFromUrl(securityUrl));
Uri uri = new Uri(securityUrl, UriKind.RelativeOrAbsolute);
if (uri.IsAbsoluteUri && !uri.IsFile)
{
evidence.AddHostEvidence<Site>(Site.CreateFromUrl(securityUrl));
}
if (uri.IsAbsoluteUri && uri.IsUnc)
{
string directoryName = Path.GetDirectoryName(uri.LocalPath);
if ((directoryName != null) && (directoryName.Length != 0))
{
evidence.AddHostEvidence<UncDirectory>(new UncDirectory(directoryName));
}
}
}
return evidence;
}
示例11: ScriptCompiler
static ScriptCompiler()
{
cParams = new CompilerParameters();
cParams.GenerateExecutable = false;
cParams.GenerateInMemory = false;
cParams.IncludeDebugInformation = false;
cParams.ReferencedAssemblies.Add(Path.Combine(Program.ExecutableDirectory, "fomm.Scripting.dll"));
cParams.ReferencedAssemblies.Add("System.dll");
cParams.ReferencedAssemblies.Add("System.Drawing.dll");
cParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
cParams.ReferencedAssemblies.Add("System.Xml.dll");
evidence = new Evidence();
evidence.AddHostEvidence(new Zone(SecurityZone.Internet));
}
示例12: CreateDomain
private static AppDomain CreateDomain(string id, string assemblyPath)
{
var permSet = new PermissionSet(PermissionState.None);
permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
var evidence = new Evidence();
evidence.AddHostEvidence(new Zone(SecurityZone.Untrusted));
var fullTrustAssembly = typeof(Sandboxer).Assembly.Evidence.GetHostEvidence<StrongName>();
var adSetup = new AppDomainSetup
{
ApplicationBase = Path.GetDirectoryName(assemblyPath),
};
var domain = AppDomain.CreateDomain(id, evidence, adSetup, permSet, fullTrustAssembly);
return domain;
}
示例13: Create
private AppDomain Create()
{
Evidence internetEvidence = new Evidence();
internetEvidence.AddHostEvidence(new Zone(SecurityZone.MyComputer));
PermissionSet internetPermissions = SecurityManager.GetStandardSandbox(internetEvidence);
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
if (internetPermissions != null)
{
return AppDomain.CreateDomain("Add-In Domain", internetEvidence, setup, internetPermissions);
}
return AppDomain.CreateDomain("Add-in Domain", internetEvidence, setup);
}
示例14: ShouldWorkEvenWithLowestPossiblePermissions
public void ShouldWorkEvenWithLowestPossiblePermissions()
{
// based on: https://msdn.microsoft.com/en-us/library/bb384237(v=vs.110).aspx
Evidence evidence = new Evidence();
evidence.AddHostEvidence(new Zone(SecurityZone.Internet));
PermissionSet permissionSet = new NamedPermissionSet("Internet", SecurityManager.GetStandardSandbox(evidence));
permissionSet.SetPermission(new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess));
AppDomainSetup appDomainSetup = new AppDomainSetup
{
ApplicationBase = "."
};
AppDomain sandbox = AppDomain.CreateDomain("Sandbox", evidence, appDomainSetup, permissionSet, null);
CrossDomain crossDomain = (CrossDomain)sandbox.CreateInstanceAndUnwrap(typeof(CrossDomain).Assembly.FullName, typeof(CrossDomain).FullName);
Assert.AreEqual(3, crossDomain.RunArrayProvider());
}
示例15: Sandbox
public Sandbox(string name = DefaultName)
{
var evidence = new Evidence();
evidence.AddHostEvidence(new Zone(SecurityZone.Internet));
var permissions = SecurityManager.GetStandardSandbox(evidence);
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
permissions.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.RestrictedMemberAccess));
var setup = new AppDomainSetup
{
ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
ApplicationName = name,
DisallowBindingRedirects = true,
DisallowCodeDownload = true,
DisallowPublisherPolicy = true
};
domain = AppDomain.CreateDomain(name, null, setup, permissions);
}