예제 #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;
            }
        }
예제 #3
0
        public static string GetFileName(string Name)
        {
            string filePath = Name;

            if (!string.IsNullOrEmpty(filePath))
            {
                string[] partnerWords = filePath.Split(' ');
                while (partnerWords.Count() > 1)
                {
                    filePath     = string.Join("", partnerWords);
                    partnerWords = filePath.Split(' ');
                }
            }
            string nameWithoutSpecialChars = StringOperations.RemoveSpecialCharacters(filePath);

            if (nameWithoutSpecialChars.Length > 80)
            {
                return(nameWithoutSpecialChars.Substring(0, 80));
            }
            else
            {
                return(nameWithoutSpecialChars);
            }
        }