Microsoft Information Protection SDK - C++ 1.17
API Reference Documentation for C++
Loading...
Searching...
No Matches
protection_handler.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) Microsoft Corporation.
4 * All rights reserved.
5 *
6 * This code is licensed under the MIT License.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files(the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions :
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 *
26 */
33#ifndef API_MIP_PROTECTION_PROTECTION_HANDLER_H_
34#define API_MIP_PROTECTION_PROTECTION_HANDLER_H_
35
36#include <chrono>
37#include <map>
38#include <memory>
39#include <string>
40#include <vector>
41
42#include "mip/common_types.h"
43#include "mip/mip_export.h"
44#include "mip/mip_namespace.h"
49#include "mip/stream.h"
50#include "mip/user_rights.h"
51#include "mip/user_roles.h"
52
53MIP_NAMESPACE_BEGIN
54
55class CryptoProvider;
56
61public:
67 class Observer {
68 public:
83 const std::shared_ptr<ProtectionHandler>& protectionHandler,
84 const std::shared_ptr<void>& context) { UNUSED(protectionHandler); UNUSED(context); };
85
100 const std::exception_ptr& error,
101 const std::shared_ptr<void>& context) { UNUSED(error); UNUSED(context); }
102
104 virtual ~Observer() { }
106 };
107
112 public:
118 ConsumptionSettings(const std::vector<uint8_t>& serializedPublishingLicense)
119 : mLicenseInfo(std::make_shared<PublishingLicenseInfo>(serializedPublishingLicense)) {}
120
128 const std::vector<uint8_t>& serializedPreLicense,
129 const std::vector<uint8_t>& serializedPublishingLicense)
130 : mLicenseInfo(std::make_shared<PublishingLicenseInfo>(serializedPreLicense, serializedPublishingLicense)) {}
131
140 ConsumptionSettings(const std::shared_ptr<PublishingLicenseInfo>& licenseInfo)
141 : mLicenseInfo(licenseInfo) {}
142
148 std::shared_ptr<PublishingLicenseInfo> GetPublishingLicenseInfo() const {
149 return mLicenseInfo;
150 }
151
159 void SetDelegatedUserEmail(const std::string& delegatedUserEmail) { mDelegatedUserEmail = delegatedUserEmail; }
160
168 const std::string& GetDelegatedUserEmail() const { return mDelegatedUserEmail; }
169
177 void SetContentName(const std::string& contentName) { mContentName = contentName;}
178
184 const std::string& GetContentName() const { return mContentName; }
185
194 MIP_API void AddRmsCapability(const std::string& capability);
195
204 MIP_API bool RemoveRmsCapability(const std::string& capability);
205
211 const std::shared_ptr<std::vector<std::string>> GetRmsCapabilities() const {
212 if (mCapabilities == nullptr) { return mCapabilities; }
213 return std::make_shared<std::vector<std::string>>(*mCapabilities);
214 }
215
217 private:
218 std::shared_ptr<PublishingLicenseInfo> mLicenseInfo;
219 std::string mDelegatedUserEmail;
220 std::string mContentName;
221 std::shared_ptr<std::vector<std::string>> mCapabilities;
223 };
224
229 public:
235 PublishingSettings(const std::shared_ptr<ProtectionDescriptor>& protectionDescriptor)
236 : mProtectionDescriptor(protectionDescriptor),
237 mIsAuditedExtractionAllowed(false),
238 mIsDeprecatedAlgorithmPreferred(false),
239 mIsPublishingFormatJson(false),
240 mRepairLabelIdAllowed(false),
241 mRegenerateContentKey(false) {}
242
250 const std::shared_ptr<ProtectionDescriptor>& protectionDescriptor,
251 const std::vector<uint8_t>& serializedPublishingLicense)
252 : mProtectionDescriptor(protectionDescriptor),
253 mRepublishingLicense(serializedPublishingLicense),
254 mIsAuditedExtractionAllowed(false),
255 mIsDeprecatedAlgorithmPreferred(false),
256 mIsPublishingFormatJson(false),
257 mRepairLabelIdAllowed(false),
258 mRegenerateContentKey(false) {}
259
267 const std::shared_ptr<ProtectionDescriptor>& protectionDescriptor,
268 const std::shared_ptr<ProtectionHandler>& protectionHandler)
269 : mProtectionDescriptor(protectionDescriptor),
270 mProtectionHandler(protectionHandler),
271 mIsAuditedExtractionAllowed(false),
272 mIsDeprecatedAlgorithmPreferred(false),
273 mIsPublishingFormatJson(false),
274 mRepairLabelIdAllowed(false),
275 mRegenerateContentKey(false) {}
276
277 std::shared_ptr<ProtectionDescriptor> GetProtectionDescriptor() const { return mProtectionDescriptor; }
278
282 std::shared_ptr<ProtectionHandler> GetProtectionHandlerForRepublish() const { return mProtectionHandler; }
283
289 bool GetIsAuditedExtractionAllowed() const { return mIsAuditedExtractionAllowed; }
290
296 void SetIsAuditedExtractionAllowed(bool isAuditedExtractionAllowed) {
297 mIsAuditedExtractionAllowed = isAuditedExtractionAllowed;
298 }
299
305 bool GetIsDeprecatedAlgorithmPreferred() const { return mIsDeprecatedAlgorithmPreferred; }
306
312 void SetIsDeprecatedAlgorithmPreferred(bool isDeprecatedAlgorithmPreferred) {
313 mIsDeprecatedAlgorithmPreferred = isDeprecatedAlgorithmPreferred;
314 }
315
323 void SetDelegatedUserEmail(const std::string& delegatedUserEmail) { mDelegatedUserEmail = delegatedUserEmail; }
324
332 const std::string& GetDelegatedUserEmail() const { return mDelegatedUserEmail; }
333
340 bool IsPublishingFormatJson() const { return mIsPublishingFormatJson; }
341
347 void SetPublishingFormatJson(bool isPublishingFormatJson) {
348 mIsPublishingFormatJson = isPublishingFormatJson;
349 }
350
356 bool GetRegenerateContentKey() const { return mRegenerateContentKey; }
357
363 void SetRegenerateContentKey(bool regenerateContentKey) {
364 mRegenerateContentKey = regenerateContentKey;
365 }
366
374#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
375 [[deprecated("SetPreLicenseUserEmail is deprecated, use SetRequestPreLicense")]]
376#endif
377 void SetPreLicenseUserEmail(const std::string& preLicenseUserEmail) {
378 if(mPublishingUseLicenseRequest == nullptr) {
380 }
381 mPublishingUseLicenseRequest->SetDelegatedUserEmail(preLicenseUserEmail);
382 }
383
389#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
390 [[deprecated("GetPreLicenseUserEmail is deprecated, use GetPreLicenseRequest")]]
391#endif
392 const std::string& GetPreLicenseUserEmail() const {
393 static std::string empty;
394 return mPublishingUseLicenseRequest != nullptr ? mPublishingUseLicenseRequest->GetDelegatedUserEmail() : empty; }
395
401 const std::vector<uint8_t>& GetPublishingLicenseForRepublish() const {
402 return mRepublishingLicense;
403 }
404
412 void SetRequestPreLicense(std::shared_ptr<PublishingUseLicenseRequest> publishingUseLicenseRequest) {
413 mPublishingUseLicenseRequest = publishingUseLicenseRequest;
414 }
415
421 std::shared_ptr<PublishingUseLicenseRequest> GetPreLicenseRequest() const {
422 return mPublishingUseLicenseRequest;
423 }
424
432 bool GetRepairLabelIdAllowed() const { return mRepairLabelIdAllowed; }
433
442 void SetRepairLabelIdAllowed(bool repairAllowed) {
443 mRepairLabelIdAllowed = repairAllowed;
444 }
445
447 private:
448 std::shared_ptr<ProtectionDescriptor> mProtectionDescriptor;
449 std::vector<uint8_t> mRepublishingLicense;
450 std::shared_ptr<ProtectionHandler> mProtectionHandler;
451 bool mIsAuditedExtractionAllowed;
452 bool mIsDeprecatedAlgorithmPreferred;
453 bool mIsPublishingFormatJson;
454 bool mRepairLabelIdAllowed;
455 bool mRegenerateContentKey;
456 std::string mDelegatedUserEmail;
457 std::shared_ptr<PublishingUseLicenseRequest> mPublishingUseLicenseRequest;
459 };
460
464 enum class PreLicenseFormat {
465 Xml,
466 Json,
467 };
468
478 virtual std::shared_ptr<Stream> CreateProtectedStream(
479 const std::shared_ptr<Stream>& backingStream,
480 int64_t contentStartPosition,
481 int64_t contentSize) = 0;
482
495 virtual int64_t EncryptBuffer(
496 int64_t offsetFromStart,
497 const uint8_t* inputBuffer,
498 int64_t inputBufferSize,
499 uint8_t* outputBuffer,
500 int64_t outputBufferSize,
501 bool isFinal) = 0;
502
515 virtual int64_t DecryptBuffer(
516 int64_t offsetFromStart,
517 const uint8_t* inputBuffer,
518 int64_t inputBufferSize,
519 uint8_t* outputBuffer,
520 int64_t outputBufferSize,
521 bool isFinal) = 0;
522
533 virtual int64_t GetProtectedContentLength(int64_t unprotectedLength, bool includesFinalBlock) = 0;
534
540 virtual int64_t GetBlockSize() = 0;
541
547 virtual std::vector<std::string> GetRights() const = 0;
548
556 virtual bool AccessCheck(const std::string& right) const = 0;
557
563 virtual const std::string GetIssuedTo() = 0;
564
570 virtual const std::string GetOwner() = 0;
571
577 virtual bool IsIssuedToOwner() = 0;
578
584 virtual std::shared_ptr<ProtectionDescriptor> GetProtectionDescriptor() = 0;
585
594 virtual const std::string GetContentId() = 0;
595
601 virtual bool DoesUseDeprecatedAlgorithms() = 0;
602
609
615 virtual bool IsAuditedExtractAllowed() = 0;
616
622 virtual const std::vector<uint8_t>& GetSerializedPublishingLicense() const = 0;
623
635 virtual const std::vector<uint8_t>& GetSerializedPreLicense(PreLicenseFormat format) const = 0;
636
642 virtual CipherMode GetCipherMode() const = 0;
643
645 virtual const std::shared_ptr<CryptoProvider> GetCryptoProvider() = 0;
646 virtual const std::shared_ptr<CryptoProvider>& GetPolicyCryptoProvider() const = 0;
647 virtual ~ProtectionHandler() {}
648
650};
651
652MIP_NAMESPACE_END
653#endif // API_MIP_PROTECTION_PROTECTION_HANDLER_H_
Settings to use for protection operations.
Definition protection_common_settings.h:46
Settings used to create a ProtectionHandler to consume existing content.
Definition protection_handler.h:111
MIP_API bool RemoveRmsCapability(const std::string &capability)
Remove one of the added usage rights capabilities which get passed to RMS.
ConsumptionSettings(const std::shared_ptr< PublishingLicenseInfo > &licenseInfo)
ProtectionHandler::ConsumptionSettings constructor for creating a new handler.
Definition protection_handler.h:140
void SetContentName(const std::string &contentName)
Defines the content name to register with document tracking.
Definition protection_handler.h:177
ConsumptionSettings(const std::vector< uint8_t > &serializedPublishingLicense)
ProtectionHandler::ConsumptionSettings constructor for creating a new handler.
Definition protection_handler.h:118
const std::string & GetContentName() const
Gets the content name to register with document tracking.
Definition protection_handler.h:184
const std::string & GetDelegatedUserEmail() const
Gets the delegated user.
Definition protection_handler.h:168
ConsumptionSettings(const std::vector< uint8_t > &serializedPreLicense, const std::vector< uint8_t > &serializedPublishingLicense)
ProtectionHandler::ConsumptionSettings constructor for creating a new handler.
Definition protection_handler.h:127
std::shared_ptr< PublishingLicenseInfo > GetPublishingLicenseInfo() const
Get the publishing license associated with the protected content.
Definition protection_handler.h:148
const std::shared_ptr< std::vector< std::string > > GetRmsCapabilities() const
The the full set of client capabilities supported when fetching usage rights from RMS.
Definition protection_handler.h:211
void SetDelegatedUserEmail(const std::string &delegatedUserEmail)
Sets the delegated user.
Definition protection_handler.h:159
MIP_API void AddRmsCapability(const std::string &capability)
Add a capability which will be passed along to RMS when fetching usage rights.
Interface that receives notifications related to ProtectionHandler.
Definition protection_handler.h:67
virtual void OnCreateProtectionHandlerFailure(const std::exception_ptr &error, const std::shared_ptr< void > &context)
Called when ProtectionHandler creation failed.
Definition protection_handler.h:99
virtual void OnCreateProtectionHandlerSuccess(const std::shared_ptr< ProtectionHandler > &protectionHandler, const std::shared_ptr< void > &context)
Called when ProtectionHandler was created successfully.
Definition protection_handler.h:82
Settings used to create a ProtectionHandler to protect new content.
Definition protection_handler.h:228
bool GetIsDeprecatedAlgorithmPreferred() const
Gets whether or not deprecated crypto algorithm (ECB) is preferred for backwards compatibility.
Definition protection_handler.h:305
void SetRequestPreLicense(std::shared_ptr< PublishingUseLicenseRequest > publishingUseLicenseRequest)
Setting this will cause the publishing request to include a pre-license.
Definition protection_handler.h:412
const std::string & GetPreLicenseUserEmail() const
Gets the pre-license user.
Definition protection_handler.h:392
std::shared_ptr< ProtectionDescriptor > GetProtectionDescriptor() const
Definition protection_handler.h:277
bool GetRegenerateContentKey() const
Gets whether or not the content key and ID should be regenerated during republishing.
Definition protection_handler.h:356
void SetRepairLabelIdAllowed(bool repairAllowed)
Sets whether or not label id can be added to publishing license on republish.
Definition protection_handler.h:442
const std::string & GetDelegatedUserEmail() const
Gets the delegated user.
Definition protection_handler.h:332
const std::vector< uint8_t > & GetPublishingLicenseForRepublish() const
Gets the serialized republishing license.
Definition protection_handler.h:401
bool GetRepairLabelIdAllowed() const
Gets whether or not label id can be added to publishing license on republish.
Definition protection_handler.h:432
void SetPublishingFormatJson(bool isPublishingFormatJson)
Sets whether or not the returned pl is in json format (xml format is more widely accepted and is the ...
Definition protection_handler.h:347
PublishingSettings(const std::shared_ptr< ProtectionDescriptor > &protectionDescriptor)
PublishingSettings constructor for enforcing protection on content.
Definition protection_handler.h:235
PublishingSettings(const std::shared_ptr< ProtectionDescriptor > &protectionDescriptor, const std::vector< uint8_t > &serializedPublishingLicense)
PublishingSettings constructor for online republishing.
Definition protection_handler.h:249
void SetIsAuditedExtractionAllowed(bool isAuditedExtractionAllowed)
Sets whether or not non-MIP-aware applications are allowed to open protected content.
Definition protection_handler.h:296
void SetIsDeprecatedAlgorithmPreferred(bool isDeprecatedAlgorithmPreferred)
Sets whether or not deprecated crypto algorithm (ECB) is preferred for backwards compatibility.
Definition protection_handler.h:312
std::shared_ptr< PublishingUseLicenseRequest > GetPreLicenseRequest() const
Gets the pre-license request.
Definition protection_handler.h:421
bool GetIsAuditedExtractionAllowed() const
Gets whether or not non-MIP-aware applications are allowed to open protected content.
Definition protection_handler.h:289
void SetDelegatedUserEmail(const std::string &delegatedUserEmail)
Sets the delegated user.
Definition protection_handler.h:323
void SetRegenerateContentKey(bool regenerateContentKey)
Sets whether or not the content key and ID should be regenerated during republishing.
Definition protection_handler.h:363
bool IsPublishingFormatJson() const
Gets whether or not the returned pl is in json format (xml format is more widely accepted and is the ...
Definition protection_handler.h:340
PublishingSettings(const std::shared_ptr< ProtectionDescriptor > &protectionDescriptor, const std::shared_ptr< ProtectionHandler > &protectionHandler)
PublishingSettings constructor for offline republishing.
Definition protection_handler.h:266
std::shared_ptr< ProtectionHandler > GetProtectionHandlerForRepublish() const
Gets protection handler for republishing scenario.
Definition protection_handler.h:282
void SetPreLicenseUserEmail(const std::string &preLicenseUserEmail)
Sets pre-license user.
Definition protection_handler.h:377
Manages protection-related actions for a specific protection configuration.
Definition protection_handler.h:60
virtual const std::string GetContentId()=0
Gets unique identifier for the document/content.
virtual bool IsAuditedExtractAllowed()=0
Gets if protection handler grants user 'audited extract' right or not.
virtual bool IsIssuedToOwner()=0
Gets if the current user is the content owner or not.
virtual int64_t DecryptBuffer(int64_t offsetFromStart, const uint8_t *inputBuffer, int64_t inputBufferSize, uint8_t *outputBuffer, int64_t outputBufferSize, bool isFinal)=0
Decrypt a buffer.
virtual const std::vector< uint8_t > & GetSerializedPublishingLicense() const =0
Serialize ProtectionHandler into a publishing license (PL)
virtual int64_t GetProtectedContentLength(int64_t unprotectedLength, bool includesFinalBlock)=0
Calculates size (in bytes) of content if it were to be encrypted with this ProtectionHandler.
virtual bool UsesApplicationDefinedPadding()=0
Gets if protected content requires application-defined padding or if it is handled internally.
virtual std::shared_ptr< ProtectionDescriptor > GetProtectionDescriptor()=0
Gets protection details.
virtual std::shared_ptr< Stream > CreateProtectedStream(const std::shared_ptr< Stream > &backingStream, int64_t contentStartPosition, int64_t contentSize)=0
Create a protected stream that will allow for encryption/decryption of content.
virtual const std::string GetIssuedTo()=0
Gets user associated with the protection handler.
virtual const std::string GetOwner()=0
Gets email address of content owner.
virtual CipherMode GetCipherMode() const =0
Gets the cipher mode of the protection handler.
virtual const std::vector< uint8_t > & GetSerializedPreLicense(PreLicenseFormat format) const =0
Get pre-license.
virtual std::vector< std::string > GetRights() const =0
Gets the rights granted to the user/identity associated with this ProtectionHandler.
virtual bool DoesUseDeprecatedAlgorithms()=0
Gets if protection handler uses deprecated crypto algorithms (ECB) for backward compatibility or not.
PreLicenseFormat
Pre-license format.
Definition protection_handler.h:464
virtual int64_t EncryptBuffer(int64_t offsetFromStart, const uint8_t *inputBuffer, int64_t inputBufferSize, uint8_t *outputBuffer, int64_t outputBufferSize, bool isFinal)=0
Encrypt a buffer.
virtual bool AccessCheck(const std::string &right) const =0
Checks if protection handler grants user access to the specified right.
virtual int64_t GetBlockSize()=0
Gets the block size (in bytes) for the cipher mode used by this ProtectionHandler.
Holds the details of a Publishing License used to create a protection handler.
Definition protection_common_types.h:53
static MIP_API std::shared_ptr< PublishingUseLicenseRequest > __CDECL CreatePublishingUseLicenseRequest()
Creates a PublishingUseLicenseRequest object.
A file Containing the common types used by the upe, file and protection modules.
A file export/import macros.
MIP namespace macros.
Defines ProtectionCommonSettings interface.
A file containing the common types used by the protection module.
CipherMode
Cipher mode identifier.
Definition protection_common_types.h:149
Defines ProtectionDescriptor interface.
Defines the PublishingUseLicenseRequest interface.
A file containing the Stream interface/class definition.
Defines UserRights class.
Defines UserRoles class.