/// <summary> /// Creates a new service provider. /// </summary> /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</param> public ServiceProvider(ITaskHandler handler) { Handler = handler ?? throw new ArgumentNullException(nameof(handler)); _feedCache = new(() => FeedCaches.Default(OpenPgp)); _trustManager = new(() => new(TrustDB.LoadSafe(), Config, OpenPgp, FeedCache, Handler)); _feedManager = new(() => new(Config, FeedCache, TrustManager, Handler)); _catalogManager = new(() => new(TrustManager, Handler)); _selectionCandidateProvider = new(() => new(Config, FeedManager, ImplementationStore, PackageManager)); _solver = new(() => { var backtrackingSolver = new BacktrackingSolver(SelectionCandidateProvider); if (Config.ExternalSolverUri == null) { return(backtrackingSolver); } else { var externalSolver = new ExternalSolver(backtrackingSolver, SelectionsManager, Fetcher, Executor, FeedManager, Handler, Config.ExternalSolverUri); return(new FallbackSolver(backtrackingSolver, externalSolver)); } }); _fetcher = new(() => new(Config, ImplementationStore, Handler)); _executor = new(() => new(ImplementationStore)); _selectionsManager = new(() => new(FeedManager, ImplementationStore, PackageManager)); }
public void AddKeyForDomain() { RunAndAssert(null, ExitCode.OK, "abc", "example.com"); TrustDB.LoadSafe() .Should().Be(new TrustDB().TrustKey("abc", new("example.com"))); }
public void RemoveKeyForDomain() { new TrustDB() .TrustKey("abc", new("example.com")) .TrustKey("abc", new("example2.com")) .Save(TrustDB.DefaultLocation); RunAndAssert(null, ExitCode.OK, "abc", "example.com"); TrustDB.LoadSafe() .Should().Be(new TrustDB().TrustKey("abc", new("example2.com"))); }
public ValidSignature CheckTrust(byte[] data, FeedUri uri, FeedUri mirrorUrl = null) { #region Sanity checks if (uri == null) { throw new ArgumentNullException("uri"); } if (data == null) { throw new ArgumentNullException("data"); } #endregion if (uri.IsFile) { throw new UriFormatException(Resources.FeedUriLocal); } var domain = new Domain(uri.Host); KeyImported: var trustDB = TrustDB.LoadSafe(); var signatures = FeedUtils.GetSignatures(_openPgp, data); foreach (var signature in signatures.OfType <ValidSignature>()) { if (trustDB.IsTrusted(signature.Fingerprint, domain)) { return(signature); } } foreach (var signature in signatures.OfType <ValidSignature>()) { if (TrustNew(trustDB, uri, signature, domain)) { return(signature); } } foreach (var signature in signatures.OfType <MissingKeySignature>()) { DownloadMissingKey(uri, mirrorUrl, signature); goto KeyImported; } throw new SignatureException(string.Format(Resources.FeedNoTrustedSignatures, uri)); }
/// <summary> /// Registers a set of scoped services for using Zero Install functionality. /// </summary> /// <typeparam name="TTaskHandler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</typeparam> /// <param name="services">The service collection to add the services to.</param> public static IServiceCollection AddZeroInstall <TTaskHandler>(this IServiceCollection services) where TTaskHandler : class, ITaskHandler => services.AddScoped <ITaskHandler, TTaskHandler>() .AddScoped(x => Config.Load()) .AddScoped(x => ImplementationStores.Default()) .AddScoped(x => OpenPgp.Verifying()) .AddScoped(x => FeedCaches.Default(x.GetService <IOpenPgp>())) .AddScoped(x => TrustDB.LoadSafe()) .AddScoped <ITrustManager, TrustManager>() .AddScoped <IFeedManager, FeedManager>() .AddScoped <ICatalogManager, CatalogManager>() .AddScoped(x => PackageManagers.Default()) .AddScoped <ISelectionsManager, SelectionsManager>() .AddScoped <ISolver, BacktrackingSolver>() .AddScoped <IFetcher, SequentialFetcher>() .AddScoped <IExecutor, Executor>() .AddScoped <ISelectionCandidateProvider, SelectionCandidateProvider>();
/// <summary> /// Registers a set of scoped services for using Zero Install functionality. /// </summary> /// <typeparam name="TTaskHandler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</typeparam> /// <param name="services">The service collection to add the services to.</param> /// <param name="configuration">An optional configuration source for building <see cref="Config"/> instead of the default config files.</param> public static IServiceCollection AddZeroInstall <TTaskHandler>(this IServiceCollection services, IConfiguration?configuration = null) where TTaskHandler : class, ITaskHandler => services.AddScoped <ITaskHandler, TTaskHandler>() .AddScoped(_ => (configuration == null) ? Config.Load() : Config.From(configuration)) .AddScoped(_ => ImplementationStores.Default()) .AddScoped(_ => OpenPgp.Verifying()) .AddScoped(provider => FeedCaches.Default(provider.GetRequiredService <IOpenPgp>())) .AddScoped(_ => TrustDB.LoadSafe()) .AddScoped <ITrustManager, TrustManager>() .AddScoped <IFeedManager, FeedManager>() .AddScoped <ICatalogManager, CatalogManager>() .AddScoped(_ => PackageManagers.Default()) .AddScoped <ISelectionsManager, SelectionsManager>() .AddScoped <ISolver, BacktrackingSolver>() .AddScoped <IFetcher, Fetcher>() .AddScoped <IExecutor, Executor>() .AddScoped <ISelectionCandidateProvider, SelectionCandidateProvider>();
private void LoadTrust() { treeViewTrustedKeys.Nodes = TrustDB.LoadSafe().ToNodes(); }