summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2017-10-03 19:41:28 -0400
committerAshod Nakashian <ashnakash@gmail.com>2017-10-05 14:47:29 +0200
commitb6d6591fafb8ad2e59a27ff1ac6b234d879b4cf7 (patch)
treeac06305ef34d9a2d661a34cf22e78e4760e0b522 /sw
parent09d70a097136719df3f8f08f5cbaa8dae4369279 (diff)
TSCP: include certificate usage in paragraph signatures
Change-Id: I6f4b891a016c67051efd9033329065d7e3c8a06b Reviewed-on: https://gerrit.libreoffice.org/43022 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/UndoParagraphSignature.hxx1
-rw-r--r--sw/source/core/edit/edfcol.cxx31
2 files changed, 26 insertions, 6 deletions
diff --git a/sw/inc/UndoParagraphSignature.hxx b/sw/inc/UndoParagraphSignature.hxx
index e0f1613d91df..8481c23dd030 100644
--- a/sw/inc/UndoParagraphSignature.hxx
+++ b/sw/inc/UndoParagraphSignature.hxx
@@ -37,6 +37,7 @@ private:
uno::Reference<text::XTextField> m_xField;
uno::Reference<text::XTextContent> m_xParent;
OUString m_signature;
+ OUString m_usage;
OUString m_display;
const bool m_bRemove;
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index 920e25032cee..7d552ad6c6be 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -91,6 +91,7 @@ namespace
static const OUString MetaFilename("bails.rdf");
static const OUString MetaNS("urn:bails");
static const OUString ParagraphSignatureRDFName = "loext:paragraph:signature";
+static const OUString ParagraphSignatureUsageRDFName = "loext:paragraph:signature:usage";
static const OUString ParagraphClassificationRDFName = "loext:paragraph:classification";
static const OUString MetadataFieldServiceName = "com.sun.star.text.textfield.MetadataField";
static const OUString DocInfoServiceName = "com.sun.star.text.TextField.DocInfo.Custom";
@@ -271,7 +272,9 @@ lcl_MakeParagraphSignatureFieldText(const uno::Reference<frame::XModel>& xModel,
valid = svl::crypto::Signing::Verify(data, false, sig, aInfo);
valid = valid && aInfo.nStatus == css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED;
- msg = SwResId(STR_SIGNED_BY) + ": " + aInfo.ouSubject + ", " + aInfo.ouDateTime + ": ";
+ const auto it2 = aStatements.find(ParagraphSignatureUsageRDFName);
+ msg = (it2 != aStatements.end() ? (it2->second + ", ") : OUString());
+ msg += SwResId(STR_SIGNED_BY) + ": " + aInfo.ouSubject + ", " + aInfo.ouDateTime + ": ";
if (valid)
msg += SwResId(STR_VALID);
else
@@ -285,7 +288,8 @@ lcl_MakeParagraphSignatureFieldText(const uno::Reference<frame::XModel>& xModel,
/// Creates and inserts Paragraph Signature Metadata field and creates the RDF entry
uno::Reference<text::XTextField> lcl_InsertParagraphSignature(const uno::Reference<frame::XModel>& xModel,
const uno::Reference<text::XTextContent>& xParent,
- const OUString& signature)
+ const OUString& signature,
+ const OUString& usage)
{
uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
auto xField = uno::Reference<text::XTextField>(xMultiServiceFactory->createInstance(MetadataFieldServiceName), uno::UNO_QUERY);
@@ -295,6 +299,7 @@ uno::Reference<text::XTextField> lcl_InsertParagraphSignature(const uno::Referen
const css::uno::Reference<css::rdf::XResource> xSubject(xField, uno::UNO_QUERY);
SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xSubject, ParagraphSignatureRDFName, signature);
+ SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xSubject, ParagraphSignatureUsageRDFName, usage);
return xField;
}
@@ -1222,6 +1227,10 @@ SwUndoParagraphSigning::SwUndoParagraphSigning(const SwPosition& rPos,
if (it != aStatements.end())
m_signature = it->second;
+ const auto it2 = aStatements.find(ParagraphSignatureUsageRDFName);
+ if (it2 != aStatements.end())
+ m_usage = it->second;
+
uno::Reference<css::text::XTextRange> xText(m_xField, uno::UNO_QUERY);
m_display = xText->getString();
}
@@ -1261,7 +1270,7 @@ void SwUndoParagraphSigning::Insert()
m_pDoc->GetIDocumentUndoRedo().DoUndo(isUndoEnabled);
});
- m_xField = lcl_InsertParagraphSignature(m_pDoc->GetDocShell()->GetBaseModel(), m_xParent, m_signature);
+ m_xField = lcl_InsertParagraphSignature(m_pDoc->GetDocShell()->GetBaseModel(), m_xParent, m_signature, m_usage);
uno::Reference<css::text::XTextRange> xText(m_xField, uno::UNO_QUERY);
xText->setString(m_display);
@@ -1308,8 +1317,8 @@ void SwEditShell::SignParagraph()
security::DocumentDigitalSignatures::createWithVersion(
comphelper::getProcessComponentContext(), "1.2" ) );
- OUString aDescription;
- uno::Reference<security::XCertificate> xCertificate = xSigner->chooseCertificate(aDescription);
+ uno::Sequence<css::beans::PropertyValue> aProperties;
+ uno::Reference<security::XCertificate> xCertificate = xSigner->chooseCertificateWithProps(aProperties);
if (!xCertificate.is())
return;
@@ -1322,6 +1331,16 @@ void SwEditShell::SignParagraph()
const OUString signature = OStringToOUString(sigBuf.makeStringAndClear(), RTL_TEXTENCODING_UTF8, 0);
+ std::vector<css::beans::PropertyValue> vec = comphelper::sequenceToContainer<std::vector<css::beans::PropertyValue>>(aProperties);
+ auto it = std::find_if(vec.begin(), vec.end(), [](const beans::PropertyValue& rValue)
+ {
+ return rValue.Name == "Usage";
+ });
+
+ OUString aUsage;
+ if (it != vec.end())
+ it->Value >>= aUsage;
+
// 4. Add metadata
// Prevent validation since this will trigger a premature validation
// upon inserting, but before setting the metadata.
@@ -1333,7 +1352,7 @@ void SwEditShell::SignParagraph()
GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::PARA_SIGN_ADD, nullptr);
const uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
- uno::Reference<css::text::XTextField> xField = lcl_InsertParagraphSignature(xModel, xParent, signature);
+ uno::Reference<css::text::XTextField> xField = lcl_InsertParagraphSignature(xModel, xParent, signature, aUsage);
lcl_UpdateParagraphSignatureField(GetDoc(), xModel, xField, utf8Text);