diff --git a/Include/Common/OPC/NMR_IOpcPackageWriter.h b/Include/Common/OPC/NMR_IOpcPackageWriter.h index 78a825033..838707a8e 100644 --- a/Include/Common/OPC/NMR_IOpcPackageWriter.h +++ b/Include/Common/OPC/NMR_IOpcPackageWriter.h @@ -3,6 +3,7 @@ #include #include +#include #include "Common/NMR_Types.h" #include "Common/NMR_Local.h" @@ -19,6 +20,7 @@ namespace NMR { virtual void addContentType(_In_ POpcPackagePart pOpcPackagePart, _In_ std::string sContentType) = 0; virtual POpcPackageRelationship addRootRelationship(_In_ std::string sType, _In_ COpcPackagePart * pTargetPart) = 0; virtual POpcPackageRelationship addPartRelationship(_In_ POpcPackagePart pOpcPackagePart, _In_ std::string sType, _In_ COpcPackagePart * pTargetPart) = 0; + virtual std::list addWriterSpecificRelationships(_In_ POpcPackagePart pOpcPackagePart, _In_ COpcPackagePart* pTargetPart) = 0; virtual void close() {} }; diff --git a/Include/Common/OPC/NMR_OpcPackageWriter.h b/Include/Common/OPC/NMR_OpcPackageWriter.h index b134f893c..5bbf3bfc5 100644 --- a/Include/Common/OPC/NMR_OpcPackageWriter.h +++ b/Include/Common/OPC/NMR_OpcPackageWriter.h @@ -72,6 +72,7 @@ namespace NMR { void addContentType(_In_ POpcPackagePart pOpcPackagePart, _In_ std::string sContentType) override; POpcPackageRelationship addRootRelationship(_In_ std::string sType, _In_ COpcPackagePart * pTargetPart) override; POpcPackageRelationship addPartRelationship(_In_ POpcPackagePart pOpcPackagePart, _In_ std::string sType, _In_ COpcPackagePart * pTargetPart) override; + std::list addWriterSpecificRelationships(_In_ POpcPackagePart pOpcPackagePart, _In_ COpcPackagePart* pTargetPart) override; }; typedef std::shared_ptr POpcPackageWriter; diff --git a/Include/Model/Classes/NMR_ModelConstants.h b/Include/Model/Classes/NMR_ModelConstants.h index 129e7e9de..21191891b 100644 --- a/Include/Model/Classes/NMR_ModelConstants.h +++ b/Include/Model/Classes/NMR_ModelConstants.h @@ -71,6 +71,7 @@ These are given by the 3MF Standard #define PACKAGE_THUMBNAIL_RELATIONSHIP_TYPE "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail" #define PACKAGE_MUST_PRESERVE_RELATIONSHIP_TYPE "http://schemas.openxmlformats.org/package/2006/relationships/mustpreserve" #define PACKAGE_KEYSTORE_RELATIONSHIP_TYPE "http://schemas.microsoft.com/3dmanufacturing/2019/04/keystore" +#define PACKAGE_ENCRYPTED_FILE_RELATIONSHIP "http://schemas.openxmlformats.org/package/2006/relationships/encryptedfile" #define XML_3MF_NAMESPACE_XML "http://www.w3.org/XML/1998/namespace" #define XML_3MF_NAMESPACE_XMLNS "http://www.w3.org/2000/xmlns/" diff --git a/Include/Model/Writer/NMR_KeyStoreOpcPackageWriter.h b/Include/Model/Writer/NMR_KeyStoreOpcPackageWriter.h index c42f9c52f..83a50e9b6 100644 --- a/Include/Model/Writer/NMR_KeyStoreOpcPackageWriter.h +++ b/Include/Model/Writer/NMR_KeyStoreOpcPackageWriter.h @@ -49,6 +49,8 @@ namespace NMR { using PKeyStoreAccessRight = std::shared_ptr; class CKeyStoreOpcPackageWriter : public IOpcPackageWriter { + private: + bool pathIsEncrypted(_In_ std::string sPath); protected: CModelContext const & m_pContext; PIOpcPackageWriter m_pPackageWriter; @@ -69,6 +71,7 @@ namespace NMR { void addContentType(_In_ POpcPackagePart pOpcPackagePart, _In_ std::string sContentType) override; POpcPackageRelationship addRootRelationship(std::string sType, COpcPackagePart * pTargetPart) override; POpcPackageRelationship addPartRelationship(_In_ POpcPackagePart pOpcPackagePart, _In_ std::string sType, _In_ COpcPackagePart * pTargetPart) override; + std::list addWriterSpecificRelationships(_In_ POpcPackagePart pOpcPackagePart, _In_ COpcPackagePart* pTargetPart) override; }; using PKeyStoreOpcPackageWriter = std::shared_ptr; diff --git a/Source/Common/OPC/NMR_OpcPackageWriter.cpp b/Source/Common/OPC/NMR_OpcPackageWriter.cpp index 60b983f4d..c0112f9da 100644 --- a/Source/Common/OPC/NMR_OpcPackageWriter.cpp +++ b/Source/Common/OPC/NMR_OpcPackageWriter.cpp @@ -121,6 +121,11 @@ namespace NMR { return pOpcPackagePart->addRelationship(generateRelationShipID(), sType, pTargetPart->getURI()); } + std::list COpcPackageWriter::addWriterSpecificRelationships(_In_ POpcPackagePart pOpcPackagePart, _In_ COpcPackagePart* pTargetPart) + { + return std::list(); + } + void COpcPackageWriter::finishPackage() { writeContentTypes(); diff --git a/Source/Model/Writer/NMR_KeyStoreOpcPackageWriter.cpp b/Source/Model/Writer/NMR_KeyStoreOpcPackageWriter.cpp index d568b8b12..a61a9d7bd 100644 --- a/Source/Model/Writer/NMR_KeyStoreOpcPackageWriter.cpp +++ b/Source/Model/Writer/NMR_KeyStoreOpcPackageWriter.cpp @@ -91,6 +91,23 @@ namespace NMR { } } + bool CKeyStoreOpcPackageWriter::pathIsEncrypted(_In_ std::string sPath) + { + PSecureContext const& secureContext = m_pContext.secureContext(); + PKeyStore const& keyStore = m_pContext.keyStore(); + + NMR::PKeyStoreResourceData rd = keyStore->findResourceData(sPath); + if (nullptr != rd) { + if (secureContext->hasDekCtx()) { + return true; + } + else { + m_pContext.warnings()->addWarning(NMR_ERROR_DEKDESCRIPTORNOTFOUND, eModelWarningLevel::mrwMissingMandatoryValue); + } + } + return false; + } + POpcPackagePart CKeyStoreOpcPackageWriter::wrapPartStream(PKeyStoreResourceData rd, POpcPackagePart part) { PSecureContext const & secureContext = m_pContext.secureContext(); ContentEncryptionDescriptor p = secureContext->getDekCtx(); @@ -190,6 +207,19 @@ namespace NMR { return m_pPackageWriter->addPartRelationship(pOpcPackagePart, sType, pTargetPart); } + std::list CKeyStoreOpcPackageWriter::addWriterSpecificRelationships(_In_ POpcPackagePart pOpcPackagePart, _In_ COpcPackagePart* pTargetPart) + { + std::list list; + std::string sPath = fnIncludeLeadingPathDelimiter(pTargetPart->getURI()); + if (pathIsEncrypted(sPath)) + { + list.push_back(addPartRelationship(pOpcPackagePart, PACKAGE_ENCRYPTED_FILE_RELATIONSHIP, pTargetPart)); + } + + list.merge(m_pPackageWriter->addWriterSpecificRelationships(pOpcPackagePart, pTargetPart)); + return list; + } + void CKeyStoreOpcPackageWriter::writeKeyStoreStream(_In_ CXmlWriter * pXMLWriter) { pXMLWriter->WriteStartDocument(); diff --git a/Source/Model/Writer/NMR_ModelWriter_3MF_Native.cpp b/Source/Model/Writer/NMR_ModelWriter_3MF_Native.cpp index ceb2a6f3e..7aea896d3 100644 --- a/Source/Model/Writer/NMR_ModelWriter_3MF_Native.cpp +++ b/Source/Model/Writer/NMR_ModelWriter_3MF_Native.cpp @@ -200,7 +200,7 @@ namespace NMR { if (pStream.get() == nullptr) throw CNMRException(NMR_ERROR_INVALIDPARAM); - // create Texture Part + // create Attachment Part POpcPackagePart pAttachmentPart = m_pPackageWriter->addPart(sPath); PExportStream pExportStream = pAttachmentPart->getExportStream(); @@ -211,6 +211,8 @@ namespace NMR { // add relationships m_pPackageWriter->addPartRelationship(pModelPart, sRelationShipType.c_str(), pAttachmentPart.get()); + m_pPackageWriter->addWriterSpecificRelationships(pModelPart, pAttachmentPart.get()); + monitor()->IncrementProgress(1); } }