Ejemplo n.º 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);
        }
 private void WriteCertiricate(ExchangeCertificateRpc outputValues)
 {
     try
     {
         string text  = this.FileName;
         string text2 = Path.GetExtension(text).Replace(".", "").ToUpper();
         text2 = text2.Replace("-", "_");
         if (!Enum.IsDefined(typeof(AllowedCertificateTypes), text2))
         {
             text += ".pfx";
         }
         if (this.BinaryEncoded)
         {
             using (FileStream fileStream = File.Create(text))
             {
                 fileStream.Write(outputValues.ReturnExportFileData, 0, outputValues.ReturnExportFileData.Length);
                 goto IL_A5;
             }
         }
         using (StreamWriter streamWriter = File.CreateText(text))
         {
             streamWriter.Write(outputValues.ReturnExportBase64);
         }
         IL_A5:;
     }
     catch (Exception ex)
     {
         if (!this.HandleException(ex))
         {
             throw;
         }
         base.WriteError(new InvalidOperationException(Strings.ExportCertificateFileInvalid(ex.Message)), ErrorCategory.InvalidOperation, null);
     }
 }
Ejemplo n.º 3
0
 internal byte[] SerializeOutputParameters(ExchangeCertificateRpcVersion rpcVersion)
 {
     if (rpcVersion == ExchangeCertificateRpcVersion.Version2)
     {
         return(this.SerializeOutputParametersAsArray());
     }
     return(ExchangeCertificateRpc.SerializeObject(this.outputParameters));
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 6
0
 internal static void OutputTaskMessages(Server server, ExchangeCertificateRpc outputValues, Task.TaskWarningLoggingDelegate warningWriter, Task.TaskErrorLoggingDelegate errorWriter)
 {
     if (outputValues.ReturnTaskWarningList != null)
     {
         foreach (LocalizedString message in outputValues.ReturnTaskWarningList)
         {
             warningWriter(message);
         }
     }
     if (!string.IsNullOrEmpty(outputValues.ReturnTaskErrorString))
     {
         errorWriter(new InvalidOperationException(Strings.DetailRpcError(server.Name, outputValues.ReturnTaskErrorString)), outputValues.ReturnTaskErrorCategory, null);
     }
 }
Ejemplo n.º 7
0
        private byte[] SerializeDictionaryAsArray <TKey, TValue>(Dictionary <TKey, TValue> list)
        {
            int num = 0;

            if (list != null)
            {
                object[] array = new object[list.Count * 2];
                foreach (KeyValuePair <TKey, TValue> keyValuePair in list)
                {
                    array[num++] = ExchangeCertificateRpc.SerializeObject(keyValuePair.Key);
                    array[num++] = ExchangeCertificateRpc.SerializeObject(keyValuePair.Value);
                }
                return(ExchangeCertificateRpc.SerializeObject(array));
            }
            return(null);
        }
Ejemplo n.º 8
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);
        }
        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);
            }
        }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
0
        private byte[] SerializeOutputParametersAsArray()
        {
            int num = 0;

            object[] array = new object[this.outputParameters.Count * 2];
            foreach (KeyValuePair <RpcOutput, object> keyValuePair in this.outputParameters)
            {
                array[num++] = ExchangeCertificateRpc.SerializeObject(keyValuePair.Key);
                RpcOutput key = keyValuePair.Key;
                switch (key)
                {
                case RpcOutput.ExchangeCertList:
                    array[num++] = this.SerializeListAsArray <ExchangeCertificate>(keyValuePair.Value as List <ExchangeCertificate>);
                    break;

                case RpcOutput.ExchangeCert:
                    array[num++] = ExchangeCertificateRpc.SerializeObject(((ExchangeCertificate)keyValuePair.Value).ExchangeCertificateAsArray());
                    break;

                default:
                    switch (key)
                    {
                    case RpcOutput.TaskWarningList:
                        array[num++] = this.SerializeListAsArray <LocalizedString>(keyValuePair.Value as List <LocalizedString>);
                        break;

                    case RpcOutput.TaskConfirmationList:
                        array[num++] = this.SerializeDictionaryAsArray <AllowedServices, LocalizedString>(keyValuePair.Value as Dictionary <AllowedServices, LocalizedString>);
                        break;

                    default:
                        array[num++] = ExchangeCertificateRpc.SerializeObject(keyValuePair.Value);
                        break;
                    }
                    break;
                }
            }
            return(ExchangeCertificateRpc.SerializeObject(array));
        }
Ejemplo n.º 12
0
        private byte[] SerializeListAsArray <TItem>(List <TItem> list)
        {
            int num = 0;

            if (list != null)
            {
                object[] array = new object[list.Count];
                foreach (TItem titem in list)
                {
                    if (typeof(TItem) == typeof(ExchangeCertificate))
                    {
                        ExchangeCertificate exchangeCertificate = titem as ExchangeCertificate;
                        array[num++] = ExchangeCertificateRpc.SerializeObject(exchangeCertificate.ExchangeCertificateAsArray());
                    }
                    else
                    {
                        array[num++] = ExchangeCertificateRpc.SerializeObject(titem);
                    }
                }
                return(ExchangeCertificateRpc.SerializeObject(array));
            }
            return(null);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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));
                    }
                }
            }
        }
Ejemplo n.º 16
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);
            }
        }