private void OnManageInstallList(object sender, RoutedEventArgs e)
        {
            Window parentWindow = FindParentWindow();

            if (parentWindow == null)
            {
                throw new Exception("Error: CertificateSelector must be a child of a Window.");
            }

            // Gather the currently 'desired' certificate file names.
            List <string> currentBlobFileNames = new List <string>();

            if (CertificateList.ItemsSource != null)
            {
                foreach (CertificateDetails certificateData in CertificateList.ItemsSource)
                {
                    currentBlobFileNames.Add(certificateData.FileName);
                }
            }

            // Show contents of the container, and make the ones in currentBlobFileNames as selected.
            AzureBlobSelector azureBlobSelector = new AzureBlobSelector(currentBlobFileNames, ConnectionString, ContainerName, ".cer");

            azureBlobSelector.Owner = parentWindow;
            azureBlobSelector.ShowDialog();

            List <CertificateSummary> certsToInstall  = new List <CertificateSummary>();
            List <CertificateDetails> certificateList = new List <CertificateDetails>();

            if (azureBlobSelector.BlobFileNames != null)
            {
                foreach (string blobName in azureBlobSelector.BlobFileNames)
                {
                    string tempFullFileName = Path.GetTempFileName();

                    AzureStorageHelpers.DownloadAzureFile(ConnectionString, ContainerName, blobName, tempFullFileName);

                    // Build the data used for UI...
                    CertificateDetails certificateData = new CertificateDetails();
                    certificateData.LoadFromCertificateFile(tempFullFileName, blobName);
                    certificateList.Add(certificateData);

                    // Build the data used for callers... (ToDo: we should not have two lists here).
                    CertificateSummary certificateSummary = new CertificateSummary();
                    certificateSummary.Hash            = certificateData.Hash;
                    certificateSummary.StorageFileName = ContainerName + "\\\\" + blobName;
                    certificateSummary.State           = CertificatesDataContract.JsonStateInstalled;
                    certsToInstall.Add(certificateSummary);
                }
            }

            _certsToInstall = certsToInstall;

            // Update the UI
            certificateList.Sort((x, y) => x.Hash.CompareTo(y.Hash));
            CertificateList.ItemsSource = certificateList;
        }
        public static X509Certificate2 GetCertificateInfo(string connectionString, string containerName, string blobName, string targetFolder)
        {
            AzureStorageHelpers.DownloadAzureFile(connectionString, containerName, blobName, targetFolder);

            string fullFileName = targetFolder + "\\" + blobName;

            if (!File.Exists(fullFileName))
            {
                throw new Exception("Error: failed to download certificate file!");
            }

            X509Certificate certp = X509Certificate2.CreateFromSignedFile(fullFileName);

            return(new X509Certificate2(certp.Handle));
        }
 private void OnShowDetails(object sender, RoutedEventArgs e)
 {
     if (ShowCertificateDetails != null)
     {
         Button             btn             = (Button)sender;
         CertificateDetails certificateData = (CertificateDetails)btn.DataContext;
         if (!certificateData.DetailsAvailable)
         {
             string blobName = certificateData.Hash + ".json";
             string certificateDetailsFile = Path.GetTempFileName();
             AzureStorageHelpers.DownloadAzureFile(ConnectionString, ContainerName, blobName, certificateDetailsFile);
             certificateData.LoadFromJsonFile(certificateDetailsFile, blobName);
         }
         ShowCertificateDetails(this, certificateData);
     }
 }
예제 #4
0
        private string LoadFromAzureBlob(string connectionString, string containerName, string blobName)
        {
            string tempPath = Path.GetTempPath();

            AzureStorageHelpers.DownloadAzureFile(connectionString, containerName, blobName, tempPath);
            string fullFileName = tempPath + blobName;

            if (!File.Exists(fullFileName))
            {
                throw new Exception("Error: failed to download wifi xml file!");
            }
            try
            {
                string wifiString = File.ReadAllText(fullFileName);
                return(wifiString);
            }
            finally
            {
                File.Delete(fullFileName);
            }
        }
            public void LoadFromJsonAzureBlob(string connectionString, string containerName, string blobName, string targetFolder)
            {
                AzureStorageHelpers.DownloadAzureFile(connectionString, containerName, blobName, targetFolder);

                string fullFileName = targetFolder + "\\" + blobName;

                if (!File.Exists(fullFileName))
                {
                    throw new Exception("Error: failed to download certificate json file!");
                }

                string jsonString = File.ReadAllText(fullFileName);

                FileName = blobName;
                CertificateJsonData data = JsonConvert.DeserializeObject <CertificateJsonData>(jsonString);

                Issuer           = data.issuedBy;
                Subject          = data.issuedTo;
                IssueDate        = DateTime.Parse(data.validFrom);
                ExpiryDate       = DateTime.Parse(data.validTo);
                Base64Encoding   = data.base64Encoding;
                TemplateName     = data.templateName;
                DetailsAvailable = true;
            }