473,626 Members | 3,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

load authorized dll

Consider a system that has exe and dlls, how can i ensure that only the
authorized .net assembly can work with my system. For example, consider your
sys got an exe, that would use dll A, B, and C; how do you ensure, other
people cannot create a dll D, that has the same interface, from being invoke
from your exe. Considering, your exe is created to dynamically load the dll,
for future extensibility, meaning, as new dll comes, you don't need to change
your exe.

thanks
Eugene
Nov 17 '05 #1
3 1809
> how do you ensure, other
people cannot create a dll D, that has the same interface, from being invoke
from your exe.
Are you loading a dynamic assembly, finding all Types that implement a certain interface defined in your assembly, and then
consuming them?

If so, just ensure that all references to your assembly must be signed with your unique key:

Find the sn.exe utility installed in "%programfiles% \Microsoft Visual Studio .NET 2003\SDK\v1.1\B in\sn.exe"

Use sn.exe to generate a strong-name public/private key pair from the command-line.

sn.exe -k "c:\mykey.s nk"

You can then use an assembly-level attribute to sign your main assembly (.exe) with your key:

[assembly: AssemblyKeyFile (@"c:\mykey.snk ")]

Also, sign all your dynamic assemblies with this key. In your code, you can check to make sure that each assembly you load has your
public key:

public void TestLoadAsm()
{
System.Reflecti on.Assembly thisAsm = System.Reflecti on.Assembly.Get ExecutingAssemb ly();
System.Reflecti on.Assembly asm = System.Reflecti on.Assembly.Loa dFile(@"c:\Test Library1.dll", thisAsm.Evidenc e);

System.Reflecti on.AssemblyName dynamicName = asm.GetName();

System.Security .Permissions.St rongNamePublicK eyBlob key =
new System.Security .Permissions.St rongNamePublicK eyBlob(thisAsm. GetName().GetPu blicKey());
System.Security .Permissions.St rongNamePublicK eyBlob dynaKey =
new System.Security .Permissions.St rongNamePublicK eyBlob(dynamicN ame.GetPublicKe y());

if (!key.Equals(dy naKey))
throw new System.Security .SecurityExcept ion(asm.FullNam e + " has an invalid key signature.");

Type type = asm.GetType("Te stLibrary1.Clas s1");
TestLibrary2.IC lass obj = Activator.Creat eInstance(type) as TestLibrary2.IC lass;

Console.WriteLi ne("{0}: {1}", dynamicName.Nam e, dynamicName.Ver sion);
Console.WriteLi ne(obj.GetType( ).FullName);
}
So, how do you stop them from plugging in a malicious assembly? Don't give them your key file.
--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Eugene" <Eu****@discuss ions.microsoft. com> wrote in message news:11******** *************** ***********@mic rosoft.com... Consider a system that has exe and dlls, how can i ensure that only the
authorized .net assembly can work with my system. For example, consider your
sys got an exe, that would use dll A, B, and C; how do you ensure, other
people cannot create a dll D, that has the same interface, from being invoke
from your exe. Considering, your exe is created to dynamically load the dll,
for future extensibility, meaning, as new dll comes, you don't need to change
your exe.

thanks
Eugene

Nov 17 '05 #2
thanks, it's very helpful. i would have a config file to determine which
assembly to look for, then load through reflection. My concern is when
someone tamper with the config file to load his/her own dll. initially i
thought that the strong name is being used in GAC, so thanks for your code
for my question :)

so, the problem of this is, only if someone else gets hold of my key file.
so my question is, is there any way that other people can reproduce my file?
like, deassemble my assembly, and get the [assembly:
AssemblyKeyFile (@"c:\mykey.snk ")] ?

Eugene

"Dave" wrote:
how do you ensure, other
people cannot create a dll D, that has the same interface, from being invoke
from your exe.


Are you loading a dynamic assembly, finding all Types that implement a certain interface defined in your assembly, and then
consuming them?

If so, just ensure that all references to your assembly must be signed with your unique key:

Find the sn.exe utility installed in "%programfiles% \Microsoft Visual Studio .NET 2003\SDK\v1.1\B in\sn.exe"

Use sn.exe to generate a strong-name public/private key pair from the command-line.

sn.exe -k "c:\mykey.s nk"

You can then use an assembly-level attribute to sign your main assembly (.exe) with your key:

[assembly: AssemblyKeyFile (@"c:\mykey.snk ")]

Also, sign all your dynamic assemblies with this key. In your code, you can check to make sure that each assembly you load has your
public key:

public void TestLoadAsm()
{
System.Reflecti on.Assembly thisAsm = System.Reflecti on.Assembly.Get ExecutingAssemb ly();
System.Reflecti on.Assembly asm = System.Reflecti on.Assembly.Loa dFile(@"c:\Test Library1.dll", thisAsm.Evidenc e);

System.Reflecti on.AssemblyName dynamicName = asm.GetName();

System.Security .Permissions.St rongNamePublicK eyBlob key =
new System.Security .Permissions.St rongNamePublicK eyBlob(thisAsm. GetName().GetPu blicKey());
System.Security .Permissions.St rongNamePublicK eyBlob dynaKey =
new System.Security .Permissions.St rongNamePublicK eyBlob(dynamicN ame.GetPublicKe y());

if (!key.Equals(dy naKey))
throw new System.Security .SecurityExcept ion(asm.FullNam e + " has an invalid key signature.");

Type type = asm.GetType("Te stLibrary1.Clas s1");
TestLibrary2.IC lass obj = Activator.Creat eInstance(type) as TestLibrary2.IC lass;

Console.WriteLi ne("{0}: {1}", dynamicName.Nam e, dynamicName.Ver sion);
Console.WriteLi ne(obj.GetType( ).FullName);
}
So, how do you stop them from plugging in a malicious assembly? Don't give them your key file.
--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Eugene" <Eu****@discuss ions.microsoft. com> wrote in message news:11******** *************** ***********@mic rosoft.com...
Consider a system that has exe and dlls, how can i ensure that only the
authorized .net assembly can work with my system. For example, consider your
sys got an exe, that would use dll A, B, and C; how do you ensure, other
people cannot create a dll D, that has the same interface, from being invoke
from your exe. Considering, your exe is created to dynamically load the dll,
for future extensibility, meaning, as new dll comes, you don't need to change
your exe.

thanks
Eugene


Nov 17 '05 #3
can this strong name be used to prevent other developer from inheriting from
my assembly as well?

"Dave" wrote:
how do you ensure, other
people cannot create a dll D, that has the same interface, from being invoke
from your exe.


Are you loading a dynamic assembly, finding all Types that implement a certain interface defined in your assembly, and then
consuming them?

If so, just ensure that all references to your assembly must be signed with your unique key:

Find the sn.exe utility installed in "%programfiles% \Microsoft Visual Studio .NET 2003\SDK\v1.1\B in\sn.exe"

Use sn.exe to generate a strong-name public/private key pair from the command-line.

sn.exe -k "c:\mykey.s nk"

You can then use an assembly-level attribute to sign your main assembly (.exe) with your key:

[assembly: AssemblyKeyFile (@"c:\mykey.snk ")]

Also, sign all your dynamic assemblies with this key. In your code, you can check to make sure that each assembly you load has your
public key:

public void TestLoadAsm()
{
System.Reflecti on.Assembly thisAsm = System.Reflecti on.Assembly.Get ExecutingAssemb ly();
System.Reflecti on.Assembly asm = System.Reflecti on.Assembly.Loa dFile(@"c:\Test Library1.dll", thisAsm.Evidenc e);

System.Reflecti on.AssemblyName dynamicName = asm.GetName();

System.Security .Permissions.St rongNamePublicK eyBlob key =
new System.Security .Permissions.St rongNamePublicK eyBlob(thisAsm. GetName().GetPu blicKey());
System.Security .Permissions.St rongNamePublicK eyBlob dynaKey =
new System.Security .Permissions.St rongNamePublicK eyBlob(dynamicN ame.GetPublicKe y());

if (!key.Equals(dy naKey))
throw new System.Security .SecurityExcept ion(asm.FullNam e + " has an invalid key signature.");

Type type = asm.GetType("Te stLibrary1.Clas s1");
TestLibrary2.IC lass obj = Activator.Creat eInstance(type) as TestLibrary2.IC lass;

Console.WriteLi ne("{0}: {1}", dynamicName.Nam e, dynamicName.Ver sion);
Console.WriteLi ne(obj.GetType( ).FullName);
}
So, how do you stop them from plugging in a malicious assembly? Don't give them your key file.
--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Eugene" <Eu****@discuss ions.microsoft. com> wrote in message news:11******** *************** ***********@mic rosoft.com...
Consider a system that has exe and dlls, how can i ensure that only the
authorized .net assembly can work with my system. For example, consider your
sys got an exe, that would use dll A, B, and C; how do you ensure, other
people cannot create a dll D, that has the same interface, from being invoke
from your exe. Considering, your exe is created to dynamically load the dll,
for future extensibility, meaning, as new dll comes, you don't need to change
your exe.

thanks
Eugene


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
19616
by: Eric.Jones | last post by:
I've encountered a strange error with loading delimited files from a Samba (SMB) network drive, has anyone else seen this before? (Platform: WinXP Pro, UDB PE 8015, level 02060106, SAMPLE db) db2 load from M:\org1.del of del replace into org SQL3109N The utility is beginning to load data from file "M:\org1.del". SQL2036N The path for the file or device "M:\org1.del" is not valid. db2diag.log:
4
3379
by: Gaetan | last post by:
I just cannot read any more MSDN articles on IIS6 and ASP.Net authentication ... everything is blurry now, tanks to old eyes. Here is a topo of my environment: - W2K3 SP1 (IIS 6) - Web site is a virtual directory under Default Web Site - Web site is configured with "Integrated Windows Authentication" and the "Enable
19
5235
by: Alex Madon | last post by:
Hello, I am testing a web application (using the DBX PHP function to call a Postgresql backend). I have 375Mb RAM on my test home box. I ran ab (apache benchmark) to test the behaviour of the application under heavy load. When increasing the number of requests, all my memory is filled, and the Linux server begins to cache and remains frozen. ab -n 100 -c 10 http://localsite/testscript
3
4310
by: ssg31415926 | last post by:
I'm getting the error: "Unable to open the Web 'http://blah/blahblah'. You are not authorized to perform the current operation". I have changed a few things recently but I can't change them back as I need them. I can't find anything about it using searches. Yesterday, I removed the "Enable anonymous access" option from my web (within the Default Web Site). The web has Integrated Windows authentication checked. The site must check AD...
0
8202
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8641
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8510
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2628
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.