Esempio n. 1
0
        private void CheckApplicationPayload(CommitApplicationParams commitParams)
        {
            if (commitParams.AppGroup == null && commitParams.appType != AppType.CustomHostSpecified)
            {
                string path = Path.Combine(commitParams.AppPayloadPath, commitParams.AppManifest.EntryPoints[0].CommandFile);
                if (!PlatformDetector.IsWin8orLater())
                {
                    SystemUtils.CheckSupportedImageAndCLRVersions(path);
                }
            }
            string str = (string)null;

            Store.IPathLock pathLock = (Store.IPathLock)null;
            try
            {
                pathLock = this._compStore.LockAssemblyPath(commitParams.AppManifest.Identity);
                str      = Path.GetDirectoryName(pathLock.Path);
                str      = Path.Combine(str, "manifests");
                str      = Path.Combine(str, Path.GetFileName(pathLock.Path) + ".manifest");
            }
            catch (DeploymentException ex)
            {
            }
            catch (COMException ex)
            {
            }
            finally
            {
                if (pathLock != null)
                {
                    pathLock.Dispose();
                }
            }
            if (string.IsNullOrEmpty(str) || !System.IO.File.Exists(str) || (string.IsNullOrEmpty(commitParams.AppManifestPath) || !System.IO.File.Exists(commitParams.AppManifestPath)))
            {
                return;
            }
            byte[] digestValue1 = ComponentVerifier.GenerateDigestValue(str, CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA1, CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_IDENTITY);
            byte[] digestValue2 = ComponentVerifier.GenerateDigestValue(commitParams.AppManifestPath, CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA1, CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_IDENTITY);
            bool   flag         = false;

            Logger.AddInternalState("In-place update check. Existing manifest path = " + str + ", Existing manifest hash=" + Encoding.UTF8.GetString(digestValue1) + ", New manifest path=" + commitParams.AppManifestPath + ", New manifest hash=" + Encoding.UTF8.GetString(digestValue2));
            if (digestValue1.Length == digestValue2.Length)
            {
                int index = 0;
                while (index < digestValue1.Length && (int)digestValue1[index] == (int)digestValue2[index])
                {
                    ++index;
                }
                if (index >= digestValue1.Length)
                {
                    flag = true;
                }
            }
            if (!flag)
            {
                throw new DeploymentException(ExceptionTypes.Subscription, Resources.GetString("Ex_ApplicationInplaceUpdate"));
            }
        }
        private void CheckApplicationPayload(CommitApplicationParams commitParams)
        {
            if ((commitParams.AppGroup == null) && (commitParams.appType != AppType.CustomHostSpecified))
            {
                SystemUtils.CheckSupportedImageAndCLRVersions(Path.Combine(commitParams.AppPayloadPath, commitParams.AppManifest.EntryPoints[0].CommandFile));
            }
            string directoryName = null;

            System.Deployment.Internal.Isolation.Store.IPathLock @lock = null;
            try
            {
                @lock         = this._compStore.LockAssemblyPath(commitParams.AppManifest.Identity);
                directoryName = Path.GetDirectoryName(@lock.Path);
                directoryName = Path.Combine(directoryName, "manifests");
                directoryName = Path.Combine(directoryName, Path.GetFileName(@lock.Path) + ".manifest");
            }
            catch (DeploymentException)
            {
            }
            catch (COMException)
            {
            }
            finally
            {
                if (@lock != null)
                {
                    @lock.Dispose();
                }
            }
            if ((!string.IsNullOrEmpty(directoryName) && System.IO.File.Exists(directoryName)) && (!string.IsNullOrEmpty(commitParams.AppManifestPath) && System.IO.File.Exists(commitParams.AppManifestPath)))
            {
                byte[] bytes   = ComponentVerifier.GenerateDigestValue(directoryName, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA1, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_IDENTITY);
                byte[] buffer2 = ComponentVerifier.GenerateDigestValue(commitParams.AppManifestPath, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_DIGESTMETHOD.CMS_HASH_DIGESTMETHOD_SHA1, System.Deployment.Internal.Isolation.Manifest.CMS_HASH_TRANSFORM.CMS_HASH_TRANSFORM_IDENTITY);
                bool   flag    = false;
                Logger.AddInternalState("In-place update check. Existing manifest path = " + directoryName + ", Existing manifest hash=" + Encoding.UTF8.GetString(bytes) + ", New manifest path=" + commitParams.AppManifestPath + ", New manifest hash=" + Encoding.UTF8.GetString(buffer2));
                if (bytes.Length == buffer2.Length)
                {
                    int index = 0;
                    while (index < bytes.Length)
                    {
                        if (bytes[index] != buffer2[index])
                        {
                            break;
                        }
                        index++;
                    }
                    if (index >= bytes.Length)
                    {
                        flag = true;
                    }
                }
                if (!flag)
                {
                    throw new DeploymentException(ExceptionTypes.Subscription, Resources.GetString("Ex_ApplicationInplaceUpdate"));
                }
            }
        }
Esempio n. 3
0
        public static void VerifyFileHash(string filePath, Hash hash)
        {
            string fileName = Path.GetFileName(filePath);

            byte[] digestValue1;
            try
            {
                digestValue1 = ComponentVerifier.GenerateDigestValue(filePath, hash.DigestMethod, hash.Transform);
            }
            catch (IOException ex)
            {
                throw new InvalidDeploymentException(ExceptionTypes.HashValidation, Resources.GetString("Ex_HashValidationException"), (Exception)ex);
            }
            byte[] digestValue2 = hash.DigestValue;
            bool   flag         = false;

            if (digestValue1.Length == digestValue2.Length)
            {
                int index = 0;
                while (index < digestValue2.Length && (int)digestValue2[index] == (int)digestValue1[index])
                {
                    ++index;
                }
                if (index >= digestValue2.Length)
                {
                    flag = true;
                }
            }
            if (!flag)
            {
                Logger.AddInternalState("File," + fileName + ", has a different computed hash than specified in manifest. Computed hash is " + Encoding.UTF8.GetString(digestValue1) + ". Specified hash is " + Encoding.UTF8.GetString(digestValue2));
                throw new InvalidDeploymentException(ExceptionTypes.HashValidation, string.Format((IFormatProvider)CultureInfo.CurrentUICulture, Resources.GetString("Ex_DifferentHashes"), new object[1]
                {
                    (object)fileName
                }));
            }
        }