示例#1
0
        internal string EnumerateLicense(EnumerateLicenseFlags enumerateLicenseFlags, int index)
        {
            CheckDisposed();

            return GetLicenseOnSession(_hSession, enumerateLicenseFlags, index);
        }
示例#2
0
        internal static string GetLicenseOnSession(SafeRightsManagementSessionHandle sessionHandle, EnumerateLicenseFlags enumerateLicenseFlags, int index)
        {
            Invariant.Assert(index >= 0);

            if ((enumerateLicenseFlags != EnumerateLicenseFlags.Machine) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.GroupIdentity) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.GroupIdentityName) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.GroupIdentityLid) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.SpecifiedGroupIdentity) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.Eul) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.EulLid) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.ClientLicensor) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.ClientLicensorLid) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.SpecifiedClientLicensor) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.RevocationList) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.RevocationListLid) &&
                (enumerateLicenseFlags != EnumerateLicenseFlags.Expired))
            {
                throw new ArgumentOutOfRangeException("enumerateLicenseFlags");
            }

            int hr = 0;
            bool sharedFlag = false;
            uint dataLen = 0;
            StringBuilder license = null;

            hr = SafeNativeMethods.DRMEnumerateLicense(
                sessionHandle, (uint)enumerateLicenseFlags, (uint)index, ref sharedFlag, ref dataLen, null);

            if (hr == (int)RightsManagementFailureCode.NoMoreData)
                return null;

            Errors.ThrowOnErrorCode(hr);

            if (dataLen > System.Int32.MaxValue)
                return null;

            //returned size accounts for null termination; we do not need to add 1 
            checked
            {
                license = new StringBuilder((int)dataLen);
            }

            hr = SafeNativeMethods.DRMEnumerateLicense(
                sessionHandle, (uint)enumerateLicenseFlags, (uint)index, ref sharedFlag, ref dataLen, license);

            Errors.ThrowOnErrorCode(hr);

            return license.ToString();
        }
示例#3
0
        private static ArrayList EnumerateAllValuesOnSession(SafeRightsManagementSessionHandle sessionHandle, EnumerateLicenseFlags enumerateLicenseFlags)
        {
            ArrayList result = new ArrayList(5);
            int index = 0;

            while (true)
            {
                string currentRes = GetLicenseOnSession(sessionHandle, enumerateLicenseFlags, index);

                if (currentRes == null)
                {
                    break;
                }
                result.Add(currentRes);
                index++;
            }
            return result;
        }
示例#4
0
        private string GetLatestCertificate(EnumerateLicenseFlags enumerateLicenseFlags)
        {
            int index = 0;

            string currentCert = EnumerateLicense(enumerateLicenseFlags, index);
            if (currentCert == null)
            {
                return null;
            }

            DateTime currentTimeStamp = ExtractIssuedTimeFromCertificateChain(currentCert, DateTime.MinValue);

            while (currentCert != null)
            {
                index++;

                string newCert = EnumerateLicense(enumerateLicenseFlags, index);

                // if we have completed the enumeration we can stop right here
                if (newCert == null)
                {
                    break;
                }

                DateTime newTimeStamp = ExtractIssuedTimeFromCertificateChain(newCert, DateTime.MinValue);

                if (DateTime.Compare(currentTimeStamp, newTimeStamp) < 0)
                {
                    currentCert = newCert;
                    currentTimeStamp = newTimeStamp;
                }
            }

            return currentCert;
        }
示例#5
0
        internal void RemoveUsersCertificates(EnumerateLicenseFlags certificateType)
        {
            CheckDisposed();

            // We only expect to be called for removal of the specific Group Identity Certs
            // and the specific Client Licensor Certs  
            Invariant.Assert((certificateType == EnumerateLicenseFlags.SpecifiedClientLicensor) ||
                                  (certificateType == EnumerateLicenseFlags.SpecifiedGroupIdentity));

            // We actually need to enumerate all the specified identity certs and then parse
            // them to get the license Id , and only then remove them 
            ArrayList certList = EnumerateAllValuesOnSession(_hSession, certificateType);

            foreach (string cert in certList)
            {
                DeleteLicense(ExtractCertificateIdFromCertificateChain(cert));
            }
        }
示例#6
0
        /// <summary>
        ///  This function is used to build a List of certificates of a given type (Licensor or Identity) 
        ///  From all of the certificates based on the matching of the User Id 
        /// </summary>
        internal List<string> EnumerateUsersCertificateIds(
                                                                                ContentUser user,
                                                                                EnumerateLicenseFlags certificateType)
        {
            CheckDisposed();

            if ((certificateType != EnumerateLicenseFlags.Machine) &&
                                    (certificateType != EnumerateLicenseFlags.GroupIdentity) &&
                                    (certificateType != EnumerateLicenseFlags.GroupIdentityName) &&
                                    (certificateType != EnumerateLicenseFlags.GroupIdentityLid) &&
                                    (certificateType != EnumerateLicenseFlags.SpecifiedGroupIdentity) &&
                                    (certificateType != EnumerateLicenseFlags.Eul) &&
                                    (certificateType != EnumerateLicenseFlags.EulLid) &&
                                    (certificateType != EnumerateLicenseFlags.ClientLicensor) &&
                                    (certificateType != EnumerateLicenseFlags.ClientLicensorLid) &&
                                    (certificateType != EnumerateLicenseFlags.SpecifiedClientLicensor) &&
                                    (certificateType != EnumerateLicenseFlags.RevocationList) &&
                                    (certificateType != EnumerateLicenseFlags.RevocationListLid) &&
                                    (certificateType != EnumerateLicenseFlags.Expired))
            {
                throw new ArgumentOutOfRangeException("certificateType");
            }

            List<string> certificateIdList = new List<string>();

            int index = 0;
            // first enumerate certificates and find the ones that match given user 
            while (true)
            {
                // we get a string which can be parsed to get the ID and type 
                string currentUserCertificate = EnumerateLicense(certificateType, index);

                if (currentUserCertificate == null)
                    break;

                // we need to parse the information out of the string 
                ContentUser currentUser = ExtractUserFromCertificateChain(currentUserCertificate);

                // let's see if we have a match on the User Id, if we do we need to add it to the list 
                if (user.GenericEquals(currentUser))
                {
                    // we got a match let's preserve the certificate in the list 
                    certificateIdList.Add(ClientSession.ExtractCertificateIdFromCertificateChain(currentUserCertificate));
                }

                index++;
            }

            return certificateIdList;
        }