Esempio n. 1
0
 public ContextProvider(RmsClientManagerContext clientContext, PerTenantRMSTrustedPublishingDomainConfiguration perTenantconfig)
 {
     if (clientContext == null)
     {
         throw new ArgumentNullException("clientContext");
     }
     if (perTenantconfig == null)
     {
         throw new ArgumentNullException("perTenantconfig");
     }
     if (perTenantconfig.PrivateKeys == null)
     {
         throw new ArgumentNullException("perTenantconfig.PrivateKeys");
     }
     this.clientContext               = clientContext;
     this.configProvider              = new ConfigurationInformationProvider(perTenantconfig);
     this.privateKeyProvider          = new TrustedPublishingDomainPrivateKeyProvider(clientContext, perTenantconfig.PrivateKeys);
     this.globalConfigurationProvider = new GlobalConfigurationCacheProvider();
     this.directoryServiceProvider    = new DirectoryServiceProvider(clientContext);
 }
Esempio n. 2
0
 public static int GetTenantActiveCryptoMode(RmsClientManagerContext clientContext)
 {
     ArgumentValidator.ThrowIfNull("clientContext", clientContext);
     ServerManager.InitializeIfNeeded();
     if (ServerManager.instance.isHostingInstance)
     {
         PerTenantRMSTrustedPublishingDomainConfiguration tenantTrustedPublishingDomainConfig = ServerManager.instance.GetTenantTrustedPublishingDomainConfig(clientContext);
         return(tenantTrustedPublishingDomainConfig.ActiveCryptoMode);
     }
     ActiveCryptoModeRpcResult[] tenantActiveCryptoMode = RpcClientWrapper.GetTenantActiveCryptoMode(clientContext);
     ActiveCryptoModeResult[]    array = new ActiveCryptoModeResult[tenantActiveCryptoMode.Length];
     for (int i = 0; i < tenantActiveCryptoMode.Length; i++)
     {
         RightsManagementServerException e = null;
         if (tenantActiveCryptoMode[i].ErrorResults != null && tenantActiveCryptoMode[i].ErrorResults.Count > 0)
         {
             e = new RightsManagementServerException(tenantActiveCryptoMode[i].GetSerializedString(), tenantActiveCryptoMode[i].IsPermanentFailure);
         }
         array[i] = new ActiveCryptoModeResult(tenantActiveCryptoMode[i].ActiveCryptoMode, e);
     }
     return(array[0].ActiveCryptoMode);
 }
 public override void ReadData(IConfigurationSession session)
 {
     RMSTrustedPublishingDomain[] array = session.Find <RMSTrustedPublishingDomain>(null, QueryScope.SubTree, null, null, 0);
     if (array == null || array.Length == 0)
     {
         throw new RightsManagementServerException(ServerStrings.FailedToLocateTPDConfig(session.SessionSettings.CurrentOrganizationId.ToString()), false);
     }
     this.compressedTrustedDomainChains = new List <string>(array.Length);
     this.compressedRMSTemplates        = new List <string>();
     this.privateKeys = new Dictionary <string, PrivateKeyInformation>(array.Length, StringComparer.OrdinalIgnoreCase);
     foreach (RMSTrustedPublishingDomain rmstrustedPublishingDomain in array)
     {
         if (string.IsNullOrEmpty(rmstrustedPublishingDomain.SLCCertChain))
         {
             throw new DataValidationException(new PropertyValidationError(new LocalizedString("SLCCertChain is null from AD for tenant " + base.OrganizationId), RMSTrustedPublishingDomainSchema.SLCCertChain, null));
         }
         if (string.IsNullOrEmpty(rmstrustedPublishingDomain.PrivateKey))
         {
             throw new DataValidationException(new PropertyValidationError(new LocalizedString("PrivateKey is null from AD for tenant " + base.OrganizationId), RMSTrustedPublishingDomainSchema.PrivateKey, null));
         }
         if (string.IsNullOrEmpty(rmstrustedPublishingDomain.KeyId))
         {
             throw new DataValidationException(new PropertyValidationError(new LocalizedString("KeyId is null from AD for tenant " + base.OrganizationId), RMSTrustedPublishingDomainSchema.KeyId, null));
         }
         if (string.IsNullOrEmpty(rmstrustedPublishingDomain.KeyIdType))
         {
             throw new DataValidationException(new PropertyValidationError(new LocalizedString("KeyIdType is null from AD for tenant " + base.OrganizationId), RMSTrustedPublishingDomainSchema.KeyIdType, null));
         }
         if (rmstrustedPublishingDomain.IntranetLicensingUrl == null || string.IsNullOrEmpty(rmstrustedPublishingDomain.IntranetLicensingUrl.OriginalString))
         {
             throw new DataValidationException(new PropertyValidationError(new LocalizedString("IntranetLicensingUrl is null from AD for tenant " + base.OrganizationId), RMSTrustedPublishingDomainSchema.IntranetLicensingUrl, null));
         }
         if (rmstrustedPublishingDomain.ExtranetLicensingUrl == null || string.IsNullOrEmpty(rmstrustedPublishingDomain.ExtranetLicensingUrl.OriginalString))
         {
             throw new DataValidationException(new PropertyValidationError(new LocalizedString("ExtranetLicensingUrl is null from AD for tenant " + base.OrganizationId), RMSTrustedPublishingDomainSchema.ExtranetLicensingUrl, null));
         }
         if (rmstrustedPublishingDomain.Default)
         {
             this.intranetLicensingUrl = rmstrustedPublishingDomain.IntranetLicensingUrl;
             this.estimatedSize       += rmstrustedPublishingDomain.IntranetLicensingUrl.OriginalString.Length * 2;
             this.extranetLicensingUrl = rmstrustedPublishingDomain.ExtranetLicensingUrl;
             this.estimatedSize       += rmstrustedPublishingDomain.ExtranetLicensingUrl.OriginalString.Length * 2;
             if (rmstrustedPublishingDomain.IntranetCertificationUrl != null && !string.IsNullOrEmpty(rmstrustedPublishingDomain.IntranetCertificationUrl.OriginalString))
             {
                 this.intranetCertificationUrl = rmstrustedPublishingDomain.IntranetCertificationUrl;
                 this.estimatedSize           += rmstrustedPublishingDomain.IntranetCertificationUrl.OriginalString.Length * 2;
             }
             if (rmstrustedPublishingDomain.ExtranetCertificationUrl != null && !string.IsNullOrEmpty(rmstrustedPublishingDomain.ExtranetCertificationUrl.OriginalString))
             {
                 this.extranetCertificationUrl = rmstrustedPublishingDomain.ExtranetCertificationUrl;
                 this.estimatedSize           += rmstrustedPublishingDomain.ExtranetCertificationUrl.OriginalString.Length * 2;
             }
             this.compressedSLCCertChain = rmstrustedPublishingDomain.SLCCertChain;
             this.estimatedSize         += rmstrustedPublishingDomain.SLCCertChain.Length * 2;
             this.activeCryptoMode       = PerTenantRMSTrustedPublishingDomainConfiguration.CryptoModeFromCompressedSLC(this.compressedSLCCertChain);
         }
         if (rmstrustedPublishingDomain.RMSTemplates != null && rmstrustedPublishingDomain.RMSTemplates.Count > 0)
         {
             foreach (string text in rmstrustedPublishingDomain.RMSTemplates)
             {
                 if (string.IsNullOrEmpty(text))
                 {
                     throw new DataValidationException(new PropertyValidationError(new LocalizedString("Template contains empty string for " + base.OrganizationId), RMSTrustedPublishingDomainSchema.ExtranetLicensingUrl, null));
                 }
                 this.CompressedRMSTemplates.Add(text);
                 this.estimatedSize += text.Length;
             }
         }
         PrivateKeyInformation privateKeyInformation = new PrivateKeyInformation(rmstrustedPublishingDomain.KeyId, rmstrustedPublishingDomain.KeyIdType, rmstrustedPublishingDomain.KeyContainerName, rmstrustedPublishingDomain.KeyNumber, rmstrustedPublishingDomain.CSPName, rmstrustedPublishingDomain.CSPType, rmstrustedPublishingDomain.PrivateKey, rmstrustedPublishingDomain.Default);
         this.estimatedSize += 8;
         this.estimatedSize += rmstrustedPublishingDomain.KeyId.Length * 2;
         this.estimatedSize += rmstrustedPublishingDomain.KeyIdType.Length * 2;
         this.estimatedSize += rmstrustedPublishingDomain.PrivateKey.Length * 2;
         if (!string.IsNullOrEmpty(rmstrustedPublishingDomain.CSPName))
         {
             this.estimatedSize += rmstrustedPublishingDomain.CSPName.Length * 2;
         }
         if (!string.IsNullOrEmpty(rmstrustedPublishingDomain.KeyContainerName))
         {
             this.estimatedSize += rmstrustedPublishingDomain.KeyContainerName.Length * 2;
         }
         this.privateKeys[privateKeyInformation.Identity] = privateKeyInformation;
         this.compressedTrustedDomainChains.Add(rmstrustedPublishingDomain.SLCCertChain);
         this.estimatedSize += rmstrustedPublishingDomain.SLCCertChain.Length * 2;
     }
 }
Esempio n. 4
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);
 }
Esempio n. 5
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);
        }