예제 #1
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;
        }
        private SafeRightsManagementPubHandle GetHandleFromUser(ContentUser user)
        {
            SafeRightsManagementPubHandle userHandle = null;
            int hr;

            // We need to create Internal Authnetication type Users differently 
            if (user.GenericEquals(ContentUser.AnyoneUser) || user.GenericEquals(ContentUser.OwnerUser))
            {
                // Anyone user 
                hr = SafeNativeMethods.DRMCreateUser(
                    user.Name, // This is an optional UI Name (some applications use this and do not work well when it is missing)
                    user.Name, // that would be string Anyone or Owner 
                    ConvertAuthenticationTypeToString(user),   // this would be internal  
                    out userHandle);
            }
            else
            {
                // Windws Passport or WindowsPassport authentication type user 
                hr = SafeNativeMethods.DRMCreateUser(
                    user.Name,
                    null,
                    ConvertAuthenticationTypeToString(user),
                    out userHandle);
            }

            Errors.ThrowOnErrorCode(hr);
            Debug.Assert((userHandle != null) && (!userHandle.IsInvalid));

            _pubHandlesList.Add(userHandle);
            return userHandle;
        }