/// <summary>
        /// creates or updates the https binding for the dns host name specified, assigning the given
        /// certificate selected from the certificate store
        /// </summary>
        /// <param name="site">  </param>
        /// <param name="certificate">  </param>
        /// <param name="host">  </param>
        /// <param name="sslPort">  </param>
        /// <param name="useSNI">  </param>
        /// <param name="ipAddress">  </param>
        public async Task <List <ActionStep> > UpdateBinding(
            IBindingDeploymentTarget deploymentTarget,
            IBindingDeploymentTargetItem site,
            List <BindingInfo> existingBindings,
            string certStoreName,
            byte[] certificateHash,
            string host,
            int sslPort                 = 443,
            bool useSNI                 = true,
            string ipAddress            = null,
            bool alwaysRecreateBindings = false,
            bool isPreviewOnly          = false
            )
        {
            var steps = new List <ActionStep>();

            var internationalHost = host ?? "";

            if (unassignedIPs.Contains(ipAddress))
            {
                ipAddress = "*";
            }
            else
            {
                // specific IP address, SNI is not applicable
                useSNI = false;
            }

            // can't use SNI is hostname is blank
            if (useSNI && string.IsNullOrEmpty(internationalHost))
            {
                useSNI = false;
            }

            var bindingSpecString = $"{ipAddress}:{sslPort}:{internationalHost}";

            var bindingSpec = new BindingInfo
            {
                Host                 = internationalHost,
                Protocol             = "https",
                IsHTTPS              = true,
                Port                 = sslPort,
                IP                   = ipAddress,
                SiteId               = site.Id,
                CertificateStore     = certStoreName,
                CertificateHashBytes = certificateHash,
                IsSNIEnabled         = useSNI
            };

            if (!HasExistingBinding(existingBindings, bindingSpec))
            {
                //there are no existing https bindings to update for this domain
                //add new https binding at default port "<ip>:port:hostDnsName";

                var action = new ActionStep
                {
                    Title       = "Install Certificate For Binding",
                    Category    = "Deployment.AddBinding",
                    Description = $"Add https binding | {site.Name} | **{bindingSpecString} {(useSNI ? "SNI" : "Non-SNI")}**",
                    Key         = $"[{site.Id}]:{bindingSpecString}:{useSNI}"
                };

                if (!isPreviewOnly)
                {
                    var result = await deploymentTarget.AddBinding(bindingSpec);

                    if (result.HasError)
                    {
                        // failed to add
                        action.HasError     = true;
                        action.Description += $" Failed to add binding. [{result.Description}]";
                    }
                    else
                    {
                        if (result.HasWarning)
                        {
                            action.HasWarning   = true;
                            action.Description += $" [{result.Description}]";
                        }
                    }
                }

                steps.Add(action);
            }
            else
            {
                // update one or more existing https bindings with new cert
                var action = new ActionStep
                {
                    Title       = "Install Certificate For Binding",
                    Category    = "Deployment.UpdateBinding",
                    Description = $"Update https binding | {site.Name} | **{bindingSpecString} {(useSNI ? "SNI" : "Non-SNI")}**"
                };

                if (!isPreviewOnly)
                {
                    // Update existing https Binding
                    var result = await deploymentTarget.UpdateBinding(bindingSpec);

                    if (result.HasError)
                    {
                        // failed to update
                        action.HasError     = true;
                        action.Description += $" Failed to update binding. [{result.Description}]";
                    }
                    else
                    {
                        if (result.HasWarning)
                        {
                            // has update warning
                            action.HasWarning   = true;
                            action.Description += $" [{result.Description}]";
                        }
                    }
                }

                steps.Add(action);
            }

            return(steps);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// creates or updates the https binding for the dns host name specified, assigning the given
        /// certificate selected from the certificate store
        /// </summary>
        /// <param name="site">  </param>
        /// <param name="certificate">  </param>
        /// <param name="host">  </param>
        /// <param name="sslPort">  </param>
        /// <param name="ipAddress">  </param>
        public async Task <List <ActionStep> > UpdateFtpBinding(
            IBindingDeploymentTarget deploymentTarget,
            IBindingDeploymentTargetItem site,
            List <BindingInfo> existingBindings,
            string certStoreName,
            string certificateHash,
            int port,
            string host,
            string ipAddress,
            bool isPreviewOnly = false
            )
        {
            var steps = new List <ActionStep>();

            var internationalHost = host ?? "";

            var bindingSpecString = $"{ipAddress}:{port}:{internationalHost}";

            var bindingSpec = new BindingInfo
            {
                Host             = internationalHost,
                Protocol         = "ftp",
                IsHTTPS          = true,
                Port             = port,
                IP               = ipAddress,
                SiteId           = site.Id,
                CertificateStore = certStoreName,
                CertificateHash  = certificateHash,
                IsFtpSite        = true
            };

            if (!HasExistingBinding(existingBindings, bindingSpec))
            {
                //there are no existing applicable bindings to update for this domain
                //add new ftp binding at default port "<ip>:port:hostDnsName";

                var action = new ActionStep
                {
                    Title       = "Install Certificate For FTP Binding",
                    Category    = "Deployment.AddBinding",
                    Description = $"Add {bindingSpec.Protocol} binding | {site.Name} | **{bindingSpecString} **",
                    Key         = $"[{site.Id}]:{bindingSpecString}"
                };

                if (!isPreviewOnly)
                {
                    var result = await deploymentTarget.AddBinding(bindingSpec);

                    if (result.HasError)
                    {
                        // failed to add
                        action.HasError     = true;
                        action.Description += $" Failed to add binding. [{result.Description}]";
                    }
                    else
                    {
                        if (result.HasWarning)
                        {
                            action.HasWarning   = true;
                            action.Description += $" [{result.Description}]";
                        }
                    }
                }

                steps.Add(action);
            }
            else
            {
                // update one or more existing bindings with new cert
                var action = new ActionStep
                {
                    Title       = "Install Certificate For Binding",
                    Category    = "Deployment.UpdateBinding",
                    Description = $"Update {bindingSpec.Protocol} binding | {site.Name} | **{bindingSpecString}**"
                };

                if (!isPreviewOnly)
                {
                    // Update existing Binding
                    var result = await deploymentTarget.UpdateBinding(bindingSpec);

                    if (result.HasError)
                    {
                        // failed to update
                        action.HasError     = true;
                        action.Description += $" Failed to update binding. [{result.Description}]";
                    }
                    else
                    {
                        if (result.HasWarning)
                        {
                            // has update warning
                            action.HasWarning   = true;
                            action.Description += $" [{result.Description}]";
                        }
                    }
                }

                steps.Add(action);
            }

            return(steps);
        }