public static void VerifyFileHash(string filePath, HashCollection hashCollection) { string fileName = Path.GetFileName(filePath); if (hashCollection.Count == 0) { if (!PolicyKeys.RequireHashInManifests()) { Logger.AddWarningInformation(string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("NoHashFile"), new object[1] { (object)fileName })); } else { throw new InvalidDeploymentException(ExceptionTypes.HashValidation, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_HashNotSpecified"), new object[1] { (object)fileName })); } } foreach (Hash hash in hashCollection) { ComponentVerifier.VerifyFileHash(filePath, hash); } }
protected static void VerifyManifestComponentFiles(AssemblyManifest manifest, string componentPath, bool ignoreSelfReferentialFileHash) { string directoryName = Path.GetDirectoryName(componentPath); foreach (System.Deployment.Application.Manifest.File file in manifest.Files) { string str = Path.Combine(directoryName, file.NameFS); if ((!ignoreSelfReferentialFileHash || string.Compare(componentPath, str, StringComparison.OrdinalIgnoreCase) != 0) && System.IO.File.Exists(str)) { ComponentVerifier.VerifyFileHash(str, file.HashCollection); } } }
private static bool FileHashVerified(HashCollection hashCollection, string location) { try { ComponentVerifier.VerifyFileHash(location, hashCollection); } catch (InvalidDeploymentException ex) { if (ex.SubType == ExceptionTypes.HashValidation) { return(false); } throw; } return(true); }
public override void Verify() { ComponentVerifier.VerifyFileHash(this._filePath, this._hashCollection); }
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); }