Beispiel #1
0
        public static Task SignPackageWithDeviceGuardFromUi(
            this ISigningManager signingManager,
            string package,
            DeviceGuardConfiguration configuration,
            string timestampUrl = null,
            IncreaseVersionMethod increaseVersion = IncreaseVersionMethod.None,
            CancellationToken cancellationToken   = default,
            IProgress <ProgressData> progress     = default)
        {
            var tokens = configuration.FromConfiguration();

            return(signingManager.SignPackageWithDeviceGuard(package, true, tokens, timestampUrl, increaseVersion, cancellationToken, progress));
        }
Beispiel #2
0
        public static async Task ShowCertSummary(this IConsole console, ISigningManager signingManager, string certificateOrSignedFile)
        {
            var isTrusted = await signingManager.IsTrusted(certificateOrSignedFile).ConfigureAwait(false);

            if (isTrusted.Trustee == null)
            {
                return;
            }

            if (isTrusted.IsTrusted)
            {
                await console.WriteSuccess(" * Signed by:  " + isTrusted.Trustee);

                await console.WriteSuccess(" * Issuer:     " + isTrusted.Issuer);

                await console.WriteSuccess(" * Thumbprint: " + isTrusted.Thumbprint);

                if (isTrusted.Expires.HasValue)
                {
                    await console.WriteSuccess(" * Expires:    " + isTrusted.Expires.Value);
                }
                else
                {
                    await console.WriteSuccess(" * Expires:    <never>");
                }
            }
            else
            {
                await console.WriteWarning(" * Signed by:  " + isTrusted.Trustee + " (untrusted)");

                await console.WriteWarning(" * Issuer:     " + isTrusted.Issuer);

                await console.WriteWarning(" * Thumbprint: " + isTrusted.Thumbprint);

                if (isTrusted.Expires.HasValue)
                {
                    await console.WriteWarning(" * Expires:    " + isTrusted.Expires.Value);
                }
                else
                {
                    await console.WriteWarning(" * Expires:    <never>");
                }
            }
        }
Beispiel #3
0
 public TrustVerbExecutor(TrustVerb verb, ISigningManager signingManager, IConsole console) : base(verb, console)
 {
     this.signingManager = signingManager;
 }
 public AppAttachManager(ISigningManager signingManager, IConfigurationService configurationService) : this(configurationService)
 {
     this.signingManager = signingManager;
 }
Beispiel #5
0
 public ExtractCertVerbExecutor(ExtractCertVerb verb, ISigningManager signingManager, IConsole console) : base(verb, console)
 {
     this.signingManager = signingManager;
 }
Beispiel #6
0
 public SignVerbExecutor(SignVerb signVerb, ISigningManager signingManager, IConfigurationService configurationService, IConsole console) : base(signVerb, console)
 {
     this.signingManager       = signingManager;
     this.configurationService = configurationService;
 }
Beispiel #7
0
        public async Task CreateVolume(string packagePath, string volumePath, uint vhdSize, bool extractCertificate, bool generateScripts, CancellationToken cancellationToken = default, IProgress <ProgressData> progressReporter = null)
        {
            if (packagePath == null)
            {
                throw new ArgumentNullException(nameof(packagePath));
            }

            if (volumePath == null)
            {
                throw new ArgumentNullException(nameof(packagePath));
            }

            var packageFileInfo = new FileInfo(packagePath);

            if (!packageFileInfo.Exists)
            {
                throw new FileNotFoundException($"File {packagePath} does not exist.", packagePath);
            }

            var volumeFileInfo = new FileInfo(volumePath);

            if (volumeFileInfo.Directory != null && !volumeFileInfo.Directory.Exists)
            {
                volumeFileInfo.Directory.Create();
            }

            var tmpPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N") + ".vhd");

            using (var progress = new WrappedProgress(progressReporter))
            {
                // ReSharper disable once UnusedVariable
                var progressSize           = vhdSize <= 0 ? progress.GetChildProgress(30) : null;
                var progressStopService    = progress.GetChildProgress(10);
                var progressInitializeDisk = progress.GetChildProgress(100);
                // var progressNewPartition = progress.GetChildProgress(30);
                // var progressFormatVolume = progress.GetChildProgress(80);
                var progressStartService = progress.GetChildProgress(10);
                var progressExpand       = progress.GetChildProgress(120);
                var progressScripts      = generateScripts ? progress.GetChildProgress(10) : null;

                try
                {
                    var minimumSize = vhdSize > 0 ? 1024 * 1024 * vhdSize : await GetVhdSize(packagePath, cancellationToken : cancellationToken).ConfigureAwait(false);

                    bool requiresRestart;
                    try
                    {
                        requiresRestart = await StopService(cancellationToken, progressStopService).ConfigureAwait(false);
                    }
                    catch (Exception)
                    {
                        requiresRestart = false;
                    }

                    Guid   volumeGuid;
                    var    wrapper = new DiskPartWrapper();
                    string pkgFullName;

                    try
                    {
                        var allDrives = DriveInfo.GetDrives().Where(d => d.IsReady && d.DriveFormat == "NTFS").Select(d => d.Name.ToLowerInvariant()).ToArray();

                        var existing = await this.GetVolumeIdentifiers().ConfigureAwait(false);

                        await wrapper.CreateVhdAndAssignDriveLetter(tmpPath, minimumSize, cancellationToken, progressInitializeDisk).ConfigureAwait(false);

                        var newVolumes = (await this.GetVolumeIdentifiers().ConfigureAwait(false)).Except(existing).ToArray();

                        var newDrives = DriveInfo.GetDrives().Where(d => d.IsReady && d.DriveFormat == "NTFS").Select(d => d.Name.ToLowerInvariant()).Except(allDrives).ToArray();

                        if (newDrives.Length != 1 || newVolumes.Length != 1)
                        {
                            throw new InvalidOperationException("Could not mount the drive.");
                        }

                        volumeGuid = newVolumes[0];
                        cancellationToken.ThrowIfCancellationRequested();
                        pkgFullName = await this.ExpandMsix(packagePath, newDrives.First() + Path.GetFileNameWithoutExtension(packagePath), cancellationToken, progressExpand).ConfigureAwait(false);
                    }
                    finally
                    {
                        await wrapper.DismountVhd(tmpPath, cancellationToken).ConfigureAwait(false);

                        if (requiresRestart)
                        {
                            try
                            {
                                await StartService(cancellationToken, progressStartService).ConfigureAwait(false);
                            }
                            catch (Exception e)
                            {
                                Logger.Warn(e, "Could not restart the service ShellHWDetection.");
                            }
                        }
                    }

                    if (File.Exists(tmpPath))
                    {
                        if (generateScripts)
                        {
                            await CreateScripts(volumeFileInfo.FullName, Path.GetFileNameWithoutExtension(packagePath), volumeGuid, pkgFullName, cancellationToken, progressScripts).ConfigureAwait(false);
                        }

                        await CreateJson(volumeFileInfo.FullName, Path.GetFileNameWithoutExtension(packagePath), volumeGuid, pkgFullName, cancellationToken, progressScripts).ConfigureAwait(false);

                        if (extractCertificate)
                        {
                            ISigningManager certMgr = this.signingManager;
                            if (certMgr == null)
                            {
                                certMgr = await this.managerFactory.GetProxyFor(SelfElevationLevel.AsInvoker, cancellationToken).ConfigureAwait(false);
                            }

                            cancellationToken.ThrowIfCancellationRequested();

                            // ReSharper disable once AssignNullToNotNullAttribute
                            await certMgr.ExtractCertificateFromMsix(packagePath, Path.Combine(volumeFileInfo.DirectoryName, Path.GetFileNameWithoutExtension(volumeFileInfo.FullName)) + ".cer", cancellationToken).ConfigureAwait(false);
                        }

                        File.Move(tmpPath, volumeFileInfo.FullName, true);
                    }
                }
                finally
                {
                    if (File.Exists(tmpPath))
                    {
                        File.Delete(tmpPath);
                    }
                }
            }
        }
Beispiel #8
0
 public AppAttachManager(ISigningManager signingManager)
 {
     this.signingManager = signingManager;
 }