HighTechTalks DotNet Forums  

Assembly loaded from URL needs to read registry - but can't

Dotnet Security microsoft.public.dotnet.security


Discuss Assembly loaded from URL needs to read registry - but can't in the Dotnet Security forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
gkelly
 
Posts: n/a

Default Assembly loaded from URL needs to read registry - but can't - 02-24-2005 , 07:49 PM






I have a set of applications that use a common assembly library.

AppA, AppB and AppC all use LibA and LibB

These will run on about 25 computers.

AppA and LibA need to read registry to determine database connect string to
use and other misc config stuff

For a while anyway, all code will be updated periodically. So, I decided
place code on our web server.

Instead of AppA and AppB being "Windows Applications" I changed them to
Class Libraries.

I created a Launcher App that will use Assembly.LoadFrom to load from a url
like http://server/applib/AppA.dll

However, since code loaded this way runs in a different context I get an
error error such as:

Request for the permission of type
System.Security.Permissions.RegistryPermission failed..

I have read about this and somewhat understand the issues involved.

Question: Is there a "simple" way to load a dll from a URL and have it run
with the same permission as code that was
loaded locally?

I thought the following would work, but it doesnt. Same error happens. So,
obviously my understanding is very limited.

Evidence ev = new Evidence();
ev.Merge( AppDomain.CurrentDomain.Evidence );
ev.AddHost( new Zone( SecurityZone.MyComputer ));
Assembly v_assembly = Assembly.LoadFrom( "http://server/applib/AppA.dll",
ev );

when creating an object instance from this assembly it still can't read the
registry. I "thought" this would load the assembly so that's
it's code would run with same permissions as the launcher. It doesn't.

Any help would be appreciated.

gkelly



Reply With Quote
  #2  
Old   
Jan Petras
 
Posts: n/a

Default RE: Assembly loaded from URL needs to read registry - but can't - 02-25-2005 , 01:39 AM






What I would do is that I would modify enterprise policy on the server to
indicate that any code comming from \\yourserver\yourdirectorywithdlls\* is
FullTrust. Then, don't worry about creating evidence and all that. Or, sign
the assemblies with your public key and modify enterprise policy that any
assembly signed with code with that public key is of "Full Trust" level...

Generally, play around with caspol.exe (or MMC snapin) to get what you need.
There may be other solutions as well, I would try this first.

Regards,
JnP76


"gkelly" wrote:

Quote:
I have a set of applications that use a common assembly library.

AppA, AppB and AppC all use LibA and LibB

These will run on about 25 computers.

AppA and LibA need to read registry to determine database connect string to
use and other misc config stuff

For a while anyway, all code will be updated periodically. So, I decided
place code on our web server.

Instead of AppA and AppB being "Windows Applications" I changed them to
Class Libraries.

I created a Launcher App that will use Assembly.LoadFrom to load from a url
like http://server/applib/AppA.dll

However, since code loaded this way runs in a different context I get an
error error such as:

Request for the permission of type
System.Security.Permissions.RegistryPermission failed..

I have read about this and somewhat understand the issues involved.

Question: Is there a "simple" way to load a dll from a URL and have it run
with the same permission as code that was
loaded locally?

I thought the following would work, but it doesnt. Same error happens. So,
obviously my understanding is very limited.

Evidence ev = new Evidence();
ev.Merge( AppDomain.CurrentDomain.Evidence );
ev.AddHost( new Zone( SecurityZone.MyComputer ));
Assembly v_assembly = Assembly.LoadFrom( "http://server/applib/AppA.dll",
ev );

when creating an object instance from this assembly it still can't read the
registry. I "thought" this would load the assembly so that's
it's code would run with same permissions as the launcher. It doesn't.

Any help would be appreciated.

gkelly




Reply With Quote
  #3  
Old   
AT
 
Posts: n/a

Default RE: Assembly loaded from URL needs to read registry - but can't - 02-25-2005 , 08:41 PM



You can also check out:
http://blogs.msdn.com/shawnfa/archiv.../20/57023.aspx for some
suggestions on implementing the strong name method.

-Shawn
http://blogs.msdn.com/shawnfa
--
This posting is provided "AS IS" with no warranties, and confers no rights.


Note:
For the benefit of the community-at-large, all responses to this message
are best directed to the newsgroup/thread from which they originated.
--------------------
Quote:
Thread-Topic: Assembly loaded from URL needs to read registry - but can't
thread-index: AcUbBLIFgoAdXMD9SBqHeglvditWfA==
X-WBNR-Posting-Host: 202.130.192.170
From: "=?Utf-8?B?SmFuIFBldHJhcw==?=" <JanPetras (AT) discussions (DOT) microsoft.com
References: <OVUPsPtGFHA.3612 (AT) TK2MSFTNGP09 (DOT) phx.gbl
Subject: RE: Assembly loaded from URL needs to read registry - but can't
Date: Thu, 24 Feb 2005 22:39:03 -0800
Lines: 64
Message-ID: <682A7213-2A24-4A96-BA34-19850603F5BB (AT) microsoft (DOT) com
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.security
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGP08.phx.gbl!TK2MSFTNGXA
03.phx.gbl
Quote:
Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.security:9232
X-Tomcat-NG: microsoft.public.dotnet.security

What I would do is that I would modify enterprise policy on the server to
indicate that any code comming from \\yourserver\yourdirectorywithdlls\*
is
FullTrust. Then, don't worry about creating evidence and all that. Or,
sign
the assemblies with your public key and modify enterprise policy that any
assembly signed with code with that public key is of "Full Trust" level...

Generally, play around with caspol.exe (or MMC snapin) to get what you
need.
There may be other solutions as well, I would try this first.

Regards,
JnP76


"gkelly" wrote:

I have a set of applications that use a common assembly library.

AppA, AppB and AppC all use LibA and LibB

These will run on about 25 computers.

AppA and LibA need to read registry to determine database connect
string to
use and other misc config stuff

For a while anyway, all code will be updated periodically. So, I
decided
place code on our web server.

Instead of AppA and AppB being "Windows Applications" I changed them to
Class Libraries.

I created a Launcher App that will use Assembly.LoadFrom to load from a
url
like http://server/applib/AppA.dll

However, since code loaded this way runs in a different context I get
an
error error such as:

Request for the permission of type
System.Security.Permissions.RegistryPermission failed..

I have read about this and somewhat understand the issues involved.

Question: Is there a "simple" way to load a dll from a URL and have it
run
with the same permission as code that was
loaded locally?

I thought the following would work, but it doesnt. Same error happens.
So,
obviously my understanding is very limited.

Evidence ev = new Evidence();
ev.Merge( AppDomain.CurrentDomain.Evidence );
ev.AddHost( new Zone( SecurityZone.MyComputer ));
Assembly v_assembly = Assembly.LoadFrom(
"http://server/applib/AppA.dll",
ev );

when creating an object instance from this assembly it still can't read
the
registry. I "thought" this would load the assembly so that's
it's code would run with same permissions as the launcher. It doesn't.

Any help would be appreciated.

gkelly






Reply With Quote
  #4  
Old   
gkelly
 
Posts: n/a

Default Re: Assembly loaded from URL needs to read registry - but can't - 02-28-2005 , 01:19 AM



For those of you that are interested. Here is a solution that works well.
However, the solution given by
Shawn Farkas should be viewed by all. It's very informative.

System.Security.Policy.Evidence v_ev = new
System.Security.Policy.Evidence();
v_ev.AddHost( new Site( "<host>" ));
v_ev.AddHost( new Zone(SecurityZone.MyComputer ));

Assembly v_assembly = null;

string v_dllhost = http://<server>/;

string[] v_dlls =
{
"dll1.dll",
"dll2.dll",
"main.dll",
};

foreach( string v_dll in v_dlls )
{
v_assembly = Assembly.LoadFrom( v_dllhost + v_dll, v_ev );
}

Type v_objtype = v_assembly.GetType( "fba.frmMain" );
try
{
BindingFlags v_bf = BindingFlags.Instance | BindingFlags.Static |
BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic;

MethodInfo mi = v_objtype.GetMethod("Main", v_bf );
mi.Invoke( null, null);
}
catch( Exception ex )
{
int a = 1;
}

....................

I will use a variation of the above code to allow multile entry points.
There are several "apps" I want to be able to run


"gkelly" <gkelly (AT) xmission (DOT) com> wrote

Quote:
I have a set of applications that use a common assembly library.

AppA, AppB and AppC all use LibA and LibB

These will run on about 25 computers.

AppA and LibA need to read registry to determine database connect string
to use and other misc config stuff

For a while anyway, all code will be updated periodically. So, I decided
place code on our web server.

Instead of AppA and AppB being "Windows Applications" I changed them to
Class Libraries.

I created a Launcher App that will use Assembly.LoadFrom to load from a
url like http://server/applib/AppA.dll

However, since code loaded this way runs in a different context I get an
error error such as:

Request for the permission of type
System.Security.Permissions.RegistryPermission failed..

I have read about this and somewhat understand the issues involved.

Question: Is there a "simple" way to load a dll from a URL and have it run
with the same permission as code that was
loaded locally?

I thought the following would work, but it doesnt. Same error happens.
So, obviously my understanding is very limited.

Evidence ev = new Evidence();
ev.Merge( AppDomain.CurrentDomain.Evidence );
ev.AddHost( new Zone( SecurityZone.MyComputer ));
Assembly v_assembly = Assembly.LoadFrom( "http://server/applib/AppA.dll",
ev );

when creating an object instance from this assembly it still can't read
the registry. I "thought" this would load the assembly so that's
it's code would run with same permissions as the launcher. It doesn't.

Any help would be appreciated.

gkelly





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.