summaryrefslogtreecommitdiff
path: root/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
diff options
context:
space:
mode:
authorIvo Hinkelmann <ihi@openoffice.org>2009-09-17 13:53:54 +0000
committerIvo Hinkelmann <ihi@openoffice.org>2009-09-17 13:53:54 +0000
commitee5962ed62371da4338424e74ed010e18ec24d78 (patch)
tree441fdc0c629b030805db59a7a7d0030423eedbac /xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
parent69301294414b98ef4ab3520fb663d63bf3b8f64e (diff)
CWS-TOOLING: integrate CWS encsig09
2009-09-14 15:11:29 +0200 oc r276125 : #i105049# MacroSignatur needs Macro 2009-09-09 17:09:46 +0200 jl r276005 : #i103989# could not signe encrypted doc containing a formular object 2009-09-09 13:11:24 +0200 jl r275985 : #i103989# could not signe encrypted doc containing a formular object 2009-09-08 15:54:02 +0200 mav r275934 : #i103906# fix the automation test scenario ( tempfile should be writable for the user ) 2009-09-07 14:01:39 +0200 mav r275895 : #i103906# fix the problem with reload 2009-09-07 09:34:48 +0200 mav r275871 : #i104786# do the ODF version check only for ODF documents 2009-09-07 08:19:06 +0200 mav r275870 : #i104389# fix text 2009-09-06 22:24:21 +0200 mav r275867 : #i104786# check the consistency of ODF version 2009-09-06 22:23:24 +0200 mav r275866 : #i104786# check the consistency of ODF version 2009-09-06 22:23:00 +0200 mav r275865 : #i104786# check the consistency of ODF version 2009-09-06 22:22:36 +0200 mav r275864 : #i104786# check the consistency of ODF version 2009-09-06 22:22:03 +0200 mav r275863 : #i104786# check the consistency of ODF version 2009-09-02 17:09:30 +0200 mav r275722 : #i104715# let repairing mechanics use the streams correctly 2009-09-01 16:52:49 +0200 mav r275670 : #i104389# notify user not to trust the corrupted document 2009-09-01 16:31:37 +0200 mav r275668 : #i104389# use vnd.sun.star.zip: protocol to access zip files 2009-09-01 16:30:32 +0200 mav r275667 : #i104389# use vnd.sun.star.zip: protocol to access zip files 2009-09-01 16:22:13 +0200 jl r275666 : #i104339# small content change 2009-09-01 14:20:42 +0200 jl r275660 : #i103519# remove some debug output 2009-09-01 13:51:52 +0200 jl r275659 : #i103519# NSS uses '\' for escaping in distinguished names 2009-09-01 12:49:47 +0200 mav r275655 : #i104389# use zip-mode to read from jar files 2009-09-01 12:40:22 +0200 mav r275653 : #i104389# use zip-mode to read from jar files 2009-09-01 12:32:29 +0200 mav r275652 : #i104389# use constants 2009-08-31 21:58:00 +0200 mav r275637 : #i10000# fix warning 2009-08-31 21:11:17 +0200 mav r275636 : #i104227# adding of scripting signature removes the document signature 2009-08-31 20:55:05 +0200 mav r275635 : #i103905# ZipStorage supports Compressed property 2009-08-31 20:53:55 +0200 mav r275634 : #i103905# adjust macro signature transfer to usage of ZipStorage 2009-08-31 15:30:49 +0200 jl r275609 : #i103989# warning is shown as long the user does not click 'OK' 2009-08-31 14:36:10 +0200 jl r275608 : #i103989# changed warning text when signing macro and there is a document signature. This warning is only displayed once 2009-08-31 13:34:41 +0200 mav r275603 : #i104452# disable macros in repaired documents 2009-08-31 13:33:42 +0200 mav r275602 : #i104452# disable macros in repaired documents 2009-08-31 13:03:56 +0200 jl r275600 : #i45212# signature dialog could not be started when using read-only documents 2009-08-31 09:26:13 +0200 mav r275583 : #i104578# store the additional entry as the last one to workaround parsing problem in OOo3.1 and later 2009-08-30 20:54:25 +0200 mav r275562 : #i10000# adopt for unix 2009-08-30 10:56:00 +0200 mav r275561 : CWS-TOOLING: rebase CWS encsig09 to trunk@275331 (milestone: DEV300:m56) 2009-08-28 16:34:00 +0200 mav r275539 : #i104578# write necessary info in manifest.xml for ODF1.2 encrypted document 2009-08-28 14:04:22 +0200 mav r275533 : #104587# fix handling of readonly streams 2009-08-28 13:58:10 +0200 mav r275531 : #i104389# fix the broken document handling 2009-08-28 11:40:39 +0200 mav r275522 : #i104389# fix the signature streams check 2009-08-27 21:48:12 +0200 mav r275509 : #i103927# show the warning 2009-08-27 21:47:48 +0200 mav r275508 : #i103927# show the warning 2009-08-27 16:45:59 +0200 jl r275495 : #i45212# remove unused variable 2009-08-27 16:34:00 +0200 jl r275494 : #i103989# 2009-08-27 13:54:28 +0200 jl r275482 : #i103519# fixed replacement of 'S' by 'ST' 2009-08-27 12:32:21 +0200 mav r275472 : #i10000# fix warning 2009-08-27 11:58:11 +0200 mav r275467 : #i104389# handle the entry path correctly 2009-08-26 17:18:35 +0200 jl r275438 : #i103519# subject and issuer distinguished names were not properly displayed. The strings were obtained by system functions (Windows, NSS), which use quotes to escape the values, when they contain special characters 2009-08-26 11:00:20 +0200 mav r275403 : #i10000# fix warnings 2009-08-26 08:25:45 +0200 mav r275392 : #i10000# fix warning 2009-08-26 08:02:22 +0200 mav r275391 : #i10000# adopt for linux 2009-08-26 07:40:30 +0200 mav r275390 : #i10000# fix warning 2009-08-26 07:35:28 +0200 mav r275389 : #i10000# use correct include file name 2009-08-25 15:01:41 +0200 jl r275356 : #i103989# better check for mimetype of streams 2009-08-25 09:07:09 +0200 mav r275335 : CWS-TOOLING: rebase CWS encsig09 to trunk@274622 (milestone: DEV300:m54) 2009-08-24 18:17:02 +0200 mav r275329 : #i103927# check the nonencrypted streams 2009-08-24 18:14:14 +0200 mav r275328 : #i103927# check the nonencrypted streams 2009-08-24 17:59:34 +0200 mav r275327 : #i103927#,#i104389# check the package consistency and nonencrypted streams 2009-08-24 16:18:28 +0200 jl r275323 : #i103989# added comment 2009-08-24 13:08:47 +0200 jl r275305 : #i45212# #i66276# only write the X509Certificate element once and allow to add remove several certificates at a time 2009-08-21 12:57:28 +0200 ufi r275239 : 104339 2009-08-21 08:39:05 +0200 jl r275213 : #i10398# comparing URIs of signed files with the 'element list' 2009-08-20 13:39:47 +0200 jl r275178 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:35:39 +0200 jl r275177 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:29:06 +0200 jl r275176 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:26:21 +0200 jl r275175 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 12:05:09 +0200 ufi r275170 : i104339 2009-08-19 12:24:54 +0200 jl r275146 : #i10398# displaying 'old signature' icon and status in signature dialog 2009-08-18 15:18:48 +0200 jl r275111 : #i103989# document signatures containing manifest.xml are now validated according to the final ODF1.2 spec 2009-08-18 11:41:06 +0200 mav r275087 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams 2009-08-18 11:35:13 +0200 mav r275085 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams 2009-08-14 17:32:41 +0200 jl r274999 : #i103989# using c14n tranformation for XML streams 2009-08-14 15:27:43 +0200 jl r274987 : #i103989# remove special handling for encrypted document streams in UriBindingHelper::OpenInputStream, since we use zip storage this is not necessary anymore 2009-08-14 15:08:10 +0200 jl r274983 : #i103989# Showing a message when adding or removing a macro signature, that the document signature will be removed 2009-08-14 14:57:27 +0200 jl r274982 : #i103989# accesing Sequence at invalid index 2009-08-11 08:55:02 +0200 mav r274846 : #i103905# let signing service know if there is already a valid document signature 2009-08-10 11:33:37 +0200 jl r274799 : #i103905# do not truncate the stream 2009-08-10 10:43:47 +0200 mav r274797 : #i103905# provide the storage version 2009-08-07 16:58:46 +0200 jl r274780 : #i103989# 2009-08-07 16:56:19 +0200 jl r274779 : #i103989# using odf version string etc. 2009-08-07 15:20:53 +0200 mav r274771 : #i103905# provide the storage version 2009-08-07 15:19:12 +0200 mav r274770 : #i103905# provide the storage version 2009-08-07 12:41:45 +0200 mav r274758 : #103930# do not store thumbnail in case of encrypted document 2009-08-07 12:36:52 +0200 mav r274757 : #i103905# provide the storage version 2009-08-07 12:15:54 +0200 mav r274754 : #i103760# the signed state is not lost on saving 2009-08-07 12:06:19 +0200 mav r274753 : #i103760# avoid warning regarding signature removal on export 2009-08-07 12:06:01 +0200 mav r274752 : #i103760# avoid warning regarding signature removal on export 2009-08-06 08:47:34 +0200 mav r274703 : #i103905# allow to transport ODF version to the signing component 2009-08-05 21:34:42 +0200 mav r274701 : #i103905# allow to transport ODF version to the signing component 2009-08-05 15:48:17 +0200 mav r274683 : #i103905# allow to transport ODF version to the signing component 2009-08-05 14:58:12 +0200 jl r274673 : #i103989# documentsignature now signes all streams except documentsignatures.xml, all streams are processed as binary files 2009-08-05 12:00:32 +0200 mav r274648 : #i103905# allow to transport ODF version to the signing component 2009-08-04 10:57:04 +0200 jl r274612 : #i103989# added XInitialization 2009-07-31 10:32:27 +0200 mav r274516 : #i103905# use zip storage to sign documents 2009-07-30 14:01:33 +0200 mav r274489 : #i103906# optimize the usage of temporary medium 2009-07-30 14:00:28 +0200 mav r274488 : #i103906# optimize the usage of temporary medium 2009-07-30 13:59:09 +0200 mav r274487 : #i103906# optimize the usage of temporary medium 2009-07-30 13:50:44 +0200 mav r274485 : #i103906# optimize the usage of temporary medium 2009-07-30 13:49:53 +0200 mav r274484 : #i103906# optimize the usage of temporary medium 2009-07-30 13:49:13 +0200 mav r274483 : #i103906# optimize the usage of temporary medium 2009-07-30 13:47:09 +0200 mav r274482 : #i103905#,#i103906# let the signing process use zip-storage; optimize the usage of temporary medium 2009-07-21 09:10:31 +0200 mav r274159 : CWS-TOOLING: rebase CWS encsig09 to trunk@273468 (milestone: DEV300:m51) 2009-05-05 08:39:01 +0200 mav r271496 : #i100832# allow to sign macros only when there are any
Diffstat (limited to 'xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx')
-rw-r--r--xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx398
1 files changed, 284 insertions, 114 deletions
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index 6be6a261e..94a29d49a 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -48,13 +48,19 @@
#include <com/sun/star/security/CertificateValidity.hdl>
#include <com/sun/star/packages/WrongPasswordException.hpp>
#include <com/sun/star/security/SerialNumberAdapter.hpp>
+#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
+#include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
+#include <com/sun/star/packages/manifest/XManifestReader.hpp>
+
#include <rtl/ustrbuf.hxx>
+#include <rtl/uri.hxx>
#include <tools/date.hxx>
#include <tools/time.hxx>
#include "dialogs.hrc"
+#include "digitalsignaturesdialog.hrc"
#include "helpids.hrc"
#include "resourcemanager.hxx"
@@ -62,18 +68,20 @@
#include <unotools/configitem.hxx>
#include <comphelper/componentcontext.hxx>
+#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
-using namespace ::com::sun::star::security;
-namespace css = ::com::sun::star;
/* HACK: disable some warnings for MS-C */
#ifdef _MSC_VER
#pragma warning (disable : 4355) // 4355: this used in initializer-list
#endif
+using namespace ::com::sun::star::security;
+using namespace ::com::sun::star::uno;
using namespace ::com::sun::star;
-using ::com::sun::star::uno::Sequence;
+namespace css = ::com::sun::star;
using ::rtl::OUString;
+
namespace
{
class SaveODFItem: public utl::ConfigItem
@@ -109,49 +117,70 @@ namespace
OUString(RTL_CONSTASCII_USTRINGPARAM(
"[xmlsecurity] Could not open property Office.Common/Save/ODF/DefaultVersion")), 0);
}
-
}
-sal_Bool HandleStreamAsXML_Impl( const uno::Reference < embed::XStorage >& rxStore, const rtl::OUString& rURI )
+/* Using the zip storage, we cannot get the properties "MediaType" and "IsEncrypted"
+ We use the manifest to find out if a file is xml and if it is encrypted.
+ The parameter is an encoded uri. However, the manifest contains paths. Therefore
+ the path is encoded as uri, so they can be compared.
+*/
+bool DigitalSignaturesDialog::isXML(const rtl::OUString& rURI )
{
- sal_Bool bResult = sal_False;
+ OSL_ASSERT(mxStore.is());
- try
+ bool bIsXML = false;
+ bool bPropsAvailable = false;
+ const OUString sPropFullPath(RTL_CONSTASCII_USTRINGPARAM("FullPath"));
+ const OUString sPropMediaType(RTL_CONSTASCII_USTRINGPARAM("MediaType"));
+ const OUString sPropDigest(RTL_CONSTASCII_USTRINGPARAM("Digest"));
+
+ for (int i = 0; i < m_manifest.getLength(); i++)
{
- sal_Int32 nSepPos = rURI.indexOf( '/' );
- if ( nSepPos == -1 )
+ Any digest;
+ const Sequence< css::beans::PropertyValue >& entry = m_manifest[i];
+ OUString sPath, sMediaType;
+ bool bEncrypted = false;
+ for (int j = 0; j < entry.getLength(); j++)
{
- uno::Reference< io::XStream > xStream;
- xStream = rxStore->cloneStreamElement( rURI );
- if ( !xStream.is() )
- throw uno::RuntimeException();
-
- ::rtl::OUString aMediaType;
- sal_Bool bEncrypted = sal_False;
- uno::Reference< beans::XPropertySet > xProps( xStream, uno::UNO_QUERY_THROW );
- xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= aMediaType;
- xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsEncrypted" ) ) ) >>= bEncrypted;
- bResult = ( aMediaType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/xml" ) ) ) && !bEncrypted );
+ const css::beans::PropertyValue & prop = entry[j];
+
+ if (prop.Name.equals( sPropFullPath ) )
+ prop.Value >>= sPath;
+ else if (prop.Name.equals( sPropMediaType ) )
+ prop.Value >>= sMediaType;
+ else if (prop.Name.equals( sPropDigest ) )
+ bEncrypted = true;
}
- else
+ if (DocumentSignatureHelper::equalsReferenceUriManifestPath(rURI, sPath))
{
- rtl::OUString aStoreName = rURI.copy( 0, nSepPos );
- rtl::OUString aElement = rURI.copy( nSepPos+1 );
- uno::Reference < embed::XStorage > xSubStore = rxStore->openStorageElement( aStoreName, embed::ElementModes::READ );
- bResult = HandleStreamAsXML_Impl( xSubStore, aElement );
+ bIsXML = sMediaType.equals(OUSTR("text/xml")) && ! bEncrypted;
+ bPropsAvailable = true;
+ break;
}
}
- catch( uno::Exception& )
+ if (!bPropsAvailable)
{
- }
-
- return bResult;
+ //This would be the case for at least mimetype, META-INF/manifest.xml
+ //META-INF/macrosignatures.xml.
+ //Files can only be encrypted if they are in the manifest.xml.
+ //That is, the current file cannot be encrypted, otherwise bPropsAvailable
+ //would be true.
+ OUString aXMLExt( RTL_CONSTASCII_USTRINGPARAM( "XML" ) );
+ sal_Int32 nSep = rURI.lastIndexOf( '.' );
+ if ( nSep != (-1) )
+ {
+ OUString aExt = rURI.copy( nSep+1 );
+ if (aExt.equalsIgnoreAsciiCase(aXMLExt ))
+ bIsXML = true;
+ }
+ }
+ return bIsXML;
}
DigitalSignaturesDialog::DigitalSignaturesDialog(
Window* pParent,
uno::Reference< uno::XComponentContext >& rxCtx, DocumentSignatureMode eMode,
- sal_Bool bReadOnly)
+ sal_Bool bReadOnly, const ::rtl::OUString& sODFVersion, bool bHasDocumentSignature)
:ModalDialog ( pParent, XMLSEC_RES( RID_XMLSECDLG_DIGSIG ) )
,mxCtx ( rxCtx )
,maSignatureHelper ( rxCtx )
@@ -166,6 +195,7 @@ DigitalSignaturesDialog::DigitalSignaturesDialog(
,maSigsInvalidFI ( this, XMLSEC_RES( FI_STATE_BROKEN ) )
,maSigsNotvalidatedImg( this, XMLSEC_RES( IMG_STATE_NOTVALIDATED ) )
,maSigsNotvalidatedFI ( this, XMLSEC_RES( FI_STATE_NOTVALIDATED ) )
+ ,maSigsOldSignatureFI ( this, XMLSEC_RES( FI_STATE_OLDSIGNATURE) )
,maViewBtn ( this, XMLSEC_RES( BTN_VIEWCERT ) )
,maAddBtn ( this, XMLSEC_RES( BTN_ADDCERT ) )
,maRemoveBtn ( this, XMLSEC_RES( BTN_REMOVECERT ) )
@@ -173,6 +203,9 @@ DigitalSignaturesDialog::DigitalSignaturesDialog(
,maOKBtn ( this, XMLSEC_RES( BTN_OK ) )
,maCancelBtn ( this, XMLSEC_RES( BTN_CANCEL ) )
,maHelpBtn ( this, XMLSEC_RES( BTN_HELP ) )
+ ,m_sODFVersion (sODFVersion)
+ ,m_bHasDocumentSignature(bHasDocumentSignature)
+ ,m_bWarningShowSignMacro(false)
{
// --> PB #i48253 the tablistbox needs its own unique id
maSignaturesLB.Window::SetUniqueId( HID_XMLSEC_TREE_SIGNATURESDLG );
@@ -209,6 +242,8 @@ DigitalSignaturesDialog::DigitalSignaturesDialog(
maRemoveBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, RemoveButtonHdl ) );
maRemoveBtn.Disable();
+ maOKBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, OKButtonHdl) );
+
switch( meSignatureMode )
{
case SignatureModeDocumentContent: maHintDocFT.Show(); break;
@@ -220,6 +255,7 @@ DigitalSignaturesDialog::DigitalSignaturesDialog(
XmlSec::AlignAndFitImageAndControl( maSigsValidImg, maSigsValidFI, 5 );
XmlSec::AlignAndFitImageAndControl( maSigsInvalidImg, maSigsInvalidFI, 5 );
XmlSec::AlignAndFitImageAndControl( maSigsNotvalidatedImg, maSigsNotvalidatedFI, 5 );
+ XmlSec::AlignAndFitImageAndControl( maSigsNotvalidatedImg, maSigsOldSignatureFI, 5 );
}
DigitalSignaturesDialog::~DigitalSignaturesDialog()
@@ -243,7 +279,21 @@ BOOL DigitalSignaturesDialog::Init( const rtl::OUString& rTokenName )
void DigitalSignaturesDialog::SetStorage( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rxStore )
{
mxStore = rxStore;
- maSignatureHelper.SetStorage( mxStore );
+ maSignatureHelper.SetStorage( mxStore, m_sODFVersion);
+
+ Reference < css::packages::manifest::XManifestReader > xReader(
+ mxCtx->getServiceManager()->createInstanceWithContext(
+ OUSTR("com.sun.star.packages.manifest.ManifestReader"), mxCtx), UNO_QUERY_THROW);
+
+ //Get the manifest.xml
+ Reference < css::embed::XStorage > xSubStore(rxStore->openStorageElement(
+ OUSTR("META-INF"), css::embed::ElementModes::READ), UNO_QUERY_THROW);
+
+ Reference< css::io::XInputStream > xStream(
+ xSubStore->openStreamElement(OUSTR("manifest.xml"), css::embed::ElementModes::READ),
+ UNO_QUERY_THROW);
+
+ m_manifest = xReader->readManifestSequence(xStream);
}
void DigitalSignaturesDialog::SetSignatureStream( const cssu::Reference < css::io::XStream >& rxStream )
@@ -251,40 +301,70 @@ void DigitalSignaturesDialog::SetSignatureStream( const cssu::Reference < css::i
mxSignatureStream = rxStream;
}
-
-bool DigitalSignaturesDialog::canAdd()
+bool DigitalSignaturesDialog::canAddRemove()
{
- bool ret = false;
+ //m56
+ bool ret = true;
OSL_ASSERT(mxStore.is());
- bool bDoc1_1 = DocumentSignatureHelper::isODFPre_1_2(mxStore);
+ bool bDoc1_1 = DocumentSignatureHelper::isODFPre_1_2(m_sODFVersion);
SaveODFItem item;
bool bSave1_1 = item.isLessODF1_2();
// see specification
//cvs: specs/www/appwide/security/Electronic_Signatures_and_Security.sxw
//Paragraph 'Behavior with regard to ODF 1.2'
+ //For both, macro and document
if ( (!bSave1_1 && bDoc1_1) || (bSave1_1 && bDoc1_1) )
{
//#4
ErrorBox err(NULL, XMLSEC_RES(RID_XMLSECDLG_OLD_ODF_FORMAT));
err.Execute();
+ ret = false;
}
- else
- ret = true;
+ //As of OOo 3.2 the document signature includes in macrosignatures.xml. That is
+ //adding a macro signature will break an existing document signature.
+ //The sfx2 will remove the documentsignature when the user adds a macro signature
+ if (meSignatureMode == SignatureModeMacros
+ && ret)
+ {
+ if (m_bHasDocumentSignature && !m_bWarningShowSignMacro)
+ {
+ //The warning says that the document signatures will be removed if the user
+ //continues. He can then either press 'OK' or 'NO'
+ //It the user presses 'Add' or 'Remove' several times then, then the warning
+ //is shown every time until the user presses 'OK'. From then on, the warning
+ //is not displayed anymore as long as the signatures dialog is alive.
+ if (QueryBox(
+ NULL, XMLSEC_RES(MSG_XMLSECDLG_QUERY_REMOVEDOCSIGNBEFORESIGN)).Execute() == RET_NO)
+ ret = false;
+ else
+ m_bWarningShowSignMacro = true;
+
+ }
+ }
return ret;
+}
+
+bool DigitalSignaturesDialog::canAdd()
+{
+ if (canAddRemove())
+ return true;
+ return false;
}
bool DigitalSignaturesDialog::canRemove()
{
- return canAdd();
+ if (canAddRemove())
+ return true;
+ return false;
}
short DigitalSignaturesDialog::Execute()
{
// Verify Signatures and add certificates to ListBox...
mbVerifySignatures = true;
- ImplGetSignatureInformations();
+ ImplGetSignatureInformations(false);
ImplFillSignaturesBox();
// Only verify once, content will not change.
@@ -304,6 +384,35 @@ IMPL_LINK( DigitalSignaturesDialog, SignatureHighlightHdl, void*, EMPTYARG )
return 0;
}
+IMPL_LINK( DigitalSignaturesDialog, OKButtonHdl, void*, EMPTYARG )
+{
+ // Export all other signatures...
+ SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(
+ embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, false );
+ uno::Reference< io::XOutputStream > xOutputStream(
+ aStreamHelper.xSignatureStream, uno::UNO_QUERY );
+ uno::Reference< com::sun::star::xml::sax::XDocumentHandler> xDocumentHandler =
+ maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream );
+
+ int nInfos = maCurrentSignatureInformations.size();
+ for( int n = 0 ; n < nInfos ; ++n )
+ maSignatureHelper.ExportSignature(
+ xDocumentHandler, maCurrentSignatureInformations[ n ] );
+
+ maSignatureHelper.CloseDocumentHandler( xDocumentHandler);
+
+ // If stream was not provided, we are responsible for committing it....
+ if ( !mxSignatureStream.is() )
+ {
+ uno::Reference< embed::XTransactedObject > xTrans(
+ aStreamHelper.xSignatureStorage, uno::UNO_QUERY );
+ xTrans->commit();
+ }
+
+ EndDialog(RET_OK);
+ return 0;
+}
+
IMPL_LINK( DigitalSignaturesDialog, SignatureSelectHdl, void*, EMPTYARG )
{
ImplShowSignaturesDetails();
@@ -353,34 +462,33 @@ IMPL_LINK( DigitalSignaturesDialog, AddButtonHdl, Button*, EMPTYARG )
xCert->getIssuerName(), aCertSerial,
aStrBuffer.makeStringAndClear());
-
- std::vector< rtl::OUString > aElements = DocumentSignatureHelper::CreateElementList( mxStore, rtl::OUString(), meSignatureMode );
+ std::vector< rtl::OUString > aElements =
+ DocumentSignatureHelper::CreateElementList(
+ mxStore, rtl::OUString(), meSignatureMode, OOo3_2Document);
- ::rtl::OUString aXMLExt( RTL_CONSTASCII_USTRINGPARAM( "XML" ) );
sal_Int32 nElements = aElements.size();
for ( sal_Int32 n = 0; n < nElements; n++ )
{
- bool bBinaryMode = true;
- sal_Int32 nSep = aElements[n].lastIndexOf( '.' );
- if ( nSep != (-1) )
- {
- ::rtl::OUString aExt = aElements[n].copy( nSep+1 );
- if ( aExt.equalsIgnoreAsciiCase( aXMLExt ) )
- {
- bBinaryMode = !HandleStreamAsXML_Impl( mxStore, aElements[n] );
- }
- }
+ bool bBinaryMode = !isXML(aElements[n]);
maSignatureHelper.AddForSigning( nSecurityId, aElements[n], aElements[n], bBinaryMode );
}
maSignatureHelper.SetDateTime( nSecurityId, Date(), Time() );
- SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream( embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE );
- uno::Reference< io::XOutputStream > xOutputStream( aStreamHelper.xSignatureStream, uno::UNO_QUERY );
- uno::Reference< com::sun::star::xml::sax::XDocumentHandler> xDocumentHandler = maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream );
+ // We open a signature stream in which the existing and the new
+ //signature is written. ImplGetSignatureInformation (later in this function) will
+ //then read the stream an will fill maCurrentSignatureInformations. The final signature
+ //is written when the user presses OK. Then only maCurrentSignatureInformation and
+ //a sax writer are used to write the information.
+ SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(
+ css::embed::ElementModes::WRITE|css::embed::ElementModes::TRUNCATE, true);
+ Reference< css::io::XOutputStream > xOutputStream(
+ aStreamHelper.xSignatureStream, UNO_QUERY_THROW);
+ Reference< css::xml::sax::XDocumentHandler> xDocumentHandler =
+ maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream );
// Export old signatures...
- int nInfos = maCurrentSignatureInformations.size();
+ int nInfos = maCurrentSignatureInformations.size();
for ( int n = 0; n < nInfos; n++ )
maSignatureHelper.ExportSignature( xDocumentHandler, maCurrentSignatureInformations[n]);
@@ -392,14 +500,9 @@ IMPL_LINK( DigitalSignaturesDialog, AddButtonHdl, Button*, EMPTYARG )
maSignatureHelper.EndMission();
- // If stream was not provided, we are responsible for committing it....
- if ( !mxSignatureStream.is() )
- {
- uno::Reference< embed::XTransactedObject > xTrans( aStreamHelper.xSignatureStorage, uno::UNO_QUERY );
- xTrans->commit();
- }
-
aStreamHelper = SignatureStreamHelper(); // release objects...
+
+ mbSignaturesChanged = true;
sal_Int32 nStatus = maSignatureHelper.GetSignatureInformation( nSecurityId ).nStatus;
@@ -412,7 +515,7 @@ IMPL_LINK( DigitalSignaturesDialog, AddButtonHdl, Button*, EMPTYARG )
// will not contain
// SecurityOperationStatus_OPERATION_SUCCEEDED
mbVerifySignatures = true;
- ImplGetSignatureInformations();
+ ImplGetSignatureInformations(true);
ImplFillSignaturesBox();
}
}
@@ -421,7 +524,7 @@ IMPL_LINK( DigitalSignaturesDialog, AddButtonHdl, Button*, EMPTYARG )
{
DBG_ERROR( "Exception while adding a signature!" );
// Don't keep invalid entries...
- ImplGetSignatureInformations();
+ ImplGetSignatureInformations(true);
ImplFillSignaturesBox();
}
@@ -440,9 +543,12 @@ IMPL_LINK( DigitalSignaturesDialog, RemoveButtonHdl, Button*, EMPTYARG )
maCurrentSignatureInformations.erase( maCurrentSignatureInformations.begin()+nSelected );
// Export all other signatures...
- SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream( embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE );
- uno::Reference< io::XOutputStream > xOutputStream( aStreamHelper.xSignatureStream, uno::UNO_QUERY );
- uno::Reference< com::sun::star::xml::sax::XDocumentHandler> xDocumentHandler = maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream );
+ SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(
+ css::embed::ElementModes::WRITE | css::embed::ElementModes::TRUNCATE, true);
+ Reference< css::io::XOutputStream > xOutputStream(
+ aStreamHelper.xSignatureStream, UNO_QUERY_THROW);
+ Reference< css::xml::sax::XDocumentHandler> xDocumentHandler =
+ maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream );
int nInfos = maCurrentSignatureInformations.size();
for( int n = 0 ; n < nInfos ; ++n )
@@ -452,13 +558,6 @@ IMPL_LINK( DigitalSignaturesDialog, RemoveButtonHdl, Button*, EMPTYARG )
mbSignaturesChanged = true;
- // If stream was not provided, we are responsible for committing it....
- if ( !mxSignatureStream.is() )
- {
- uno::Reference< embed::XTransactedObject > xTrans( aStreamHelper.xSignatureStorage, uno::UNO_QUERY );
- xTrans->commit();
- }
-
aStreamHelper = SignatureStreamHelper(); // release objects...
ImplFillSignaturesBox();
@@ -467,7 +566,7 @@ IMPL_LINK( DigitalSignaturesDialog, RemoveButtonHdl, Button*, EMPTYARG )
{
DBG_ERROR( "Exception while removing a signature!" );
// Don't keep invalid entries...
- ImplGetSignatureInformations();
+ ImplGetSignatureInformations(true);
ImplFillSignaturesBox();
}
}
@@ -493,12 +592,18 @@ void DigitalSignaturesDialog::ImplFillSignaturesBox()
String aNullStr;
int nInfos = maCurrentSignatureInformations.size();
int nValidSigs = 0, nValidCerts = 0;
+ bool bAllNewSignatures = true;
if( nInfos )
{
- std::vector< rtl::OUString > aElementsToBeVerified = DocumentSignatureHelper::CreateElementList( mxStore, ::rtl::OUString(), meSignatureMode );
for( int n = 0; n < nInfos; ++n )
{
+ DocumentSignatureAlgorithm mode = DocumentSignatureHelper::getDocumentAlgorithm(
+ m_sODFVersion, maCurrentSignatureInformations[n]);
+ std::vector< rtl::OUString > aElementsToBeVerified =
+ DocumentSignatureHelper::CreateElementList(
+ mxStore, ::rtl::OUString(), meSignatureMode, mode);
+
const SignatureInformation& rInfo = maCurrentSignatureInformations[n];
//First we try to get the certificate which is embedded in the XML Signature
if (rInfo.ouX509Certificate.getLength())
@@ -559,29 +664,43 @@ void DigitalSignaturesDialog::ImplFillSignaturesBox()
if ( bSigValid )
{
- // Can only be valid if ALL streams are signed, which means real stream count == signed stream count
- unsigned int nRealCount = 0;
- for ( int i = rInfo.vSignatureReferenceInfors.size(); i; )
- {
- const SignatureReferenceInformation& rInf = rInfo.vSignatureReferenceInfors[--i];
- // There is also an extra entry of type TYPE_SAMEDOCUMENT_REFERENCE because of signature date.
- if ( ( rInf.nType == TYPE_BINARYSTREAM_REFERENCE ) || ( rInf.nType == TYPE_XMLSTREAM_REFERENCE ) )
- nRealCount++;
- }
- bSigValid = ( aElementsToBeVerified.size() == nRealCount );
+ bSigValid = DocumentSignatureHelper::checkIfAllFilesAreSigned(
+ aElementsToBeVerified, rInfo, mode);
if( bSigValid )
nValidSigs++;
}
-
+
Image aImage;
- if ( bSigValid && bCertValid )
- aImage = maSigsValidImg.GetImage();
- else if ( bSigValid && !bCertValid )
- aImage = maSigsNotvalidatedImg.GetImage();
- else if ( !bSigValid )
+ if (!bSigValid)
+ {
aImage = maSigsInvalidImg.GetImage();
-
+ }
+ else if (bSigValid && !bCertValid)
+ {
+ aImage = maSigsNotvalidatedImg.GetImage();
+ }
+ //Check if the signature is a "old" document signature, that is, which was created
+ //by an version of OOo previous to 3.2
+ else if (meSignatureMode == SignatureModeDocumentContent
+ && bSigValid && bCertValid && !DocumentSignatureHelper::isOOo3_2_Signature(
+ maCurrentSignatureInformations[n]))
+ {
+ aImage = maSigsNotvalidatedImg.GetImage();
+ bAllNewSignatures &= false;
+ }
+ else if (meSignatureMode == SignatureModeDocumentContent
+ && bSigValid && bCertValid && DocumentSignatureHelper::isOOo3_2_Signature(
+ maCurrentSignatureInformations[n]))
+ {
+ aImage = maSigsValidImg.GetImage();
+ }
+ else if (meSignatureMode == SignatureModeMacros
+ && bSigValid && bCertValid)
+ {
+ aImage = aImage = maSigsValidImg.GetImage();
+ }
+
SvLBoxEntry* pEntry = maSignaturesLB.InsertEntry( aNullStr, aImage, aImage );
maSignaturesLB.SetEntryText( aSubject, pEntry, 1 );
maSignaturesLB.SetEntryText( aIssuer, pEntry, 2 );
@@ -590,28 +709,37 @@ void DigitalSignaturesDialog::ImplFillSignaturesBox()
}
}
- bool bAllSigsValid = ( nValidSigs == nInfos );
- bool bAllCertsValid = ( nValidCerts == nInfos );
- bool bShowValidState = nInfos && ( bAllSigsValid && bAllCertsValid );
- bool bShowNotValidatedState = nInfos && ( bAllSigsValid && !bAllCertsValid );
+ bool bAllSigsValid = (nValidSigs == nInfos);
+ bool bAllCertsValid = (nValidCerts == nInfos);
+ bool bShowValidState = nInfos && (bAllSigsValid && bAllCertsValid && bAllNewSignatures);
+
+ bool bShowNotValidatedState = nInfos && (bAllSigsValid && (!bAllCertsValid || !bAllNewSignatures));
bool bShowInvalidState = nInfos && !bAllSigsValid;
- maSigsValidImg.Show( bShowValidState );
+
+ maSigsValidImg.Show( bShowValidState);
maSigsValidFI.Show( bShowValidState );
maSigsInvalidImg.Show( bShowInvalidState );
maSigsInvalidFI.Show( bShowInvalidState );
- maSigsNotvalidatedImg.Show( bShowNotValidatedState );
- maSigsNotvalidatedFI.Show( bShowNotValidatedState );
+
+ maSigsNotvalidatedImg.Show(bShowNotValidatedState);
+ //bAllNewSignatures is always true if we are not in document mode
+ maSigsNotvalidatedFI.Show(nInfos && bAllSigsValid && ! bAllCertsValid);
+ maSigsOldSignatureFI.Show(nInfos && bAllSigsValid && bAllCertsValid && !bAllNewSignatures);
SignatureHighlightHdl( NULL );
}
-void DigitalSignaturesDialog::ImplGetSignatureInformations()
+
+//If bUseTempStream is true then the temporary signature stream is used.
+//Otherwise the real signature stream is used.
+void DigitalSignaturesDialog::ImplGetSignatureInformations(bool bUseTempStream)
{
maCurrentSignatureInformations.clear();
maSignatureHelper.StartMission();
- SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream( embed::ElementModes::READ );
+ SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(
+ css::embed::ElementModes::READ, bUseTempStream);
if ( aStreamHelper.xSignatureStream.is() )
{
uno::Reference< io::XInputStream > xInputStream( aStreamHelper.xSignatureStream, uno::UNO_QUERY );
@@ -651,30 +779,72 @@ void DigitalSignaturesDialog::ImplShowSignaturesDetails()
}
}
-SignatureStreamHelper DigitalSignaturesDialog::ImplOpenSignatureStream( sal_Int32 nStreamOpenMode )
+//If bTempStream is true, then a temporary stream is return. If it is false then, the actual
+//signature stream is used.
+//Everytime the user presses Add a new temporary stream is created.
+//We keep the temporary stream as member because ImplGetSignatureInformations
+//will later access the stream to create DocumentSignatureInformation objects
+//which are stored in maCurrentSignatureInformations.
+SignatureStreamHelper DigitalSignaturesDialog::ImplOpenSignatureStream(
+ sal_Int32 nStreamOpenMode, bool bTempStream)
{
SignatureStreamHelper aHelper;
- if ( !mxSignatureStream.is() )
+ if (bTempStream)
{
- aHelper = DocumentSignatureHelper::OpenSignatureStream( mxStore, nStreamOpenMode, meSignatureMode );
+ if (nStreamOpenMode & css::embed::ElementModes::TRUNCATE)
+ {
+ //We write always into a new temporary stream.
+ mxTempSignatureStream = Reference < css::io::XStream >(
+ mxCtx->getServiceManager()->createInstanceWithContext(
+ OUSTR( "com.sun.star.io.TempFile" ), mxCtx) ,
+ UNO_QUERY_THROW);
+ aHelper.xSignatureStream = mxTempSignatureStream;
+ }
+ else
+ {
+ //When we read from the temp stream, then we must have previously
+ //created one.
+ OSL_ASSERT(mxTempSignatureStream.is());
+ }
+ aHelper.xSignatureStream = mxTempSignatureStream;
}
else
{
- aHelper.xSignatureStream = mxSignatureStream;
- if ( nStreamOpenMode & embed::ElementModes::TRUNCATE )
+ //No temporary stream
+ if (!mxSignatureStream.is())
{
- css::uno::Reference < css::io::XTruncate > xTruncate( mxSignatureStream, uno::UNO_QUERY );
- DBG_ASSERT( xTruncate.is(), "ImplOpenSignatureStream - Stream does not support xTruncate!" );
- xTruncate->truncate();
+ //We may not have a dedicated stream for writing the signature
+ //So we take one directly from the storage
+ //Or DocumentDigitalSignatures::showDocumentContentSignatures was called,
+ //in which case Add/Remove is not allowed. This is done, for example, if the
+ //document is readonly
+ aHelper = DocumentSignatureHelper::OpenSignatureStream(
+ mxStore, nStreamOpenMode, meSignatureMode );
}
else
{
- css::uno::Reference < css::io::XSeekable > xSeek( mxSignatureStream, uno::UNO_QUERY );
- DBG_ASSERT( xSeek.is(), "ImplOpenSignatureStream - Stream does not support xSeekable!" );
- xSeek->seek( 0 );
+ aHelper.xSignatureStream = mxSignatureStream;
}
}
+ if (nStreamOpenMode & css::embed::ElementModes::TRUNCATE)
+ {
+ css::uno::Reference < css::io::XTruncate > xTruncate(
+ aHelper.xSignatureStream, UNO_QUERY_THROW);
+ DBG_ASSERT( xTruncate.is(), "ImplOpenSignatureStream - Stream does not support xTruncate!" );
+ xTruncate->truncate();
+ }
+ else if ( bTempStream || mxSignatureStream.is())
+ {
+ //In case we read the signature stream from the storage directly,
+ //which is the case when DocumentDigitalSignatures::showDocumentContentSignatures
+ //then XSeakable is not supported
+ css::uno::Reference < css::io::XSeekable > xSeek(
+ aHelper.xSignatureStream, UNO_QUERY_THROW);
+ DBG_ASSERT( xSeek.is(), "ImplOpenSignatureStream - Stream does not support xSeekable!" );
+ xSeek->seek( 0 );
+ }
+
return aHelper;
}