예제 #1
0
 public void Remove(MultiValueKey key)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     if (this.dictionary.Remove(key))
     {
         this.serializer.TryWriteToDisk(this.dictionary);
     }
 }
예제 #2
0
 private static bool TryWriteValues(MultiValueKey key, RmsLicenseStoreInfo value, out string[] values)
 {
     if (key == null || value == null)
     {
         RmsLicenseStoreInfoMap.Tracer.TraceDebug(0L, "Rms License Store Info Map failed to write values.");
         values = null;
         return(false);
     }
     values = value.ToStringArray();
     return(true);
 }
예제 #3
0
 private static bool TryReadValues(string[] values, out MultiValueKey key, out RmsLicenseStoreInfo value)
 {
     if (RmsLicenseStoreInfo.TryParse(values, out value))
     {
         key = new MultiValueKey(new object[]
         {
             value.TenantId,
             value.Url
         });
         return(true);
     }
     key = null;
     return(false);
 }
예제 #4
0
 private bool ReadFromCache(MultiValueKey key, out TenantLicensePair tenantLicenses)
 {
     if (this.cache.TryGetValue(key, out tenantLicenses) && tenantLicenses != null)
     {
         DateTime utcNow = DateTime.UtcNow;
         if (!(tenantLicenses.RacExpire < utcNow) && !(tenantLicenses.ClcExpire < utcNow))
         {
             return(true);
         }
         this.cache.Remove(key);
         tenantLicenses = null;
     }
     RmsLicenseStoreManager.Tracer.TraceDebug <MultiValueKey>(0L, "License Store Manager failed to get certs from cache for key {0}.", key);
     return(false);
 }
예제 #5
0
        public void Add(RmsLicenseStoreInfo entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }
            MultiValueKey key = new MultiValueKey(new object[]
            {
                entry.TenantId,
                entry.Url
            });

            this.dictionary.Add(key, entry);
            this.serializer.TryWriteToDisk(this.dictionary);
        }
예제 #6
0
 public bool ReadFromStore(Guid tenantId, Uri serviceLocation, Uri publishLocation, byte version, out TenantLicensePair tenantLicenses)
 {
     if (!this.ReadFromStore(tenantId, RmsLicenseStoreInfo.DefaultUri, version, out tenantLicenses))
     {
         return(false);
     }
     RmsLicenseStoreManager.Tracer.TraceDebug <Uri, Uri, int>(0L, "Verifying ServiceLocation {0}, PublishLocation {1} and Version {2}", serviceLocation, publishLocation, (int)version);
     if (tenantLicenses.HasConfigurationChanged(serviceLocation, publishLocation, version))
     {
         MultiValueKey key = new MultiValueKey(new object[]
         {
             tenantId,
             RmsLicenseStoreInfo.DefaultUri
         });
         RmsLicenseStoreManager.Tracer.TraceDebug <Guid>(0L, "Failed to match the RAC/CLC distribution point to the tenant's current configuration. Deleting the current entry. TenantId: {0}", tenantId);
         this.licenseMap.Remove(key);
         this.cache.Remove(key);
         return(false);
     }
     RmsLicenseStoreManager.Tracer.TraceDebug(0L, "Distribution points and version not changed");
     return(true);
 }
예제 #7
0
        public bool TryGet(MultiValueKey key, out RmsLicenseStoreInfo entry)
        {
            if (key == null)
            {
                entry = null;
                return(false);
            }
            if (!this.dictionary.TryGetValue(key, out entry))
            {
                return(false);
            }
            DateTime utcNow = DateTime.UtcNow;

            if (entry.RacExpire < utcNow || entry.ClcExpire < utcNow)
            {
                RmsLicenseStoreInfoMap.Tracer.TraceDebug <MultiValueKey>(0L, "Rms License Store Info Map removed expired entry for key ({0}).", key);
                this.Remove(key);
                entry = null;
                return(false);
            }
            return(true);
        }
예제 #8
0
        public bool ReadFromStore(Guid tenantId, Uri url, byte version, out TenantLicensePair tenantLicenses)
        {
            if (null == url)
            {
                throw new ArgumentNullException("url");
            }
            MultiValueKey multiValueKey = new MultiValueKey(new object[]
            {
                tenantId,
                url
            });
            RmsLicenseStoreInfo rmsLicenseStoreInfo;

            if (this.ReadFromCache(multiValueKey, out tenantLicenses))
            {
                this.licenseMap.TryGet(multiValueKey, out rmsLicenseStoreInfo);
                return(true);
            }
            if (!this.licenseMap.TryGet(multiValueKey, out rmsLicenseStoreInfo))
            {
                RmsLicenseStoreManager.Tracer.TraceDebug <MultiValueKey>(0L, "License Store Manager doesn't have entry in map for key ({0}) or certs are expired.", multiValueKey);
                return(false);
            }
            string text  = null;
            string text2 = null;

            try
            {
                text = DrmClientUtils.GetCertFromLicenseStore(rmsLicenseStoreInfo.RacFileName);
                if (!string.IsNullOrEmpty(rmsLicenseStoreInfo.ClcFileName))
                {
                    text2 = DrmClientUtils.GetCertFromLicenseStore(rmsLicenseStoreInfo.ClcFileName);
                    this.perfCounters.FileRead(2);
                }
                else
                {
                    this.perfCounters.FileRead(1);
                }
            }
            catch (IOException arg)
            {
                RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey, IOException>(0L, "License Store Manager failed to read certs from store for key ({0}). IOException - {1}.", multiValueKey, arg);
                return(false);
            }
            catch (UnauthorizedAccessException arg2)
            {
                RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey, UnauthorizedAccessException>(0L, "License Store Manager failed to read certs from store for key ({0}). UnauthorizedAccessException - {1}.", multiValueKey, arg2);
                return(false);
            }
            catch (SecurityException arg3)
            {
                RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey, SecurityException>(0L, "License Store Manager failed to read certs from store for key ({0}). SecurityException - {1}.", multiValueKey, arg3);
                return(false);
            }
            XmlNode[] rac;
            XmlNode[] array;
            if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(text2) && RMUtil.TryConvertAppendedCertsToXmlNodeArray(text, out rac) && RMUtil.TryConvertAppendedCertsToXmlNodeArray(text2, out array))
            {
                tenantLicenses = new TenantLicensePair(tenantId, rac, array[0], null, DrmClientUtils.ConvertXmlNodeArrayToCertificateChain(array), rmsLicenseStoreInfo.RacExpire, rmsLicenseStoreInfo.ClcExpire, rmsLicenseStoreInfo.Version, RmsClientManager.EnvironmentHandle, RmsClientManager.LibraryHandle);
                this.cache.TryAdd(multiValueKey, tenantLicenses);
                return(true);
            }
            if (!string.IsNullOrEmpty(text) && RMUtil.TryConvertAppendedCertsToXmlNodeArray(text, out rac) && version == rmsLicenseStoreInfo.Version)
            {
                tenantLicenses = new TenantLicensePair(tenantId, rac, null, null, null, rmsLicenseStoreInfo.RacExpire, rmsLicenseStoreInfo.ClcExpire, rmsLicenseStoreInfo.Version, RmsClientManager.EnvironmentHandle, RmsClientManager.LibraryHandle);
                this.cache.TryAdd(multiValueKey, tenantLicenses);
                return(true);
            }
            RmsLicenseStoreManager.Tracer.TraceError <MultiValueKey>(0L, "License Store Manager failed to read certs from store for key ({0}) - certs are empty or invalid.", multiValueKey);
            this.licenseMap.Remove(multiValueKey);
            return(false);
        }