Ejemplo n.º 1
0
        /// <summary>
        /// Build path from dependent assambly
        /// </summary>
        /// <param name="assembly">assembly to resolve</param>
        /// <returns>resolved path</returns>
        public static string BuildLocalPathFromDependentAssembly(DependentAssembly assembly)
        {
            string fileName = assembly.ParentAssembly.CodeBase.Substring(0, assembly.ParentAssembly.CodeBase.LastIndexOf("/")) + "/" + assembly.Name;

            fileName = fileName.Replace("/", "\\").Substring(8);
            return(fileName);
        }
Ejemplo n.º 2
0
        public void SerializeDeserialize()
        {
            DependentAssembly dependentAssembly = new DependentAssembly();

            string xml = "<assemblyIdentity name='ClassLibrary1'/>";

            dependentAssembly.Read(new XmlTextReader(xml, XmlNodeType.Document, null));

            Assert.IsTrue(dependentAssembly.PartialAssemblyName != null);
        }
        private AssemblyName RedirectByCodeBase(AssemblyName assemblyName, DependentAssembly dependentAssembly)
        {
            if (dependentAssembly.CodeBase != null && dependentAssembly.CodeBase.Version != null && !string.IsNullOrEmpty(dependentAssembly.CodeBase.Href))
            {
                assemblyName.Version  = dependentAssembly.CodeBase.Version;
                assemblyName.CodeBase = FileUtil.MapPath(dependentAssembly.CodeBase.Href);

                return(assemblyName);
            }
            return(null);
        }
 private static void ProcessDownloadedFile(object sender, DownloadEventArgs e)
 {
     if (e.Cookie != null)
     {
         string         fileName   = Path.GetFileName(e.FileLocalPath);
         FileDownloader downloader = (FileDownloader)sender;
         if ((e.FileResponseUri != null) && !e.FileResponseUri.Equals(e.FileSourceUri))
         {
             throw new InvalidDeploymentException(ExceptionTypes.AppFileLocationValidation, string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_DownloadAppFileAsmRedirected"), new object[] { fileName }));
         }
         DependencyDownloadCookie cookie = (DependencyDownloadCookie)e.Cookie;
         if (cookie.ManifestElement is DependentAssembly)
         {
             DependentAssembly manifestElement  = (DependentAssembly)cookie.ManifestElement;
             AssemblyManifest  deployManifest   = cookie.DeployManifest;
             AssemblyManifest  appManifest      = cookie.AppManifest;
             AssemblyManifest  assemblyManifest = new AssemblyManifest(e.FileLocalPath);
             if (!assemblyManifest.Identity.Matches(manifestElement.Identity, true))
             {
                 throw new InvalidDeploymentException(ExceptionTypes.RefDefValidation, string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_DownloadRefDefMismatch"), new object[] { fileName }));
             }
             if (assemblyManifest.Identity.Equals(deployManifest.Identity) || assemblyManifest.Identity.Equals(appManifest.Identity))
             {
                 throw new InvalidDeploymentException(ExceptionTypes.ManifestSemanticValidation, string.Format(CultureInfo.CurrentUICulture, Resources.GetString("Ex_AppPrivAsmIdSameAsDeployOrApp"), new object[] { assemblyManifest.Identity.ToString() }));
             }
             System.Deployment.Application.Manifest.File[] files = assemblyManifest.Files;
             for (int i = 0; i < files.Length; i++)
             {
                 Uri fileSourceUri = MapFileSourceUri(deployManifest, e.FileSourceUri, files[i].Name);
                 if (!fileSourceUri.AbsoluteUri.Equals(e.FileSourceUri.AbsoluteUri, StringComparison.OrdinalIgnoreCase))
                 {
                     string directoryName = Path.GetDirectoryName(e.FileLocalPath);
                     AddFileToDownloader(downloader, deployManifest, appManifest, files[i], fileSourceUri, directoryName, files[i].NameFS, files[i].HashCollection);
                 }
             }
             downloader.ComponentVerifier.AddFileForVerification(e.FileLocalPath, manifestElement.HashCollection);
             if (assemblyManifest.Identity.PublicKeyToken == null)
             {
                 downloader.ComponentVerifier.AddSimplyNamedAssemblyForVerification(e.FileLocalPath, assemblyManifest);
             }
             else
             {
                 downloader.ComponentVerifier.AddStrongNameAssemblyForVerification(e.FileLocalPath, assemblyManifest);
             }
         }
         else if (cookie.ManifestElement is System.Deployment.Application.Manifest.File)
         {
             System.Deployment.Application.Manifest.File file = (System.Deployment.Application.Manifest.File)cookie.ManifestElement;
             downloader.ComponentVerifier.AddFileForVerification(e.FileLocalPath, file.HashCollection);
         }
     }
 }
        /// <summary>
        /// Redirects the by binding redirect.
        /// </summary>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="dependentAssembly">The dependent assembly.</param>
        /// <returns></returns>
        private AssemblyName RedirectByBindingRedirect(AssemblyName assemblyName, DependentAssembly dependentAssembly)
        {
            if (dependentAssembly.BindingRedirect != null && dependentAssembly.BindingRedirect.OldVersionMax != null &&
                dependentAssembly.BindingRedirect.OldVersionMin != null &&
                dependentAssembly.BindingRedirect.OldVersionMin <= assemblyName.Version &&
                dependentAssembly.BindingRedirect.OldVersionMax >= assemblyName.Version)
            {
                assemblyName.Version = dependentAssembly.BindingRedirect.NewVersion;

                return(assemblyName);
            }
            return(null);
        }
Ejemplo n.º 6
0
        public static bool FollowDeploymentProviderUri(SubscriptionStore subStore, ref AssemblyManifest deployment, ref Uri sourceUri, out TempFile tempFile, IDownloadNotification notification, DownloadOptions options)
        {
            Logger.AddMethodCall("FollowDeploymentProviderUri called.");
            tempFile = (TempFile)null;
            bool flag1    = false;
            Zone fromUrl1 = Zone.CreateFromUrl(sourceUri.AbsoluteUri);
            bool flag2    = false;

            if (fromUrl1.SecurityZone != SecurityZone.MyComputer)
            {
                Logger.AddInternalState("Deployment manifest zone is not local machine. Zone = " + (object)fromUrl1.SecurityZone);
                flag2 = true;
            }
            else
            {
                Logger.AddInternalState("Deployment manifest zone is local machine. Zone = " + (object)fromUrl1.SecurityZone);
                DependentAssembly dependentAssembly = deployment.MainDependentAssembly;
                if (dependentAssembly == null || dependentAssembly.Codebase == null)
                {
                    throw new InvalidDeploymentException(ExceptionTypes.ManifestSemanticValidation, Resources.GetString("Ex_NoAppInDeploymentManifest"));
                }
                Uri  uri      = new Uri(sourceUri, dependentAssembly.Codebase);
                Zone fromUrl2 = Zone.CreateFromUrl(uri.AbsoluteUri);
                if (fromUrl2.SecurityZone == SecurityZone.MyComputer)
                {
                    Logger.AddInternalState("Application manifest zone is local machine. Zone = " + (object)fromUrl2.SecurityZone);
                    if (!System.IO.File.Exists(uri.LocalPath))
                    {
                        Logger.AddInternalState(uri.LocalPath + " does not exist in local machine.");
                        flag2 = true;
                    }
                }
            }
            if (flag2)
            {
                Uri providerCodebaseUri = deployment.Deployment.ProviderCodebaseUri;
                Logger.SetDeploymentProviderUrl(providerCodebaseUri);
                Logger.AddInternalState("providerUri=" + (object)providerCodebaseUri + ",sourceUri=" + (object)sourceUri);
                if (!PolicyKeys.SkipDeploymentProvider() && providerCodebaseUri != (Uri)null && !providerCodebaseUri.Equals((object)sourceUri))
                {
                    ServerInformation serverInformation;
                    AssemblyManifest  deployment1;
                    try
                    {
                        deployment1 = DownloadManager.DownloadDeploymentManifestDirect(subStore, ref providerCodebaseUri, out tempFile, notification, options, out serverInformation);
                    }
                    catch (InvalidDeploymentException ex)
                    {
                        if (ex.SubType == ExceptionTypes.Manifest || ex.SubType == ExceptionTypes.ManifestLoad || (ex.SubType == ExceptionTypes.ManifestParse || ex.SubType == ExceptionTypes.ManifestSemanticValidation))
                        {
                            throw new InvalidDeploymentException(ExceptionTypes.Manifest, Resources.GetString("Ex_InvalidProviderManifest"), (Exception)ex);
                        }
                        throw;
                    }
                    Logger.SetDeploymentProviderServerInformation(serverInformation);
                    SubscriptionState subscriptionState = subStore.GetSubscriptionState(deployment);
                    if (!subStore.GetSubscriptionState(deployment1).SubscriptionId.Equals((object)subscriptionState.SubscriptionId))
                    {
                        throw new InvalidDeploymentException(ExceptionTypes.SubscriptionSemanticValidation, Resources.GetString("Ex_ProviderNotInSubscription"));
                    }
                    Logger.AddInternalState("Deployment provider followed: " + (object)providerCodebaseUri);
                    deployment = deployment1;
                    sourceUri  = providerCodebaseUri;
                    flag1      = true;
                }
            }
            if (!flag1)
            {
                Logger.AddInternalState("Deployment provider not followed.");
            }
            return(flag1);
        }
Ejemplo n.º 7
0
        public static AssemblyManifest DownloadApplicationManifest(AssemblyManifest deploymentManifest, string targetDir, Uri deploymentUri, IDownloadNotification notification, DownloadOptions options, out Uri appSourceUri, out string appManifestPath)
        {
            Logger.AddMethodCall("DownloadApplicationManifest called.");
            DependentAssembly dependentAssembly = deploymentManifest.MainDependentAssembly;

            if (dependentAssembly == null || dependentAssembly.Codebase == null)
            {
                throw new InvalidDeploymentException(ExceptionTypes.ManifestSemanticValidation, Resources.GetString("Ex_NoAppInDeploymentManifest"));
            }
            appSourceUri = new Uri(deploymentUri, dependentAssembly.Codebase);
            Zone fromUrl1 = Zone.CreateFromUrl(deploymentUri.AbsoluteUri);
            Zone fromUrl2 = Zone.CreateFromUrl(appSourceUri.AbsoluteUri);

            if (!fromUrl1.Equals((object)fromUrl2))
            {
                Logger.AddInternalState("Deployment and application does not have matching security zones. deploymentZone=" + (object)fromUrl1 + ",applicationZone=" + (object)fromUrl2);
                throw new InvalidDeploymentException(ExceptionTypes.Zone, Resources.GetString("Ex_DeployAppZoneMismatch"));
            }
            appManifestPath = Path.Combine(targetDir, dependentAssembly.Identity.Name + ".manifest");
            ServerInformation serverInformation;
            AssemblyManifest  assemblyManifest = DownloadManager.DownloadManifest(ref appSourceUri, appManifestPath, notification, options, AssemblyManifest.ManifestType.Application, out serverInformation);

            Logger.SetApplicationUrl(appSourceUri);
            Logger.SetApplicationServerInformation(serverInformation);
            Zone fromUrl3 = Zone.CreateFromUrl(appSourceUri.AbsoluteUri);

            if (!fromUrl1.Equals((object)fromUrl3))
            {
                Logger.AddInternalState("Deployment and application does not have matching security zones. deploymentZone=" + (object)fromUrl1 + ",applicationZone=" + (object)fromUrl3);
                throw new InvalidDeploymentException(ExceptionTypes.Zone, Resources.GetString("Ex_DeployAppZoneMismatch"));
            }
            if (assemblyManifest.Identity.Equals((object)deploymentManifest.Identity))
            {
                throw new InvalidDeploymentException(ExceptionTypes.ManifestSemanticValidation, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_DepSameDeploymentAndApplicationIdentity"), new object[1]
                {
                    (object)assemblyManifest.Identity.ToString()
                }));
            }
            if (!assemblyManifest.Identity.Matches(dependentAssembly.Identity, assemblyManifest.Application))
            {
                throw new InvalidDeploymentException(ExceptionTypes.SubscriptionSemanticValidation, Resources.GetString("Ex_RefDefMismatch"));
            }
            if (!PolicyKeys.SkipApplicationDependencyHashCheck())
            {
                try
                {
                    ComponentVerifier.VerifyFileHash(appManifestPath, dependentAssembly.HashCollection);
                }
                catch (InvalidDeploymentException ex)
                {
                    if (ex.SubType == ExceptionTypes.HashValidation)
                    {
                        throw new InvalidDeploymentException(ExceptionTypes.HashValidation, Resources.GetString("Ex_AppManInvalidHash"), (Exception)ex);
                    }
                    throw;
                }
            }
            if (assemblyManifest.RequestedExecutionLevel != null)
            {
                Logger.AddInternalState("Application manifest has RequestedExecutionLevel specified. Check requested privileges.");
                DownloadManager.VerifyRequestedPrivilegesSupport(assemblyManifest.RequestedExecutionLevel);
            }
            return(assemblyManifest);
        }
        public static bool FollowDeploymentProviderUri(SubscriptionStore subStore, ref AssemblyManifest deployment, ref Uri sourceUri, out TempFile tempFile, IDownloadNotification notification, DownloadOptions options)
        {
            Logger.AddMethodCall("FollowDeploymentProviderUri called.");
            tempFile = null;
            bool flag  = false;
            Zone zone  = Zone.CreateFromUrl(sourceUri.AbsoluteUri);
            bool flag2 = false;

            if (zone.SecurityZone != SecurityZone.MyComputer)
            {
                Logger.AddInternalState("Deployment manifest zone is not local machine. Zone = " + zone.SecurityZone);
                flag2 = true;
            }
            else
            {
                Logger.AddInternalState("Deployment manifest zone is local machine. Zone = " + zone.SecurityZone);
                DependentAssembly mainDependentAssembly = deployment.MainDependentAssembly;
                if ((mainDependentAssembly == null) || (mainDependentAssembly.Codebase == null))
                {
                    throw new InvalidDeploymentException(ExceptionTypes.ManifestSemanticValidation, Resources.GetString("Ex_NoAppInDeploymentManifest"));
                }
                Uri  uri   = new Uri(sourceUri, mainDependentAssembly.Codebase);
                Zone zone2 = Zone.CreateFromUrl(uri.AbsoluteUri);
                if (zone2.SecurityZone == SecurityZone.MyComputer)
                {
                    Logger.AddInternalState("Application manifest zone is local machine. Zone = " + zone2.SecurityZone);
                    if (!System.IO.File.Exists(uri.LocalPath))
                    {
                        Logger.AddInternalState(uri.LocalPath + " does not exist in local machine.");
                        flag2 = true;
                    }
                }
            }
            if (flag2)
            {
                Uri providerCodebaseUri = deployment.Deployment.ProviderCodebaseUri;
                Logger.SetDeploymentProviderUrl(providerCodebaseUri);
                Logger.AddInternalState(string.Concat(new object[] { "providerUri=", providerCodebaseUri, ",sourceUri=", sourceUri }));
                if ((!PolicyKeys.SkipDeploymentProvider() && (providerCodebaseUri != null)) && !providerCodebaseUri.Equals(sourceUri))
                {
                    ServerInformation information;
                    AssemblyManifest  manifest = null;
                    try
                    {
                        manifest = DownloadDeploymentManifestDirect(subStore, ref providerCodebaseUri, out tempFile, notification, options, out information);
                    }
                    catch (InvalidDeploymentException exception)
                    {
                        if (((exception.SubType != ExceptionTypes.Manifest) && (exception.SubType != ExceptionTypes.ManifestLoad)) && ((exception.SubType != ExceptionTypes.ManifestParse) && (exception.SubType != ExceptionTypes.ManifestSemanticValidation)))
                        {
                            throw;
                        }
                        throw new InvalidDeploymentException(ExceptionTypes.Manifest, Resources.GetString("Ex_InvalidProviderManifest"), exception);
                    }
                    Logger.SetDeploymentProviderServerInformation(information);
                    SubscriptionState subscriptionState = subStore.GetSubscriptionState(deployment);
                    if (!subStore.GetSubscriptionState(manifest).SubscriptionId.Equals(subscriptionState.SubscriptionId))
                    {
                        throw new InvalidDeploymentException(ExceptionTypes.SubscriptionSemanticValidation, Resources.GetString("Ex_ProviderNotInSubscription"));
                    }
                    Logger.AddInternalState("Deployment provider followed: " + providerCodebaseUri);
                    deployment = manifest;
                    sourceUri  = providerCodebaseUri;
                    flag       = true;
                }
            }
            if (!flag)
            {
                Logger.AddInternalState("Deployment provider not followed.");
            }
            return(flag);
        }