/// <summary> /// Adds the client and service certificate that the provisioning call returned to the local machine's certificate store. /// Also, the certificates will be saved as files in the executable's folder, so that they can be installed /// on other machines that need to connect to the newly provisioned Austin instance. /// </summary> /// <param name="response">Provisioning response including the certificates.</param> private static void AddServiceAndClientCertsToStore(CreateResponse response) { // Remove existing certificates from store string serviceName = ConfigurationManager.AppSettings["HostedServiceName"]; string clientCertName = string.Format("StreamInsight Client ({0})", serviceName); string serviceCertName = string.Format("{0}.cloudapp.net", serviceName); Console.WriteLine("Removing old certificates from local store..."); CertificateHelper.RemoveCertificate(clientCertName, StoreName.My, StoreLocation.CurrentUser); CertificateHelper.RemoveCertificate(serviceCertName, StoreName.TrustedPeople, StoreLocation.CurrentUser); // Add new certificates Console.WriteLine("Adding certificates to local store..."); byte[] clientRawCert = Convert.FromBase64String(response.ClientCertificate); byte[] serviceRawCert = Convert.FromBase64String(response.ServiceCertificate); X509Certificate2 clientCert = new X509Certificate2(clientRawCert, response.ClientCertificatePassword, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet); X509Certificate2 serviceCert = new X509Certificate2(serviceRawCert); CertificateHelper.AddCertificate(clientCert, StoreName.My, StoreLocation.CurrentUser); CertificateHelper.AddCertificate(serviceCert, StoreName.TrustedPeople, StoreLocation.CurrentUser); // Save certificates to file string clientCertFileName = serviceName + "_client.pfx"; string serviceCertFileName = serviceName + "_service.cer"; File.WriteAllBytes(clientCertFileName, clientCert.Export(X509ContentType.Pfx, ConfigurationManager.AppSettings["ClientCertificatePassword"])); File.WriteAllBytes(serviceCertFileName, serviceCert.Export(X509ContentType.Cert)); Console.WriteLine("Client Certificate also saved as {0}.", clientCertFileName); Console.WriteLine("Service Certificate also saved as {0}.", serviceCertFileName); }