How can an assembly work without the SequrityPermission that give it execute permission

T

Tony Johansson

Hi!

I have the following three declarative permissions.

[assembly:RegistryPermission(SecurityAction.RequestMinimum,
Read=@"HKEY_LOCAL_MACHINE\Software")]
[assembly: UIPermission(SecurityAction.RequestMinimum, Unrestricted=true)]
[assembly:RegistryPermission(SecurityAction.RequestOptional,
Read=@"HKEY_LOCAL_MACHINE\Software")]

Now to my question the assembly only have the following permission
1. RegistryPermission
2. UIPermission

The other has been given away so to speak because of how the
RequestedOptional work.
So according to me this assembly doesn't even have the SequrityPermission
that give it permission to execute ?
I'm I right in my conclusion ?
The strange thing is that I can execute the assembly.

If I do this
[assembly:SecurityPermission(SecurityAction.RequestRefuse)]
I can still execute the assembly. This SequrityPermission has no effect at
all on the assembly

//Tony
 
W

Willem van Rumpt

The other has been given away so to speak because of how the
RequestedOptional work.
So according to me this assembly doesn't even have the SequrityPermission
that give it permission to execute ?
I'm I right in my conclusion ?
The strange thing is that I can execute the assembly.

If I do this

Is the application running under full trust?
AFAIK, if that's the case, caspol is completely bypassed.
 
T

Tony Johansson

Willem van Rumpt said:
Is the application running under full trust?
AFAIK, if that's the case, caspol is completely bypassed.

Hi!

Now I have changed from FullTrust to Everything meaning that the assembly
should act and handle according to all CAS declarations.
This assembly work fine but as far as I know the assembly must have the
permission SecurityPermission to be able to execute. These CAS declarations
would result in that the assembly doesn't have the SecurityPermission so it
should not be able to run.
I can run the assembly from within VS and outside VS.
I must have missed something here

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Permissions;

[assembly: UIPermission(SecurityAction.RequestOptional, Unrestricted =
true)]
[assembly: FileIOPermission(SecurityAction.RequestOptional, ViewAndModify =
@"C:\Hello.txt")]
[assembly: SecurityPermission(SecurityAction.RequestRefuse)]

namespace Lesson2_Exercise1_CS
{
class Program
{
static void Main(string[] args)
{
// Create a file
TextWriter tw = new StreamWriter(@"C:\Hello.txt");
tw.WriteLine("Hello, world!");
tw.Close();

// Display the text of the file
TextReader tr = new StreamReader(@"C:\Hello.txt");
Console.WriteLine(tr.ReadToEnd());
tr.Close();
}
}
}

//Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top