Kaydet (Commit) 345994da authored tarafından Ashod Nakashian's avatar Ashod Nakashian Kaydeden (comit) Ashod Nakashian

sw: sign paragraph text

The results are not stored anywhere just yet.

Change-Id: I99a701ee8a16f166350c7c342b34b8fc476a81ae
Reviewed-on: https://gerrit.libreoffice.org/40721Reviewed-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
Tested-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
üst 0a64fa41
......@@ -51,7 +51,7 @@ public:
/// Add a range to sign.
/// Note: for efficiency this takes a naked pointer, which must remain valid
/// until this object is discarded.
void AddDataRange(void* pData, sal_Int32 size)
void AddDataRange(const void* pData, sal_Int32 size)
{
m_dataBlocks.emplace_back(pData, size);
}
......@@ -81,7 +81,7 @@ private:
const css::uno::Reference<css::security::XCertificate> m_xCertificate;
/// Data blocks (pointer-size pairs).
std::vector<std::pair<void*, sal_Int32>> m_dataBlocks;
std::vector<std::pair<const void*, sal_Int32>> m_dataBlocks;
OUString m_aSignTSA;
OUString m_aSignPassword;
};
......
......@@ -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);
......
......@@ -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.
}
}
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment