1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: digitalsignaturesdialog.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
33 #include <xmlsecurity/digitalsignaturesdialog.hxx>
34 #include <xmlsecurity/certificatechooser.hxx>
35 #include <xmlsecurity/certificateviewer.hxx>
36 #include <xmlsecurity/biginteger.hxx>
37 #include <xmloff/xmluconv.hxx>
38 #include <com/sun/star/embed/XStorage.hpp>
39 #include <com/sun/star/embed/ElementModes.hpp>
40 #include <com/sun/star/io/XSeekable.hpp>
41 #include <com/sun/star/io/XTruncate.hpp>
42 #include <com/sun/star/embed/XTransactedObject.hpp>
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <com/sun/star/lang/XComponent.hpp>
45 #include <com/sun/star/security/NoPasswordException.hpp>
46 #include <com/sun/star/lang/DisposedException.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/security/CertificateValidity.hdl>
49 #include <com/sun/star/packages/WrongPasswordException.hpp>
50 #include <com/sun/star/security/SerialNumberAdapter.hpp>
52 #include <rtl/ustrbuf.hxx>
54 #include <tools/date.hxx>
55 #include <tools/time.hxx>
57 #include "dialogs.hrc"
58 #include "helpids.hrc"
59 #include "resourcemanager.hxx"
61 #include <vcl/msgbox.hxx> // Until encrypted docs work...
62 #include <unotools/configitem.hxx>
63 #include <comphelper/componentcontext.hxx>
66 using namespace ::com::sun::star::security
;
67 namespace css
= ::com::sun::star
;
69 /* HACK: disable some warnings for MS-C */
71 #pragma warning (disable : 4355) // 4355: this used in initializer-list
74 using namespace ::com::sun::star
;
75 using ::com::sun::star::uno::Sequence
;
76 using ::rtl::OUString
;
79 class SaveODFItem
: public utl::ConfigItem
84 //See group ODF in Common.xcs
91 SaveODFItem::SaveODFItem(): utl::ConfigItem(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
92 "Office.Common/Save"))), m_nODF(0)
94 OUString
sDef(RTL_CONSTASCII_USTRINGPARAM("ODF/DefaultVersion"));
95 Sequence
< css::uno::Any
> aValues
= GetProperties( Sequence
<OUString
>(&sDef
,1) );
96 if ( aValues
.getLength() == 1)
99 if ( aValues
[0] >>= nTmp
)
102 throw uno::RuntimeException(
103 OUString(RTL_CONSTASCII_USTRINGPARAM(
104 "[xmlsecurity]SaveODFItem::SaveODFItem(): Wrong Type!")), 0 );
108 throw uno::RuntimeException(
109 OUString(RTL_CONSTASCII_USTRINGPARAM(
110 "[xmlsecurity] Could not open property Office.Common/Save/ODF/DefaultVersion")), 0);
115 sal_Bool
HandleStreamAsXML_Impl( const uno::Reference
< embed::XStorage
>& rxStore
, const rtl::OUString
& rURI
)
117 sal_Bool bResult
= sal_False
;
121 sal_Int32 nSepPos
= rURI
.indexOf( '/' );
124 uno::Reference
< io::XStream
> xStream
;
125 xStream
= rxStore
->cloneStreamElement( rURI
);
127 throw uno::RuntimeException();
129 ::rtl::OUString aMediaType
;
130 sal_Bool bEncrypted
= sal_False
;
131 uno::Reference
< beans::XPropertySet
> xProps( xStream
, uno::UNO_QUERY_THROW
);
132 xProps
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= aMediaType
;
133 xProps
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsEncrypted" ) ) ) >>= bEncrypted
;
134 bResult
= ( aMediaType
.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/xml" ) ) ) && !bEncrypted
);
138 rtl::OUString aStoreName
= rURI
.copy( 0, nSepPos
);
139 rtl::OUString aElement
= rURI
.copy( nSepPos
+1 );
140 uno::Reference
< embed::XStorage
> xSubStore
= rxStore
->openStorageElement( aStoreName
, embed::ElementModes::READ
);
141 bResult
= HandleStreamAsXML_Impl( xSubStore
, aElement
);
144 catch( uno::Exception
& )
151 DigitalSignaturesDialog::DigitalSignaturesDialog(
153 uno::Reference
< uno::XComponentContext
>& rxCtx
, DocumentSignatureMode eMode
,
155 :ModalDialog ( pParent
, XMLSEC_RES( RID_XMLSECDLG_DIGSIG
) )
157 ,maSignatureHelper ( rxCtx
)
158 ,meSignatureMode ( eMode
)
159 ,maHintDocFT ( this, XMLSEC_RES( FT_HINT_DOC
) )
160 ,maHintBasicFT ( this, XMLSEC_RES( FT_HINT_BASIC
) )
161 ,maHintPackageFT ( this, XMLSEC_RES( FT_HINT_PACK
) )
162 ,maSignaturesLB ( this, XMLSEC_RES( LB_SIGNATURES
) )
163 ,maSigsValidImg ( this, XMLSEC_RES( IMG_STATE_VALID
) )
164 ,maSigsValidFI ( this, XMLSEC_RES( FI_STATE_VALID
) )
165 ,maSigsInvalidImg ( this, XMLSEC_RES( IMG_STATE_BROKEN
) )
166 ,maSigsInvalidFI ( this, XMLSEC_RES( FI_STATE_BROKEN
) )
167 ,maSigsNotvalidatedImg( this, XMLSEC_RES( IMG_STATE_NOTVALIDATED
) )
168 ,maSigsNotvalidatedFI ( this, XMLSEC_RES( FI_STATE_NOTVALIDATED
) )
169 ,maViewBtn ( this, XMLSEC_RES( BTN_VIEWCERT
) )
170 ,maAddBtn ( this, XMLSEC_RES( BTN_ADDCERT
) )
171 ,maRemoveBtn ( this, XMLSEC_RES( BTN_REMOVECERT
) )
172 ,maBottomSepFL ( this, XMLSEC_RES( FL_BOTTOM_SEP
) )
173 ,maOKBtn ( this, XMLSEC_RES( BTN_OK
) )
174 ,maCancelBtn ( this, XMLSEC_RES( BTN_CANCEL
) )
175 ,maHelpBtn ( this, XMLSEC_RES( BTN_HELP
) )
177 // --> PB #i48253 the tablistbox needs its own unique id
178 maSignaturesLB
.Window::SetUniqueId( HID_XMLSEC_TREE_SIGNATURESDLG
);
180 static long nTabs
[] = { 4, 0, 6*DS_LB_WIDTH
/100, 36*DS_LB_WIDTH
/100, 74*DS_LB_WIDTH
/100 };
181 maSignaturesLB
.SetTabs( &nTabs
[ 0 ] );
182 maSignaturesLB
.InsertHeaderEntry( String( XMLSEC_RES( STR_HEADERBAR
) ) );
184 maSigsNotvalidatedFI
.SetText( String( XMLSEC_RES( STR_NO_INFO_TO_VERIFY
) ) );
186 if ( GetBackground().GetColor().IsDark() )
188 // high contrast mode needs other images
189 maSigsValidImg
.SetImage( Image( XMLSEC_RES( IMG_STATE_VALID_HC
) ) );
190 maSigsInvalidImg
.SetImage( Image( XMLSEC_RES( IMG_STATE_BROKEN_HC
) ) );
191 maSigsNotvalidatedImg
.SetImage( Image( XMLSEC_RES( IMG_STATE_NOTVALIDATED_HC
) ) );
196 mbVerifySignatures
= true;
197 mbSignaturesChanged
= false;
199 maSignaturesLB
.SetSelectHdl( LINK( this, DigitalSignaturesDialog
, SignatureHighlightHdl
) );
200 maSignaturesLB
.SetDoubleClickHdl( LINK( this, DigitalSignaturesDialog
, SignatureSelectHdl
) );
202 maViewBtn
.SetClickHdl( LINK( this, DigitalSignaturesDialog
, ViewButtonHdl
) );
205 maAddBtn
.SetClickHdl( LINK( this, DigitalSignaturesDialog
, AddButtonHdl
) );
209 maRemoveBtn
.SetClickHdl( LINK( this, DigitalSignaturesDialog
, RemoveButtonHdl
) );
210 maRemoveBtn
.Disable();
212 switch( meSignatureMode
)
214 case SignatureModeDocumentContent
: maHintDocFT
.Show(); break;
215 case SignatureModeMacros
: maHintBasicFT
.Show(); break;
216 case SignatureModePackage
: maHintPackageFT
.Show(); break;
219 // adjust fixed text to images
220 XmlSec::AlignAndFitImageAndControl( maSigsValidImg
, maSigsValidFI
, 5 );
221 XmlSec::AlignAndFitImageAndControl( maSigsInvalidImg
, maSigsInvalidFI
, 5 );
222 XmlSec::AlignAndFitImageAndControl( maSigsNotvalidatedImg
, maSigsNotvalidatedFI
, 5 );
225 DigitalSignaturesDialog::~DigitalSignaturesDialog()
229 BOOL
DigitalSignaturesDialog::Init( const rtl::OUString
& rTokenName
)
231 bool bInit
= maSignatureHelper
.Init( rTokenName
);
233 DBG_ASSERT( bInit
, "Error initializing security context!" );
237 maSignatureHelper
.SetStartVerifySignatureHdl( LINK( this, DigitalSignaturesDialog
, StartVerifySignatureHdl
) );
243 void DigitalSignaturesDialog::SetStorage( const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>& rxStore
)
246 maSignatureHelper
.SetStorage( mxStore
);
249 void DigitalSignaturesDialog::SetSignatureStream( const cssu::Reference
< css::io::XStream
>& rxStream
)
251 mxSignatureStream
= rxStream
;
255 bool DigitalSignaturesDialog::canAdd()
258 OSL_ASSERT(mxStore
.is());
259 bool bDoc1_1
= DocumentSignatureHelper::isODFPre_1_2(mxStore
);
261 bool bSave1_1
= item
.isLessODF1_2();
264 //cvs: specs/www/appwide/security/Electronic_Signatures_and_Security.sxw
265 //Paragraph 'Behavior with regard to ODF 1.2'
266 if ( (!bSave1_1
&& bDoc1_1
) || (bSave1_1
&& bDoc1_1
) )
269 ErrorBox
err(NULL
, XMLSEC_RES(RID_XMLSECDLG_OLD_ODF_FORMAT
));
278 bool DigitalSignaturesDialog::canRemove()
283 short DigitalSignaturesDialog::Execute()
285 // Verify Signatures and add certificates to ListBox...
286 mbVerifySignatures
= true;
287 ImplGetSignatureInformations();
288 ImplFillSignaturesBox();
290 // Only verify once, content will not change.
291 // But for refreshing signature information, StartVerifySignatureHdl will be called after each add/remove
292 mbVerifySignatures
= false;
294 return Dialog::Execute();
297 IMPL_LINK( DigitalSignaturesDialog
, SignatureHighlightHdl
, void*, EMPTYARG
)
299 bool bSel
= maSignaturesLB
.FirstSelected() ? true : false;
300 maViewBtn
.Enable( bSel
);
301 if ( maAddBtn
.IsEnabled() ) // not read only
302 maRemoveBtn
.Enable( bSel
);
307 IMPL_LINK( DigitalSignaturesDialog
, SignatureSelectHdl
, void*, EMPTYARG
)
309 ImplShowSignaturesDetails();
313 IMPL_LINK( DigitalSignaturesDialog
, ViewButtonHdl
, Button
*, EMPTYARG
)
315 ImplShowSignaturesDetails();
319 IMPL_LINK( DigitalSignaturesDialog
, AddButtonHdl
, Button
*, EMPTYARG
)
325 uno::Reference
<com::sun::star::xml::crypto::XSecurityEnvironment
> xSecEnv
= maSignatureHelper
.GetSecurityEnvironment();
327 uno::Reference
<com::sun::star::security::XSerialNumberAdapter
> xSerialNumberAdapter
=
328 ::com::sun::star::security::SerialNumberAdapter::create(mxCtx
);
329 CertificateChooser
aChooser( this, mxCtx
, xSecEnv
, maCurrentSignatureInformations
);
330 if ( aChooser
.Execute() == RET_OK
)
332 uno::Reference
< ::com::sun::star::security::XCertificate
> xCert
= aChooser
.GetSelectedCertificate();
335 DBG_ERRORFILE( "no certificate selected" );
338 rtl::OUString aCertSerial
= xSerialNumberAdapter
->toString( xCert
->getSerialNumber() );
339 if ( !aCertSerial
.getLength() )
341 DBG_ERROR( "Error in Certificate, problem with serial number!" );
345 maSignatureHelper
.StartMission();
347 sal_Int32 nSecurityId
= maSignatureHelper
.GetNewSecurityId();
349 rtl::OUStringBuffer aStrBuffer
;
350 SvXMLUnitConverter::encodeBase64(aStrBuffer
, xCert
->getEncoded());
352 maSignatureHelper
.SetX509Certificate( nSecurityId
,
353 xCert
->getIssuerName(), aCertSerial
,
354 aStrBuffer
.makeStringAndClear());
357 std::vector
< rtl::OUString
> aElements
= DocumentSignatureHelper::CreateElementList( mxStore
, rtl::OUString(), meSignatureMode
);
359 ::rtl::OUString
aXMLExt( RTL_CONSTASCII_USTRINGPARAM( "XML" ) );
360 sal_Int32 nElements
= aElements
.size();
361 for ( sal_Int32 n
= 0; n
< nElements
; n
++ )
363 bool bBinaryMode
= true;
364 sal_Int32 nSep
= aElements
[n
].lastIndexOf( '.' );
367 ::rtl::OUString aExt
= aElements
[n
].copy( nSep
+1 );
368 if ( aExt
.equalsIgnoreAsciiCase( aXMLExt
) )
370 bBinaryMode
= !HandleStreamAsXML_Impl( mxStore
, aElements
[n
] );
373 maSignatureHelper
.AddForSigning( nSecurityId
, aElements
[n
], aElements
[n
], bBinaryMode
);
376 maSignatureHelper
.SetDateTime( nSecurityId
, Date(), Time() );
378 SignatureStreamHelper aStreamHelper
= ImplOpenSignatureStream( embed::ElementModes::WRITE
|embed::ElementModes::TRUNCATE
);
379 uno::Reference
< io::XOutputStream
> xOutputStream( aStreamHelper
.xSignatureStream
, uno::UNO_QUERY
);
380 uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
> xDocumentHandler
= maSignatureHelper
.CreateDocumentHandlerWithHeader( xOutputStream
);
382 // Export old signatures...
383 int nInfos
= maCurrentSignatureInformations
.size();
384 for ( int n
= 0; n
< nInfos
; n
++ )
385 maSignatureHelper
.ExportSignature( xDocumentHandler
, maCurrentSignatureInformations
[n
]);
387 // Create a new one...
388 maSignatureHelper
.CreateAndWriteSignature( xDocumentHandler
);
391 maSignatureHelper
.CloseDocumentHandler( xDocumentHandler
);
393 maSignatureHelper
.EndMission();
395 // If stream was not provided, we are responsible for committing it....
396 if ( !mxSignatureStream
.is() )
398 uno::Reference
< embed::XTransactedObject
> xTrans( aStreamHelper
.xSignatureStorage
, uno::UNO_QUERY
);
402 aStreamHelper
= SignatureStreamHelper(); // release objects...
404 sal_Int32 nStatus
= maSignatureHelper
.GetSignatureInformation( nSecurityId
).nStatus
;
406 if ( nStatus
== ::com::sun::star::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED
)
408 mbSignaturesChanged
= true;
410 // Can't simply remember current information, need parsing for getting full information :(
411 // We need to verify the signatures again, otherwise the status in the signature information
413 // SecurityOperationStatus_OPERATION_SUCCEEDED
414 mbVerifySignatures
= true;
415 ImplGetSignatureInformations();
416 ImplFillSignaturesBox();
420 catch ( uno::Exception
& )
422 DBG_ERROR( "Exception while adding a signature!" );
423 // Don't keep invalid entries...
424 ImplGetSignatureInformations();
425 ImplFillSignaturesBox();
431 IMPL_LINK( DigitalSignaturesDialog
, RemoveButtonHdl
, Button
*, EMPTYARG
)
435 if( maSignaturesLB
.FirstSelected() )
439 USHORT nSelected
= (USHORT
) (sal_uIntPtr
) maSignaturesLB
.FirstSelected()->GetUserData();
440 maCurrentSignatureInformations
.erase( maCurrentSignatureInformations
.begin()+nSelected
);
442 // Export all other signatures...
443 SignatureStreamHelper aStreamHelper
= ImplOpenSignatureStream( embed::ElementModes::WRITE
|embed::ElementModes::TRUNCATE
);
444 uno::Reference
< io::XOutputStream
> xOutputStream( aStreamHelper
.xSignatureStream
, uno::UNO_QUERY
);
445 uno::Reference
< com::sun::star::xml::sax::XDocumentHandler
> xDocumentHandler
= maSignatureHelper
.CreateDocumentHandlerWithHeader( xOutputStream
);
447 int nInfos
= maCurrentSignatureInformations
.size();
448 for( int n
= 0 ; n
< nInfos
; ++n
)
449 maSignatureHelper
.ExportSignature( xDocumentHandler
, maCurrentSignatureInformations
[ n
] );
451 maSignatureHelper
.CloseDocumentHandler( xDocumentHandler
);
453 mbSignaturesChanged
= true;
455 // If stream was not provided, we are responsible for committing it....
456 if ( !mxSignatureStream
.is() )
458 uno::Reference
< embed::XTransactedObject
> xTrans( aStreamHelper
.xSignatureStorage
, uno::UNO_QUERY
);
462 aStreamHelper
= SignatureStreamHelper(); // release objects...
464 ImplFillSignaturesBox();
466 catch ( uno::Exception
& )
468 DBG_ERROR( "Exception while removing a signature!" );
469 // Don't keep invalid entries...
470 ImplGetSignatureInformations();
471 ImplFillSignaturesBox();
478 IMPL_LINK( DigitalSignaturesDialog
, StartVerifySignatureHdl
, void*, EMPTYARG
)
480 return mbVerifySignatures
? 1 : 0;
483 void DigitalSignaturesDialog::ImplFillSignaturesBox()
485 maSignaturesLB
.Clear();
487 uno::Reference
< ::com::sun::star::xml::crypto::XSecurityEnvironment
> xSecEnv
= maSignatureHelper
.GetSecurityEnvironment();
488 uno::Reference
<com::sun::star::security::XSerialNumberAdapter
> xSerialNumberAdapter
=
489 ::com::sun::star::security::SerialNumberAdapter::create(mxCtx
);
491 uno::Reference
< ::com::sun::star::security::XCertificate
> xCert
;
494 int nInfos
= maCurrentSignatureInformations
.size();
495 int nValidSigs
= 0, nValidCerts
= 0;
499 std::vector
< rtl::OUString
> aElementsToBeVerified
= DocumentSignatureHelper::CreateElementList( mxStore
, ::rtl::OUString(), meSignatureMode
);
500 for( int n
= 0; n
< nInfos
; ++n
)
502 const SignatureInformation
& rInfo
= maCurrentSignatureInformations
[n
];
503 //First we try to get the certificate which is embedded in the XML Signature
504 if (rInfo
.ouX509Certificate
.getLength())
505 xCert
= xSecEnv
->createCertificateFromAscii(rInfo
.ouX509Certificate
);
507 //There must be an embedded certificate because we use it to get the
508 //issuer name. We cannot use /Signature/KeyInfo/X509Data/X509IssuerName
509 //because it could be modified by an attacker. The issuer is displayed
510 //in the digital signature dialog.
511 //Comparing the X509IssuerName with the one from the X509Certificate in order
512 //to find out if the X509IssuerName was modified does not work. See #i62684
513 DBG_ASSERT(sal_False
, "Could not find embedded certificate!");
516 //In case there is no embedded certificate we try to get it from a local store
517 //Todo: This probably could be removed, see above.
519 xCert
= xSecEnv
->getCertificate( rInfo
.ouX509IssuerName
, xSerialNumberAdapter
->toSequence( rInfo
.ouX509SerialNumber
) );
521 DBG_ASSERT( xCert
.is(), "Certificate not found and can't be created!" );
527 bool bSigValid
= false;
528 bool bCertValid
= false;
531 //check the validity of the cert
533 sal_Int32 certResult
= xSecEnv
->verifyCertificate(xCert
,
534 Sequence
<css::uno::Reference
<css::security::XCertificate
> >());
536 //These errors are alloweds
537 sal_Int32 validErrors
= css::security::CertificateValidity::VALID
538 | css::security::CertificateValidity::UNKNOWN_REVOKATION
;
540 //Build a mask to filter out the allowed errors
541 sal_Int32 mask
= ~validErrors
;
542 // "subtract" the allowed error flags from the result
543 sal_Int32 errors
= certResult
& mask
;
544 bCertValid
= errors
> 0 ? false : true;
548 } catch (css::uno::SecurityException
& ) {
549 OSL_ENSURE(0, "Verification of certificate failed");
553 aSubject
= XmlSec::GetContentPart( xCert
->getSubjectName() );
554 aIssuer
= XmlSec::GetContentPart( xCert
->getIssuerName() );
555 // --> PB 2004-10-12 #i20172# String with date and time information
556 aDateTimeStr
= XmlSec::GetDateTimeString( rInfo
.stDateTime
);
558 bSigValid
= ( rInfo
.nStatus
== ::com::sun::star::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED
);
562 // Can only be valid if ALL streams are signed, which means real stream count == signed stream count
563 unsigned int nRealCount
= 0;
564 for ( int i
= rInfo
.vSignatureReferenceInfors
.size(); i
; )
566 const SignatureReferenceInformation
& rInf
= rInfo
.vSignatureReferenceInfors
[--i
];
567 // There is also an extra entry of type TYPE_SAMEDOCUMENT_REFERENCE because of signature date.
568 if ( ( rInf
.nType
== TYPE_BINARYSTREAM_REFERENCE
) || ( rInf
.nType
== TYPE_XMLSTREAM_REFERENCE
) )
571 bSigValid
= ( aElementsToBeVerified
.size() == nRealCount
);
578 if ( bSigValid
&& bCertValid
)
579 aImage
= maSigsValidImg
.GetImage();
580 else if ( bSigValid
&& !bCertValid
)
581 aImage
= maSigsNotvalidatedImg
.GetImage();
582 else if ( !bSigValid
)
583 aImage
= maSigsInvalidImg
.GetImage();
585 SvLBoxEntry
* pEntry
= maSignaturesLB
.InsertEntry( aNullStr
, aImage
, aImage
);
586 maSignaturesLB
.SetEntryText( aSubject
, pEntry
, 1 );
587 maSignaturesLB
.SetEntryText( aIssuer
, pEntry
, 2 );
588 maSignaturesLB
.SetEntryText( aDateTimeStr
, pEntry
, 3 );
589 pEntry
->SetUserData( ( void* ) n
); // missuse user data as index
593 bool bAllSigsValid
= ( nValidSigs
== nInfos
);
594 bool bAllCertsValid
= ( nValidCerts
== nInfos
);
595 bool bShowValidState
= nInfos
&& ( bAllSigsValid
&& bAllCertsValid
);
596 bool bShowNotValidatedState
= nInfos
&& ( bAllSigsValid
&& !bAllCertsValid
);
597 bool bShowInvalidState
= nInfos
&& !bAllSigsValid
;
598 maSigsValidImg
.Show( bShowValidState
);
599 maSigsValidFI
.Show( bShowValidState
);
600 maSigsInvalidImg
.Show( bShowInvalidState
);
601 maSigsInvalidFI
.Show( bShowInvalidState
);
602 maSigsNotvalidatedImg
.Show( bShowNotValidatedState
);
603 maSigsNotvalidatedFI
.Show( bShowNotValidatedState
);
605 SignatureHighlightHdl( NULL
);
608 void DigitalSignaturesDialog::ImplGetSignatureInformations()
610 maCurrentSignatureInformations
.clear();
612 maSignatureHelper
.StartMission();
614 SignatureStreamHelper aStreamHelper
= ImplOpenSignatureStream( embed::ElementModes::READ
);
615 if ( aStreamHelper
.xSignatureStream
.is() )
617 uno::Reference
< io::XInputStream
> xInputStream( aStreamHelper
.xSignatureStream
, uno::UNO_QUERY
);
618 maSignatureHelper
.ReadAndVerifySignature( xInputStream
);
620 maSignatureHelper
.EndMission();
622 maCurrentSignatureInformations
= maSignatureHelper
.GetSignatureInformations();
624 mbVerifySignatures
= false;
627 void DigitalSignaturesDialog::ImplShowSignaturesDetails()
629 if( maSignaturesLB
.FirstSelected() )
631 USHORT nSelected
= (USHORT
) (sal_uIntPtr
) maSignaturesLB
.FirstSelected()->GetUserData();
632 const SignatureInformation
& rInfo
= maCurrentSignatureInformations
[ nSelected
];
633 css::uno::Reference
<css::xml::crypto::XSecurityEnvironment
> xSecEnv
=
634 maSignatureHelper
.GetSecurityEnvironment();
635 css::uno::Reference
<com::sun::star::security::XSerialNumberAdapter
> xSerialNumberAdapter
=
636 ::com::sun::star::security::SerialNumberAdapter::create(mxCtx
);
637 // Use Certificate from doc, not from key store
638 uno::Reference
< dcss::security::XCertificate
> xCert
;
639 if (rInfo
.ouX509Certificate
.getLength())
640 xCert
= xSecEnv
->createCertificateFromAscii(rInfo
.ouX509Certificate
);
641 //fallback if no certificate is embedded, get if from store
643 xCert
= xSecEnv
->getCertificate( rInfo
.ouX509IssuerName
, xSerialNumberAdapter
->toSequence( rInfo
.ouX509SerialNumber
) );
645 DBG_ASSERT( xCert
.is(), "Error getting cCertificate!" );
648 CertificateViewer
aViewer( this, maSignatureHelper
.GetSecurityEnvironment(), xCert
, FALSE
);
654 SignatureStreamHelper
DigitalSignaturesDialog::ImplOpenSignatureStream( sal_Int32 nStreamOpenMode
)
656 SignatureStreamHelper aHelper
;
657 if ( !mxSignatureStream
.is() )
659 aHelper
= DocumentSignatureHelper::OpenSignatureStream( mxStore
, nStreamOpenMode
, meSignatureMode
);
663 aHelper
.xSignatureStream
= mxSignatureStream
;
664 if ( nStreamOpenMode
& embed::ElementModes::TRUNCATE
)
666 css::uno::Reference
< css::io::XTruncate
> xTruncate( mxSignatureStream
, uno::UNO_QUERY
);
667 DBG_ASSERT( xTruncate
.is(), "ImplOpenSignatureStream - Stream does not support xTruncate!" );
668 xTruncate
->truncate();
672 css::uno::Reference
< css::io::XSeekable
> xSeek( mxSignatureStream
, uno::UNO_QUERY
);
673 DBG_ASSERT( xSeek
.is(), "ImplOpenSignatureStream - Stream does not support xSeekable!" );