summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Behrens <Thorsten.Behrens@CIB.de>2017-08-18 21:34:11 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-12-04 00:36:38 +0100
commiteca7573be0dc04548e664b96d812d82c399f1808 (patch)
treeee71e8ef43d0fb837217157ac191d4d1ca572ae4
parent9914ca04ac6a63f14adcd0fe58b2be44b84ee15f (diff)
gpg4libre: add manifest entries for gpg encryption
Change-Id: I71bd7e2c6c73d997fa1ed5bb36fdc2873daca10c
-rw-r--r--package/source/manifest/ManifestDefines.hxx11
-rw-r--r--package/source/manifest/ManifestExport.cxx108
2 files changed, 117 insertions, 2 deletions
diff --git a/package/source/manifest/ManifestDefines.hxx b/package/source/manifest/ManifestDefines.hxx
index 968aed648e6a..42ff1ceeadbc 100644
--- a/package/source/manifest/ManifestDefines.hxx
+++ b/package/source/manifest/ManifestDefines.hxx
@@ -24,8 +24,10 @@
#define MANIFEST_NSPREFIX "manifest:"
#define ELEMENT_MANIFEST "manifest:manifest"
#define ATTRIBUTE_XMLNS "xmlns:manifest"
+#define ATTRIBUTE_XMLNS_LOEXT "xmlns:loext"
#define MANIFEST_NAMESPACE "http://openoffice.org/2001/manifest"
#define MANIFEST_OASIS_NAMESPACE "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"
+#define MANIFEST_LOEXT_NAMESPACE "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
#define MANIFEST_DOCTYPE "<!DOCTYPE manifest:manifest PUBLIC \"-//OpenOffice.org//DTD Manifest 1.0//EN\" \"Manifest.dtd\">"
#define ATTRIBUTE_CDATA "CDATA"
@@ -34,6 +36,15 @@
#define ATTRIBUTE_VERSION "manifest:version"
#define ATTRIBUTE_MEDIA_TYPE "manifest:media-type"
#define ATTRIBUTE_SIZE "manifest:size"
+#define ELEMENT_KEYINFO "loext:KeyInfo"
+#define ELEMENT_ENCRYPTEDKEY "loext:EncryptedKey"
+#define ELEMENT_ENCRYPTIONMETHOD "loext:EncryptionMethod"
+#define ELEMENT_PGPDATA "loext:PGPData"
+#define ELEMENT_PGPKEYID "loext:PGPKeyID"
+#define ELEMENT_PGPKEYPACKET "loext:PGPKeyPacket"
+#define ATTRIBUTE_ALGORITHM "loext:Algorithm"
+#define ELEMENT_CIPHERDATA "loext:CipherData"
+#define ELEMENT_CIPHERVALUE "loext:CipherValue"
#define ELEMENT_ENCRYPTION_DATA "manifest:encryption-data"
#define ATTRIBUTE_CHECKSUM_TYPE "manifest:checksum-type"
diff --git a/package/source/manifest/ManifestExport.cxx b/package/source/manifest/ManifestExport.cxx
index 60a5128e945d..1148c1120133 100644
--- a/package/source/manifest/ManifestExport.cxx
+++ b/package/source/manifest/ManifestExport.cxx
@@ -66,11 +66,23 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con
const OUString sChecksumTypeAttribute ( ATTRIBUTE_CHECKSUM_TYPE );
const OUString sChecksumAttribute ( ATTRIBUTE_CHECKSUM);
+ const OUString sKeyInfoElement ( ELEMENT_KEYINFO );
+ const OUString sEncryptedKeyElement ( ELEMENT_ENCRYPTEDKEY );
+ const OUString sEncryptionMethodElement ( ELEMENT_ENCRYPTIONMETHOD );
+ const OUString sPgpDataElement ( ELEMENT_PGPDATA );
+ const OUString sPgpKeyIDElement ( ELEMENT_PGPKEYID );
+ const OUString sPGPKeyPacketElement ( ELEMENT_PGPKEYPACKET );
+ const OUString sAlgorithmAttribute ( ATTRIBUTE_ALGORITHM );
+ const OUString sCipherDataElement ( ELEMENT_CIPHERDATA );
+ const OUString sCipherValueElement ( ELEMENT_CIPHERVALUE );
+ const OUString sPgpKeyIDProperty ( "KeyId" );
+ const OUString sPgpKeyPacketProperty ( "KeyPacket" );
+ const OUString sCipherValueProperty ( "CipherValue" );
const OUString sFullPathProperty ( "FullPath" );
const OUString sVersionProperty ( "Version" );
const OUString sMediaTypeProperty ( "MediaType" );
const OUString sIterationCountProperty ( "IterationCount" );
- const OUString sDerivedKeySizeProperty ( "DerivedKeySize" );
+ const OUString sDerivedKeySizeProperty ( "DerivedKeySize" );
const OUString sSaltProperty ( "Salt" );
const OUString sInitialisationVectorProperty( "InitialisationVector" );
const OUString sSizeProperty ( "Size" );
@@ -164,9 +176,14 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con
bAcceptNonemptyVersion = true;
if ( aDocVersion.compareTo( ODFVER_012_TEXT ) >= 0 )
{
- // this is ODF12 generation, let encrypted streams contain start-key-generation entry
+ // this is ODF12 or later generation, let encrypted
+ // streams contain start-key-generation entry
bStoreStartKeyGeneration = true;
pRootAttrList->AddAttribute ( sVersionAttribute, sCdataAttribute, aDocVersion );
+ // plus gpg4libre extensions - loext NS for that
+ pRootAttrList->AddAttribute ( ATTRIBUTE_XMLNS_LOEXT,
+ sCdataAttribute,
+ MANIFEST_LOEXT_NAMESPACE );
}
}
else
@@ -192,6 +209,93 @@ ManifestExport::ManifestExport( uno::Reference< xml::sax::XDocumentHandler > con
}
xHandler->startElement( sManifestElement, xRootAttrList );
+ if (nManLength > 0)
+ {
+ const beans::PropertyValue *pValue = pSequence[0].getConstArray();
+ OUString aString;
+ const uno::Any *pPgpKeyIDProperty = nullptr, *pPgpKeyPacketProperty = nullptr,
+ *pCipherValueProperty = nullptr;
+ for (sal_uInt32 j = 0, nNum = pSequence[0].getLength(); j < nNum; j++, pValue++)
+ {
+ if (pValue->Name == sPgpKeyIDProperty )
+ pPgpKeyIDProperty = &pValue->Value;
+ else if (pValue->Name == sPgpKeyPacketProperty )
+ pPgpKeyPacketProperty = &pValue->Value;
+ else if (pValue->Name == sCipherValueProperty )
+ pCipherValueProperty = &pValue->Value;
+ }
+
+ if ( pPgpKeyIDProperty && pPgpKeyPacketProperty && pCipherValueProperty )
+ {
+ // TODO make this work for multiple recipients
+ // ==== OpenPGP - encryped session data
+ ::comphelper::AttributeList * pNewAttrList = new ::comphelper::AttributeList;
+ uno::Reference < xml::sax::XAttributeList > xNewAttrList (pNewAttrList);
+ OUStringBuffer aBuffer;
+ uno::Sequence < sal_Int8 > aSequence;
+
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ // ==== KeyInfo & children
+ xHandler->startElement( sKeyInfoElement, nullptr );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ xHandler->startElement( sEncryptedKeyElement, nullptr );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ // TODO this should rather be configurable
+ pNewAttrList->AddAttribute ( sAlgorithmAttribute, sCdataAttribute,
+ "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" );
+ xHandler->startElement( sEncryptionMethodElement, xNewAttrList );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ xHandler->endElement( sEncryptionMethodElement );
+
+ xHandler->startElement( sKeyInfoElement, nullptr );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->startElement( sPgpDataElement, nullptr );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->startElement( sPgpKeyIDElement, nullptr );
+ *pPgpKeyIDProperty >>= aSequence;
+ ::sax::Converter::encodeBase64(aBuffer, aSequence);
+ xHandler->characters( aBuffer.makeStringAndClear() );
+ xHandler->endElement( sPgpKeyIDElement );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->startElement( sPGPKeyPacketElement, nullptr );
+ *pPgpKeyPacketProperty >>= aSequence;
+ ::sax::Converter::encodeBase64(aBuffer, aSequence);
+ xHandler->characters( aBuffer.makeStringAndClear() );
+ xHandler->endElement( sPGPKeyPacketElement );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->endElement( sPgpDataElement );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->endElement( sKeyInfoElement );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->startElement( sCipherDataElement, nullptr );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->startElement( sCipherValueElement, nullptr );
+ *pCipherValueProperty >>= aSequence;
+ ::sax::Converter::encodeBase64(aBuffer, aSequence);
+ xHandler->characters( aBuffer.makeStringAndClear() );
+ xHandler->endElement( sCipherValueElement );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->endElement( sCipherDataElement );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->endElement( sEncryptedKeyElement );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+
+ xHandler->endElement( sKeyInfoElement );
+ xHandler->ignorableWhitespace ( sWhiteSpace );
+ }
+ }
+
for (sal_uInt32 i = 0 ; i < nManLength ; i++)
{
::comphelper::AttributeList *pAttrList = new ::comphelper::AttributeList;