public void TestSingleVhdWithCustomSize()
        {
            var msixHeroPackage = new FileInfo(Path.Combine("Resources", "SamplePackages", "CreatedByMsixHero.msix"));
            var targetDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "app-attach", "custom-size"));

            var appAttachManager = new AppAttachManager(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), new DummyConfigurationService());
            var vhdPath1         = Path.Combine(targetDirectory.FullName, "output1.vhd");
            var vhdPath2         = Path.Combine(targetDirectory.FullName, "output2.vhd");

            try
            {
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPath1, 0, AppAttachVolumeType.Vhd, true, true, CancellationToken.None).Wait();
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPath2, 50, AppAttachVolumeType.Vhd, true, true, CancellationToken.None).Wait();
            }
            catch (AggregateException e)
            {
                throw e.GetBaseException();
            }

            Assert.IsTrue(File.Exists(vhdPath1));
            Assert.IsTrue(File.Exists(vhdPath2));

            var fileSize1 = new FileInfo(vhdPath1).Length;
            var fileSize2 = new FileInfo(vhdPath2).Length;

            Assert.AreEqual(50, (int)fileSize2 / 1024 / 1024);
            Assert.Greater(fileSize2, fileSize1, "Custom size 50MB must product a bigger package than the auto-size of a relatively small package.");
        }
示例#2
0
        public static void Main(string[] args)
        {
            try
            {
                if (args.Length > 0 && args[0] == "--selfElevate")
                {
                    Logger.Debug("Preparing to start the pipe server...");

                    IConfigurationService configurationService = new LocalConfigurationService();
                    ISigningManager       signingManager       = new SigningManager(MsixHeroGistTimeStampFeed.CreateCached());
                    IAppAttachManager     appAttachManager     = new AppAttachManager(signingManager, configurationService);
                    IAppxVolumeManager    appxVolumeManager    = new AppxVolumeManager();
                    IRegistryManager      registryManager      = new RegistryManager();
                    IAppxPackageManager   appxPackageManager   = new AppxPackageManager();
                    IAppxPackageQuery     appxPackageQuery     = new AppxPackageQuery(registryManager, configurationService);
                    IAppxPackageInstaller appxPackageInstaller = new AppxPackageInstaller();
                    IAppxPackageRunner    appxPackageRunner    = new AppxPackageRunner();
                    IAppxLogManager       appxLogManager       = new AppxLogManager();

                    var receivers = new ISelfElevationProxyReceiver[]
                    {
                        new AppAttachManagerProxyReceiver(appAttachManager),
                        new AppxPackageManagerProxyReceiver(appxPackageManager),
                        new AppxPackageQueryProxyReceiver(appxPackageQuery),
                        new AppxPackageInstallerProxyReceiver(appxPackageInstaller),
                        new AppxPackageRunnerProxyReceiver(appxPackageRunner),
                        new AppxLogManagerProxyReceiver(appxLogManager),
                        new AppxVolumeManagerProxyReceiver(appxVolumeManager),
                        new RegistryManagerProxyReceiver(registryManager),
                        new SigningManagerProxyReceiver(signingManager)
                    };

                    var server = new Server(receivers);
                    server.Start().GetAwaiter().GetResult();
                    Console.ReadKey();
                }
                else
                {
                    Logger.Fatal("Unsupported command line arguments, terminating...");
                    Environment.ExitCode = 1;
                }
            }
            catch (AggregateException e)
            {
                Logger.Fatal(e.GetBaseException(), "Fatal exception, the program will be closed.");
            }
            catch (Exception e)
            {
                Logger.Fatal(e, "Fatal exception, the program will be closed.");
            }

            Logger.Info("Waiting for the user to press a key...");
            Console.ReadKey();
        }
        public void TestSingleVhdWithJsonAndExtraFiles()
        {
            var msixHeroPackage = new FileInfo(Path.Combine("Resources", "SamplePackages", "CreatedByMsixHero.msix"));
            var targetDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "app-attach", "scripts-json"));

            var appAttachManager   = new AppAttachManager(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), new DummyConfigurationService());
            var vhdPathNothing     = Path.Combine(targetDirectory.FullName, "nothing", "output.vhd");
            var vhdPathScripts     = Path.Combine(targetDirectory.FullName, "scripts", "output.vhd");
            var vhdPathCertificate = Path.Combine(targetDirectory.FullName, "certificate", "output.vhd");
            var vhdPathBoth        = Path.Combine(targetDirectory.FullName, "both", "output.vhd");

            try
            {
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPathNothing, 0, AppAttachVolumeType.Vhd, false, false, CancellationToken.None).Wait();
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPathScripts, 0, AppAttachVolumeType.Vhd, false, true, CancellationToken.None).Wait();
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPathCertificate, 0, AppAttachVolumeType.Vhd, true, false, CancellationToken.None).Wait();
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdPathBoth, 0, AppAttachVolumeType.Vhd, true, true, CancellationToken.None).Wait();
            }
            catch (AggregateException e)
            {
                throw e.GetBaseException();
            }

            var cerPathNothing     = Path.Combine(targetDirectory.FullName, "nothing", "output.cer");
            var cerPathScripts     = Path.Combine(targetDirectory.FullName, "scripts", "output.cer");
            var cerPathCertificate = Path.Combine(targetDirectory.FullName, "certificate", "output.cer");
            var cerPathBoth        = Path.Combine(targetDirectory.FullName, "both", "output.cer");

            var scriptPathNothing     = Path.Combine(targetDirectory.FullName, "nothing", "stage.ps1");
            var scriptPathScripts     = Path.Combine(targetDirectory.FullName, "scripts", "stage.ps1");
            var scriptPathCertificate = Path.Combine(targetDirectory.FullName, "certificate", "stage.ps1");
            var scriptPathBoth        = Path.Combine(targetDirectory.FullName, "both", "stage.ps1");

            var jsonPathNothing     = Path.Combine(targetDirectory.FullName, "nothing", "app-attach.json");
            var jsonPathScripts     = Path.Combine(targetDirectory.FullName, "scripts", "app-attach.json");
            var jsonPathCertificate = Path.Combine(targetDirectory.FullName, "certificate", "app-attach.json");
            var jsonPathBoth        = Path.Combine(targetDirectory.FullName, "both", "app-attach.json");

            Assert.False(File.Exists(cerPathNothing));
            Assert.False(File.Exists(cerPathScripts));
            Assert.True(File.Exists(cerPathCertificate));
            Assert.True(File.Exists(cerPathBoth));

            Assert.False(File.Exists(scriptPathNothing));
            Assert.True(File.Exists(scriptPathScripts));
            Assert.False(File.Exists(scriptPathCertificate));
            Assert.True(File.Exists(scriptPathBoth));

            Assert.True(File.Exists(jsonPathNothing));
            Assert.True(File.Exists(jsonPathScripts));
            Assert.True(File.Exists(jsonPathCertificate));
            Assert.True(File.Exists(jsonPathBoth));
        }
示例#4
0
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton <IInteractionService, InteractionService>();
            containerRegistry.RegisterSingleton <ISelfElevationProxyProvider <IAppxVolumeManager>, SelfElevationManagerFactory>();
            containerRegistry.RegisterSingleton <ISelfElevationProxyProvider <IRegistryManager>, SelfElevationManagerFactory>();
            containerRegistry.RegisterSingleton <ISelfElevationProxyProvider <ISigningManager>, SelfElevationManagerFactory>();
            containerRegistry.RegisterSingleton <ISelfElevationProxyProvider <IAppxLogManager>, SelfElevationManagerFactory>();
            containerRegistry.RegisterSingleton <ISelfElevationProxyProvider <IAppxPackageManager>, SelfElevationManagerFactory>();
            containerRegistry.RegisterSingleton <ISelfElevationProxyProvider <IAppxPackageQuery>, SelfElevationManagerFactory>();
            containerRegistry.RegisterSingleton <ISelfElevationProxyProvider <IAppxPackageInstaller>, SelfElevationManagerFactory>();
            containerRegistry.RegisterSingleton <ISelfElevationProxyProvider <IAppxPackageRunner>, SelfElevationManagerFactory>();
            containerRegistry.RegisterSingleton <ISelfElevationProxyProvider <IAppAttachManager>, SelfElevationManagerFactory>();
            containerRegistry.RegisterSingleton <IAppxPacker, AppxPacker>();
            containerRegistry.RegisterSingleton <IModificationPackageBuilder, ModificationPackageBuilder>();
            containerRegistry.RegisterSingleton <IElevatedClient, Client>();
            containerRegistry.RegisterSingleton <IBusyManager, BusyManager>();
            containerRegistry.RegisterSingleton <INotificationManager>(() => new NotificationManager(NotificationPosition.TopRight));
            containerRegistry.RegisterSingleton <IConfigurationService, LocalConfigurationService>();
            containerRegistry.RegisterSingleton <IUpdateChecker, HttpUpdateChecker>();
            containerRegistry.RegisterSingleton <IAppxVolumeManager, AppxVolumeManager>();
            containerRegistry.RegisterSingleton <IAppxFileViewer, AppxFileViewer>();
            containerRegistry.RegisterSingleton <IAppxPackageManager, AppxPackageManager>();
            containerRegistry.RegisterSingleton <IAppxPackageRunner, AppxPackageRunner>();
            containerRegistry.RegisterSingleton <IAppxPackageQuery, AppxPackageQuery>();
            containerRegistry.RegisterSingleton <IAppxPackageInstaller, AppxPackageInstaller>();
            containerRegistry.RegisterSingleton <IAppxUpdateImpactAnalyzer, AppxUpdateImpactAnalyzer>();
            containerRegistry.RegisterSingleton <IMsixHeroCommandExecutor, MsixHeroCommandExecutor>();
            containerRegistry.RegisterSingleton <IMsixHeroApplication, MsixHeroApplication>();
            containerRegistry.RegisterSingleton <IRunningAppsDetector, RunningAppsDetector>();
            containerRegistry.RegisterSingleton <IAppxManifestCreator, AppxManifestCreator>();
            containerRegistry.RegisterSingleton <IEventAggregator, EventAggregator>();
            containerRegistry.RegisterSingleton <IInterProcessCommunicationManager, InterProcessCommunicationManager>();
            containerRegistry.Register <IDependencyMapper, DependencyMapper>();
            containerRegistry.Register <IThirdPartyAppProvider, ThirdPartyAppProvider>();
            containerRegistry.Register <IServiceRecommendationAdvisor, ServiceRecommendationAdvisor>();
            containerRegistry.RegisterSingleton <PrismServices>();
            containerRegistry.RegisterSingleton <ITimeStampFeed>(_ => MsixHeroGistTimeStampFeed.CreateCached());
            containerRegistry.RegisterSingleton <IMediator>(containerProvider => new Mediator(containerProvider.Resolve));

            containerRegistry.RegisterDialog <PackageExpertDialogView, PackageExpertDialogViewModel>(NavigationPaths.DialogPaths.PackageExpert);

            if (Environment.GetCommandLineArgs().Length < 2)
            {
                containerRegistry.RegisterDialogWindow <AcrylicDialogWindow>();
            }

            this.Container.GetContainer().RegisterMediatorHandlers(typeof(App).Assembly);
        }
        public void TestMultipleFiles()
        {
            var msixHeroPackage = new FileInfo(Path.Combine("Resources", "SamplePackages", "CreatedByMsixHero.msix"));
            var targetDirectory = Path.Combine(Environment.CurrentDirectory, "app-attach", "multiple");
            var targetVhd       = Path.Combine(targetDirectory, "vhd");
            var targetVhdx      = Path.Combine(targetDirectory, "vhdx");
            var targetCim       = Path.Combine(targetDirectory, "cim");

            var baseSourceFolder = Path.Combine(Environment.CurrentDirectory, "copied");

            Directory.CreateDirectory(baseSourceFolder);

            var sourceFiles = new[] { "pkg1.msix", "pkg2.msix", "pkg3.msix" }.Select(f => Path.Combine(baseSourceFolder, f)).ToArray();

            foreach (var src in sourceFiles)
            {
                msixHeroPackage.CopyTo(src, true);
            }

            var appAttachManager = new AppAttachManager(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), new DummyConfigurationService());

            try
            {
                appAttachManager.CreateVolumes(sourceFiles, targetVhd, AppAttachVolumeType.Vhd, true, true, CancellationToken.None).Wait();
                appAttachManager.CreateVolumes(sourceFiles, targetVhdx, AppAttachVolumeType.Vhdx, true, true, CancellationToken.None).Wait();
                appAttachManager.CreateVolumes(sourceFiles, targetCim, AppAttachVolumeType.Cim, true, true, CancellationToken.None).Wait();
            }
            catch (AggregateException e)
            {
                throw e.GetBaseException();
            }

            Assert.True(File.Exists(Path.Combine(targetVhd, "pkg1.vhd")));
            Assert.True(File.Exists(Path.Combine(targetVhd, "pkg2.vhd")));
            Assert.True(File.Exists(Path.Combine(targetVhd, "pkg3.vhd")));

            Assert.True(File.Exists(Path.Combine(targetVhdx, "pkg1.vhdx")));
            Assert.True(File.Exists(Path.Combine(targetVhdx, "pkg2.vhdx")));
            Assert.True(File.Exists(Path.Combine(targetVhdx, "pkg3.vhdx")));

            Assert.True(Directory.Exists(Path.Combine(targetCim, "pkg1")));
            Assert.True(Directory.Exists(Path.Combine(targetCim, "pkg2")));
            Assert.True(Directory.Exists(Path.Combine(targetCim, "pkg3")));
        }
示例#6
0
        public void TestCertValidator()
        {
            var fileSignedButUntrusted = new FileInfo(Path.Combine("Resources", "ConEmuPack-O2004-M1220.603-P380-F_19.1.8.0_x64__xwfzvwzp69w2e.msix"));
            var fileUnsigned           = new FileInfo(Path.Combine("Resources", "nsis.exe"));
            var fileSignedAndTrusted   = new FileInfo(Path.Combine("Resources", "inno.exe"));
            var fileNotSignable        = new FileInfo(Path.Combine("Resources", "wintrust.dll.ini"));

            var manager = new SigningManager(MsixHeroGistTimeStampFeed.CreateCached());

            var check1 = manager.IsTrusted(fileSignedButUntrusted.FullName, CancellationToken.None).GetAwaiter().GetResult();
            var check2 = manager.IsTrusted(fileSignedAndTrusted.FullName, CancellationToken.None).GetAwaiter().GetResult();
            var check3 = manager.IsTrusted(fileUnsigned.FullName, CancellationToken.None).GetAwaiter().GetResult();
            var check4 = manager.IsTrusted(fileNotSignable.FullName, CancellationToken.None).GetAwaiter().GetResult();

            Assert.IsFalse(check1.IsTrusted);
            Assert.IsTrue(check2.IsTrusted);
            Assert.IsFalse(check3.IsTrusted);
            Assert.IsFalse(check4.IsTrusted);
        }
        public void TestSingleNonVhd()
        {
            var msixHeroPackage = new FileInfo(Path.Combine("Resources", "SamplePackages", "CreatedByMsixHero.msix"));
            var targetDirectory = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "app-attach", "single"));

            var appAttachManager = new AppAttachManager(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), new DummyConfigurationService());
            var vhdxPath         = Path.Combine(targetDirectory.FullName, "output.vhdx");
            var cimPath          = Path.Combine(targetDirectory.FullName, "output.cim");

            try
            {
                appAttachManager.CreateVolume(msixHeroPackage.FullName, vhdxPath, 0, AppAttachVolumeType.Vhdx, true, true, CancellationToken.None).Wait();
                appAttachManager.CreateVolume(msixHeroPackage.FullName, cimPath, 0, AppAttachVolumeType.Cim, true, true, CancellationToken.None).Wait();
            }
            catch (AggregateException e)
            {
                throw e.GetBaseException();
            }

            Assert.IsTrue(File.Exists(vhdxPath));
            Assert.IsTrue(File.Exists(cimPath));
        }
示例#8
0
        async Task <ISigningManager> ISelfElevationProxyProvider <ISigningManager> .GetProxyFor(SelfElevationLevel selfElevationLevel, CancellationToken cancellationToken)
        {
            if (selfElevationLevel == SelfElevationLevel.HighestAvailable)
            {
                selfElevationLevel = await this.GetMaxAvailableElevation(cancellationToken).ConfigureAwait(false);
            }

            switch (selfElevationLevel)
            {
            case SelfElevationLevel.AsInvoker:
                return(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()));

            case SelfElevationLevel.AsAdministrator:
                if (await UserHelper.IsAdministratorAsync(cancellationToken).ConfigureAwait(false))
                {
                    return(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()));
                }

                return(new SigningManagerElevationProxy(this.client, this));

            default:
                throw new InvalidOperationException("Elevation API returned wrong results.");
            }
        }
        public VerbExecutor CreateStandardVerbExecutor(IEnumerable <string> arguments)
        {
            VerbExecutor verbExecutor = null;

            var p = Parser.Default.ParseArguments(
                arguments,
                typeof(SignVerb),
                typeof(PackVerb),
                typeof(UnpackVerb),
                typeof(NewCertVerb),
                typeof(TrustVerb),
                typeof(AppAttachVerb),
                typeof(NewModPackVerb),
                typeof(ExtractCertVerb),
                typeof(DependenciesVerb),
                typeof(UpdateImpactVerb),
                typeof(EditVerbPlaceholder));

            p.WithParsed <SignVerb>(verb =>
            {
                verbExecutor = new SignVerbExecutor(verb, new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), new LocalConfigurationService(), this.console);
            });

            p.WithParsed <PackVerb>(verb =>
            {
                verbExecutor = new PackVerbExecutor(verb, this.console);
            });

            p.WithParsed <UnpackVerb>(verb =>
            {
                verbExecutor = new UnpackVerbExecutor(verb, this.console);
            });

            p.WithParsed <NewCertVerb>(verb =>
            {
                verbExecutor = new NewCertVerbExecutor(verb, new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), this.console);
            });

            p.WithParsed <NewModPackVerb>(verb =>
            {
                verbExecutor = new NewModPackVerbExecutor(verb, new ModificationPackageBuilder(new AppxPacker()), this.console);
            });

            p.WithParsed <TrustVerb>(verb =>
            {
                verbExecutor = new TrustVerbExecutor(verb, new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), this.console);
            });

            p.WithParsed <ExtractCertVerb>(verb =>
            {
                verbExecutor = new ExtractCertVerbExecutor(verb, new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), this.console);
            });

            p.WithParsed <AppAttachVerb>(verb =>
            {
                verbExecutor = new AppAttachVerbExecutor(verb, new AppAttachManager(new SigningManager(MsixHeroGistTimeStampFeed.CreateCached()), new LocalConfigurationService()), this.console);
            });

            p.WithParsed <UpdateImpactVerb>(verb =>
            {
                verbExecutor = new UpdateImpactVerbExecutor(verb, this.console);
            });

            p.WithParsed <DependenciesVerb>(verb =>
            {
                verbExecutor = new DependenciesVerbExecutor(verb, this.console);
            });

            p.WithParsed <EditVerbPlaceholder>(_ => Task.FromResult(0));

            p.WithNotParsed(arg =>
            {
                var err = arg.FirstOrDefault();
                if (err != null)
                {
                    Environment.ExitCode = (int)err.Tag;
                }
                else
                {
                    Environment.ExitCode = StandardExitCodes.ErrorGeneric;
                }
            });

            return(verbExecutor);
        }
示例#10
0
 public void TestReader()
 {
     ISigningManager signManager = new SigningManager(MsixHeroGistTimeStampFeed.CreateCached());
     var             certs       = signManager.GetCertificatesFromStore(CertificateStoreType.MachineUser).GetAwaiter().GetResult();
 }