Ejemplo n.º 1
0
        public static UploadCertificateResponse Unmarshall(UnmarshallerContext _ctx)
        {
            UploadCertificateResponse uploadCertificateResponse = new UploadCertificateResponse();

            uploadCertificateResponse.HttpResponse = _ctx.HttpResponse;
            uploadCertificateResponse.RequestId    = _ctx.StringValue("UploadCertificate.RequestId");

            return(uploadCertificateResponse);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method to update vault certificate
        /// </summary>
        /// <param name="cert">certificate object </param>
        /// <returns>Upload Certificate Response</returns>
        private async Task <UploadCertificateResponse> UpdateVaultCertificate(X509Certificate2 cert)
        {
            var certificateArgs = new CertificateArgs();

            certificateArgs.Properties = new Dictionary <string, string>();
            certificateArgs.Properties.Add("certificate", Convert.ToBase64String(cert.GetRawCertData()));
            // CertificateArgs.Properties.Add("ContractVersion", "V2012_12");

            UploadCertificateResponse response = await this.UpdateVaultCertificate(certificateArgs, cert.FriendlyName);

            return(response);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method to update vault certificate
        /// </summary>
        /// <param name="cert">certificate object </param>
        /// <returns>Upload Certificate Response</returns>
        private async Task <UploadCertificateResponse> UpdateVaultCertificate(X509Certificate2 cert)
        {
            var certificateArgs = new CertificateArgs()
            {
                Certificate     = Convert.ToBase64String(cert.GetRawCertData()),
                ContractVersion = "V2012_12"
            };

            UploadCertificateResponse response = await this.UpdateVaultCertificate(certificateArgs);

            return(response);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Uploads the vault certificate.
        /// </summary>
        /// <param name="resourceGroupName"></param>
        /// <param name="resourceName"></param>
        /// <param name="resourceLocation"></param>
        /// <param name="certWithPrivateKey"></param>
        /// <param name="uploadCertificate"></param>
        /// <returns></returns>
        internal static string GetAadActivationKey(string resourceGroupName, string resourceName,
                                                   string resourceLocation, string certWithPrivateKey,
                                                   UploadCertificateResponse uploadCertificate, string subscriptionId, string cik)
        {
            var RegistrationKeyHashSize = 16;
            var vault = GetVaultCredentials(resourceGroupName, resourceName, resourceLocation, certWithPrivateKey, uploadCertificate, subscriptionId, cik);

            var st             = JsonConvert.SerializeObject(vault);
            var plainTextBytes = Encoding.UTF8.GetBytes(st);
            var activation     = Convert.ToBase64String(plainTextBytes);
            var hash           = GenerateSha512Hash(activation);

            return($"{activation}#{hash.Substring(0, RegistrationKeyHashSize)}");
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AcsNamespace"/> class.
 /// </summary>
 /// <param name="acsDetails">authenticating service Details name</param>
 public AcsNamespace(UploadCertificateResponse acsDetails)
 {
     this.HostName              = acsDetails.Properties.GlobalAcsHostName;
     this.Namespace             = acsDetails.Properties.GlobalAcsNamespace;
     this.ResourceProviderRealm = acsDetails.Properties.GlobalAcsRPRealm;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Method to generate the credential file content
        /// </summary>
        /// <param name="managementCert">management cert</param>
        /// <param name="acsDetails">ACS details</param>
        /// <param name="channelIntegrityKey">Integrity key</param>
        /// <param name="vault">vault object</param>
        /// <param name="site">site object</param>
        /// <returns>vault credential object</returns>
        private ASRVaultCreds GenerateCredentialObject(X509Certificate2 managementCert, UploadCertificateResponse acsDetails, string channelIntegrityKey, ASRVault vault, ASRSite site)
        {
            string serializedCertifivate = Convert.ToBase64String(managementCert.Export(X509ContentType.Pfx));

            AcsNamespace acsNamespace = new AcsNamespace(acsDetails);

            string resourceProviderNamespace = string.Empty;
            string resourceType = string.Empty;

            Utilities.GetResourceProviderNamespaceAndType(vault.ID, out resourceProviderNamespace, out resourceType);
            ASRVaultCreds vaultCreds = new ASRVaultCreds(
                vault.SubscriptionId,
                vault.Name,
                serializedCertifivate,
                acsNamespace,
                channelIntegrityKey,
                vault.ResourceGroupName,
                site.ID,
                site.Name,
                resourceProviderNamespace,
                resourceType);

            return(vaultCreds);
        }
        /// <summary>
        /// Upload certificate
        /// </summary>
        /// <param name="cert">management certificate</param>
        /// <returns>acs namespace of the uploaded cert</returns>
        private AcsNamespace UploadCert(X509Certificate2 cert)
        {
            UploadCertificateResponse response = RecoveryServicesClient.UploadCertificate(cert, this.Vault);

            return(new AcsNamespace(response));
        }
        /// <summary>
        /// Get the vault extended info.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the resource group containing the job
        /// collection.
        /// </param>
        /// <param name='resourceName'>
        /// Required. The name of the resource.
        /// </param>
        /// <param name='parameters'>
        /// Required. Upload Vault Certificate input parameters.
        /// </param>
        /// <param name='certFriendlyName'>
        /// Required. Certificate friendly name
        /// </param>
        /// <param name='customRequestHeaders'>
        /// Optional. Request header parameters.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the upload certificate response
        /// </returns>
        public async Task <UploadCertificateResponse> UploadCertificateAsync(string resourceGroupName, string resourceName, CertificateArgs parameters, string certFriendlyName, CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (resourceName == null)
            {
                throw new ArgumentNullException("resourceName");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (parameters.Properties == null)
            {
                throw new ArgumentNullException("parameters.Properties");
            }
            if (certFriendlyName == null)
            {
                throw new ArgumentNullException("certFriendlyName");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("resourceGroupName", resourceGroupName);
                tracingParameters.Add("resourceName", resourceName);
                tracingParameters.Add("parameters", parameters);
                tracingParameters.Add("certFriendlyName", certFriendlyName);
                tracingParameters.Add("customRequestHeaders", customRequestHeaders);
                TracingAdapter.Enter(invocationId, this, "UploadCertificateAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/Subscriptions/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/resourceGroups/";
            url = url + Uri.EscapeDataString(resourceGroupName);
            url = url + "/providers/";
            url = url + Uri.EscapeDataString(this.Client.ResourceNamespace);
            url = url + "/";
            url = url + Uri.EscapeDataString(this.Client.ResourceType);
            url = url + "/";
            url = url + Uri.EscapeDataString(resourceName);
            url = url + "/certificates/";
            url = url + Uri.EscapeDataString(certFriendlyName);
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2015-08-15");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Put;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept-Language", customRequestHeaders.Culture);
                httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId);

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Serialize Request
                string requestContent = null;
                JToken requestDoc     = null;

                JObject parametersValue = new JObject();
                requestDoc = parametersValue;

                if (parameters.Properties != null)
                {
                    if (parameters.Properties is ILazyCollection == false || ((ILazyCollection)parameters.Properties).IsInitialized)
                    {
                        JObject propertiesDictionary = new JObject();
                        foreach (KeyValuePair <string, string> pair in parameters.Properties)
                        {
                            string propertiesKey   = pair.Key;
                            string propertiesValue = pair.Value;
                            propertiesDictionary[propertiesKey] = propertiesValue;
                        }
                        parametersValue["properties"] = propertiesDictionary;
                    }
                }

                requestContent      = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
                httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    UploadCertificateResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new UploadCertificateResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            JToken propertiesValue2 = responseDoc["properties"];
                            if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
                            {
                                CertificateProperties propertiesInstance = new CertificateProperties();
                                result.Properties = propertiesInstance;

                                JToken friendlyNameValue = propertiesValue2["friendlyName"];
                                if (friendlyNameValue != null && friendlyNameValue.Type != JTokenType.Null)
                                {
                                    string friendlyNameInstance = ((string)friendlyNameValue);
                                    propertiesInstance.FriendlyName = friendlyNameInstance;
                                }

                                JToken globalAcsHostNameValue = propertiesValue2["globalAcsHostName"];
                                if (globalAcsHostNameValue != null && globalAcsHostNameValue.Type != JTokenType.Null)
                                {
                                    string globalAcsHostNameInstance = ((string)globalAcsHostNameValue);
                                    propertiesInstance.GlobalAcsHostName = globalAcsHostNameInstance;
                                }

                                JToken globalAcsNamespaceValue = propertiesValue2["globalAcsNamespace"];
                                if (globalAcsNamespaceValue != null && globalAcsNamespaceValue.Type != JTokenType.Null)
                                {
                                    string globalAcsNamespaceInstance = ((string)globalAcsNamespaceValue);
                                    propertiesInstance.GlobalAcsNamespace = globalAcsNamespaceInstance;
                                }

                                JToken globalAcsRPRealmValue = propertiesValue2["globalAcsRPRealm"];
                                if (globalAcsRPRealmValue != null && globalAcsRPRealmValue.Type != JTokenType.Null)
                                {
                                    string globalAcsRPRealmInstance = ((string)globalAcsRPRealmValue);
                                    propertiesInstance.GlobalAcsRPRealm = globalAcsRPRealmInstance;
                                }

                                JToken resourceIdValue = propertiesValue2["resourceId"];
                                if (resourceIdValue != null && resourceIdValue.Type != JTokenType.Null)
                                {
                                    long resourceIdInstance = ((long)resourceIdValue);
                                    propertiesInstance.ResourceId = resourceIdInstance;
                                }
                            }

                            JToken clientRequestIdValue = responseDoc["ClientRequestId"];
                            if (clientRequestIdValue != null && clientRequestIdValue.Type != JTokenType.Null)
                            {
                                string clientRequestIdInstance = ((string)clientRequestIdValue);
                                result.ClientRequestId = clientRequestIdInstance;
                            }

                            JToken correlationRequestIdValue = responseDoc["CorrelationRequestId"];
                            if (correlationRequestIdValue != null && correlationRequestIdValue.Type != JTokenType.Null)
                            {
                                string correlationRequestIdInstance = ((string)correlationRequestIdValue);
                                result.CorrelationRequestId = correlationRequestIdInstance;
                            }

                            JToken dateValue = responseDoc["Date"];
                            if (dateValue != null && dateValue.Type != JTokenType.Null)
                            {
                                string dateInstance = ((string)dateValue);
                                result.Date = dateInstance;
                            }

                            JToken contentTypeValue = responseDoc["ContentType"];
                            if (contentTypeValue != null && contentTypeValue.Type != JTokenType.Null)
                            {
                                string contentTypeInstance = ((string)contentTypeValue);
                                result.ContentType = contentTypeInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get the vault extended info.
        /// </summary>
        /// <param name='certificateArgs'>
        /// Required. Upload Vault Certificate input parameters.
        /// </param>
        /// <param name='customRequestHeaders'>
        /// Optional. Request header parameters.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the upload certificate response
        /// </returns>
        public async Task <UploadCertificateResponse> UploadCertificateAsync(CertificateArgs certificateArgs, CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken)
        {
            // Validate
            if (certificateArgs == null)
            {
                throw new ArgumentNullException("certificateArgs");
            }
            if (certificateArgs.Certificate == null)
            {
                throw new ArgumentNullException("certificateArgs.Certificate");
            }
            if (certificateArgs.ContractVersion == null)
            {
                throw new ArgumentNullException("certificateArgs.ContractVersion");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("certificateArgs", certificateArgs);
                tracingParameters.Add("customRequestHeaders", customRequestHeaders);
                TracingAdapter.Enter(invocationId, this, "UploadCertificateAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/cloudservices/";
            url = url + Uri.EscapeDataString(this.Client.CloudServiceName);
            url = url + "/resources/";
            url = url + "WAHyperVRecoveryManager";
            url = url + "/~/";
            url = url + "HyperVRecoveryManagerVault";
            url = url + "/";
            url = url + Uri.EscapeDataString(this.Client.ResourceName);
            url = url + "/management/certificate";
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Post;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept", "application/xml");
                httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId);
                httpRequest.Headers.Add("x-ms-version", "2013-03-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Serialize Request
                string    requestContent = null;
                XDocument requestDoc     = new XDocument();

                XElement certificateArgsElement = new XElement(XName.Get("CertificateArgs", "http://schemas.microsoft.com/windowsazure"));
                requestDoc.Add(certificateArgsElement);

                XElement contractVersionElement = new XElement(XName.Get("ContractVersion", "http://schemas.microsoft.com/windowsazure"));
                contractVersionElement.Value = certificateArgs.ContractVersion;
                certificateArgsElement.Add(contractVersionElement);

                XElement certificateElement = new XElement(XName.Get("certificate", "http://schemas.microsoft.com/windowsazure"));
                certificateElement.Value = certificateArgs.Certificate;
                certificateArgsElement.Add(certificateElement);

                requestContent      = requestDoc.ToString();
                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
                httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml");

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    UploadCertificateResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new UploadCertificateResponse();
                        XDocument responseDoc = XDocument.Parse(responseContent);

                        XElement uploadCertificateResponseElement = responseDoc.Element(XName.Get("UploadCertificateResponse", "http://schemas.microsoft.com/windowsazure"));
                        if (uploadCertificateResponseElement != null)
                        {
                            XElement contractVersionElement2 = uploadCertificateResponseElement.Element(XName.Get("ContractVersion", "http://schemas.microsoft.com/windowsazure"));
                            if (contractVersionElement2 != null)
                            {
                                string contractVersionInstance = contractVersionElement2.Value;
                                result.ContractVersion = contractVersionInstance;
                            }

                            XElement globalAcsHostNameElement = uploadCertificateResponseElement.Element(XName.Get("GlobalAcsHostName", "http://schemas.microsoft.com/windowsazure"));
                            if (globalAcsHostNameElement != null)
                            {
                                string globalAcsHostNameInstance = globalAcsHostNameElement.Value;
                                result.GlobalAcsHostName = globalAcsHostNameInstance;
                            }

                            XElement globalAcsNamespaceElement = uploadCertificateResponseElement.Element(XName.Get("GlobalAcsNamespace", "http://schemas.microsoft.com/windowsazure"));
                            if (globalAcsNamespaceElement != null)
                            {
                                string globalAcsNamespaceInstance = globalAcsNamespaceElement.Value;
                                result.GlobalAcsNamespace = globalAcsNamespaceInstance;
                            }

                            XElement globalAcsRPRealmElement = uploadCertificateResponseElement.Element(XName.Get("GlobalAcsRPRealm", "http://schemas.microsoft.com/windowsazure"));
                            if (globalAcsRPRealmElement != null)
                            {
                                string globalAcsRPRealmInstance = globalAcsRPRealmElement.Value;
                                result.GlobalAcsRPRealm = globalAcsRPRealmInstance;
                            }

                            XElement resourceIdElement = uploadCertificateResponseElement.Element(XName.Get("ResourceId", "http://schemas.microsoft.com/windowsazure"));
                            if (resourceIdElement != null)
                            {
                                long resourceIdInstance = long.Parse(resourceIdElement.Value, CultureInfo.InvariantCulture);
                                result.ResourceId = resourceIdInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Method to generate the credential file content
        /// </summary>
        /// <param name="managementCert">management cert</param>
        /// <param name="acsDetails">ACS details</param>
        /// <param name="channelIntegrityKey">Integrity key</param>
        /// <param name="vault">vault object</param>
        /// <param name="site">site object</param>
        /// <returns>vault credential object</returns>
        private ASRVaultCreds GenerateCredentialObject(X509Certificate2 managementCert, UploadCertificateResponse acsDetails, string channelIntegrityKey, ASRVault vault, Site site)
        {
            string serializedCertifivate = Convert.ToBase64String(managementCert.Export(X509ContentType.Pfx));

            AcsNamespace acsNamespace = new AcsNamespace(acsDetails);

            ASRVaultCreds vaultCreds = new ASRVaultCreds(
                vault.SubscriptionId,
                vault.Name,
                serializedCertifivate,
                acsNamespace,
                channelIntegrityKey,
                vault.CloudServiceName,
                site.ID,
                site.Name);

            return(vaultCreds);
        }
        /// <summary>
        /// Method to generate the credential file content
        /// </summary>
        /// <param name="managementCert">management cert</param>
        /// <param name="acsDetails">ACS details</param>
        /// <param name="channelIntegrityKey">Integrity key</param>
        /// <param name="vault">vault object</param>
        /// <param name="site">site object</param>
        /// <returns>vault credential object</returns>
        private ASRVaultCreds GenerateCredentialObject(X509Certificate2 managementCert, UploadCertificateResponse acsDetails, string channelIntegrityKey, ASRVault vault)
        {
            string serializedCertifivate = Convert.ToBase64String(managementCert.Export(X509ContentType.Pfx));

            AcsNamespace acsNamespace = new AcsNamespace(acsDetails);

            ASRVaultCreds vaultCreds = new ASRVaultCreds(
                                            vault.SubscriptionId,
                                            vault.Name,
                                            serializedCertifivate,
                                            acsNamespace,
                                            channelIntegrityKey,
                                            vault.ResouceGroupName);

            return vaultCreds;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the vault credentials.
        /// </summary>
        /// <param name="resourceGroupName"></param>
        /// <param name="resourceName"></param>
        /// <param name="resourceLocation"></param>
        /// <param name="serializedCertificate"></param>
        /// <param name="uploadCertificate"></param>
        /// <returns></returns>
        public static ActivationKeyComponents GetVaultCredentials(string resourceGroupName,
                                                                  string resourceName, string resourceLocation, string serializedCertificate, UploadCertificateResponse uploadCertificate, string subscriptionId, string cik)
        {
            const string AudienceFormat = @"https://azuredataboxedge/{0}/{1}/{2}";

            var aadAudience = string.IsNullOrWhiteSpace(uploadCertificate.AadAudience) ?
                              string.Format(AudienceFormat, resourceLocation, uploadCertificate.ResourceId, uploadCertificate.ResourceId) :
                              uploadCertificate.AadAudience;

            var vault = new ActivationKeyComponents
            {
                SubscriptionId                  = subscriptionId,
                ResourceType                    = "dataBoxEdgeDevices",
                ResourceName                    = resourceName,
                ManagementCert                  = serializedCertificate,
                ResourceId                      = uploadCertificate.ResourceId,
                AadAuthority                    = uploadCertificate.AadAuthority,
                AadAudience                     = aadAudience,
                AadTenantId                     = uploadCertificate.AadTenantId,
                ServicePrincipalClientId        = uploadCertificate.ServicePrincipalClientId,
                AzureManagementEndpointAudience = uploadCertificate.AzureManagementEndpointAudience,
                ProviderNamespace               = "Microsoft.DataBoxEdge",
                ResourceGroup                   = resourceGroupName,
                ServiceDataIntegrityKey         = cik,
                IdentityProvider                = "AAD"
            };

            return(vault);
        }
        /// <summary>
        /// Method to generate the credential file content
        /// </summary>
        /// <param name="managementCert">management cert</param>
        /// <param name="acsDetails">ACS details</param>
        /// <param name="channelIntegrityKey">Integrity key</param>
        /// <param name="vault">vault object</param>
        /// <param name="site">site object</param>
        /// <returns>vault credential object</returns>
        private ASRVaultCreds GenerateCredentialObject(X509Certificate2 managementCert, UploadCertificateResponse acsDetails, string channelIntegrityKey, ASRVault vault, ASRSite site)
        {
            string serializedCertifivate = Convert.ToBase64String(managementCert.Export(X509ContentType.Pfx));

            AcsNamespace acsNamespace = new AcsNamespace(acsDetails);

            string resourceProviderNamespace = string.Empty;
            string resourceType = string.Empty;
            Utilities.GetResourceProviderNamespaceAndType(vault.ID, out resourceProviderNamespace, out resourceType);
            ASRVaultCreds vaultCreds = new ASRVaultCreds(
                                            vault.SubscriptionId,
                                            vault.Name,
                                            serializedCertifivate,
                                            acsNamespace,
                                            channelIntegrityKey,
                                            vault.ResouceGroupName,
                                            site.ID,
                                            site.Name,
                                            resourceProviderNamespace,
                                            resourceType);

            return vaultCreds;
        }