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);
            }
        }
Beispiel #2
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));
        }