Microsoft Information Protection SDK - C++ 1.18
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 mShouldRefreshTemplates(false) {}
243
251 const std::shared_ptr<ProtectionDescriptor>& protectionDescriptor,
252 const std::vector<uint8_t>& serializedPublishingLicense)
253 : mProtectionDescriptor(protectionDescriptor),
254 mRepublishingLicense(serializedPublishingLicense),
255 mIsAuditedExtractionAllowed(false),
256 mIsDeprecatedAlgorithmPreferred(false),
257 mIsPublishingFormatJson(false),
258 mRepairLabelIdAllowed(false),
259 mRegenerateContentKey(false),
260 mShouldRefreshTemplates(false) {}
261
269 const std::shared_ptr<ProtectionDescriptor>& protectionDescriptor,
270 const std::shared_ptr<ProtectionHandler>& protectionHandler)
271 : mProtectionDescriptor(protectionDescriptor),
272 mProtectionHandler(protectionHandler),
273 mIsAuditedExtractionAllowed(false),
274 mIsDeprecatedAlgorithmPreferred(false),
275 mIsPublishingFormatJson(false),
276 mRepairLabelIdAllowed(false),
277 mRegenerateContentKey(false),
278 mShouldRefreshTemplates(false) {}
279
280 std::shared_ptr<ProtectionDescriptor> GetProtectionDescriptor() const { return mProtectionDescriptor; }
281
285 std::shared_ptr<ProtectionHandler> GetProtectionHandlerForRepublish() const { return mProtectionHandler; }
286
292 bool GetIsAuditedExtractionAllowed() const { return mIsAuditedExtractionAllowed; }
293
299 void SetIsAuditedExtractionAllowed(bool isAuditedExtractionAllowed) {
300 mIsAuditedExtractionAllowed = isAuditedExtractionAllowed;
301 }
302
308 bool GetIsDeprecatedAlgorithmPreferred() const { return mIsDeprecatedAlgorithmPreferred; }
309
315 void SetIsDeprecatedAlgorithmPreferred(bool isDeprecatedAlgorithmPreferred) {
316 mIsDeprecatedAlgorithmPreferred = isDeprecatedAlgorithmPreferred;
317 }
318
326 void SetDelegatedUserEmail(const std::string& delegatedUserEmail) { mDelegatedUserEmail = delegatedUserEmail; }
327
335 const std::string& GetDelegatedUserEmail() const { return mDelegatedUserEmail; }
336
343 bool IsPublishingFormatJson() const { return mIsPublishingFormatJson; }
344
350 void SetPublishingFormatJson(bool isPublishingFormatJson) {
351 mIsPublishingFormatJson = isPublishingFormatJson;
352 }
353
359 bool GetRegenerateContentKey() const { return mRegenerateContentKey; }
360
366 void SetRegenerateContentKey(bool regenerateContentKey) {
367 mRegenerateContentKey = regenerateContentKey;
368 }
369
377#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
378 [[deprecated("SetPreLicenseUserEmail is deprecated, use SetRequestPreLicense")]]
379#endif
380 void SetPreLicenseUserEmail(const std::string& preLicenseUserEmail) {
381 if(mPublishingUseLicenseRequest == nullptr) {
383 }
384 mPublishingUseLicenseRequest->SetDelegatedUserEmail(preLicenseUserEmail);
385 }
386
392#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
393 [[deprecated("GetPreLicenseUserEmail is deprecated, use GetPreLicenseRequest")]]
394#endif
395 const std::string& GetPreLicenseUserEmail() const {
396 static std::string empty;
397 return mPublishingUseLicenseRequest != nullptr ? mPublishingUseLicenseRequest->GetDelegatedUserEmail() : empty; }
398
404 const std::vector<uint8_t>& GetPublishingLicenseForRepublish() const {
405 return mRepublishingLicense;
406 }
407
415 void SetRequestPreLicense(std::shared_ptr<PublishingUseLicenseRequest> publishingUseLicenseRequest) {
416 mPublishingUseLicenseRequest = publishingUseLicenseRequest;
417 }
418
424 std::shared_ptr<PublishingUseLicenseRequest> GetPreLicenseRequest() const {
425 return mPublishingUseLicenseRequest;
426 }
427
435 bool GetRepairLabelIdAllowed() const { return mRepairLabelIdAllowed; }
436
445 void SetRepairLabelIdAllowed(bool repairAllowed) {
446 mRepairLabelIdAllowed = repairAllowed;
447 }
448
455 return mShouldRefreshTemplates;
456 }
457
463 void SetShouldRefreshTemplates(bool shouldRefreshTemplates) {
464 mShouldRefreshTemplates = shouldRefreshTemplates;
465 }
466
468 private:
469 std::shared_ptr<ProtectionDescriptor> mProtectionDescriptor;
470 std::vector<uint8_t> mRepublishingLicense;
471 std::shared_ptr<ProtectionHandler> mProtectionHandler;
472 bool mIsAuditedExtractionAllowed;
473 bool mIsDeprecatedAlgorithmPreferred;
474 bool mIsPublishingFormatJson;
475 bool mRepairLabelIdAllowed;
476 bool mRegenerateContentKey;
477 bool mShouldRefreshTemplates;
478 std::string mDelegatedUserEmail;
479 std::shared_ptr<PublishingUseLicenseRequest> mPublishingUseLicenseRequest;
481 };
482
486 enum class PreLicenseFormat {
487 Xml,
488 Json,
489 };
490
500 virtual std::shared_ptr<Stream> CreateProtectedStream(
501 const std::shared_ptr<Stream>& backingStream,
502 int64_t contentStartPosition,
503 int64_t contentSize) = 0;
504
517 virtual int64_t EncryptBuffer(
518 int64_t offsetFromStart,
519 const uint8_t* inputBuffer,
520 int64_t inputBufferSize,
521 uint8_t* outputBuffer,
522 int64_t outputBufferSize,
523 bool isFinal) = 0;
524
537 virtual int64_t DecryptBuffer(
538 int64_t offsetFromStart,
539 const uint8_t* inputBuffer,
540 int64_t inputBufferSize,
541 uint8_t* outputBuffer,
542 int64_t outputBufferSize,
543 bool isFinal) = 0;
544
555 virtual int64_t GetProtectedContentLength(int64_t unprotectedLength, bool includesFinalBlock) = 0;
556
562 virtual int64_t GetBlockSize() = 0;
563
569 virtual std::vector<std::string> GetRights() const = 0;
570
578 virtual bool AccessCheck(const std::string& right) const = 0;
579
585 virtual const std::string GetIssuedTo() = 0;
586
592 virtual const std::string GetOwner() = 0;
593
599 virtual bool IsIssuedToOwner() = 0;
600
606 virtual std::shared_ptr<ProtectionDescriptor> GetProtectionDescriptor() = 0;
607
616 virtual const std::string GetContentId() = 0;
617
623 virtual bool DoesUseDeprecatedAlgorithms() = 0;
624
631
637 virtual bool IsAuditedExtractAllowed() = 0;
638
644 virtual const std::vector<uint8_t>& GetSerializedPublishingLicense() const = 0;
645
657 virtual const std::vector<uint8_t>& GetSerializedPreLicense(PreLicenseFormat format) const = 0;
658
664 virtual CipherMode GetCipherMode() const = 0;
665
667 virtual const std::shared_ptr<CryptoProvider> GetCryptoProvider() = 0;
668 virtual const std::shared_ptr<CryptoProvider>& GetPolicyCryptoProvider() const = 0;
669 virtual ~ProtectionHandler() {}
670
672};
673
674MIP_NAMESPACE_END
675#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:308
void SetRequestPreLicense(std::shared_ptr< PublishingUseLicenseRequest > publishingUseLicenseRequest)
Setting this will cause the publishing request to include a pre-license.
Definition protection_handler.h:415
const std::string & GetPreLicenseUserEmail() const
Gets the pre-license user.
Definition protection_handler.h:395
std::shared_ptr< ProtectionDescriptor > GetProtectionDescriptor() const
Definition protection_handler.h:280
bool GetRegenerateContentKey() const
Gets whether or not the content key and ID should be regenerated during republishing.
Definition protection_handler.h:359
void SetRepairLabelIdAllowed(bool repairAllowed)
Sets whether or not label id can be added to publishing license on republish.
Definition protection_handler.h:445
const std::string & GetDelegatedUserEmail() const
Gets the delegated user.
Definition protection_handler.h:335
const std::vector< uint8_t > & GetPublishingLicenseForRepublish() const
Gets the serialized republishing license.
Definition protection_handler.h:404
bool GetRepairLabelIdAllowed() const
Gets whether or not label id can be added to publishing license on republish.
Definition protection_handler.h:435
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:350
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:250
void SetIsAuditedExtractionAllowed(bool isAuditedExtractionAllowed)
Sets whether or not non-MIP-aware applications are allowed to open protected content.
Definition protection_handler.h:299
bool GetShouldRefreshTemplates() const
Gets whether or not templates should be forcibly refreshed during offline publishing.
Definition protection_handler.h:454
void SetShouldRefreshTemplates(bool shouldRefreshTemplates)
Sets whether or not templates should be forcibly refreshed during offline publishing.
Definition protection_handler.h:463
void SetIsDeprecatedAlgorithmPreferred(bool isDeprecatedAlgorithmPreferred)
Sets whether or not deprecated crypto algorithm (ECB) is preferred for backwards compatibility.
Definition protection_handler.h:315
std::shared_ptr< PublishingUseLicenseRequest > GetPreLicenseRequest() const
Gets the pre-license request.
Definition protection_handler.h:424
bool GetIsAuditedExtractionAllowed() const
Gets whether or not non-MIP-aware applications are allowed to open protected content.
Definition protection_handler.h:292
void SetDelegatedUserEmail(const std::string &delegatedUserEmail)
Sets the delegated user.
Definition protection_handler.h:326
void SetRegenerateContentKey(bool regenerateContentKey)
Sets whether or not the content key and ID should be regenerated during republishing.
Definition protection_handler.h:366
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:343
PublishingSettings(const std::shared_ptr< ProtectionDescriptor > &protectionDescriptor, const std::shared_ptr< ProtectionHandler > &protectionHandler)
PublishingSettings constructor for offline republishing.
Definition protection_handler.h:268
std::shared_ptr< ProtectionHandler > GetProtectionHandlerForRepublish() const
Gets protection handler for republishing scenario.
Definition protection_handler.h:285
void SetPreLicenseUserEmail(const std::string &preLicenseUserEmail)
Sets pre-license user.
Definition protection_handler.h:380
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:486
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.