Beispiel #1
0
        internal static FederationTrustCertificateState TestForCertificate(string serverName, string thumbprint, out ExchangeCertificate cert)
        {
            if (string.IsNullOrEmpty(serverName))
            {
                throw new ArgumentNullException("serverName");
            }
            if (string.IsNullOrEmpty(thumbprint))
            {
                throw new ArgumentNullException("thumbprint");
            }
            cert = null;
            ExchangeCertificateRpc exchangeCertificateRpc = new ExchangeCertificateRpc();

            exchangeCertificateRpc.GetByThumbprint = thumbprint;
            ExchangeCertificateRpcVersion   exchangeCertificateRpcVersion   = ExchangeCertificateRpcVersion.Version1;
            FederationTrustCertificateState federationTrustCertificateState = FederationTrustCertificateState.NotInstalled;

            byte[] outputBlob = null;
            try
            {
                byte[] inBlob = exchangeCertificateRpc.SerializeInputParameters(ExchangeCertificateRpcVersion.Version2);
                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient = new ExchangeCertificateRpcClient2(serverName);
                outputBlob = exchangeCertificateRpcClient.GetCertificate2(0, inBlob);
                exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version2;
            }
            catch (RpcException)
            {
                exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;
            }
            if (exchangeCertificateRpcVersion == ExchangeCertificateRpcVersion.Version1)
            {
                try
                {
                    byte[] inBlob2 = exchangeCertificateRpc.SerializeInputParameters(exchangeCertificateRpcVersion);
                    ExchangeCertificateRpcClient exchangeCertificateRpcClient2 = new ExchangeCertificateRpcClient(serverName);
                    outputBlob = exchangeCertificateRpcClient2.GetCertificate(0, inBlob2);
                }
                catch (RpcException)
                {
                    federationTrustCertificateState = FederationTrustCertificateState.ServerUnreachable;
                }
            }
            if (federationTrustCertificateState != FederationTrustCertificateState.ServerUnreachable)
            {
                ExchangeCertificateRpc exchangeCertificateRpc2 = new ExchangeCertificateRpc(exchangeCertificateRpcVersion, null, outputBlob);
                if (exchangeCertificateRpc2.ReturnCertList != null && exchangeCertificateRpc2.ReturnCertList.Count == 1)
                {
                    federationTrustCertificateState = FederationTrustCertificateState.Installed;
                    cert = exchangeCertificateRpc2.ReturnCertList[0];
                }
            }
            return(federationTrustCertificateState);
        }
        private Exception ValidateCertificateForSmtp(SmtpSendConnectorConfig sendConnector)
        {
            SmtpX509Identifier tlsCertificateName = sendConnector.TlsCertificateName;

            if (sendConnector.SourceTransportServers.Count > 0)
            {
                ADObjectId                    adobjectId                    = sendConnector.SourceTransportServers[0];
                ExchangeCertificateRpc        exchangeCertificateRpc        = new ExchangeCertificateRpc();
                ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;
                byte[] outputBlob = null;
                try
                {
                    byte[] inBlob = exchangeCertificateRpc.SerializeInputParameters(ExchangeCertificateRpcVersion.Version2);
                    ExchangeCertificateRpcClient2 exchangeCertificateRpcClient = new ExchangeCertificateRpcClient2(adobjectId.Name);
                    outputBlob = exchangeCertificateRpcClient.GetCertificate2(0, inBlob);
                    exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version2;
                }
                catch (RpcException)
                {
                    exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;
                }
                if (exchangeCertificateRpcVersion == ExchangeCertificateRpcVersion.Version1 && adobjectId.Name != null && adobjectId.DomainId != null && !string.IsNullOrEmpty(adobjectId.DistinguishedName))
                {
                    try
                    {
                        byte[] inBlob2 = exchangeCertificateRpc.SerializeInputParameters(exchangeCertificateRpcVersion);
                        ExchangeCertificateRpcClient exchangeCertificateRpcClient2 = new ExchangeCertificateRpcClient(adobjectId.Name);
                        outputBlob = exchangeCertificateRpcClient2.GetCertificate(0, inBlob2);
                    }
                    catch (RpcException)
                    {
                        return(null);
                    }
                }
                ExchangeCertificateRpc exchangeCertificateRpc2 = new ExchangeCertificateRpc(exchangeCertificateRpcVersion, null, outputBlob);
                foreach (ExchangeCertificate exchangeCertificate in exchangeCertificateRpc2.ReturnCertList)
                {
                    if (exchangeCertificate.Issuer.Equals(tlsCertificateName.CertificateIssuer) && exchangeCertificate.Subject.Equals(tlsCertificateName.CertificateSubject) && (exchangeCertificate.Services & AllowedServices.SMTP) != AllowedServices.SMTP)
                    {
                        return(new InvalidOperationException(Strings.SMTPNotEnabledForTlsCertificate));
                    }
                }
            }
            return(null);
        }
Beispiel #3
0
        public override void Work()
        {
            Thread.Sleep(15000);
            int num = 1440;

            for (;;)
            {
                try
                {
                    if (!int.TryParse(ConfigurationManager.AppSettings["CertificateNotificationPollIntervalInMinutes"], out num))
                    {
                        num = 1440;
                    }
                }
                catch (ConfigurationException)
                {
                    num = 1440;
                }
                if (num <= 0 || num > 14400)
                {
                    num = 1440;
                }
                try
                {
                    if (!int.TryParse(ConfigurationManager.AppSettings["CertificateNotificationWarningDays"], out this.warningDays))
                    {
                        this.warningDays = 30;
                    }
                }
                catch (ConfigurationException)
                {
                    this.warningDays = 30;
                }
                if (this.warningDays <= 0 || this.warningDays > 400)
                {
                    this.warningDays = 30;
                }
                this.adSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.PartiallyConsistent, ADSessionSettings.FromRootOrgScopeSet(), 185, "Work", "f:\\15.00.1497\\sources\\dev\\Management\\src\\ServiceHost\\Servicelets\\CertificateNotification\\Program\\CertificateNotificationServicelet.cs");
                this.orgId     = ADSessionSettings.FromRootOrgScopeSet().CurrentOrganizationId;
                ExchangeCertificateRpc exchangeCertificateRpc = new ExchangeCertificateRpc();
                byte[] outputBlob = null;
                ExchangeCertificateRpcClient  exchangeCertificateRpcClient  = null;
                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient2 = null;
                try
                {
                    IEnumerable <Server> objects = new ServerIdParameter().GetObjects <Server>(this.orgId.ConfigurationUnit, this.adSession);
                    if (objects == null || objects.Count <Server>() == 0)
                    {
                        goto IL_28B;
                    }
                    this.serverObj = objects.First <Server>();
                    ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;
                    try
                    {
                        byte[] inBlob = exchangeCertificateRpc.SerializeInputParameters(ExchangeCertificateRpcVersion.Version2);
                        exchangeCertificateRpcClient2 = new ExchangeCertificateRpcClient2(this.serverObj.Name);
                        outputBlob = exchangeCertificateRpcClient2.GetCertificate2(0, inBlob);
                        exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version2;
                    }
                    catch (RpcException)
                    {
                        exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;
                    }
                    if (exchangeCertificateRpcVersion == ExchangeCertificateRpcVersion.Version1)
                    {
                        byte[] inBlob2 = exchangeCertificateRpc.SerializeInputParameters(exchangeCertificateRpcVersion);
                        exchangeCertificateRpcClient = new ExchangeCertificateRpcClient(this.serverObj.Name);
                        outputBlob = exchangeCertificateRpcClient.GetCertificate(0, inBlob2);
                    }
                    ExchangeCertificateRpc exchangeCertificateRpc2 = new ExchangeCertificateRpc(exchangeCertificateRpcVersion, null, outputBlob);
                    this.UpdateDataInMbx(exchangeCertificateRpc2.ReturnCertList);
                }
                catch (RpcClientException ex)
                {
                    this.EventLog.LogEvent(CertificateNotificationEventLogConstants.Tuple_TransientException, string.Empty, new object[]
                    {
                        ex.ToString()
                    });
                }
                catch (LocalizedException ex2)
                {
                    this.EventLog.LogEvent(CertificateNotificationEventLogConstants.Tuple_TransientException, string.Empty, new object[]
                    {
                        ex2.ToString()
                    });
                }
                catch (RpcException ex3)
                {
                    this.EventLog.LogEvent(CertificateNotificationEventLogConstants.Tuple_TransientException, string.Empty, new object[]
                    {
                        ex3.ToString()
                    });
                }
                finally
                {
                    if (exchangeCertificateRpcClient2 != null)
                    {
                        exchangeCertificateRpcClient2.Dispose();
                    }
                    if (exchangeCertificateRpcClient != null)
                    {
                        exchangeCertificateRpcClient.Dispose();
                    }
                    this.adSession         = null;
                    this.asyncDataProvider = null;
                    this.serverObj         = null;
                    this.orgId             = null;
                }
                goto IL_252;
IL_28B:
                if (base.StopEvent.WaitOne(TimeSpan.FromMinutes((double)num), false))
                {
                    break;
                }
                continue;
IL_252:
                this.EventLog.LogEvent(CertificateNotificationEventLogConstants.Tuple_OneRoundCompleted, string.Empty, new object[]
                {
                    ExDateTime.Now.AddMinutes((double)num)
                });
                goto IL_28B;
            }
        }
Beispiel #4
0
        protected override void InternalProcessRecord()
        {
            base.InternalProcessRecord();
            if (base.HasErrors)
            {
                return;
            }
            ExchangeCertificateRpc exchangeCertificateRpc = new ExchangeCertificateRpc();

            if (this.Instance != null)
            {
                exchangeCertificateRpc.GetByCertificate = this.Instance.Export(X509ContentType.SerializedCert);
            }
            if (this.DomainName != null && this.DomainName.Count > 0)
            {
                exchangeCertificateRpc.GetByDomains = this.DomainName;
            }
            if (this.Thumbprint != null)
            {
                exchangeCertificateRpc.GetByThumbprint = this.Thumbprint;
            }
            ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;

            byte[] outputBlob = null;
            try
            {
                byte[] inBlob = exchangeCertificateRpc.SerializeInputParameters(ExchangeCertificateRpcVersion.Version2);
                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient = new ExchangeCertificateRpcClient2(this.serverObject.Name);
                outputBlob = exchangeCertificateRpcClient.GetCertificate2(0, inBlob);
                exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version2;
            }
            catch (RpcException)
            {
                exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;
            }
            if (exchangeCertificateRpcVersion == ExchangeCertificateRpcVersion.Version1)
            {
                try
                {
                    byte[] inBlob2 = exchangeCertificateRpc.SerializeInputParameters(exchangeCertificateRpcVersion);
                    ExchangeCertificateRpcClient exchangeCertificateRpcClient2 = new ExchangeCertificateRpcClient(this.serverObject.Name);
                    outputBlob = exchangeCertificateRpcClient2.GetCertificate(0, inBlob2);
                }
                catch (RpcException e)
                {
                    ManageExchangeCertificate.WriteRpcError(e, this.serverObject.Name, new Task.TaskErrorLoggingDelegate(base.WriteError));
                }
            }
            ExchangeCertificateRpc exchangeCertificateRpc2 = new ExchangeCertificateRpc(exchangeCertificateRpcVersion, null, outputBlob);

            ExchangeCertificateRpc.OutputTaskMessages(this.serverObject, exchangeCertificateRpc2, new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskErrorLoggingDelegate(base.WriteError));
            foreach (ExchangeCertificate exchangeCertificate in exchangeCertificateRpc2.ReturnCertList)
            {
                exchangeCertificate.Identity = this.serverObject.Fqdn + "\\" + exchangeCertificate.Thumbprint;
                if (string.IsNullOrEmpty(exchangeCertificate.FriendlyName))
                {
                    exchangeCertificate.FriendlyName = exchangeCertificate.Issuer;
                }
                base.WriteObject(exchangeCertificate);
            }
        }