Example #1
0
 protected override void InternalValidate()
 {
     base.InternalValidate();
     if (base.HasErrors)
     {
         return;
     }
     GetExchangeCertificate.PrepareParameters(this);
     this.serverObject = (Server)base.GetDataObject <Server>(this.Server, base.DataSession, null, new LocalizedString?(Strings.ErrorServerNotFound((string)this.Server)), new LocalizedString?(Strings.ErrorServerNotUnique((string)this.Server)));
     if (!this.serverObject.IsE14OrLater)
     {
         base.WriteError(new ArgumentException(Strings.RemoteCertificateExchangeVersionNotSupported(this.serverObject.Name)), ErrorCategory.InvalidArgument, null);
     }
     if (!string.IsNullOrEmpty(this.Thumbprint))
     {
         this.Thumbprint = ManageExchangeCertificate.UnifyThumbprintFormat(this.Thumbprint);
     }
 }
 protected override void InternalValidate()
 {
     base.InternalValidate();
     if (base.HasErrors)
     {
         return;
     }
     GetExchangeCertificate.PrepareParameters(this);
     this.serverObject = (Server)base.GetDataObject <Server>(this.Server, base.DataSession, null, new LocalizedString?(Strings.ErrorServerNotFound((string)this.Server)), new LocalizedString?(Strings.ErrorServerNotUnique((string)this.Server)));
     if (!this.serverObject.IsE14OrLater)
     {
         base.WriteError(new ArgumentException(Strings.RemoteCertificateExchangeVersionNotSupported(this.serverObject.Name)), ErrorCategory.InvalidArgument, null);
     }
     base.VerifyIsWithinScopes(DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromCustomScopeSet(base.ScopeSet, ADSystemConfigurationSession.GetRootOrgContainerId(this.DomainController, null), base.CurrentOrganizationId, base.ExecutingUserOrganizationId, true), 186, "InternalValidate", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\MessageSecurity\\ExchangeCertificate\\EnableExchangeCertificate.cs"), this.serverObject, true, new DataAccessTask <Server> .ADObjectOutOfScopeString(Strings.ErrorServerOutOfScope));
     if (!string.IsNullOrEmpty(this.Thumbprint))
     {
         this.Thumbprint = ManageExchangeCertificate.UnifyThumbprintFormat(this.Thumbprint);
     }
 }
        protected override void InternalProcessRecord()
        {
            X509Certificate2 x509Certificate = null;

            if (!string.IsNullOrEmpty(this.thumbprint))
            {
                this.thumbprint = ManageExchangeCertificate.UnifyThumbprintFormat(this.thumbprint);
                x509Certificate = this.FindCertificate(this.thumbprint);
                if (x509Certificate == null)
                {
                    base.WriteError(new ArgumentException(Strings.CertificateNotFound(this.thumbprint), "Thumbprint"), ErrorCategory.InvalidArgument, this.thumbprint);
                }
            }
            else
            {
                AllowedServices allowedServices = this.Services;
                if (allowedServices != AllowedServices.IIS && allowedServices != (AllowedServices.IMAP | AllowedServices.POP | AllowedServices.IIS))
                {
                    if (allowedServices != AllowedServices.SMTP)
                    {
                        return;
                    }
                }
                else
                {
                    x509Certificate = this.FindIisCertificate();
                }
                if (x509Certificate == null && this.Services != AllowedServices.SMTP)
                {
                    try
                    {
                        x509Certificate = InstallExchangeCertificate.GetDefaultCertificate();
                    }
                    catch (ArgumentException exception)
                    {
                        base.WriteError(exception, ErrorCategory.InvalidData, null);
                        return;
                    }
                }
                if (x509Certificate == null)
                {
                    if (!this.rawDomains.Any <string>())
                    {
                        base.WriteError(new UnableToResolveValidDomainExchangeCertificateTasksException(ComputerInformation.DnsHostName, ComputerInformation.DnsPhysicalHostName, ComputerInformation.DnsFullyQualifiedDomainName, ComputerInformation.DnsPhysicalFullyQualifiedDomainName), ErrorCategory.InvalidOperation, null);
                    }
                    try
                    {
                        x509Certificate = this.GenerateSelfSignedCertificate();
                    }
                    catch (CryptographicException exception2)
                    {
                        base.WriteError(exception2, ErrorCategory.InvalidOperation, null);
                    }
                }
                if (x509Certificate != null && this.InstallInTrustedRootCAIfSelfSigned && TlsCertificateInfo.IsSelfSignedCertificate(x509Certificate))
                {
                    TlsCertificateInfo.TryInstallCertificateInTrustedRootCA(x509Certificate);
                }
            }
            base.WriteVerbose(Strings.CertificateInformation(x509Certificate.Issuer, x509Certificate.NotBefore, x509Certificate.NotAfter, x509Certificate.Subject));
            if ((DateTime)ExDateTime.Now < x509Certificate.NotBefore || (DateTime)ExDateTime.Now > x509Certificate.NotAfter)
            {
                base.WriteError(new CryptographicException(Strings.CertificateStatusDateInvalid), ErrorCategory.InvalidData, null);
            }
            try
            {
                this.EnableForServices(x509Certificate, this.Services);
            }
            catch (IISNotInstalledException)
            {
                base.WriteError(new ArgumentException(Strings.IISNotInstalled, "Services"), ErrorCategory.InvalidArgument, null);
            }
            catch (InvalidOperationException exception3)
            {
                base.WriteError(exception3, ErrorCategory.ObjectNotFound, null);
            }
        }