public ComponentsContainer(ApplicationConfiguration appConfig, IDomainPrivateKeyProvider domainPrivateKeyProvider, IDomainScopeResolver domainScopeResolver, ILogger logger) { this.domainPrivateKeyProvider = domainPrivateKeyProvider; this.domainScopeResolver = domainScopeResolver; this.logger = logger; configurationProvider = new ConfigurationProvider(appConfig); }
public SecurityProvider(Func <HMAC> macImplFactory, IDomainScopeResolver domainScopeResolver, IDomainPrivateKeyProvider domainPrivateKeyProvider, bool disableSigning = false) { this.disableSigning = disableSigning; nameToDomainMap = domainPrivateKeyProvider.GetAllowedDomainKeys() .ToDictionary(dk => dk.Domain, dk => dk); messageToDomainMap = CreateMessageMapping(nameToDomainMap, domainScopeResolver); mac = macImplFactory(); unsignableDomains = domainPrivateKeyProvider.GetUnsignedDomains() ?? new Dictionary <string, HashSet <EquatableIdentity> >(); }
private static IDictionary <AnyVersionMessageIdentifier, DomainPrivateKey> CreateMessageMapping(IDictionary <string, DomainPrivateKey> domainKeys, IDomainScopeResolver domainScopeResolver) { var mappings = new Dictionary <AnyVersionMessageIdentifier, DomainPrivateKey>(); var domainScopes = domainScopeResolver.GetDomainMessages(domainKeys.Select(dk => dk.Key)); foreach (var message in domainScopes.SelectMany(dm => dm.MessageIdentities, (dm, id) => new { Identity = id, Domain = dm.Domain })) { if (domainKeys.TryGetValue(message.Domain, out var key)) { var messageIdentifier = new AnyVersionMessageIdentifier(message.Identity.GetBytes()); DomainPrivateKey _; if (!mappings.TryGetValue(messageIdentifier, out _)) { mappings.Add(messageIdentifier, key); } else { throw new Exception($"Message {message.Identity} is already mapped to Domain {_.Domain}!"); } } else { throw new Exception($"PrivateKey for Domain {message.Domain} is not found!"); } } return(mappings); }