private void ValidateReferenceForPartialTrust(AssemblyReference assembly, Microsoft.Build.Tasks.Deployment.ManifestUtilities.TrustInfo trustInfo) { if (!trustInfo.IsFullTrust) { string resolvedPath = assembly.ResolvedPath; AssemblyAttributeFlags flags = new AssemblyAttributeFlags(resolvedPath); if (Util.CompareFrameworkVersions(this.TargetFrameworkVersion, "v3.5") <= 0) { if ((assembly.IsPrimary && flags.IsSigned) && !flags.HasAllowPartiallyTrustedCallersAttribute) { base.OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", new string[] { Path.GetFileNameWithoutExtension(resolvedPath) }); } } else if ((assembly.AssemblyIdentity != null) && assembly.AssemblyIdentity.IsFrameworkAssembly) { if ((assembly.IsPrimary && !flags.HasAllowPartiallyTrustedCallersAttribute) && !flags.HasSecurityTransparentAttribute) { base.OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", new string[] { Path.GetFileNameWithoutExtension(resolvedPath) }); } } else if ((assembly.IsPrimary && flags.IsSigned) && (!flags.HasAllowPartiallyTrustedCallersAttribute && !flags.HasSecurityTransparentAttribute)) { base.OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", new string[] { Path.GetFileNameWithoutExtension(resolvedPath) }); } if (flags.HasPrimaryInteropAssemblyAttribute || flags.HasImportedFromTypeLibAttribute) { base.OutputMessages.AddWarningMessage("GenerateManifest.UnmanagedCodePermission", new string[] { Path.GetFileNameWithoutExtension(resolvedPath) }); } } }
private void ValidateReferenceForPartialTrust(AssemblyReference assembly, TrustInfo trustInfo) { if (trustInfo.IsFullTrust) { return; } string path = assembly.ResolvedPath; AssemblyAttributeFlags flags = new AssemblyAttributeFlags(path); // if it's targeting v2.0 CLR then use the old logic to check for partial trust callers. if (Util.CompareFrameworkVersions(this.TargetFrameworkVersion, Constants.TargetFrameworkVersion35) <= 0) { if (assembly.IsPrimary && flags.IsSigned && !flags.HasAllowPartiallyTrustedCallersAttribute) { OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", Path.GetFileNameWithoutExtension(path)); } } else { if (assembly.AssemblyIdentity != null && assembly.AssemblyIdentity.IsInFramework(Constants.DotNetFrameworkIdentifier, TargetFrameworkVersion)) { // if the binary is targeting v4.0 and it has the transparent attribute then we may allow partially trusted callers. if (assembly.IsPrimary && !(flags.HasAllowPartiallyTrustedCallersAttribute || flags.HasSecurityTransparentAttribute)) { OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", Path.GetFileNameWithoutExtension(path)); } } else { // if the binary is targeting v4.0 and it has the transparent attribute then we may allow partially trusted callers. if (assembly.IsPrimary && flags.IsSigned && !(flags.HasAllowPartiallyTrustedCallersAttribute || flags.HasSecurityTransparentAttribute)) { OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", Path.GetFileNameWithoutExtension(path)); } } } if (flags.HasPrimaryInteropAssemblyAttribute || flags.HasImportedFromTypeLibAttribute) { OutputMessages.AddWarningMessage("GenerateManifest.UnmanagedCodePermission", Path.GetFileNameWithoutExtension(path)); } }
private void ValidateReferenceForPartialTrust(AssemblyReference assembly, Microsoft.Build.Tasks.Deployment.ManifestUtilities.TrustInfo trustInfo) { if (!trustInfo.IsFullTrust) { string resolvedPath = assembly.ResolvedPath; AssemblyAttributeFlags flags = new AssemblyAttributeFlags(resolvedPath); if (Util.CompareFrameworkVersions(this.TargetFrameworkVersion, "v3.5") <= 0) { if ((assembly.IsPrimary && flags.IsSigned) && !flags.HasAllowPartiallyTrustedCallersAttribute) { base.OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", new string[] { Path.GetFileNameWithoutExtension(resolvedPath) }); } } else if ((assembly.AssemblyIdentity != null) && assembly.AssemblyIdentity.IsFrameworkAssembly) { if ((assembly.IsPrimary && !flags.HasAllowPartiallyTrustedCallersAttribute) && !flags.HasSecurityTransparentAttribute) { base.OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", new string[] { Path.GetFileNameWithoutExtension(resolvedPath) }); } } else if ((assembly.IsPrimary && flags.IsSigned) && (!flags.HasAllowPartiallyTrustedCallersAttribute && !flags.HasSecurityTransparentAttribute)) { base.OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", new string[] { Path.GetFileNameWithoutExtension(resolvedPath) }); } if (flags.HasPrimaryInteropAssemblyAttribute || flags.HasImportedFromTypeLibAttribute) { base.OutputMessages.AddWarningMessage("GenerateManifest.UnmanagedCodePermission", new string[] { Path.GetFileNameWithoutExtension(resolvedPath) }); } } }
private void ValidateReferenceForPartialTrust(AssemblyReference assembly, TrustInfo trustInfo) { if (trustInfo.IsFullTrust) return; string path = assembly.ResolvedPath; AssemblyAttributeFlags flags = new AssemblyAttributeFlags(path); // if it's targeting v2.0 CLR then use the old logic to check for partial trust callers. if (Util.CompareFrameworkVersions(this.TargetFrameworkVersion, Constants.TargetFrameworkVersion35) <= 0) { if (assembly.IsPrimary && flags.IsSigned && !flags.HasAllowPartiallyTrustedCallersAttribute) OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", Path.GetFileNameWithoutExtension(path)); } else { if (assembly.AssemblyIdentity != null && assembly.AssemblyIdentity.IsInFramework(Constants.DotNetFrameworkIdentifier, TargetFrameworkVersion)) { // if the binary is targeting v4.0 and it has the transparent attribute then we may allow partially trusted callers. if (assembly.IsPrimary && !(flags.HasAllowPartiallyTrustedCallersAttribute || flags.HasSecurityTransparentAttribute)) OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", Path.GetFileNameWithoutExtension(path)); } else { // if the binary is targeting v4.0 and it has the transparent attribute then we may allow partially trusted callers. if (assembly.IsPrimary && flags.IsSigned && !(flags.HasAllowPartiallyTrustedCallersAttribute || flags.HasSecurityTransparentAttribute)) OutputMessages.AddWarningMessage("GenerateManifest.AllowPartiallyTrustedCallers", Path.GetFileNameWithoutExtension(path)); } } if (flags.HasPrimaryInteropAssemblyAttribute || flags.HasImportedFromTypeLibAttribute) OutputMessages.AddWarningMessage("GenerateManifest.UnmanagedCodePermission", Path.GetFileNameWithoutExtension(path)); }