/// <summary> /// Load the key ring from Azure Key Vault and render it on screen /// </summary> /// <returns></returns> public IActionResult Index() { var keys = new Dictionary <string, string>(); int counter = 1; foreach (var entry in _keyring.GetAllElements()) { string str = PrettyXml(entry); keys.Add("Entry" + counter, str); counter++; } return(View(keys)); }
public IReadOnlyCollection <IKey> GetAllKeys() { var allElements = _xmlRepository.GetAllElements(); Dictionary <Guid, Key> idToKeyMap = new Dictionary <Guid, Key>(); HashSet <Guid> revokedKeyIds = null; DateTimeOffset? mostRecentMassRevocationDate = null; foreach (var element in allElements) { if (element.Name == KeyElementName) { var thisKey = ParseKeyElement(element); if (idToKeyMap.ContainsKey(thisKey.KeyId)) { CryptoUtil.Fail("TODO: Duplicate key."); } idToKeyMap.Add(thisKey.KeyId, thisKey); } else if (element.Name == RevocationElementName) { object revocationInfo = ParseRevocationElement(element); DateTimeOffset?revocationInfoAsDate = revocationInfo as DateTimeOffset?; if (revocationInfoAsDate != null) { // We're revoking all keys created on or after a specific date. if (!mostRecentMassRevocationDate.HasValue || mostRecentMassRevocationDate < revocationInfoAsDate) { // This new value is the most recent mass revocation date. mostRecentMassRevocationDate = revocationInfoAsDate; } } else { // We're revoking only a specific key if (revokedKeyIds == null) { revokedKeyIds = new HashSet <Guid>(); } revokedKeyIds.Add((Guid)revocationInfo); } } else { CryptoUtil.Fail("TODO: Unknown element."); } } // Now process all revocations if (revokedKeyIds != null || mostRecentMassRevocationDate.HasValue) { foreach (Key key in idToKeyMap.Values) { if ((revokedKeyIds != null && revokedKeyIds.Contains(key.KeyId)) || (mostRecentMassRevocationDate.HasValue && mostRecentMassRevocationDate >= key.CreationDate)) { key.SetRevoked(); } } } // And we're done! return(idToKeyMap.Values.ToArray()); }