Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restricting the use of an assembly from assemblies that are not signed

Tags:

c#

.net

I have a requirement to have a restriction in an assembly such that only assemblies that are signed with a given key can use it. I am inexperienced, but what I understand is signing is done to help identify who created the assembly. Hence, just signing this assembly should not be enough to ensure that all calling assemblies are signed. Probably the reverse is true, i.e. if an assembly is signed, all the assemblies it depends on should be signed(by the same key perhaps). What would be the way to meet the requirement?

like image 386
Tulika Verma Avatar asked Dec 04 '12 06:12

Tulika Verma


People also ask

How do you secure an assembly?

You can sign an assembly in two different but complementary ways: with a strong name or by using SignTool.exe (Sign Tool). Signing an assembly with a strong name adds public key encryption to the file containing the assembly manifest.

Is a delay signed or test signed assembly?

Delay signing is a technique for signing assemblies outside of the build process. A delay signed assembly is marked with a blank strong-name key: it basically reserves space for the key to be added later, by an authorized user. We can sign the assembly using the Sn.exe tool.


1 Answers

You can use PublisherIdentityPermissionAttribute.

If you apply PublisherIdentityPermissionAttribute to MyClass class then only classes in assemblies signed by the mycert.cer certificate can use your class. You need to put SecurityAction.Demand

All callers higher in the call stack are required to have been granted the permission specified by the current permission object

Use like

[PublisherIdentityPermission(SecurityAction.Demand, CertFile = "mycert.cer")]
public class MyClass 

You can also use it on assembly level to protect entire assembly (however assembly level security will not work since .Net 4.0 unless you set <NetFx40_LegacySecurityPolicy enabled="true"/> in configuration).

like image 64
Alexander Bortnik Avatar answered Oct 09 '22 11:10

Alexander Bortnik