示例#1
0
        public PendingAuthorization BeginRegistrationAndValidation(CertRequestConfig requestConfig, string identifierAlias, string challengeType = "http-01", string domain = null)
        {
            //if no alternative domain specified, use the primary domains as the subject
            if (domain == null)
            {
                domain = requestConfig.PrimaryDomain;
            }

            if (GetIdentifier(identifierAlias) == null)
            {
                //if an identifier exists for the same dns in vault, remove it to avoid confusion
                this.DeleteIdentifierByDNS(domain);

                // ACME service requires international domain names in ascii mode

                if (UsePowershell)
                {
                    var result = powershellManager.NewIdentifier(idnMapping.GetAscii(domain), identifierAlias, "Identifier:" + domain);
                    if (!result.IsOK)
                    {
                        return(null);
                    }
                }
                else
                {
                    var cmd = new ACMESharp.POSH.NewIdentifier();
                    cmd.Dns   = idnMapping.GetAscii(domain);
                    cmd.Alias = identifierAlias;
                    cmd.Label = "Identifier:" + domain;

                    try
                    {
                        cmd.ExecuteCommand();
                    }
                    catch (Exception exp)
                    {
                        this.LogAction("NewIdentifier", exp.ToString());
                        return(null);
                    }
                }
            }

            var identifier = this.GetIdentifier(identifierAlias, reloadVaultConfig: true);

            if (identifier.Authorization.IsPending())
            {
                bool ccrResultOK = false;
                if (UsePowershell)
                {
                    var result = powershellManager.CompleteChallenge(identifier.Alias, challengeType, regenerate: true);
                    ccrResultOK = result.IsOK;
                }
                else
                {
                    var cmd = new ACMESharp.POSH.CompleteChallenge();
                    cmd.IdentifierRef = identifier.Alias;
                    cmd.ChallengeType = challengeType;
                    cmd.Handler       = "manual";
                    cmd.Regenerate    = new System.Management.Automation.SwitchParameter(true);
                    cmd.Repeat        = new System.Management.Automation.SwitchParameter(true);
                    cmd.ExecuteCommand();
                    ccrResultOK = true;
                }

                //get challenge info
                ReloadVaultConfig();
                identifier = GetIdentifier(identifierAlias);
                var challengeInfo = identifier.Challenges.FirstOrDefault(c => c.Value.Type == challengeType).Value;

                //identifier challenege specification is now ready for use to prepare and answer for LetsEncrypt to check
                return(new PendingAuthorization()
                {
                    Challenge = challengeInfo, Identifier = identifier, TempFilePath = "", ExtensionlessConfigCheckedOK = false
                });
            }
            else
            {
                //identifier is already valid (previously authorized)
                return(new PendingAuthorization()
                {
                    Challenge = null, Identifier = identifier, TempFilePath = "", ExtensionlessConfigCheckedOK = false
                });
            }
        }