private static X509Certificate2 GetCertificate(bool useRSACert = false) { X509Certificate2 cert = CertificateHelper.FindCertificateByThumbprint(useRSACert ? TestConstants.RSATestCertThumbprint : TestConstants.AutomationTestThumbprint); if (cert == null) { throw new InvalidOperationException( "Test setup error - cannot find a certificate in the My store for KeyVault. This is available for Microsoft employees only."); } return(cert); }
public void GetWithCertificate(string uri, string thumbprint) { var certificate = CertificateHelper.FindCertificateByThumbprint(thumbprint); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); req.PreAuthenticate = true; req.AllowAutoRedirect = true; req.ClientCertificates.Add(certificate); req.Method = "GET"; WebResponse resp = req.GetResponse(); using (StreamReader reader = new StreamReader(resp.GetResponseStream())) { string line = reader.ReadLine(); while (line != null) { Console.WriteLine(line); line = reader.ReadLine(); } Console.WriteLine(line); } }
public FederationMember(Endpoint ep) { Name = ep.Name; Url = ep.Address; if (ep.PayloadMimeType.Contains("application/fhir+xml")) { Format = Hl7.Fhir.Rest.ResourceFormat.Xml; } else if (ep.PayloadMimeType.Contains("application/fhir+json")) { Format = Hl7.Fhir.Rest.ResourceFormat.Json; } else { Format = Hl7.Fhir.Rest.ResourceFormat.Xml; } Headers = ep.Header.ToArray(); string thubmprint = ep.GetStringExtension("http://standards.telstrahealth.com.au/fhir/federation-thumbprint"); if (!string.IsNullOrEmpty(thubmprint)) { Certificate = CertificateHelper.FindCertificateByThumbprint(thubmprint); } }
/// <summary> /// /// </summary> /// <param name="configurtaion"></param> public static void GetCert(IConfiguration configurtaion) { var clientAssertionCertPfx = CertificateHelper.FindCertificateByThumbprint(configurtaion["General:KeyVaultCertThumbPrint"].ToString()); AssertionCert = new ClientAssertionCertificate(configurtaion["General:KeyVaultClientID"], clientAssertionCertPfx); }
public async Task <ActionResult> Index(Message newMessage) { ModelState.Remove("NewMessage.MessageText"); var model = new MessageBoardModel(); try { model.Trace.Add(""); ////////////////////////////// //Trace out the config settings ////////////////////////////// model.Trace.Add("Configuration:"); model.Trace.Add("\tStorage account name: " + CloudConfigurationManager.GetSetting(Constants.StorageAccountNameSetting)); model.Trace.Add("\tStorage account key (URL to the Key Vault secret): " + CloudConfigurationManager.GetSetting(Constants.StorageAccountKeySecretUrlSetting)); model.Trace.Add("\tKey Vault client ID: " + CloudConfigurationManager.GetSetting(Constants.KeyVaultAuthClientIdSetting)); model.Trace.Add("\tKey Vault authentication certificate: " + CloudConfigurationManager.GetSetting(Constants.KeyVaultAuthCertThumbprintSetting) + "\n\n"); ////////////////////////////// //Load the auth cert ////////////////////////////// model.Trace.Add("Processing: Finding Key Vault authentication certificate"); var cert = CertificateHelper.FindCertificateByThumbprint(CloudConfigurationManager.GetSetting(Constants.KeyVaultAuthCertThumbprintSetting)); if (cert == null) { model.Trace.Add("\tCould not find the certificate in the Local Machine's Personal certificate store."); model.Trace.Add("\tTo import a certificate: right-click on the certificate, click Install Certificate, set Store Location to 'Local Machine', set Certificate store to 'Personal', and click finish."); model.Trace.Add("\tDid you get the right thumbprint from your Operator? A certificate thumbprint can be found in the 'Details' tab of a certificate and should be added to the service configuration."); model.Trace.Add("\tDid your Operator upload the certificate to the Azure portal for this service?"); return(View(model)); } model.Trace.Add("\tSuccess!\n"); ////////////////////////////// //Get the secret from Key Vault ////////////////////////////// model.Trace.Add("Processing: Calling Key Vault Service to get storage account key"); string storageAccountKey = ""; try { storageAccountKey = await KeyVaultAccessor.GetSecret(CloudConfigurationManager.GetSetting(Constants.StorageAccountKeySecretUrlSetting)); } catch { model.Trace.Add("\tCould not get the secret from Key Vault."); model.Trace.Add("\tDid you get the right client ID?"); model.Trace.Add("\tDid you get the correct secret URI?"); model.Trace.Add("\tDid your Operator actually add the storage account key to Key Vault?"); throw; } model.Trace.Add("\tSuccess!\n"); ////////////////////////////// //Use the secret to connect to storage ////////////////////////////// model.Trace.Add("Processing: Connecting to Azure Storage using the storage account key"); StorageTableAccessor storageTable; try { var storageCred = new StorageCredentials(CloudConfigurationManager.GetSetting(Constants.StorageAccountNameSetting), storageAccountKey); var storageAccount = new CloudStorageAccount(storageCred, false); storageTable = new StorageTableAccessor(storageAccount); } catch { model.Trace.Add("\tCould not connect to Azure Storage."); model.Trace.Add("\tDid you get the right secret URI?"); model.Trace.Add("\tDid your Operator add the right secret to Key Vault?"); model.Trace.Add("\tDid your Operator change the storage account key after saving it in Key Vault?"); throw; } model.Trace.Add("\tSuccess!\n"); ////////////////////////////// //Do something useful with storage ////////////////////////////// if (newMessage != null && !string.IsNullOrWhiteSpace(newMessage.UserName) && !string.IsNullOrWhiteSpace(newMessage.MessageText)) { model.Trace.Add("Processing: Save a new message to the storage table"); storageTable.AddEntry(newMessage); model.Trace.Add("\tSuccess!\n"); } model.Trace.Add("Processing: Retrieving recent messages from the storage table"); model.RecentMessages = new List <Message>(storageTable.GetRecentEntries()); model.Trace.Add("\tSuccess!\n"); model.Trace[0] = "Everything is working great :). Scroll down for details!\n"; } catch (Exception e) { model.Trace[0] = "Hmm...something went wrong :(. Scroll down for details!\n"; model.Trace.Add("\n\nError details:\n" + e.ToString()); } return(View(model)); }