Пример #1
0
        public static string GetKeyVaultJsonFilePath(string keyvault)
        {
            var fileLocation = Resources.JsonKeyVaultFilesLocalPath;
            var fileName     = string.Format(fileLocation, StringOperations.RemoveAllSpecialCharacters(GetFileName(keyvault)), ".json");

            return(fileName);
        }
Пример #2
0
        public void CheckIfCertificateIsprivate(TEntity item, string certificateName, IntegrationAccountDetails iaDetails)
        {
            try
            {
                string filepath    = FileOperations.GetCertificateJsonFilePath(certificateName);
                string content     = File.ReadAllText(filepath);
                var    certificate = JsonConvert.DeserializeObject <JsonCertificate.Rootobject>(content);
                if (certificate.properties.key != null)
                {
                    string keyvaultname = iaDetails.KeyVaultName;
                    if (string.IsNullOrEmpty(keyvaultname))
                    {
                        throw new Exception("Couldn't find the name of the Key Vault to upload the Private key for the Private Certificate. Make sure you selected a Key Vault at the Integration Account Details Screen");
                    }
                    string certName                      = FileOperations.GetFileName(certificateName);
                    string keyvaultfilepath              = FileOperations.GetKeyVaultJsonFilePath(certName + "Privatekey");
                    IntegrationAccountContext sclient    = new IntegrationAccountContext();
                    AuthenticationResult      authresult = thisApplicationContext.GetProperty("KeyVaultAuthorization") as AuthenticationResult;
                    string kid = sclient.UploadCertificatePrivateKeyToKeyVault(StringOperations.RemoveAllSpecialCharacters(certName) + "Privatekey", keyvaultname, keyvaultfilepath, authresult);
                    certificate.properties.key.keyName     = StringOperations.RemoveAllSpecialCharacters(certName) + "Privatekey";
                    certificate.properties.key.keyVersion  = kid;
                    certificate.properties.key.keyVault.id = string.Format(ConfigurationManager.AppSettings["KeyVaultResourceIdTemplate"], iaDetails.SubscriptionId, iaDetails.ResourceGroupName, keyvaultname);
                    //certificate.properties.key.keyVault.name = certName + "Privatekey";

                    string fileName = FileOperations.GetCertificateJsonFilePath(certName);
                    string partnerJsonFileContent = JsonConvert.SerializeObject(certificate);
                    File.WriteAllText(fileName, partnerJsonFileContent);
                }
            }
            catch (Exception ex)
            {
                SetStatus(item, MigrationStatus.Failed, string.Format("Certificate Migration Failed. Reason:{0}", ExceptionHelper.GetExceptionMessage(ex)));
                TraceProvider.WriteLine(string.Format("Certificate Migration Failed. Reason:{0}", ExceptionHelper.GetExceptionMessage(ex)));
                TraceProvider.WriteLine();
                throw ex;
            }
        }