summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2018-04-20 12:19:12 +0200
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2018-05-15 16:16:22 +0200
commit86e8cfdd54ac1b9413f0c86cbc23a80162806685 (patch)
treee62c721f66cb95490fcedc41d3c22303d89de182 /sfx2
parent863d2485e60251ac45b019b2c58ced7cfc9d978e (diff)
Sign Signature Line
This adds a new context menu entry "Sign Signature Line" to signature lines. You can directly sign the document from there. Still missing is the updating of the graphic to reflect the valid/invalid signature state. Change-Id: Ib8bc8c57f9d5370a10e379f86f9e41e57c715e3f Reviewed-on: https://gerrit.libreoffice.org/53778 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/doc/docfile.cxx32
-rw-r--r--sfx2/source/doc/objserv.cxx29
2 files changed, 45 insertions, 16 deletions
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index a589d1134d90..9de896d77a62 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -70,6 +70,7 @@
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/security/DocumentSignatureInformation.hpp>
#include <com/sun/star/security/DocumentDigitalSignatures.hpp>
+#include <com/sun/star/security/XCertificate.hpp>
#include <o3tl/make_unique.hxx>
#include <tools/urlobj.hxx>
#include <tools/fileutil.hxx>
@@ -136,6 +137,7 @@ using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::security;
namespace {
@@ -3659,7 +3661,8 @@ void SfxMedium::CreateTempFileNoCopy()
CloseStorage();
}
-bool SfxMedium::SignContents_Impl( bool bScriptingContent, const OUString& aODFVersion, bool bHasValidDocumentSignature )
+bool SfxMedium::SignContents_Impl(const Reference<XCertificate> xCert, bool bScriptingContent,
+ const OUString& aODFVersion, bool bHasValidDocumentSignature)
{
bool bChanges = false;
@@ -3747,7 +3750,15 @@ bool SfxMedium::SignContents_Impl( bool bScriptingContent, const OUString& aODFV
if (GetFilter() && GetFilter()->IsOwnFormat())
xStream.set(xMetaInf->openStreamElement(xSigner->getDocumentContentSignatureDefaultStreamName(), embed::ElementModes::READWRITE), uno::UNO_SET_THROW);
- if ( xSigner->signDocumentContent( GetZipStorageToSign_Impl(), xStream ) )
+ bool bSuccess = false;
+ if (xCert.is())
+ bSuccess = xSigner->signDocumentContentWithCertificate(
+ GetZipStorageToSign_Impl(), xStream, xCert);
+ else
+ bSuccess = xSigner->signDocumentContent(GetZipStorageToSign_Impl(),
+ xStream);
+
+ if (bSuccess)
{
uno::Reference< embed::XTransactedObject > xTransact( xMetaInf, uno::UNO_QUERY_THROW );
xTransact->commit();
@@ -3763,8 +3774,21 @@ bool SfxMedium::SignContents_Impl( bool bScriptingContent, const OUString& aODFV
{
// OOXML.
uno::Reference<io::XStream> xStream;
- // We need read-write to be able to add the signature relation.
- if (xSigner->signDocumentContent(GetZipStorageToSign_Impl(/*bReadOnly=*/false), xStream))
+
+ bool bSuccess = false;
+ if (xCert.is())
+ {
+ bSuccess = xSigner->signDocumentContentWithCertificate(
+ GetZipStorageToSign_Impl(), xStream, xCert);
+ }
+ else
+ {
+ // We need read-write to be able to add the signature relation.
+ bSuccess =xSigner->signDocumentContent(
+ GetZipStorageToSign_Impl(/*bReadOnly=*/false), xStream);
+ }
+
+ if (bSuccess)
{
uno::Reference<embed::XTransactedObject> xTransact(xWriteableZipStor, uno::UNO_QUERY_THROW);
xTransact->commit();
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 4f9e6b193d75..edac57aeceee 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -33,6 +33,7 @@
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/document/XCmisDocument.hpp>
#include <com/sun/star/document/XExporter.hpp>
+#include <com/sun/star/security/XCertificate.hpp>
#include <com/sun/star/task/ErrorCodeIOException.hpp>
#include <com/sun/star/task/InteractionHandler.hpp>
#include <com/sun/star/task/XStatusIndicator.hpp>
@@ -111,6 +112,7 @@ using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::security;
using namespace ::com::sun::star::task;
#define ShellClass_SfxObjectShell
@@ -1359,7 +1361,8 @@ SignatureState SfxObjectShell::ImplGetSignatureState( bool bScriptingContent )
return *pState;
}
-void SfxObjectShell::ImplSign( bool bScriptingContent )
+void SfxObjectShell::ImplSign(Reference<XCertificate> xCert,
+ bool bScriptingContent)
{
// Check if it is stored in OASIS format...
if ( GetMedium()
@@ -1480,21 +1483,18 @@ void SfxObjectShell::ImplSign( bool bScriptingContent )
{
GetMedium()->CloseAndRelease();
- // We sign only ODF1.2, that means that if this point has been reached,
- // the ODF1.2 signing process should be used.
- // This code still might be called to show the signature of ODF1.1 document.
- bool bSigned = GetMedium()->SignContents_Impl(
- bScriptingContent,
- aODFVersion,
- pImpl->nDocumentSignatureState == SignatureState::OK
+ bool bHasValidSignatures = pImpl->nDocumentSignatureState == SignatureState::OK
|| pImpl->nDocumentSignatureState == SignatureState::NOTVALIDATED
- || pImpl->nDocumentSignatureState == SignatureState::PARTIAL_OK);
+ || pImpl->nDocumentSignatureState == SignatureState::PARTIAL_OK;
+
+ bool bSignSuccess = GetMedium()->SignContents_Impl(
+ xCert, bScriptingContent, aODFVersion, bHasValidSignatures);
pImpl->m_bSavingForSigning = true;
DoSaveCompleted( GetMedium() );
pImpl->m_bSavingForSigning = false;
- if ( bSigned )
+ if ( bSignSuccess )
{
if ( bScriptingContent )
{
@@ -1523,7 +1523,12 @@ SignatureState SfxObjectShell::GetDocumentSignatureState()
void SfxObjectShell::SignDocumentContent()
{
- ImplSign();
+ ImplSign(Reference<XCertificate>());
+}
+
+void SfxObjectShell::SignDocumentContent(const Reference<XCertificate> xCert)
+{
+ ImplSign(xCert);
}
SignatureState SfxObjectShell::GetScriptingSignatureState()
@@ -1533,7 +1538,7 @@ SignatureState SfxObjectShell::GetScriptingSignatureState()
void SfxObjectShell::SignScriptingContent()
{
- ImplSign( true );
+ ImplSign( Reference<XCertificate>(), true );
}
namespace