Beispiel #1
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));
        }
Beispiel #2
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);
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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;
            }
        }