/// <summary> /// Test for equality. /// </summary> public override bool Equals(object x) { if (x == null) { return(false); // Standard behavior. } if (x.GetType() != GetType()) { return(false); // Not the same type. } // Note that because of the GetType() checking above, the casting must be valid. UseLicense obj = (UseLicense)x; return(String.CompareOrdinal(_serializedUseLicense, obj._serializedUseLicense) == 0); }
/// <summary> /// This functions signs the Publish License offline, and as a result produces 2 objects. It makes an instance of the PublishLicense /// and it also builds an instance of the UseLicense, which represeents the authors UseLicense /// </summary> public PublishLicense Sign(SecureEnvironment secureEnvironment, out UseLicense authorUseLicense) { SecurityHelper.DemandRightsManagementPermission(); if (secureEnvironment == null) { throw new ArgumentNullException("secureEnvironment"); } // in case owner wasn't specified we can just assume default owner // based on the user identity that was used to build the secure environment ContentUser contentOwner; if (_owner != null) { contentOwner = _owner; } else { contentOwner = secureEnvironment.User; } using (IssuanceLicense issuanceLicense = new IssuanceLicense( DateTime.MinValue, // validFrom, - default DateTime.MaxValue, // validUntil, - default _referralInfoName, _referralInfoUri, contentOwner, null, SafeRightsManagementHandle.InvalidHandle, // boundLicenseHandle, _contentId, Grants, LocalizedNameDescriptionDictionary, ApplicationSpecificDataDictionary, _rightValidityIntervalDays, _revocationPoint)) { // The SecureEnvironment constructor makes sure ClientSession cannot be null. // Accordingly suppressing preSharp warning about having to validate ClientSession. #pragma warning suppress 6506 return(secureEnvironment.ClientSession.SignIssuanceLicense(issuanceLicense, out authorUseLicense)); } }
internal PublishLicense SignIssuanceLicense(IssuanceLicense issuanceLicense, out UseLicense authorUseLicense) { CheckDisposed(); Invariant.Assert(issuanceLicense != null); Invariant.Assert(!_envHandle.IsInvalid); using (CallbackHandler signIssuanceLicenseCallbackHandler = new CallbackHandler()) { string clientLicensorCertificate = GetClientLicensorCert(); if (clientLicensorCertificate == null) throw new RightsManagementException(SR.Get(SRID.UserHasNoClientLicensorCert)); // Trim all the leading and trailing white space characters // of the clientLicensorCertificate. clientLicensorCertificate = clientLicensorCertificate.Trim(); // Make sure the clientLicensorCertificate is valid. By trimming white spaces // above, if the certificate string is empty or contains only white spaces, it // is empty now. if (clientLicensorCertificate.Length == 0) throw new RightsManagementException(SR.Get(SRID.UserHasNoClientLicensorCert)); // Offline publishing supported no Online publishing support int hr = SafeNativeMethods.DRMGetSignedIssuanceLicense( _envHandle, issuanceLicense.Handle, (uint)(SignIssuanceLicenseFlags.Offline | SignIssuanceLicenseFlags.AutoGenerateKey | SignIssuanceLicenseFlags.OwnerLicenseNoPersist), null, 0, NativeConstants.ALGORITHMID_AES, // currently AES is the only supported key type clientLicensorCertificate, signIssuanceLicenseCallbackHandler.CallbackDelegate, null, // we are only supporting offline publishing no url needed 0); // no context required Errors.ThrowOnErrorCode(hr); signIssuanceLicenseCallbackHandler.WaitForCompletion(); // it will throw a proper exception in a failure case // build publish License from th result PublishLicense publishLicense = new PublishLicense( signIssuanceLicenseCallbackHandler.CallbackData); // After Issuance license is signed we should build the Author's Use License authorUseLicense = new UseLicense(GetOwnerLicense(issuanceLicense.Handle)); return publishLicense; } }
/// <summary> /// Save a use license for the specified user into the RM transform's instance data /// storage in the compound file. /// </summary> /// <param name="userKey"> /// The user to whom the use license was issued. /// </param> /// <param name="useLicense"> /// The use license issued to that user. /// </param> /// <remarks> /// Any existing use license for the specified user is removed from the compound /// file before the new use license is saved. /// </remarks> /// <exception cref="ArgumentNullException"> /// If <paramref name="userKey"/> or <paramref name="useLicense"/> is null. /// </exception> /// <exception cref="FileFormatException"> /// If the RM information in this file cannot be written by the current version of /// this class. /// </exception> public void SaveUseLicense(ContentUser userKey, UseLicense useLicense) { _rmet.SaveUseLicense(userKey, useLicense); }
SaveUseLicenseForUser( ContentUser user, UseLicense useLicense ) { // // Generate a unique name for the use license stream, and create the stream. // string useLicenseStreamName = MakeUseLicenseStreamName(); StreamInfo si = new StreamInfo(_useLicenseStorage, useLicenseStreamName); // This guarantees a call to Stream.Dispose, which is equivalent to Stream.Close. using (Stream licenseStream = si.Create()) { // Create a BinaryWriter on the stream. using (BinaryWriter utf8Writer = new BinaryWriter(licenseStream, Encoding.UTF8)) { // // Construct a type-prefixed user name of the form // "Passport:[....][email protected]" or "Windows:domain\username", // depending on the authentication type of the user. // string typePrefixedUserName = MakeTypePrefixedUserName(user); // // For compatibility with Office, Base64 encode the type-prefixed user name // for the sake of some minimal obfuscation. The parameters to the // UnicodeEncoding ctor mean: "UTF-16 little-endian, no byte order mark". // Then convert the Base64 characters to UTF-8 encoding. // byte [] userNameBytes = _unicodeEncoding.GetBytes(typePrefixedUserName); string base64UserName = Convert.ToBase64String(userNameBytes); byte [] utf8Bytes = Encoding.UTF8.GetBytes(base64UserName); Int32 utf8ByteLength = utf8Bytes.Length; // // Write out a header preceding the use license. The header is of the form: // Int32 headerLength // Int32 userNameLength (in bytes) // Byte userName[userNameLength] // Byte paddings Int32 headerLength = checked ( 2 * CU.Int32Size + utf8ByteLength + CU.CalculateDWordPadBytesLength(utf8ByteLength)); utf8Writer.Write(headerLength); utf8Writer.Write(utf8ByteLength); utf8Writer.Write(utf8Bytes, 0, utf8ByteLength); WriteDwordPadding(utf8ByteLength, utf8Writer); // // Write out the use license itself. // WriteByteLengthPrefixedDwordPaddedString(useLicense.ToString(), utf8Writer, Encoding.UTF8); } } }
SaveUseLicense( ContentUser user, UseLicense useLicense ) { if (user == null) { throw new ArgumentNullException("user"); } if (useLicense == null) { throw new ArgumentNullException("useLicense"); } if (user.AuthenticationType != AuthenticationType.Windows && user.AuthenticationType != AuthenticationType.Passport) { throw new ArgumentException( SR.Get(SRID.OnlyPassportOrWindowsAuthenticatedUsersAreAllowed), "user" ); } // // Delete any existing use license for this user. // EnumUseLicenseStreams( new UseLicenseStreamCallback(this.DeleteUseLicenseForUser), user ); // // Save the new use license for this user in a new stream. // SaveUseLicenseForUser(user, useLicense); }
/// <summary> /// This functions signs the Publish License offline, and as a result produces 2 objects. It makes an instance of the PublishLicense /// and it also builds an instance of the UseLicense, which represeents the authors UseLicense /// </summary> public PublishLicense Sign(SecureEnvironment secureEnvironment, out UseLicense authorUseLicense) { SecurityHelper.DemandRightsManagementPermission(); if (secureEnvironment == null) { throw new ArgumentNullException("secureEnvironment"); } // in case owner wasn't specified we can just assume default owner // based on the user identity that was used to build the secure environment ContentUser contentOwner; if (_owner != null) { contentOwner = _owner; } else { contentOwner = secureEnvironment.User; } using(IssuanceLicense issuanceLicense = new IssuanceLicense( DateTime.MinValue, // validFrom, - default DateTime.MaxValue, // validUntil, - default _referralInfoName, _referralInfoUri, contentOwner, null, SafeRightsManagementHandle.InvalidHandle, // boundLicenseHandle, _contentId, Grants, LocalizedNameDescriptionDictionary, ApplicationSpecificDataDictionary, _rightValidityIntervalDays, _revocationPoint)) { // The SecureEnvironment constructor makes sure ClientSession cannot be null. // Accordingly suppressing preSharp warning about having to validate ClientSession. #pragma warning suppress 6506 return secureEnvironment.ClientSession.SignIssuanceLicense(issuanceLicense, out authorUseLicense); } }
public void SaveUseLicense(ContentUser userKey, UseLicense useLicense) { throw new NotImplementedException (); }
public PublishLicense Sign(SecureEnvironment secureEnvironment, out UseLicense authorUseLicense) { throw new NotImplementedException(); }
public PublishLicense Sign (SecureEnvironment secureEnvironment, out UseLicense authorUseLicense) { throw new NotImplementedException (); }