Пример #1
0
        private PerTenantRMSTrustedPublishingDomainConfiguration GetTenantTrustedPublishingDomainConfig(RmsClientManagerContext clientContext)
        {
            PerTenantRMSTrustedPublishingDomainConfiguration value;

            try
            {
                if (ServerManager.aDSession != null)
                {
                    value = this.trustedPublishingDomainConfigCache.GetValue(ServerManager.aDSession);
                }
                else
                {
                    value = this.trustedPublishingDomainConfigCache.GetValue(clientContext.OrgId);
                }
            }
            catch (ADTransientException ex)
            {
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.PerTenantRMSTrustedPublishingDomainConfiguration, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to GetTenantTrustedPublishingDomainConfig with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                throw new RightsManagementServerException(ServerStrings.FailedToReadConfiguration, ex, false);
            }
            catch (ADOperationException ex2)
            {
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.PerTenantRMSTrustedPublishingDomainConfiguration, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to GetTenantTrustedPublishingDomainConfig with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex2, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                throw new RightsManagementServerException(ServerStrings.FailedToReadConfiguration, ex2, true);
            }
            catch (DataValidationException ex3)
            {
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.PerTenantRMSTrustedPublishingDomainConfiguration, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to GetTenantTrustedPublishingDomainConfig with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex3, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                throw new RightsManagementServerException(ServerStrings.FailedToReadConfiguration, ex3, true);
            }
            return(value);
        }
Пример #2
0
        public override byte[] GetTenantActiveCryptoMode(int version, byte[] inputParameterBytes)
        {
            GetTenantActiveCryptoModeRpcParameters getTenantActiveCryptoModeRpcParameters = null;

            byte[] result;
            try
            {
                getTenantActiveCryptoModeRpcParameters = new GetTenantActiveCryptoModeRpcParameters(inputParameterBytes);
                int tenantActiveCryptoMode = ServerManager.GetTenantActiveCryptoMode(getTenantActiveCryptoModeRpcParameters.ClientManagerContext);
                ActiveCryptoModeResult[] originalResults = new ActiveCryptoModeResult[]
                {
                    new ActiveCryptoModeResult(tenantActiveCryptoMode, null)
                };
                GetTenantActiveCryptoModeRpcResults getTenantActiveCryptoModeRpcResults = new GetTenantActiveCryptoModeRpcResults(new OverallRpcResult(null), originalResults);
                result = getTenantActiveCryptoModeRpcResults.Serialize();
            }
            catch (Exception ex)
            {
                if (!(ex is RightsManagementServerException))
                {
                    ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcServerWrapper, ServerManagerLog.EventType.Error, (getTenantActiveCryptoModeRpcParameters != null) ? getTenantActiveCryptoModeRpcParameters.ClientManagerContext : null, string.Format("ServerManager.GetTenantActiveCryptoMode has thrown unhandled exception {0}", ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                    ExWatson.SendReportAndCrashOnAnotherThread(ex);
                }
                GetTenantActiveCryptoModeRpcResults getTenantActiveCryptoModeRpcResults2 = new GetTenantActiveCryptoModeRpcResults(new OverallRpcResult(ex), Array <ActiveCryptoModeResult> .Empty);
                result = getTenantActiveCryptoModeRpcResults2.Serialize();
            }
            return(result);
        }
Пример #3
0
        public override byte[] AcquireTenantLicenses(int version, byte[] inputParameterBytes)
        {
            XmlNode[] rac = null;
            XmlNode[] clc = null;
            AcquireTenantLicensesRpcParameters acquireTenantLicensesRpcParameters = null;

            byte[] result;
            try
            {
                acquireTenantLicensesRpcParameters = new AcquireTenantLicensesRpcParameters(inputParameterBytes);
                ServerManager.AcquireTenantLicenses(acquireTenantLicensesRpcParameters.ClientManagerContext, acquireTenantLicensesRpcParameters.MachineCertificateChain, acquireTenantLicensesRpcParameters.Identity, out rac, out clc);
                AcquireTenantLicensesRpcResults acquireTenantLicensesRpcResults = new AcquireTenantLicensesRpcResults(new OverallRpcResult(null), rac, clc);
                result = acquireTenantLicensesRpcResults.Serialize();
            }
            catch (Exception ex)
            {
                if (!(ex is RightsManagementServerException))
                {
                    ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcServerWrapper, ServerManagerLog.EventType.Error, (acquireTenantLicensesRpcParameters != null) ? acquireTenantLicensesRpcParameters.ClientManagerContext : null, string.Format("ServerManager.AcquireTenantLicenses has thrown unhandled exception {0}", ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                    ExWatson.SendReportAndCrashOnAnotherThread(ex);
                }
                AcquireTenantLicensesRpcResults acquireTenantLicensesRpcResults2 = new AcquireTenantLicensesRpcResults(new OverallRpcResult(ex), Array <XmlNode> .Empty, Array <XmlNode> .Empty);
                result = acquireTenantLicensesRpcResults2.Serialize();
            }
            return(result);
        }
Пример #4
0
        public static ActiveCryptoModeRpcResult[] GetTenantActiveCryptoMode(RmsClientManagerContext clientContext)
        {
            if (clientContext == null)
            {
                throw new ArgumentNullException("clientContext");
            }
            RpcClientWrapper.InitializeIfNeeded();
            string randomRpcTargetServerName = RpcClientWrapper.instance.GetRandomRpcTargetServerName();

            byte[] data = null;
            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Entry, clientContext, string.Format("OfflineRmsRpcClient.GetTenantActiveCryptoMode against RPC server {0}", randomRpcTargetServerName));
            try
            {
                using (OfflineRmsRpcClient offlineRmsRpcClient = new OfflineRmsRpcClient(randomRpcTargetServerName))
                {
                    data = offlineRmsRpcClient.GetTenantActiveCryptoMode(1, new GetTenantActiveCryptoModeRpcParameters(clientContext).Serialize());
                }
            }
            catch (RpcException ex)
            {
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.GetTenantActiveCryptoMode against RPC server {0} failed with RPC Exception {1}", randomRpcTargetServerName, ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                throw new RightsManagementServerException(ServerStrings.RpcClientException("GetTenantActiveCryptoMode", randomRpcTargetServerName), ex, false);
            }
            GetTenantActiveCryptoModeRpcResults getTenantActiveCryptoModeRpcResults = new GetTenantActiveCryptoModeRpcResults(data);

            if (getTenantActiveCryptoModeRpcResults.OverallRpcResult.Status == OverallRpcStatus.Success)
            {
                return(getTenantActiveCryptoModeRpcResults.ActiveCryptoModeRpcResults);
            }
            string serializedString = ErrorResult.GetSerializedString(getTenantActiveCryptoModeRpcResults.OverallRpcResult.ErrorResults);

            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.GetTenantActiveCryptoMode against RPC server {0} failed with WellKnownErrorCode {1}, and with Exception {2}", randomRpcTargetServerName, getTenantActiveCryptoModeRpcResults.OverallRpcResult.WellKnownErrorCode, serializedString));
            throw new RightsManagementServerException(ServerStrings.FailedToRpcAcquireUseLicenses(clientContext.OrgId.ToString(), serializedString, randomRpcTargetServerName), getTenantActiveCryptoModeRpcResults.OverallRpcResult.WellKnownErrorCode, getTenantActiveCryptoModeRpcResults.OverallRpcResult.Status == OverallRpcStatus.PermanentFailure);
        }
Пример #5
0
        private void Initialize()
        {
            string processName = Process.GetCurrentProcess().ProcessName;

            this.isHostingInstance = (processName.Equals("EdgeTransport", StringComparison.OrdinalIgnoreCase) || this.isHostingInstanceOverride);
            if (this.isHostingInstance)
            {
                this.trustedPublishingDomainConfigCache = new TenantConfigurationCache <PerTenantRMSTrustedPublishingDomainConfiguration>(ServerManager.CacheSizeInBytes, ServerManager.CacheTimeout, ServerManager.CacheTimeout, null, null);
                this.isMemberOfAdAdapter = new IsMemberOfResolverADAdapter <RoutingAddress> .RoutingAddressResolver(false);

                this.isMemberOfResolver = new IsMemberOfResolver <RoutingAddress>(new ServerManager.OfflineRMSIsMemberOfResolverConfig(), new IsMemberOfResolverPerformanceCounters("OfflineRMSServerManager"), this.isMemberOfAdAdapter);
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.ServerInit, ServerManagerLog.EventType.Success, null, "Successfully intialized OfflineRms Server Instance");
            }
        }
Пример #6
0
        public static bool IsMemberOf(RmsClientManagerContext clientContext, string recipientAddress, string groupAddress)
        {
            ArgumentValidator.ThrowIfNull("recipientAddress", recipientAddress);
            ArgumentValidator.ThrowIfNullOrEmpty("groupAddress", groupAddress);
            if (!ServerManager.instance.isHostingInstance)
            {
                throw new InvalidOperationException("Can't call IsMemberOf directly as ServerManager is NOT allowed to host in current calling process");
            }
            if (!SmtpAddress.IsValidSmtpAddress(recipientAddress))
            {
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.DirectoryServiceProvider, ServerManagerLog.EventType.Error, clientContext, string.Format("recipientAddress {0} is invalid SMTP Address", recipientAddress));
                return(false);
            }
            if (!RoutingAddress.IsValidAddress(groupAddress))
            {
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.DirectoryServiceProvider, ServerManagerLog.EventType.Error, clientContext, string.Format("groupAddress {0} is invalid SMTP Address", groupAddress));
                return(false);
            }
            ServerManager.InitializeIfNeeded();
            bool result;

            if (ServerManager.CheckForSpecialRmsOnlineTenantMembershipQuery(recipientAddress, groupAddress, out result))
            {
                return(result);
            }
            ADRawEntry adrawEntry = clientContext.ResolveRecipient(recipientAddress);

            if (adrawEntry == null)
            {
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.DirectoryServiceProvider, ServerManagerLog.EventType.Verbose, clientContext, string.Format("Failed to resolve recipientAddress {0} in Active Directory. Treat IsMemberOf for {1} against {2} as false", recipientAddress, recipientAddress, groupAddress));
                return(false);
            }
            ProxyAddressCollection proxyAddressCollection = (ProxyAddressCollection)adrawEntry[ADRecipientSchema.EmailAddresses];
            SmtpProxyAddress       other = new SmtpProxyAddress(groupAddress, true);

            foreach (ProxyAddress proxyAddress in proxyAddressCollection)
            {
                if (proxyAddress.Equals(other))
                {
                    ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.DirectoryServiceProvider, ServerManagerLog.EventType.Success, clientContext, string.Format("IsMemberOf return true as proxyAddress {0} is the same is groupAddress {1}", recipientAddress, groupAddress));
                    return(true);
                }
            }
            RoutingAddress groupKey = new RoutingAddress(groupAddress);
            bool           result2  = ServerManager.instance.isMemberOfResolver.IsMemberOf(clientContext.RecipientSession, adrawEntry.Id, groupKey);

            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.DirectoryServiceProvider, ServerManagerLog.EventType.Success, clientContext, string.Format("IsMemberOf return {0} for proxyAddress {1} against groupAddress {2}", result2.ToString(CultureInfo.InvariantCulture), recipientAddress, groupAddress));
            return(result2);
        }
Пример #7
0
        internal void Record(long elapsedMilliseconds)
        {
            bool     flag     = false;
            long     num      = 0L;
            long     num2     = 0L;
            long     num3     = 0L;
            int      num4     = 0;
            TimeSpan timeSpan = TimeSpan.MinValue;

            lock (this.syncObject)
            {
                this.totalCostMilliseconds += elapsedMilliseconds;
                this.sampleCount++;
                if (elapsedMilliseconds > this.highestCost)
                {
                    this.highestCost = elapsedMilliseconds;
                }
                if (elapsedMilliseconds < this.lowestCost)
                {
                    this.lowestCost = elapsedMilliseconds;
                }
                timeSpan = DateTime.UtcNow - this.lastReset;
                num4     = this.sampleCount;
                if (num4 >= this.minimumRequiredSampleCount && timeSpan >= this.minimumRequiredSamplePeriod)
                {
                    num                        = this.lowestCost;
                    num2                       = this.highestCost;
                    num3                       = this.totalCostMilliseconds / (long)this.sampleCount;
                    flag                       = true;
                    this.lowestCost            = long.MaxValue;
                    this.highestCost           = 0L;
                    this.totalCostMilliseconds = 0L;
                    this.sampleCount           = 0;
                    this.lastReset             = DateTime.UtcNow;
                }
            }
            if (flag)
            {
                ServerManagerLog.LogEvent(this.component, ServerManagerLog.EventType.Statistics, null, string.Format("Performance for {0}: AverageCost {1} ms, HighestCost {2} ms, LowestCost {3} ms, SampleCount {4}, SamplePeriod {5}", new object[]
                {
                    this.name,
                    num3,
                    num2,
                    num,
                    num4,
                    timeSpan
                }));
            }
        }
Пример #8
0
        public static UseLicenseRpcResult[] AcquireUseLicenses(RmsClientManagerContext clientContext, XmlNode[] rightsAccountCertificate, XmlNode[] issuanceLicense, LicenseeIdentity[] licenseeIdentities)
        {
            if (clientContext == null)
            {
                throw new ArgumentNullException("clientContext");
            }
            if (rightsAccountCertificate == null)
            {
                throw new ArgumentNullException("rightsAccountCertificate");
            }
            if (issuanceLicense == null || issuanceLicense.Length < 1)
            {
                throw new ArgumentNullException("issuanceLicense");
            }
            if (licenseeIdentities == null || licenseeIdentities.Length < 1)
            {
                throw new ArgumentNullException("licenseeIdentities");
            }
            RpcClientWrapper.InitializeIfNeeded();
            string randomRpcTargetServerName = RpcClientWrapper.instance.GetRandomRpcTargetServerName();

            byte[] data = null;
            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Entry, clientContext, string.Format("OfflineRmsRpcClient.AcquireUseLicenses against RPC server {0}", randomRpcTargetServerName));
            try
            {
                using (OfflineRmsRpcClient offlineRmsRpcClient = new OfflineRmsRpcClient(randomRpcTargetServerName))
                {
                    data = offlineRmsRpcClient.AcquireUseLicenses(1, new AcquireUseLicensesRpcParameters(clientContext, rightsAccountCertificate, issuanceLicense, licenseeIdentities).Serialize());
                }
            }
            catch (RpcException ex)
            {
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.AcquireUseLicenses against RPC server {0} failed with RPC Exception {1}", randomRpcTargetServerName, ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                throw new RightsManagementServerException(ServerStrings.RpcClientException("AcquireUseLicenses", randomRpcTargetServerName), ex, false);
            }
            AcquireUseLicensesRpcResults acquireUseLicensesRpcResults = new AcquireUseLicensesRpcResults(data);

            if (acquireUseLicensesRpcResults.OverallRpcResult.Status == OverallRpcStatus.Success)
            {
                return(acquireUseLicensesRpcResults.UseLicenseRpcResults);
            }
            string serializedString = ErrorResult.GetSerializedString(acquireUseLicensesRpcResults.OverallRpcResult.ErrorResults);

            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.AcquireUseLicenses against RPC server {0} failed with WellKnownErrorCode {1}, and with Exception {2}", randomRpcTargetServerName, acquireUseLicensesRpcResults.OverallRpcResult.WellKnownErrorCode, serializedString));
            throw new RightsManagementServerException(ServerStrings.FailedToRpcAcquireUseLicenses(clientContext.OrgId.ToString(), serializedString, randomRpcTargetServerName), acquireUseLicensesRpcResults.OverallRpcResult.WellKnownErrorCode, acquireUseLicensesRpcResults.OverallRpcResult.Status == OverallRpcStatus.PermanentFailure);
        }
Пример #9
0
        public static void AcquireTenantLicenses(RmsClientManagerContext clientContext, XmlNode[] machineCertificateChain, string identity, out XmlNode[] racXml, out XmlNode[] clcXml)
        {
            if (clientContext == null)
            {
                throw new ArgumentNullException("clientContext");
            }
            if (machineCertificateChain == null || machineCertificateChain.Length < 1)
            {
                throw new ArgumentNullException("machineCertificateChain");
            }
            if (string.IsNullOrEmpty(identity))
            {
                throw new ArgumentNullException("identity");
            }
            racXml = null;
            clcXml = null;
            RpcClientWrapper.InitializeIfNeeded();
            string randomRpcTargetServerName = RpcClientWrapper.instance.GetRandomRpcTargetServerName();

            byte[] data = null;
            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Entry, clientContext, string.Format("OfflineRmsRpcClient.AcquireTenantLicenses against RPC server {0}", randomRpcTargetServerName));
            try
            {
                using (OfflineRmsRpcClient offlineRmsRpcClient = new OfflineRmsRpcClient(randomRpcTargetServerName))
                {
                    data = offlineRmsRpcClient.AcquireTenantLicenses(1, new AcquireTenantLicensesRpcParameters(clientContext, identity, machineCertificateChain).Serialize());
                }
            }
            catch (RpcException ex)
            {
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.AcquireTenantLicenses against RPC server {0} failed with RPC Exception {1}", randomRpcTargetServerName, ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                throw new RightsManagementServerException(ServerStrings.RpcClientException("AcquireTenantLicenses", randomRpcTargetServerName), ex, false);
            }
            AcquireTenantLicensesRpcResults acquireTenantLicensesRpcResults = new AcquireTenantLicensesRpcResults(data);

            if (acquireTenantLicensesRpcResults.OverallRpcResult.Status == OverallRpcStatus.Success)
            {
                racXml = acquireTenantLicensesRpcResults.RacXml;
                clcXml = acquireTenantLicensesRpcResults.ClcXml;
                return;
            }
            string serializedString = ErrorResult.GetSerializedString(acquireTenantLicensesRpcResults.OverallRpcResult.ErrorResults);

            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, clientContext, string.Format("OfflineRmsRpcClient.AcquireTenantLicenses against RPC server {0} failed with WellKnownErrorCode {1} and with Exception {2}", randomRpcTargetServerName, acquireTenantLicensesRpcResults.OverallRpcResult.WellKnownErrorCode, serializedString));
            throw new RightsManagementServerException(ServerStrings.FailedToRpcAcquireRacAndClc(clientContext.OrgId.ToString(), serializedString, randomRpcTargetServerName), acquireTenantLicensesRpcResults.OverallRpcResult.WellKnownErrorCode, acquireTenantLicensesRpcResults.OverallRpcResult.Status == OverallRpcStatus.PermanentFailure);
        }
Пример #10
0
        public static void LogEvent(ServerManagerLog.Subcomponent subcomponent, ServerManagerLog.EventType eventType, RmsClientManagerContext clientManagerContext, string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                throw new ArgumentNullException("data");
            }
            ServerManagerLog.InitializeIfNeeded();
            LogRowFormatter logRowFormatter = new LogRowFormatter(ServerManagerLog.LogSchema);

            logRowFormatter[1] = subcomponent;
            logRowFormatter[2] = eventType;
            if (clientManagerContext != null)
            {
                logRowFormatter[3] = clientManagerContext.OrgId.OrganizationalUnit.ToString();
                logRowFormatter[6] = clientManagerContext.TransactionId.ToString();
                if (clientManagerContext.ContextID != RmsClientManagerContext.ContextId.None && !string.IsNullOrEmpty(clientManagerContext.ContextStringForm))
                {
                    logRowFormatter[5] = clientManagerContext.ContextStringForm;
                }
            }
            logRowFormatter[4] = data;
            ServerManagerLog.instance.logInstance.Append(logRowFormatter, 0);
        }
Пример #11
0
        public override byte[] AcquireUseLicenses(int version, byte[] inputParameterBytes)
        {
            AcquireUseLicensesRpcParameters acquireUseLicensesRpcParameters = null;

            byte[] result;
            try
            {
                acquireUseLicensesRpcParameters = new AcquireUseLicensesRpcParameters(inputParameterBytes);
                UseLicenseResult[]           originalResults = ServerManager.AcquireUseLicenses(acquireUseLicensesRpcParameters.ClientManagerContext, acquireUseLicensesRpcParameters.RightsAccountCertificate, acquireUseLicensesRpcParameters.IssuanceLicense, acquireUseLicensesRpcParameters.LicenseeIdentities);
                AcquireUseLicensesRpcResults acquireUseLicensesRpcResults = new AcquireUseLicensesRpcResults(new OverallRpcResult(null), originalResults);
                result = acquireUseLicensesRpcResults.Serialize();
            }
            catch (Exception ex)
            {
                if (!(ex is RightsManagementServerException))
                {
                    ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcServerWrapper, ServerManagerLog.EventType.Error, (acquireUseLicensesRpcParameters != null) ? acquireUseLicensesRpcParameters.ClientManagerContext : null, string.Format("ServerManager.AcquireTenantLicenses has thrown unhandled exception {0}", ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                    ExWatson.SendReportAndCrashOnAnotherThread(ex);
                }
                AcquireUseLicensesRpcResults acquireUseLicensesRpcResults2 = new AcquireUseLicensesRpcResults(new OverallRpcResult(ex), Array <UseLicenseResult> .Empty);
                result = acquireUseLicensesRpcResults2.Serialize();
            }
            return(result);
        }
Пример #12
0
 public static void AcquireTenantLicenses(RmsClientManagerContext clientContext, XmlNode[] machineCertificateChain, string identity, out XmlNode[] racXml, out XmlNode[] clcXml)
 {
     ArgumentValidator.ThrowIfNull("clientContext", clientContext);
     ArgumentValidator.ThrowIfNull("machineCertificateChain", machineCertificateChain);
     ArgumentValidator.ThrowIfNullOrEmpty("identity", identity);
     racXml = null;
     clcXml = null;
     ServerManager.InitializeIfNeeded();
     if (ServerManager.instance.isHostingInstance)
     {
         PerTenantRMSTrustedPublishingDomainConfiguration tenantTrustedPublishingDomainConfig = ServerManager.instance.GetTenantTrustedPublishingDomainConfig(clientContext);
         ContextProvider contextProvider = null;
         try
         {
             IRightsAccountCertificateGenerator  rightsAccountCertificateGenerator;
             IClientLicensorCertificateGenerator clientLicensorCertificateGenerator;
             try
             {
                 contextProvider = new ContextProvider(clientContext, tenantTrustedPublishingDomainConfig);
                 rightsAccountCertificateGenerator  = GeneratorFactory.CreateRightsAccountCertificateGenerator(contextProvider);
                 clientLicensorCertificateGenerator = GeneratorFactory.CreateClientLicensorCertificateGenerator(contextProvider);
             }
             catch (ConfigurationProviderException ex)
             {
                 ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to create Generator with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                 throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "RacClc"), ex);
             }
             catch (CertificationException ex2)
             {
                 ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to create Generator with WellKnownErrorCode {0}, Exception: {1}", ex2.ErrorCode, ServerManagerLog.GetExceptionLogString(ex2, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                 throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "Rac"), ex2);
             }
             catch (PublishingException ex3)
             {
                 ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to create Generator with WellKnownErrorCode {0}, Exception: {1}", ex3.ErrorCode, ServerManagerLog.GetExceptionLogString(ex3, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                 throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "Clc"), ex3);
             }
             XrmlCertificateChain xrmlCertificateChain = new XrmlCertificateChain(DrmClientUtils.ConvertXmlNodeArrayToStringArray(machineCertificateChain));
             ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Entry, clientContext, string.Format("AcquireTenantLicenses for identity {0}", identity));
             XrmlCertificateChain xrmlCertificateChain2;
             XrmlCertificateChain xrmlCertificateChain3;
             try
             {
                 string text = ServerManager.ReadOrganizationRacKeysFromIRMConfig(clientContext.OrgId);
                 xrmlCertificateChain2 = rightsAccountCertificateGenerator.AcquireCertificate(xrmlCertificateChain, identity, text);
                 xrmlCertificateChain3 = clientLicensorCertificateGenerator.AcquireCertificate(xrmlCertificateChain2);
             }
             catch (CertificationException ex4)
             {
                 ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to AcquireTenantLicenses with WellKnownErrorCode {0}, Exception: {1}", ex4.ErrorCode, ServerManagerLog.GetExceptionLogString(ex4, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                 throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), ex4);
             }
             catch (PublishingException ex5)
             {
                 ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireTenantLicenses, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to AcquireTenantLicenses with WellKnownErrorCode {0}, Exception: {1}", ex5.ErrorCode, ServerManagerLog.GetExceptionLogString(ex5, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                 throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), ex5);
             }
             if (!RMUtil.TryConvertCertChainStringArrayToXmlNodeArray(xrmlCertificateChain2.ToStringArray(), out racXml))
             {
                 throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), true);
             }
             if (!RMUtil.TryConvertCertChainStringArrayToXmlNodeArray(xrmlCertificateChain3.ToStringArray(), out clcXml))
             {
                 throw new RightsManagementServerException(ServerStrings.FailedToAcquireRacAndClc(clientContext.OrgId.ToString(), identity), true);
             }
             return;
         }
         finally
         {
             if (contextProvider != null)
             {
                 contextProvider.Dispose();
             }
         }
     }
     RpcClientWrapper.AcquireTenantLicenses(clientContext, machineCertificateChain, identity, out racXml, out clcXml);
 }
Пример #13
0
        public static UseLicenseResult[] AcquireUseLicenses(RmsClientManagerContext clientContext, XmlNode[] rightsAccountCertificate, XmlNode[] issuanceLicense, LicenseeIdentity[] licenseeIdentities)
        {
            ArgumentValidator.ThrowIfNull("clientContext", clientContext);
            ArgumentValidator.ThrowIfNull("rightsAccountCertificate", rightsAccountCertificate);
            ArgumentValidator.ThrowIfNull("issuanceLicense", issuanceLicense);
            ArgumentValidator.ThrowIfNull("licenseeIdentities", licenseeIdentities);
            Stopwatch watch = Stopwatch.StartNew();

            ServerManager.InitializeIfNeeded();
            if (ServerManager.instance.isHostingInstance)
            {
                PerTenantRMSTrustedPublishingDomainConfiguration tenantTrustedPublishingDomainConfig = ServerManager.instance.GetTenantTrustedPublishingDomainConfig(clientContext);
                ContextProvider contextProvider = null;
                try
                {
                    IEndUserLicenseGenerator endUserLicenseGenerator;
                    try
                    {
                        contextProvider         = new ContextProvider(clientContext, tenantTrustedPublishingDomainConfig);
                        endUserLicenseGenerator = GeneratorFactory.CreateEndUserLicenseGenerator(contextProvider);
                    }
                    catch (ConfigurationProviderException ex)
                    {
                        ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed in CreateEndUserLicenseGenerator with Exception: {0}", ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                        throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "UseLicenseGenerator"), ex);
                    }
                    catch (LicensingException ex2)
                    {
                        ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed in CreateEndUserLicenseGenerator with WellKnownError {0} and Exception: {1}", ex2.ErrorCode, ServerManagerLog.GetExceptionLogString(ex2, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                        throw new RightsManagementServerException(ServerStrings.FailedToCreateLicenseGenerator(clientContext.OrgId.ToString(), "UseLicenseGenerator"), ex2);
                    }
                    XrmlCertificateChain xrmlCertificateChain  = new XrmlCertificateChain(DrmClientUtils.ConvertXmlNodeArrayToStringArray(issuanceLicense));
                    XrmlCertificateChain xrmlCertificateChain2 = new XrmlCertificateChain(DrmClientUtils.ConvertXmlNodeArrayToStringArray(rightsAccountCertificate));
                    ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, ServerManagerLog.EventType.Entry, clientContext, string.Format("AcquireLicenses for {0} licensees, they are {1}", licenseeIdentities.Length, ServerManager.GetLicenseeLogString(licenseeIdentities)));
                    LicensingBatchResults licensingBatchResults;
                    try
                    {
                        licensingBatchResults = endUserLicenseGenerator.AcquireLicenses(xrmlCertificateChain2, xrmlCertificateChain, licenseeIdentities);
                    }
                    catch (LicensingException ex3)
                    {
                        ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed useLicenseGenerator.AcquireLicenses with WellKnownErrorCode {0}, Exception: {1}", ex3.ErrorCode, ServerManagerLog.GetExceptionLogString(ex3, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                        throw new RightsManagementServerException(ServerStrings.FailedToAcquireUseLicenses(clientContext.OrgId.ToString()), ex3);
                    }
                    int num = 0;
                    UseLicenseResult[] array = new UseLicenseResult[licensingBatchResults.LicensingResults.Count];
                    for (int i = 0; i < licensingBatchResults.LicensingResults.Count; i++)
                    {
                        StringBuilder stringBuilder = null;
                        if (licensingBatchResults.LicensingResults[i].EndUserLicense != null && licensingBatchResults.LicensingResults[i].Error == null)
                        {
                            stringBuilder = new StringBuilder();
                            stringBuilder.Append(licensingBatchResults.LicensingResults[i].EndUserLicense);
                            string[] array2 = licensingBatchResults.ServerLicensorCertificateChain.ToStringArray();
                            foreach (string value in array2)
                            {
                                stringBuilder.Append(value);
                            }
                        }
                        LicensingException error            = licensingBatchResults.LicensingResults[i].Error;
                        RightsManagementServerException ex4 = (error != null) ? new RightsManagementServerException(ServerStrings.FailedToAcquireUseLicenses(clientContext.OrgId.ToString()), error) : null;
                        if (error != null)
                        {
                            num++;
                            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, ServerManagerLog.EventType.Error, clientContext, string.Format("Failed to AcquireLicenses for Licensee {0} with WellKnownErrorCode {1}, Exception: {2}", licenseeIdentities[i], error.ErrorCode, ServerManagerLog.GetExceptionLogString(error, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                        }
                        if (stringBuilder != null && ex4 != null)
                        {
                            throw new InvalidOperationException("LicensingResult.EndUserLicense and LicensingResult.Error are both non-null");
                        }
                        if (stringBuilder == null && ex4 == null)
                        {
                            throw new InvalidOperationException("LicensingResult.EndUserLicense and LicensingResult.Error are null");
                        }
                        array[i] = new UseLicenseResult((stringBuilder != null) ? stringBuilder.ToString() : null, ex4);
                    }
                    ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.AcquireUseLicense, (num == 0) ? ServerManagerLog.EventType.Success : ServerManagerLog.EventType.Error, clientContext, string.Format("AcquireLicenses finishes with successs count {0} and failed count {1}", array.Length - num, num));
                    ServerManager.instance.rpcAcquireUseLicensePerformanceMonitor.Record(watch);
                    return(array);
                }
                finally
                {
                    if (contextProvider != null)
                    {
                        contextProvider.Dispose();
                    }
                }
            }
            UseLicenseRpcResult[] array4 = RpcClientWrapper.AcquireUseLicenses(clientContext, rightsAccountCertificate, issuanceLicense, licenseeIdentities);
            UseLicenseResult[]    array5 = new UseLicenseResult[array4.Length];
            for (int k = 0; k < array4.Length; k++)
            {
                RightsManagementServerException e = null;
                if (array4[k].ErrorResults != null && array4[k].ErrorResults.Count > 0)
                {
                    e = new RightsManagementServerException(array4[k].GetSerializedString(), array4[k].IsPermanentFailure);
                }
                array5[k] = new UseLicenseResult(array4[k].EndUseLicense, e);
            }
            ServerManager.instance.acquireUseLicensePerformanceMonitor.Record(watch);
            return(array5);
        }
Пример #14
0
        private bool TryLoadTopologies(out Exception e)
        {
            bool result;

            try
            {
                e = null;
                if (Interlocked.Increment(ref this.loadTopologyCount) == 1)
                {
                    ADOperationResult adoperationResult;
                    if (this.localServer == null)
                    {
                        adoperationResult = ADNotificationAdapter.TryRunADOperation(delegate()
                        {
                            this.localServer = this.rootOrgConfigSession.FindLocalServer();
                        }, 3);
                        if (!adoperationResult.Succeeded)
                        {
                            e = adoperationResult.Exception;
                            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, null, string.Format("Failed find local server with Exception {0}", ServerManagerLog.GetExceptionLogString(e, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                            return(false);
                        }
                        if (this.localServer.ServerSite == null)
                        {
                            ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, null, "Local server doesn't have AD site");
                            return(false);
                        }
                        this.localSiteHubsFilter = new AndFilter(new QueryFilter[]
                        {
                            new BitMaskAndFilter(ServerSchema.CurrentServerRole, 32UL),
                            new ComparisonFilter(ComparisonOperator.Equal, ServerSchema.ServerSite, this.localServer.ServerSite)
                        });
                    }
                    List <Server> bridgeheadServers = new List <Server>();
                    if (!ADNotificationAdapter.TryReadConfigurationPaged <Server>(() => this.rootOrgConfigSession.FindPaged <Server>(null, QueryScope.SubTree, this.localSiteHubsFilter, null, 0), delegate(Server server)
                    {
                        ServerVersion a = new ServerVersion(server.VersionNumber);
                        if (ServerVersion.Compare(a, RpcClientWrapper.minRequiredRpcServerVersion) >= 0)
                        {
                            bridgeheadServers.Add(server);
                        }
                    }, out adoperationResult))
                    {
                        e = adoperationResult.Exception;
                        ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Error, null, string.Format("Failed to load topology with exception {0}", ServerManagerLog.GetExceptionLogString(e, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                        result = false;
                    }
                    else
                    {
                        Interlocked.Exchange <List <Server> >(ref this.localSiteBridgeheadServers, bridgeheadServers);
                        RpcClientWrapper.instance.topologyLastUpdated = DateTime.UtcNow;
                        StringBuilder stringBuilder = new StringBuilder();
                        foreach (Server server2 in bridgeheadServers)
                        {
                            stringBuilder.Append(server2.Name);
                            stringBuilder.Append(",");
                        }
                        ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.RpcClientWrapper, ServerManagerLog.EventType.Success, null, string.Format("Sucessfully load topology with servers {0}", stringBuilder.ToString()));
                        result = true;
                    }
                }
                else
                {
                    result = true;
                }
            }
            finally
            {
                Interlocked.Decrement(ref this.loadTopologyCount);
            }
            return(result);
        }
Пример #15
0
        private RsaCapiKey GetKey(string keyIdentification)
        {
            PrivateKeyInformation privateKeyInformation;

            if (string.IsNullOrEmpty(keyIdentification))
            {
                privateKeyInformation = this.slcKey;
            }
            else if (!this.privateKeyInfos.TryGetValue(keyIdentification, out privateKeyInformation))
            {
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.TrustedPublishingDomainPrivateKeyProvider, ServerManagerLog.EventType.Error, this.clientContext, string.Format("Failed to locate Key {0} in TrustedPublishingDomainPrivateKeyProvider", keyIdentification));
                StringBuilder stringBuilder = new StringBuilder();
                foreach (PrivateKeyInformation privateKeyInformation2 in this.privateKeyInfos.Values)
                {
                    stringBuilder.Append(privateKeyInformation2.KeyId);
                    stringBuilder.Append(" ");
                }
                ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.TrustedPublishingDomainPrivateKeyProvider, ServerManagerLog.EventType.Verbose, this.clientContext, string.Format("Dump of TPDs keyIds for current tenant is {0} ", stringBuilder));
                throw new PrivateKeyProviderException(false, "Failed to locate private key for " + keyIdentification, null);
            }
            if (this.capiKeys.ContainsKey(privateKeyInformation.Identity))
            {
                return(this.capiKeys[privateKeyInformation.Identity]);
            }
            CspParameters parameters = new CspParameters
            {
                Flags            = CspProviderFlags.UseMachineKeyStore,
                ProviderType     = privateKeyInformation.CSPType,
                KeyNumber        = privateKeyInformation.KeyNumber,
                KeyContainerName = null,
                ProviderName     = (string.IsNullOrEmpty(privateKeyInformation.CSPName) ? null : privateKeyInformation.CSPName)
            };
            RsaCapiKey rsaCapiKey = new RsaCapiKey(parameters)
            {
                PersistKeyInCryptoServiceProvider = false
            };

            byte[]     array = null;
            RsaCapiKey result;

            try
            {
                Guid             guid = (this.clientContext == null) ? Guid.Empty : this.clientContext.ExternalDirectoryOrgId;
                ExchangeGroupKey exchangeGroupKey;
                Exception        ex;
                if (!ServerManager.TryGetDkmKey(guid, out exchangeGroupKey, out ex))
                {
                    ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.TrustedPublishingDomainPrivateKeyProvider, ServerManagerLog.EventType.Error, this.clientContext, string.Format("Unable to create ExchangeGroupKey object for tenant with external directory org id {0} with exception {1}", guid, ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                    throw new PrivateKeyProviderException(true, string.Format("Unable to create ExchangeGroupKey object for tenant with external directory org id {0}", guid), ex);
                }
                if (!exchangeGroupKey.TryEncryptedStringToBuffer(privateKeyInformation.EncryptedPrivateKeyBlob, out array, out ex))
                {
                    ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.TrustedPublishingDomainPrivateKeyProvider, ServerManagerLog.EventType.Error, this.clientContext, string.Format("Failed to DKM decrypt private key {0} with Exception {1}", keyIdentification, ServerManagerLog.GetExceptionLogString(ex, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                    StorageGlobals.EventLogger.LogEvent(StorageEventLogConstants.Tuple_DkmDecryptionFailure, null, new object[]
                    {
                        (this.clientContext == null) ? Guid.Empty.ToString() : this.clientContext.OrgId.ToString(),
                        ex
                    });
                    throw new PrivateKeyProviderException(true, "Failed to DKM decrypt the private key", ex);
                }
                try
                {
                    rsaCapiKey.Init(array);
                    this.capiKeys[privateKeyInformation.Identity] = rsaCapiKey;
                }
                catch (CryptographicException ex2)
                {
                    ServerManagerLog.LogEvent(ServerManagerLog.Subcomponent.TrustedPublishingDomainPrivateKeyProvider, ServerManagerLog.EventType.Error, this.clientContext, string.Format("Failed to intialize RsaCapiKey for {0} with Exception {1}", keyIdentification, ServerManagerLog.GetExceptionLogString(ex2, ServerManagerLog.ExceptionLogOption.IncludeStack | ServerManagerLog.ExceptionLogOption.IncludeInnerException)));
                    StorageGlobals.EventLogger.LogEvent(StorageEventLogConstants.Tuple_RsaCapiKeyImportFailure, null, new object[]
                    {
                        (this.clientContext == null) ? Guid.Empty.ToString() : this.clientContext.OrgId.ToString(),
                        ex2
                    });
                    throw new PrivateKeyProviderException(true, "Failed to intialize RsaCapiKey", ex2);
                }
                result = rsaCapiKey;
            }
            finally
            {
                if (array != null)
                {
                    Array.Clear(array, 0, array.Length);
                }
            }
            return(result);
        }