예제 #1
0
        private LocalizedString GetWhatIfMessage()
        {
            this.inputParams.CreateWhatIf = true;
            ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;

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

            this.inputParams.CreateWhatIf = false;
            return(exchangeCertificateRpc.ReturnConfirmation);
        }
예제 #2
0
 public ExchangeCertificateRpc(ExchangeCertificateRpcVersion version, byte[] inputBlob, byte[] outputBlob)
 {
     this.inputParameters = new Dictionary <RpcParameters, object>();
     if (inputBlob != null)
     {
         if (version == ExchangeCertificateRpcVersion.Version1)
         {
             this.inputParameters = (Dictionary <RpcParameters, object>) this.DeserializeObject(inputBlob, false);
         }
         else if (version == ExchangeCertificateRpcVersion.Version2)
         {
             this.inputParameters = this.BuildInputParameters(inputBlob);
         }
     }
     this.outputParameters = new Dictionary <RpcOutput, object>();
     if (outputBlob != null)
     {
         if (version == ExchangeCertificateRpcVersion.Version1)
         {
             this.outputParameters = (Dictionary <RpcOutput, object>) this.DeserializeObject(outputBlob, false);
             return;
         }
         if (version == ExchangeCertificateRpcVersion.Version2)
         {
             this.outputParameters = this.BuildOutputParameters(outputBlob);
         }
     }
 }
예제 #3
0
 internal byte[] SerializeOutputParameters(ExchangeCertificateRpcVersion rpcVersion)
 {
     if (rpcVersion == ExchangeCertificateRpcVersion.Version2)
     {
         return(this.SerializeOutputParametersAsArray());
     }
     return(ExchangeCertificateRpc.SerializeObject(this.outputParameters));
 }
예제 #4
0
 internal byte[] SerializeInputParameters(ExchangeCertificateRpcVersion rpcVersion)
 {
     if (rpcVersion == ExchangeCertificateRpcVersion.Version2)
     {
         return(this.SerializeDictionaryAsArray <RpcParameters, object>(this.inputParameters));
     }
     return(ExchangeCertificateRpc.SerializeObject(this.inputParameters));
 }
        protected override void InternalProcessRecord()
        {
            base.InternalProcessRecord();
            if (base.HasErrors)
            {
                return;
            }
            ExchangeCertificateRpc exchangeCertificateRpc = new ExchangeCertificateRpc();

            exchangeCertificateRpc.ExportByThumbprint = this.Thumbprint;
            exchangeCertificateRpc.ExportBinary       = this.BinaryEncoded;
            ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;

            byte[] outputBlob = null;
            try
            {
                byte[] inBlob = exchangeCertificateRpc.SerializeInputParameters(ExchangeCertificateRpcVersion.Version2);
                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient = new ExchangeCertificateRpcClient2(this.serverObject.Name);
                outputBlob = exchangeCertificateRpcClient.ExportCertificate2(0, inBlob, this.Password);
                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.ExportCertificate(0, inBlob2, this.Password);
                }
                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));
            if (this.BinaryEncoded)
            {
                base.WriteObject(new BinaryFileDataObject
                {
                    FileData = exchangeCertificateRpc2.ReturnExportFileData
                });
            }
            else
            {
                base.WriteObject(exchangeCertificateRpc2.ReturnExportBase64);
            }
            if (!string.IsNullOrEmpty(this.FileName))
            {
                this.WriteCertiricate(exchangeCertificateRpc2);
            }
        }
예제 #6
0
        internal static string ExportCertificate(string source, SecureString securePassword, string thumbprint)
        {
            if (string.IsNullOrEmpty(source))
            {
                throw new ArgumentNullException("source");
            }
            if (securePassword == null)
            {
                throw new ArgumentNullException("securePassword");
            }
            if (string.IsNullOrEmpty(thumbprint))
            {
                throw new ArgumentNullException("thumbprint");
            }
            ExchangeCertificateRpc exchangeCertificateRpc = new ExchangeCertificateRpc();

            exchangeCertificateRpc.ExportByThumbprint = thumbprint;
            exchangeCertificateRpc.ExportBinary       = true;
            ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;

            byte[] outputBlob = null;
            try
            {
                byte[] inBlob = exchangeCertificateRpc.SerializeInputParameters(ExchangeCertificateRpcVersion.Version2);
                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient = new ExchangeCertificateRpcClient2(source);
                outputBlob = exchangeCertificateRpcClient.ExportCertificate2(0, inBlob, securePassword);
                exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version2;
            }
            catch (RpcException)
            {
                exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;
            }
            if (exchangeCertificateRpcVersion == ExchangeCertificateRpcVersion.Version1)
            {
                try
                {
                    byte[] inBlob2 = exchangeCertificateRpc.SerializeInputParameters(exchangeCertificateRpcVersion);
                    ExchangeCertificateRpcClient exchangeCertificateRpcClient2 = new ExchangeCertificateRpcClient(source);
                    outputBlob = exchangeCertificateRpcClient2.ExportCertificate(0, inBlob2, securePassword);
                }
                catch (RpcException e)
                {
                    ManageExchangeCertificate.ThrowLocalizedException(e, source);
                }
            }
            ExchangeCertificateRpc exchangeCertificateRpc2 = new ExchangeCertificateRpc(exchangeCertificateRpcVersion, null, outputBlob);

            if (!string.IsNullOrEmpty(exchangeCertificateRpc2.ReturnTaskErrorString))
            {
                throw new InvalidOperationException(exchangeCertificateRpc2.ReturnTaskErrorString);
            }
            return(Convert.ToBase64String(exchangeCertificateRpc2.ReturnExportFileData));
        }
예제 #7
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);
        }
예제 #8
0
        internal static void ImportCertificate(string destination, SecureString securePassword, string base64cert)
        {
            if (string.IsNullOrEmpty(destination))
            {
                throw new ArgumentNullException("destination");
            }
            if (securePassword == null)
            {
                throw new ArgumentNullException("securePassword");
            }
            if (string.IsNullOrEmpty(base64cert))
            {
                throw new ArgumentNullException("base64cert");
            }
            ExchangeCertificateRpc exchangeCertificateRpc = new ExchangeCertificateRpc();

            exchangeCertificateRpc.ImportCert       = base64cert;
            exchangeCertificateRpc.ImportExportable = true;
            ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;

            byte[] outputBlob = null;
            try
            {
                byte[] inBlob = exchangeCertificateRpc.SerializeInputParameters(ExchangeCertificateRpcVersion.Version2);
                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient = new ExchangeCertificateRpcClient2(destination);
                outputBlob = exchangeCertificateRpcClient.ImportCertificate2(0, inBlob, securePassword);
                exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version2;
            }
            catch (RpcException)
            {
                exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;
            }
            if (exchangeCertificateRpcVersion == ExchangeCertificateRpcVersion.Version1)
            {
                try
                {
                    byte[] inBlob2 = exchangeCertificateRpc.SerializeInputParameters(exchangeCertificateRpcVersion);
                    ExchangeCertificateRpcClient exchangeCertificateRpcClient2 = new ExchangeCertificateRpcClient(destination);
                    outputBlob = exchangeCertificateRpcClient2.ImportCertificate(0, inBlob2, securePassword);
                }
                catch (RpcException e)
                {
                    ManageExchangeCertificate.ThrowLocalizedException(e, destination);
                }
            }
            ExchangeCertificateRpc exchangeCertificateRpc2 = new ExchangeCertificateRpc(exchangeCertificateRpcVersion, null, outputBlob);

            if (!string.IsNullOrEmpty(exchangeCertificateRpc2.ReturnTaskErrorString))
            {
                throw new InvalidOperationException(exchangeCertificateRpc2.ReturnTaskErrorString);
            }
        }
예제 #9
0
        internal static void EnableCertificateForNetworkService(string destination, string thumbprint)
        {
            if (string.IsNullOrEmpty(destination))
            {
                throw new ArgumentNullException("destination");
            }
            if (string.IsNullOrEmpty(thumbprint))
            {
                throw new ArgumentNullException("thumbprint");
            }
            ExchangeCertificateRpc exchangeCertificateRpc = new ExchangeCertificateRpc();

            exchangeCertificateRpc.EnableByThumbprint   = thumbprint;
            exchangeCertificateRpc.EnableNetworkService = true;
            exchangeCertificateRpc.EnableServices       = AllowedServices.None;
            ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;

            byte[] outputBlob = null;
            try
            {
                byte[] inBlob = exchangeCertificateRpc.SerializeInputParameters(ExchangeCertificateRpcVersion.Version2);
                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient = new ExchangeCertificateRpcClient2(destination);
                outputBlob = exchangeCertificateRpcClient.EnableCertificate2(0, inBlob);
                exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version2;
            }
            catch (RpcException)
            {
                exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;
            }
            if (exchangeCertificateRpcVersion == ExchangeCertificateRpcVersion.Version1)
            {
                try
                {
                    byte[] inBlob2 = exchangeCertificateRpc.SerializeInputParameters(exchangeCertificateRpcVersion);
                    ExchangeCertificateRpcClient exchangeCertificateRpcClient2 = new ExchangeCertificateRpcClient(destination);
                    outputBlob = exchangeCertificateRpcClient2.EnableCertificate(0, inBlob2);
                }
                catch (RpcException e)
                {
                    ManageExchangeCertificate.ThrowLocalizedException(e, destination);
                }
            }
            ExchangeCertificateRpc exchangeCertificateRpc2 = new ExchangeCertificateRpc(exchangeCertificateRpcVersion, null, outputBlob);

            if (!string.IsNullOrEmpty(exchangeCertificateRpc2.ReturnTaskErrorString))
            {
                throw new InvalidOperationException(exchangeCertificateRpc2.ReturnTaskErrorString);
            }
        }
        protected override void InternalProcessRecord()
        {
            base.InternalProcessRecord();
            if (base.HasErrors)
            {
                return;
            }
            ExchangeCertificateRpc exchangeCertificateRpc = new ExchangeCertificateRpc();

            exchangeCertificateRpc.RemoveByThumbprint = 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.RemoveCertificate2(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.RemoveCertificate(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));
            if (string.IsNullOrEmpty(exchangeCertificateRpc2.ReturnTaskErrorString))
            {
                AsyncOperationNotificationDataProvider.RemoveNotification(base.CurrentOrganizationId, this.serverObject.Fqdn + "\\" + this.Thumbprint, false);
            }
        }
예제 #11
0
        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);
        }
예제 #12
0
        internal static byte[] SerializeError(ExchangeCertificateRpcVersion version, string message, ErrorCategory category)
        {
            if (version == ExchangeCertificateRpcVersion.Version2)
            {
                return(ExchangeCertificateRpc.SerializeObject(new object[]
                {
                    ExchangeCertificateRpc.SerializeObject(RpcOutput.TaskErrorString),
                    ExchangeCertificateRpc.SerializeObject(message),
                    ExchangeCertificateRpc.SerializeObject(RpcOutput.TaskErrorCategory),
                    ExchangeCertificateRpc.SerializeObject(category)
                }));
            }
            Dictionary <RpcOutput, object> dictionary = new Dictionary <RpcOutput, object>();

            dictionary[RpcOutput.TaskErrorString]   = message;
            dictionary[RpcOutput.TaskErrorCategory] = category;
            return(ExchangeCertificateRpc.SerializeObject(dictionary));
        }
예제 #13
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;
            }
        }
예제 #14
0
        protected override void InternalProcessRecord()
        {
            base.InternalProcessRecord();
            if (base.HasErrors)
            {
                return;
            }
            ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;

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

            ExchangeCertificateRpc.OutputTaskMessages(this.serverObject, exchangeCertificateRpc, new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskErrorLoggingDelegate(base.WriteError));
            if (this.GenerateRequest)
            {
                this.ProcessRequestResults(exchangeCertificateRpc.ReturnCert, exchangeCertificateRpc.ReturnCertRequest);
                return;
            }
            if (exchangeCertificateRpc.ReturnConfirmationList != null)
            {
                foreach (KeyValuePair <AllowedServices, LocalizedString> keyValuePair in exchangeCertificateRpc.ReturnConfirmationList)
                {
                    if (base.ShouldContinue(keyValuePair.Value))
                    {
                        ExchangeCertificateRpc exchangeCertificateRpc2 = new ExchangeCertificateRpc();
                        exchangeCertificateRpc2.EnableAllowConfirmation = false;
                        exchangeCertificateRpc2.EnableServices          = keyValuePair.Key;
                        AllowedServices key = keyValuePair.Key;
                        if (key == AllowedServices.SMTP)
                        {
                            exchangeCertificateRpc2.EnableUpdateAD = true;
                        }
                        exchangeCertificateRpc2.EnableByThumbprint = exchangeCertificateRpc.ReturnCert.Thumbprint;
                        try
                        {
                            byte[] inBlob3 = exchangeCertificateRpc2.SerializeInputParameters(exchangeCertificateRpcVersion);
                            if (exchangeCertificateRpcVersion == ExchangeCertificateRpcVersion.Version1)
                            {
                                ExchangeCertificateRpcClient exchangeCertificateRpcClient3 = new ExchangeCertificateRpcClient(this.serverObject.Name);
                                outputBlob = exchangeCertificateRpcClient3.EnableCertificate(0, inBlob3);
                            }
                            else
                            {
                                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient4 = new ExchangeCertificateRpcClient2(this.serverObject.Name);
                                outputBlob = exchangeCertificateRpcClient4.EnableCertificate2(0, inBlob3);
                            }
                            exchangeCertificateRpc.ReturnCert.Services |= keyValuePair.Key;
                        }
                        catch (RpcException e2)
                        {
                            ManageExchangeCertificate.WriteRpcError(e2, this.serverObject.Name, new Task.TaskErrorLoggingDelegate(base.WriteError));
                        }
                        ExchangeCertificateRpc outputValues = new ExchangeCertificateRpc(exchangeCertificateRpcVersion, null, outputBlob);
                        ExchangeCertificateRpc.OutputTaskMessages(this.serverObject, outputValues, new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskErrorLoggingDelegate(base.WriteError));
                    }
                }
            }
            exchangeCertificateRpc.ReturnCert.Identity = this.serverObject.Fqdn + "\\" + exchangeCertificateRpc.ReturnCert.Thumbprint;
            base.WriteObject(exchangeCertificateRpc.ReturnCert);
        }
예제 #15
0
        protected override void InternalProcessRecord()
        {
            base.InternalProcessRecord();
            if (base.HasErrors)
            {
                return;
            }
            ExchangeCertificateRpc exchangeCertificateRpc = new ExchangeCertificateRpc();
            string text;

            if (this.FileData != null)
            {
                text = ImportExchangeCertificate.RemoveBase64HeaderFooter(CertificateEnroller.ToBase64String(this.FileData));
            }
            else if (this.Instance != null)
            {
                text = ImportExchangeCertificate.RemoveBase64HeaderFooter(string.Join(null, this.Instance));
            }
            else
            {
                text = ImportExchangeCertificate.RemoveBase64HeaderFooter(CertificateEnroller.ToBase64String(this.GetFileData(this.FileName)));
            }
            if (text.Length == 0)
            {
                base.WriteError(new ImportCertificateDataInvalidException(), ErrorCategory.ReadError, 0);
            }
            exchangeCertificateRpc.ImportCert        = text;
            exchangeCertificateRpc.ImportDescription = this.FriendlyName;
            exchangeCertificateRpc.ImportExportable  = this.PrivateKeyExportable;
            ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;

            byte[] outputBlob = null;
            try
            {
                byte[] inBlob = exchangeCertificateRpc.SerializeInputParameters(ExchangeCertificateRpcVersion.Version2);
                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient = new ExchangeCertificateRpcClient2(this.serverObject.Name);
                outputBlob = exchangeCertificateRpcClient.ImportCertificate2(0, inBlob, this.Password);
                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.ImportCertificate(0, inBlob2, this.Password);
                }
                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));
            if (exchangeCertificateRpc2.ReturnCert != null)
            {
                exchangeCertificateRpc2.ReturnCert.Identity = this.serverObject.Fqdn + "\\" + exchangeCertificateRpc2.ReturnCert.Thumbprint;
            }
            base.WriteObject(exchangeCertificateRpc2.ReturnCert);
        }
        protected override void InternalProcessRecord()
        {
            base.InternalProcessRecord();
            if (base.HasErrors)
            {
                return;
            }
            ExchangeCertificateRpc exchangeCertificateRpc = new ExchangeCertificateRpc();

            exchangeCertificateRpc.EnableByThumbprint      = this.Thumbprint;
            exchangeCertificateRpc.EnableServices          = this.Services;
            exchangeCertificateRpc.RequireSsl              = !this.DoNotRequireSsl;
            exchangeCertificateRpc.EnableAllowConfirmation = !this.Force;
            exchangeCertificateRpc.EnableNetworkService    = this.NetworkServiceAllowed;
            ExchangeCertificateRpcVersion exchangeCertificateRpcVersion = ExchangeCertificateRpcVersion.Version1;

            byte[] outputBlob = null;
            try
            {
                byte[] inBlob = exchangeCertificateRpc.SerializeInputParameters(ExchangeCertificateRpcVersion.Version2);
                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient = new ExchangeCertificateRpcClient2(this.serverObject.Name);
                outputBlob = exchangeCertificateRpcClient.EnableCertificate2(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.EnableCertificate(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));
            if (exchangeCertificateRpc2.ReturnConfirmationList != null)
            {
                foreach (KeyValuePair <AllowedServices, LocalizedString> keyValuePair in exchangeCertificateRpc2.ReturnConfirmationList)
                {
                    if (base.ShouldContinue(keyValuePair.Value))
                    {
                        ExchangeCertificateRpc exchangeCertificateRpc3 = new ExchangeCertificateRpc();
                        exchangeCertificateRpc3.EnableAllowConfirmation = false;
                        exchangeCertificateRpc3.EnableByThumbprint      = this.Thumbprint;
                        exchangeCertificateRpc3.RequireSsl           = !this.DoNotRequireSsl;
                        exchangeCertificateRpc3.EnableNetworkService = this.NetworkServiceAllowed;
                        exchangeCertificateRpc3.EnableServices       = keyValuePair.Key;
                        AllowedServices key = keyValuePair.Key;
                        if (key == AllowedServices.SMTP)
                        {
                            exchangeCertificateRpc3.EnableUpdateAD = true;
                        }
                        try
                        {
                            byte[] inBlob3 = exchangeCertificateRpc3.SerializeInputParameters(exchangeCertificateRpcVersion);
                            if (exchangeCertificateRpcVersion == ExchangeCertificateRpcVersion.Version1)
                            {
                                ExchangeCertificateRpcClient exchangeCertificateRpcClient3 = new ExchangeCertificateRpcClient(this.serverObject.Name);
                                outputBlob = exchangeCertificateRpcClient3.EnableCertificate(0, inBlob3);
                            }
                            else
                            {
                                ExchangeCertificateRpcClient2 exchangeCertificateRpcClient4 = new ExchangeCertificateRpcClient2(this.serverObject.Name);
                                outputBlob = exchangeCertificateRpcClient4.EnableCertificate2(0, inBlob3);
                            }
                        }
                        catch (RpcException e2)
                        {
                            ManageExchangeCertificate.WriteRpcError(e2, this.serverObject.Name, new Task.TaskErrorLoggingDelegate(base.WriteError));
                        }
                        exchangeCertificateRpc2 = new ExchangeCertificateRpc(exchangeCertificateRpcVersion, null, outputBlob);
                        ExchangeCertificateRpc.OutputTaskMessages(this.serverObject, exchangeCertificateRpc2, new Task.TaskWarningLoggingDelegate(this.WriteWarning), new Task.TaskErrorLoggingDelegate(base.WriteError));
                    }
                }
            }
        }
예제 #17
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);
            }
        }