summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2017-08-01 18:07:56 -0400
committerAshod Nakashian <ashnakash@gmail.com>2017-08-04 02:12:26 +0200
commit345994dad91765e5356f95786146bf8aca5a4aa3 (patch)
tree56e09f549534d18b195e4ca470690806955fea57 /sw
parent0a64fa41045eea8ea179bbf0eee306ffb5851500 (diff)
sw: sign paragraph text
The results are not stored anywhere just yet. Change-Id: I99a701ee8a16f166350c7c342b34b8fc476a81ae Reviewed-on: https://gerrit.libreoffice.org/40721 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/editsh.hxx5
-rw-r--r--sw/source/core/edit/edfcol.cxx48
-rw-r--r--sw/source/uibase/shells/textsh1.cxx2
3 files changed, 49 insertions, 6 deletions
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index c539007c34c9..7e2d8b739427 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -372,7 +372,10 @@ public:
void SetWatermark(const SfxWatermarkItem& rText);
/// Sign the paragraph at the cursor.
- static void SignParagraph(SwPaM* pPaM);
+ void SignParagraph(SwPaM* pPaM);
+
+ /// Verify the paragraph at the cursor.
+ void VerifyParagraph(SwPaM* pPaM);
void Insert2(SwField&, const bool bForceExpandHints);
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index 808525287c75..28d2907c939b 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -32,6 +32,7 @@
#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <com/sun/star/text/VertOrientation.hpp>
#include <com/sun/star/text/WrapTextMode.hpp>
+#include <com/sun/star/xml/crypto/SEInitializer.hpp>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <comphelper/propertysequence.hxx>
@@ -40,6 +41,7 @@
#include <editeng/formatbreakitem.hxx>
#include <editeng/unoprnms.hxx>
#include <sfx2/classificationhelper.hxx>
+#include <svl/cryptosign.hxx>
#include <vcl/svapp.hxx>
#include <hintids.hxx>
@@ -60,6 +62,8 @@
#include <pagefrm.hxx>
#include <sfx2/watermarkitem.hxx>
+#include <cppuhelper/bootstrap.hxx>
+
#define WATERMARK_NAME "PowerPlusWaterMarkObject"
namespace
@@ -541,15 +545,51 @@ void SwEditShell::SignParagraph(SwPaM* pPaM)
if (!pPaM)
return;
+ SwDocShell* pDocShell = GetDoc()->GetDocShell();
+ if (!pDocShell)
+ return;
+ SwWrtShell* pCurShell = pDocShell->GetWrtShell();
+ if (!pCurShell)
+ return;
+
const SwPosition* pPosStart = pPaM->Start();
SwTextNode* pNode = pPosStart->nNode.GetNode().GetTextNode();
if (pNode)
{
- // Get the text (without fields).
+ // 1. Get the text (without fields).
const OUString text = pNode->GetText();
- (void)text;
-
- //TODO: get signature, add signature field and metadata.
+ if (text.isEmpty())
+ return;
+
+ // 2. Get certificate and SignatureInformation (needed to show signer name).
+ //FIXME: Temporary until the Paragraph Signing Dialog is available.
+ uno::Reference<uno::XComponentContext> xComponentContext = cppu::defaultBootstrap_InitialComponentContext();
+ uno::Reference<xml::crypto::XSEInitializer> xSEInitializer = xml::crypto::SEInitializer::create(xComponentContext);
+ uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContext = xSEInitializer->createSecurityContext(OUString());
+ uno::Reference<xml::crypto::XSecurityEnvironment> xSecurityEnvironment = xSecurityContext->getSecurityEnvironment();
+ uno::Sequence<uno::Reference<security::XCertificate>> aCertificates = xSecurityEnvironment->getPersonalCertificates();
+ if (!aCertificates.hasElements())
+ return;
+
+ SignatureInformation aInfo(0);
+ uno::Reference<security::XCertificate> xCert = aCertificates[0];
+ if (!xCert.is())
+ return;
+
+ // 3. Sign it.
+ svl::crypto::Signing signing(xCert);
+ signing.AddDataRange(text.getStr(), text.getLength());
+ OStringBuffer signature;
+ if (!signing.Sign(signature))
+ return;
+
+ const auto pData = reinterpret_cast<const unsigned char*>(text.getStr());
+ const std::vector<unsigned char> data(pData, pData + text.getLength());
+ const std::vector<unsigned char> sig(svl::crypto::DecodeHexString(signature.makeStringAndClear()));
+ if (!svl::crypto::Signing::Verify(data, true, sig, aInfo))
+ return;
+
+ // 4. Add metadata.
}
}
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 313dabcf835b..30e923ae0eb5 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -1107,7 +1107,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
rWrtSh.StartUndo(SwUndoId::PARA_SIGN_ADD);
rWrtSh.StartAction();
- SwWrtShell::SignParagraph(pPaM);
+ rWrtSh.SignParagraph(pPaM);
rWrtSh.EndAction();