예제 #1
0
 private void ValidateDeploymentProvider()
 {
     if (!String.IsNullOrEmpty(_deploymentUrl) && PathUtil.IsLocalPath(_deploymentUrl))
     {
         OutputMessages.AddWarningMessage("GenerateManifest.InvalidDeploymentProvider");
     }
 }
예제 #2
0
        private void ValidateConfig()
        {
            if (String.IsNullOrEmpty(ConfigFile))
            {
                return;
            }
            FileReference configFile = FileReferences.FindTargetPath(ConfigFile);

            if (configFile == null)
            {
                return;
            }

            if (!TrustInfo.IsFullTrust)
            {
                XmlDocument document = new XmlDocument();

                XmlReaderSettings xrs = new XmlReaderSettings();
                xrs.DtdProcessing = DtdProcessing.Ignore;

                using (XmlReader xr = XmlReader.Create(configFile.ResolvedPath, xrs))
                {
                    document.Load(xr);
                }
                XmlNamespaceManager nsmgr = XmlNamespaces.GetNamespaceManager(document.NameTable);
                XmlNodeList         nodes = document.SelectNodes(XPaths.configBindingRedirect, nsmgr);
                if (nodes.Count > 0)
                {
                    OutputMessages.AddWarningMessage("GenerateManifest.ConfigBindingRedirectsWithPartialTrust");
                }
            }
        }
예제 #3
0
 protected void ValidatePlatform()
 {
     foreach (AssemblyReference assembly in AssemblyReferences)
     {
         if (IsMismatchedPlatform(assembly))
         {
             OutputMessages.AddWarningMessage("GenerateManifest.PlatformMismatch", assembly.ToString());
         }
     }
 }
예제 #4
0
        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));
            }
        }
예제 #5
0
        private void ValidateReferences()
        {
            if (AssemblyReferences.Count <= 1)
            {
                return;
            }

            Dictionary <string, NGen <bool> > identityList = new Dictionary <string, NGen <bool> >();

            foreach (AssemblyReference assembly in AssemblyReferences)
            {
                if (assembly.AssemblyIdentity != null)
                {
                    // Check for two or more assemblies with the same identity...
                    string identity = assembly.AssemblyIdentity.GetFullName(AssemblyIdentity.FullNameFlags.All);
                    string key      = identity.ToLowerInvariant();
                    if (!identityList.ContainsKey(key))
                    {
                        identityList.Add(key, false);
                    }
                    else if (identityList[key] == false)
                    {
                        OutputMessages.AddWarningMessage("GenerateManifest.DuplicateAssemblyIdentity", identity);
                        identityList[key] = true; // only warn once per identity
                    }
                }

                // Check that resolved assembly identity matches filename...
                if (!assembly.IsPrerequisite)
                {
                    if (assembly.AssemblyIdentity != null)
                    {
                        if (!String.Equals(assembly.AssemblyIdentity.Name, Path.GetFileNameWithoutExtension(assembly.TargetPath), StringComparison.OrdinalIgnoreCase))
                        {
                            OutputMessages.AddWarningMessage("GenerateManifest.IdentityFileNameMismatch", assembly.ToString(), assembly.AssemblyIdentity.Name, assembly.AssemblyIdentity.Name + Path.GetExtension(assembly.TargetPath));
                        }
                    }
                }
            }
        }
예제 #6
0
        private void ValidateReferencesForClickOnceApplication()
        {
            int  t1             = Environment.TickCount;
            bool isPartialTrust = !TrustInfo.IsFullTrust;
            Dictionary <string, NGen <bool> > targetPathList = new Dictionary <string, NGen <bool> >();

            foreach (AssemblyReference assembly in AssemblyReferences)
            {
                // Check all resolved dependencies for partial trust apps...
                if (isPartialTrust && (assembly != EntryPoint) && !String.IsNullOrEmpty(assembly.ResolvedPath))
                {
                    ValidateReferenceForPartialTrust(assembly, TrustInfo);
                }

                // Check TargetPath for all local dependencies, ignoring any Prerequisites
                if (!assembly.IsPrerequisite && !String.IsNullOrEmpty(assembly.TargetPath))
                {
                    // Check target path does not exceed maximum...
                    if (_maxTargetPath > 0 && assembly.TargetPath.Length > _maxTargetPath)
                    {
                        OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", assembly.ToString(), _maxTargetPath.ToString(CultureInfo.CurrentCulture));
                    }

                    // Check for two or more items with the same TargetPath...
                    string key = assembly.TargetPath.ToLowerInvariant();
                    if (!targetPathList.ContainsKey(key))
                    {
                        targetPathList.Add(key, false);
                    }
                    else if (targetPathList[key] == false)
                    {
                        OutputMessages.AddWarningMessage("GenerateManifest.DuplicateTargetPath", assembly.ToString());
                        targetPathList[key] = true; // only warn once per path
                    }
                }
                else
                {
                    // Check assembly name does not exceed maximum...
                    if (_maxTargetPath > 0 && assembly.AssemblyIdentity.Name.Length > _maxTargetPath)
                    {
                        OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", assembly.AssemblyIdentity.Name, _maxTargetPath.ToString(CultureInfo.CurrentCulture));
                    }
                }

                // Check that all prerequisites are strong named...
                if (assembly.IsPrerequisite && !assembly.AssemblyIdentity.IsStrongName && !assembly.IsVirtual)
                {
                    OutputMessages.AddErrorMessage("GenerateManifest.PrerequisiteNotSigned", assembly.ToString());
                }
            }
            foreach (FileReference file in FileReferences)
            {
                // Check that file is not an assembly...
                if (!String.IsNullOrEmpty(file.ResolvedPath) && PathUtil.IsAssembly(file.ResolvedPath))
                {
                    OutputMessages.AddWarningMessage("GenerateManifest.AssemblyAsFile", file.ToString());
                }

                if (!String.IsNullOrEmpty(file.TargetPath))
                {
                    // Check target path does not exceed maximum...
                    if (_maxTargetPath > 0 && file.TargetPath.Length > _maxTargetPath)
                    {
                        OutputMessages.AddWarningMessage("GenerateManifest.TargetPathTooLong", file.TargetPath, _maxTargetPath.ToString(CultureInfo.CurrentCulture));
                    }

                    // Check for two or more items with the same TargetPath...
                    string key = file.TargetPath.ToLowerInvariant();
                    if (!targetPathList.ContainsKey(key))
                    {
                        targetPathList.Add(key, false);
                    }
                    else if (targetPathList[key] == false)
                    {
                        OutputMessages.AddWarningMessage("GenerateManifest.DuplicateTargetPath", file.TargetPath);
                        targetPathList[key] = true; // only warn once per path
                    }
                }
            }
            Util.WriteLog(String.Format(CultureInfo.CurrentCulture, "GenerateManifest.CheckManifestReferences t={0}", Environment.TickCount - t1));
        }