Represents the identity of a software publisher. This class cannot be inherited.
Namespace:
System.Security.Permissions
Assembly:
mscorlib (in mscorlib.dll)
Visual Basic (Declaration)
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class PublisherIdentityPermission _
Inherits CodeAccessPermission
Dim instance As PublisherIdentityPermission
[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class PublisherIdentityPermission : CodeAccessPermission
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class PublisherIdentityPermission sealed : public CodeAccessPermission
public final class PublisherIdentityPermission extends CodeAccessPermission
Important Note: |
|---|
In the .NET Framework versions 1.0 and 1.1, identity permissions cannot have an Unrestricted permission state value. In the .NET Framework version 2.0, identity permissions can have any permission state value. This means that in version 2.0, identity permissions have the same behavior as permissions that implement the IUnrestrictedPermission interface. That is, a demand for an identity always succeeds, regardless of the identity of the assembly, if the assembly has been granted full trust. For information on executing version 2.0 applications with version 1.1 code access security (CAS) policy, see <legacyV1CASPolicy> Element. In the .NET Framework versions 1.0 and 1.1, demands on the identity permissions are effective, even when the calling assembly is fully trusted. That is, although the calling assembly has full trust, a demand for an identity permission fails if the assembly does not meet the demanded criteria. In the .NET Framework version 2.0, demands for identity permissions are ineffective if the calling assembly has full trust. This assures consistency for all permissions, eliminating the treatment of identity permissions as a special case. |
Note: |
|---|
By default, code access security does not check for Publisher evidence. Unless your computer has a custom code group based on the PublisherMembershipCondition class, you can improve performance by bypassing Authenticode signature verification. This is accomplished by configuring the runtime to not provide Publisher evidence for code access security. For more information about how to configure this option and which applications can use it, see the <generatePublisherEvidence> element. |
The following code example shows the behavior of the PublisherIdentityPermission class methods.
Note: |
|---|
The code example is intended to show the behavior of the methods, not to demonstrate their use. In general, the methods of permission classes are used by the security infrastructure; they are not typically used in applications. Generally, only the constructors are used in application code. The created instance validates or controls resource access by using inherited CodeAccessPermission methods such as Demand. |
' To execute this sample you will need two certification files, MyCert1.cer and MyCert2.cer.
' The certification files can be created using the Certification Creation Tool, MakeCert.exe.
Imports System
Imports System.Security
Imports System.Security.Permissions
Imports System.Security.Cryptography.X509Certificates
Imports System.IO
Public Class PublisherIdentityPermissionDemo
Private Shared publisherCertificate(1) As X509Certificate
Private Shared publisherPerm1 As PublisherIdentityPermission
Private Shared publisherPerm2 As PublisherIdentityPermission
' Demonstrate all methods.
Public Shared Sub Main(ByVal args() As String)
' Initialize the PublisherIdentityPermissions for use in the sample
Dim fs1 As New FileStream("..\..\..\MyCert1.cer", FileMode.Open)
Dim certSBytes1(Fix(fs1.Length)) As [Byte]
fs1.Read(certSBytes1, 0, Fix(fs1.Length))
publisherCertificate(0) = New X509Certificate(certSBytes1)
fs1.Close()
Dim fs2 As New FileStream("..\..\..\MyCert2.cer", FileMode.Open)
Dim certSBytes2(Fix(fs2.Length)) As [Byte]
fs2.Read(certSBytes2, 0, Fix(fs2.Length))
publisherCertificate(1) = New X509Certificate(certSBytes2)
fs2.Close()
publisherPerm1 = New PublisherIdentityPermission(publisherCertificate(0))
publisherPerm2 = New PublisherIdentityPermission(publisherCertificate(1))
IsSubsetOfDemo()
CopyDemo()
UnionDemo()
IntersectDemo()
ToFromXmlDemo()
End Sub 'Main
' IsSubsetOf determines whether the current permission is a subset of the specified permission.
Private Shared Sub IsSubsetOfDemo()
If publisherPerm2.IsSubsetOf(publisherPerm1) Then
Console.WriteLine(publisherPerm2.Certificate.Subject.ToString() + _
" is a subset of " + publisherPerm1.Certificate.Subject.ToString())
Else
Console.WriteLine(publisherPerm2.Certificate.Subject.ToString() + _
" is not a subset of " + publisherPerm1.Certificate.Subject.ToString())
End If
End Sub 'IsSubsetOfDemo
' Union creates a new permission that is the union of the current permission and the specified permission.
Private Shared Sub UnionDemo()
Dim publisherPerm3 As PublisherIdentityPermission = CType(publisherPerm1.Union(publisherPerm2), PublisherIdentityPermission)
If publisherPerm3 Is Nothing Then
Console.WriteLine("The union of " + publisherPerm1.ToString() + " and " _
+ publisherPerm2.Certificate.Subject.ToString() + " is null.")
Else
Console.WriteLine("The union of " + publisherPerm1.Certificate.Subject.ToString() + _
" and " + publisherPerm2.Certificate.Subject.ToString() + " = " + _
CType(publisherPerm3, PublisherIdentityPermission).Certificate.Subject.ToString())
End If
End Sub 'UnionDemo
' Intersect creates and returns a new permission that is the intersection of the current
' permission and the permission specified.
Private Shared Sub IntersectDemo()
Dim publisherPerm3 As PublisherIdentityPermission = CType(publisherPerm1.Union(publisherPerm2), PublisherIdentityPermission)
If Not (publisherPerm3 Is Nothing) Then
Console.WriteLine("The intersection of " + publisherPerm1.Certificate.Subject.ToString() + " = " + _
CType(publisherPerm3, PublisherIdentityPermission).Certificate.Subject.ToString())
Else
Console.WriteLine("The intersection of " + publisherPerm1.Certificate.Subject.ToString() + _
" and " + publisherPerm2.Certificate.Subject.ToString() + " is null.")
End If
End Sub 'IntersectDemo
'Copy creates and returns an identical copy of the current permission.
Private Shared Sub CopyDemo()
' Create an empty PublisherIdentityPermission to serve as the target of the copy.
publisherPerm2 = New PublisherIdentityPermission(PermissionState.None)
publisherPerm2 = CType(publisherPerm1.Copy(), PublisherIdentityPermission)
Console.WriteLine("Result of copy = " + publisherPerm2.ToString())
End Sub 'CopyDemo
' ToXml creates an XML encoding of the permission and its current state;
' FromXml reconstructs a permission with the specified state from the XML encoding.
Private Shared Sub ToFromXmlDemo()
publisherPerm2 = New PublisherIdentityPermission(PermissionState.None)
publisherPerm2.FromXml(publisherPerm1.ToXml())
Console.WriteLine("Result of ToFromXml = " + publisherPerm2.ToString())
End Sub 'ToFromXmlDemo
End Class 'PublisherIdentityPermissionDemo
// To execute this sample you will need two certification files, MyCert1.cer and MyCert2.cer.
// The certification files can be created using the Certification Creation Tool, MakeCert.exe.
using System;
using System.Security;
using System.Security.Permissions;
using System.Security.Cryptography.X509Certificates;
using System.IO;
public class PublisherIdentityPermissionDemo
{
private static X509Certificate[] publisherCertificate = new X509Certificate[2];
private static PublisherIdentityPermission publisherPerm1;
private static PublisherIdentityPermission publisherPerm2;
// Demonstrate all methods.
public static void Main(String[] args)
{
// Initialize the PublisherIdentityPermissions for use in the sample
FileStream fs1 = new FileStream("..\\..\\..\\MyCert1.cer", FileMode.Open);
Byte[] certSBytes1 = new Byte[(int)fs1.Length];
fs1.Read(certSBytes1, 0, (int)fs1.Length);
publisherCertificate[0] = new X509Certificate(certSBytes1);
fs1.Close();
FileStream fs2 = new FileStream("..\\..\\..\\MyCert2.cer", FileMode.Open);
Byte[] certSBytes2 = new Byte[(int)fs2.Length];
fs2.Read(certSBytes2, 0, (int)fs2.Length);
publisherCertificate[1] = new X509Certificate(certSBytes2);
fs2.Close();
publisherPerm1 = new PublisherIdentityPermission(publisherCertificate[0]);
publisherPerm2 = new PublisherIdentityPermission(publisherCertificate[1]);
IsSubsetOfDemo();
CopyDemo();
UnionDemo();
IntersectDemo();
ToFromXmlDemo();
}
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private static void IsSubsetOfDemo()
{
if (publisherPerm2.IsSubsetOf(publisherPerm1))
{
Console.WriteLine(publisherPerm2.Certificate.Subject + " is a subset of " +
publisherPerm1.Certificate.Subject);
}
else
{
Console.WriteLine(publisherPerm2.Certificate.Subject + " is not a subset of " +
publisherPerm1.Certificate.Subject);
}
}
// Union creates a new permission that is the union of the current permission and the specified permission.
private static void UnionDemo()
{
PublisherIdentityPermission publisherPerm3 = (PublisherIdentityPermission)publisherPerm1.Union(publisherPerm2);
if (publisherPerm3 == null)
{
Console.WriteLine("The union of " + publisherPerm1 + " and " +
publisherPerm2.Certificate.Subject + " is null.");
}
else
{
Console.WriteLine("The union of " + publisherPerm1.Certificate.Subject + " and " +
publisherPerm2.Certificate.Subject + " = " +
((PublisherIdentityPermission)publisherPerm3).Certificate.Subject.ToString());
}
}
// Intersect creates and returns a new permission that is the intersection of the current
// permission and the permission specified.
private static void IntersectDemo()
{
PublisherIdentityPermission publisherPerm3 = (PublisherIdentityPermission)publisherPerm1.Union(publisherPerm2);
if (publisherPerm3 != null)
{
Console.WriteLine("The intersection of " + publisherPerm1.Certificate.Subject +
" and " + publisherPerm2.Certificate.Subject + " = " +
((PublisherIdentityPermission)publisherPerm3).Certificate.Subject.ToString());
}
else
{
Console.WriteLine("The intersection of " + publisherPerm1.Certificate.Subject + " and " +
publisherPerm2.Certificate.Subject + " is null.");
}
}
//Copy creates and returns an identical copy of the current permission.
private static void CopyDemo()
{
// Create an empty PublisherIdentityPermission to serve as the target of the copy.
publisherPerm2 = new PublisherIdentityPermission(PermissionState.None);
publisherPerm2 = (PublisherIdentityPermission)publisherPerm1.Copy();
Console.WriteLine("Result of copy = " + publisherPerm2.ToString());
}
// ToXml creates an XML encoding of the permission and its current state;
// FromXml reconstructs a permission with the specified state from the XML encoding.
private static void ToFromXmlDemo()
{
publisherPerm2 = new PublisherIdentityPermission(PermissionState.None);
publisherPerm2.FromXml(publisherPerm1.ToXml());
Console.WriteLine("Result of ToFromXml = " +
publisherPerm2.ToString());
}
}
// To execute this sample you will need two certification files, MyCert1.cer and MyCert2.cer.
// The certification files can be created using the Certification Creation Tool, MakeCert.exe,
// which runs from the command line. Usage: MakeCert MyCert1.cer
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Security::Cryptography::X509Certificates;
using namespace System::IO;
// Demonstrate all methods.
void main()
{
Console::WriteLine("Welcome to the PublisherIdentityPermission CPP sample\n");
array<X509Certificate^>^publisherCertificate = gcnew array<X509Certificate^>(2);
PublisherIdentityPermission ^ publisherPerm1;
PublisherIdentityPermission ^ publisherPerm2;
// Initialize the PublisherIdentityPermissions for use in the sample
FileStream ^ fs1 = gcnew FileStream("MyCert1.cer", FileMode::Open);
array<Byte>^certSBytes1 = gcnew array<Byte>((int)fs1->Length);
fs1->Read(certSBytes1, 0, (int)fs1->Length);
publisherCertificate[0] = gcnew X509Certificate(certSBytes1);
fs1->Close();
FileStream ^ fs2 = gcnew FileStream("MyCert2.cer", FileMode::Open);
array<Byte>^certSBytes2 = gcnew array<Byte>((int)fs2->Length);
fs2->Read(certSBytes2, 0, (int)fs2->Length);
publisherCertificate[1] = gcnew X509Certificate(certSBytes2);
fs2->Close();
publisherPerm1 = gcnew PublisherIdentityPermission(publisherCertificate[0]);
publisherPerm2 = gcnew PublisherIdentityPermission(publisherCertificate[1]);
Console::WriteLine("\n******************** IsSubsetOf DEMO ********************\n");
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
if (publisherPerm2->IsSubsetOf(publisherPerm1))
Console::WriteLine(publisherPerm2->Certificate->Subject + " is a subset of " +
publisherPerm1->Certificate->Subject);
else
Console::WriteLine(publisherPerm2->Certificate->Subject + " is not a subset of " +
publisherPerm1->Certificate->Subject);
Console::WriteLine("\n******************** Copy DEMO ********************\n");
// Copy creates and returns an identical copy of the current permission.
// Create an empty PublisherIdentityPermission to serve as the target of the copy.
publisherPerm2 = gcnew PublisherIdentityPermission(PermissionState::None);
publisherPerm2 = (PublisherIdentityPermission^)publisherPerm1->Copy();
Console::WriteLine("Result of copy = " + publisherPerm2);
Console::WriteLine("\n******************** Union DEMO ********************\n");
PublisherIdentityPermission ^ publisherPerm3 = (PublisherIdentityPermission ^)publisherPerm1->Union(publisherPerm2);
if (publisherPerm3 == nullptr)
Console::WriteLine("The union of " + publisherPerm1 + " and " +
publisherPerm2->Certificate->Subject + " is null.");
else
Console::WriteLine("The union of " + publisherPerm1->Certificate->Subject + " and " +
publisherPerm2->Certificate->Subject + " = " +
publisherPerm3->Certificate->Subject);
// Intersect creates and returns a new permission that is the intersection of the current
// permission and the permission specified.
Console::WriteLine("\n******************** Intersect DEMO ********************\n");
publisherPerm3 = (PublisherIdentityPermission^)publisherPerm1->Intersect(publisherPerm2);
if (publisherPerm3 != nullptr)
Console::WriteLine("The intersection of " + publisherPerm1->Certificate->Subject +
" and " + publisherPerm2->Certificate->Subject + " = " +
publisherPerm3->Certificate->Subject);
else
Console::WriteLine("The intersection of " + publisherPerm1->Certificate->Subject + " and " +
publisherPerm2->Certificate->Subject + " is null.");
// ToXml creates an XML encoding of the permission and its current state;
// FromXml reconstructs a permission with the specified state from the XML encoding.
Console::WriteLine("\n******************** ToXml DEMO ********************\n");
publisherPerm2 = gcnew PublisherIdentityPermission(PermissionState::None);
publisherPerm2->FromXml(publisherPerm1->ToXml());
Console::WriteLine("Result of ToFromXml = " + publisherPerm2);
Console::WriteLine("Press Enter to return");
Console::ReadLine();
}
/*
Expected output:
Welcome to the PublisherIdentityPermission CPP sample
******************** IsSubsetOf DEMO ********************
CN=Joe's-Software-Emporium is not a subset of CN=Joe's-Software-Emporium
******************** Copy DEMO ********************
Result of copy = <IPermission class="System.Security.Permissions.PublisherIdenti
tyPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5
61934e089"
version="1"
X509v3Certificate="308201C730820171A003020102021006EC2474BF2489AB4AA453927C93421
1300D06092A864886F70D01010405003016311430120603550403130B526F6F74204167656E63793
01E170D3037313030323230333232335A170D3339313233313233353935395A30223120301E06035
5040313174A6F6527732D536F6674776172652D456D706F7269756D30819F300D06092A864886F70
D010101050003818D0030818902818100B2987B627918013BF3AC153D8868E35E2640F5190F10207
E9A1792755F818AC9940F4112E8ADA911EA23542AE9758606A78A1C90C03433B4254BDD226290532
DAAC87AFA5FBCAD42FE2CA17FD471D7C95644AD3C76BA91F07339B278CC4B92FC8FE134E17E09F60
52F390E7C2A471246C8288B76FE80A7F805764A2B986917350203010001A34B304930470603551D0
10440303E801012E4092D061D1D4F008D6121DC166463A1183016311430120603550403130B526F6
F74204167656E6379821006376C00AA00648A11CFB8D4AA5C35F4300D06092A864886F70D0101040
50003410072906C0A0B42FE4A77CAC283CDECFCA0707B4E8D596BD27D2E8ECD9A1C1C6A9E7CD5CA1
362C9884A0062F9CDFAF26DB901A490DD0DE17D55B27B0C5520E247E2"/>
******************** Union DEMO ********************
The union of CN=Joe's-Software-Emporium and CN=Joe's-Software-Emporium = CN=Joe'
s-Software-Emporium
******************** Intersect DEMO ********************
The intersection of CN=Joe's-Software-Emporium and CN=Joe's-Software-Emporium =
CN=Joe's-Software-Emporium
******************** ToXml DEMO ********************
Result of ToFromXml = <IPermission class="System.Security.Permissions.PublisherI
dentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b7
7a5c561934e089"
version="1"
X509v3Certificate="308201C730820171A003020102021006EC2474BF2489AB4AA453927C93421
1300D06092A864886F70D01010405003016311430120603550403130B526F6F74204167656E63793
01E170D3037313030323230333232335A170D3339313233313233353935395A30223120301E06035
5040313174A6F6527732D536F6674776172652D456D706F7269756D30819F300D06092A864886F70
D010101050003818D0030818902818100B2987B627918013BF3AC153D8868E35E2640F5190F10207
E9A1792755F818AC9940F4112E8ADA911EA23542AE9758606A78A1C90C03433B4254BDD226290532
DAAC87AFA5FBCAD42FE2CA17FD471D7C95644AD3C76BA91F07339B278CC4B92FC8FE134E17E09F60
52F390E7C2A471246C8288B76FE80A7F805764A2B986917350203010001A34B304930470603551D0
10440303E801012E4092D061D1D4F008D6121DC166463A1183016311430120603550403130B526F6
F74204167656E6379821006376C00AA00648A11CFB8D4AA5C35F4300D06092A864886F70D0101040
50003410072906C0A0B42FE4A77CAC283CDECFCA0707B4E8D596BD27D2E8ECD9A1C1C6A9E7CD5CA1
362C9884A0062F9CDFAF26DB901A490DD0DE17D55B27B0C5520E247E2"/>
Press Enter to return
*/
System..::.Object
System.Security..::.CodeAccessPermission
System.Security.Permissions..::.PublisherIdentityPermission
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference
Other Resources