xref: /trunk/main/xmlsecurity/workben/signaturetest.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
30 
31 #include <sal/main.h>
32 #include <vcl/event.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/wrkwin.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <vcl/fixed.hxx>
37 #include <vcl/edit.hxx>
38 #include <vcl/button.hxx>
39 #include <vcl/lstbox.hxx>
40 #include <svtools/filectrl.hxx>
41 #include <tools/urlobj.hxx>
42 #include <osl/file.hxx>
43 
44 #include <svtools/docpasswdrequest.hxx>
45 
46 #include <comphelper/processfactory.hxx>
47 #include <cppuhelper/servicefactory.hxx>
48 #include <cppuhelper/bootstrap.hxx>
49 #include <unotools/streamhelper.hxx>
50 
51 #include <ucbhelper/contentbroker.hxx>
52 #include <ucbhelper/configurationkeys.hxx>
53 
54 // Will be in comphelper if CWS MAV09 is integrated
55 #include <comphelper/storagehelper.hxx>
56 
57 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
58 
59 #include <xmlsecurity/xmlsignaturehelper.hxx>
60 #include <xmlsecurity/digitalsignaturesdialog.hxx>
61 #include <xmlsecurity/certificatechooser.hxx>
62 #include <xmlsecurity/biginteger.hxx>
63 
64 #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
65 
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star;
68 
69 void Main();
70 
71 #define TEXTFIELDWIDTH  80
72 #define TEXTFIELDSTARTX 10
73 
74 #define EDITWIDTH       200
75 #define EDITHEIGHT      20
76 
77 #define FIXEDLINEHEIGHT 15
78 
79 #define BUTTONWIDTH     50
80 #define BUTTONHEIGHT    22
81 #define BUTTONSPACE     20
82 
83 #define LISTBOXHEIGHT   120
84 
85 // #define TEST_IMPLEMENTATION_DIRECTLY
86 
87 
88 // -----------------------------------------------------------------------
89 
90     SAL_IMPLEMENT_MAIN()
91 {
92     uno::Reference< lang::XMultiServiceFactory > xMSF;
93     try
94     {
95         uno::Reference< uno::XComponentContext > xCtx( cppu::defaultBootstrap_InitialComponentContext() );
96         if ( !xCtx.is() )
97         {
98             DBG_ERROR( "Error creating initial component context!" );
99             return -1;
100         }
101 
102         xMSF = uno::Reference< lang::XMultiServiceFactory >(xCtx->getServiceManager(), uno::UNO_QUERY );
103 
104         if ( !xMSF.is() )
105         {
106             DBG_ERROR( "No service manager!" );
107             return -1;
108         }
109 
110         // Init USB
111         uno::Sequence< uno::Any > aArgs( 2 );
112         aArgs[ 0 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL );
113         aArgs[ 1 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE );
114         sal_Bool bSuccess = ::ucb::ContentBroker::initialize( xMSF, aArgs );
115         if ( !bSuccess )
116         {
117             DBG_ERROR( "Error creating UCB!" );
118             return -1;
119         }
120 
121     }
122     catch ( uno::Exception const & )
123     {
124         DBG_ERROR( "Exception during creation of initial component context!" );
125         return -1;
126     }
127     comphelper::setProcessServiceFactory( xMSF );
128 
129     InitVCL( xMSF );
130     ::Main();
131     DeInitVCL();
132 
133     return 0;
134 }
135 
136 // -----------------------------------------------------------------------
137 
138 class MyWin : public WorkWindow
139 {
140 private:
141     FixedLine   maTokenLine;
142     CheckBox    maCryptoCheckBox;
143     FixedText   maFixedTextTokenName;
144     FileControl maEditTokenName;
145     FixedLine   maTest1Line;
146     FixedText   maFixedTextXMLFileName;
147     FileControl maEditXMLFileName;
148     FixedText   maFixedTextBINFileName;
149     FileControl maEditBINFileName;
150     FixedText   maFixedTextSIGFileName;
151     FileControl maEditSIGFileName;
152     PushButton  maSignButton;
153     PushButton  maVerifyButton;
154     FixedLine   maTest2Line;
155     FixedText   maFixedTextDOCFileName;
156     FileControl maEditDOCFileName;
157     PushButton  maDigitalSignaturesButton;
158     PushButton  maVerifyDigitalSignaturesButton;
159     FixedLine   maHintLine;
160     FixedText   maHintText;
161 
162     DECL_LINK(  CryptoCheckBoxHdl, CheckBox* );
163     DECL_LINK(  SignButtonHdl, Button* );
164     DECL_LINK(  VerifyButtonHdl, Button* );
165     DECL_LINK(  DigitalSignaturesWithServiceHdl, Button* );
166     DECL_LINK(  VerifyDigitalSignaturesHdl, Button* );
167     DECL_LINK(  DigitalSignaturesWithTokenHdl, Button* );
168     DECL_LINK(  StartVerifySignatureHdl, void* );
169 
170 public:
171                 MyWin( Window* pParent, WinBits nWinStyle );
172 
173 };
174 
175 // -----------------------------------------------------------------------
176 
177 void Main()
178 {
179     MyWin aMainWin( NULL, WB_APP | WB_STDWORK | WB_3DLOOK);
180     aMainWin.Show();
181 
182     Application::Execute();
183 }
184 
185 // -----------------------------------------------------------------------
186 
187 MyWin::MyWin( Window* pParent, WinBits nWinStyle ) :
188     WorkWindow( pParent, nWinStyle ),
189     maTokenLine( this ),
190     maTest1Line( this ),
191     maTest2Line( this ),
192     maHintLine( this ),
193     maFixedTextXMLFileName( this ),
194     maEditXMLFileName( this, WB_BORDER ),
195     maFixedTextBINFileName( this ),
196     maEditBINFileName( this, WB_BORDER ),
197     maFixedTextSIGFileName( this ),
198     maEditSIGFileName( this, WB_BORDER ),
199     maFixedTextTokenName( this ),
200     maEditTokenName( this, WB_BORDER ),
201     maFixedTextDOCFileName( this ),
202     maEditDOCFileName( this, WB_BORDER ),
203     maSignButton( this ),
204     maVerifyButton( this ),
205     maDigitalSignaturesButton( this ),
206     maVerifyDigitalSignaturesButton( this ),
207     maHintText( this, WB_WORDBREAK ),
208     maCryptoCheckBox( this )
209 
210 {
211 #ifdef TEST_IMPLEMENTATION_DIRECTLY
212     Size aOutputSize( 400, 600 );
213 #else
214     Size aOutputSize( 400, 400 );
215 #endif
216     SetOutputSizePixel( aOutputSize );
217     SetText( String( RTL_CONSTASCII_USTRINGPARAM( "XML Signature Test" ) ) );
218 
219     long nY = 15;
220 
221     maTokenLine.SetPosSizePixel( TEXTFIELDSTARTX, nY, aOutputSize.Width()-2*TEXTFIELDSTARTX, FIXEDLINEHEIGHT );
222     maTokenLine.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Crypto Settings" ) ) );
223     maTokenLine.Show();
224 
225     nY += EDITHEIGHT*3/2;
226 
227     maCryptoCheckBox.SetPosSizePixel( TEXTFIELDSTARTX, nY, aOutputSize.Width()-2*TEXTFIELDSTARTX, FIXEDLINEHEIGHT );
228     maCryptoCheckBox.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Use Default Token (NSS option only)" ) ) );
229     maCryptoCheckBox.Check( sal_True );
230     maEditTokenName.Disable();
231     maFixedTextTokenName.Disable();
232     maCryptoCheckBox.SetClickHdl( LINK( this, MyWin, CryptoCheckBoxHdl ) );
233     maCryptoCheckBox.Show();
234 
235     nY += EDITHEIGHT;
236 
237     maFixedTextTokenName.SetPosSizePixel( TEXTFIELDSTARTX, nY, TEXTFIELDWIDTH, EDITHEIGHT );
238     maFixedTextTokenName.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Crypto Token:" ) ) );
239     maFixedTextTokenName.Show();
240 
241     maEditTokenName.SetPosSizePixel( TEXTFIELDSTARTX+TEXTFIELDWIDTH, nY, EDITWIDTH, EDITHEIGHT );
242     maEditTokenName.Show();
243 
244     nY += EDITHEIGHT*3;
245 
246 #ifdef TEST_IMPLEMENTATION_DIRECTLY
247 
248     maTest1Line.SetPosSizePixel( TEXTFIELDSTARTX, nY, aOutputSize.Width()-2*TEXTFIELDSTARTX, FIXEDLINEHEIGHT );
249     maTest1Line.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Test simple files" ) ) );
250     maTest1Line.Show();
251 
252     nY += EDITHEIGHT*3/2;
253 
254     maFixedTextXMLFileName.SetPosSizePixel( TEXTFIELDSTARTX, nY, TEXTFIELDWIDTH, EDITHEIGHT );
255     maFixedTextXMLFileName.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "XML File:" ) ) );
256     maFixedTextXMLFileName.Show();
257 
258     maEditXMLFileName.SetPosSizePixel( TEXTFIELDSTARTX+TEXTFIELDWIDTH, nY, EDITWIDTH, EDITHEIGHT );
259     maEditXMLFileName.Show();
260 
261     nY += EDITHEIGHT*3/2;
262 
263     maFixedTextBINFileName.SetPosSizePixel( TEXTFIELDSTARTX, nY, TEXTFIELDWIDTH, EDITHEIGHT );
264     maFixedTextBINFileName.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Binary File:" ) ) );
265     maFixedTextBINFileName.Show();
266 
267     maEditBINFileName.SetPosSizePixel( TEXTFIELDSTARTX+TEXTFIELDWIDTH, nY, EDITWIDTH, EDITHEIGHT );
268     maEditBINFileName.Show();
269 
270     nY += EDITHEIGHT*3/2;
271 
272     maFixedTextSIGFileName.SetPosSizePixel( TEXTFIELDSTARTX, nY, TEXTFIELDWIDTH, EDITHEIGHT );
273     maFixedTextSIGFileName.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Signature File:" ) ) );
274     maFixedTextSIGFileName.Show();
275 
276     maEditSIGFileName.SetPosSizePixel( TEXTFIELDSTARTX+TEXTFIELDWIDTH, nY, EDITWIDTH, EDITHEIGHT );
277     maEditSIGFileName.Show();
278 
279     nY += EDITHEIGHT*2;
280 
281     maSignButton.SetPosSizePixel( TEXTFIELDSTARTX, nY, BUTTONWIDTH, BUTTONHEIGHT );
282     maSignButton.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Sign" ) ) );
283     maSignButton.SetClickHdl( LINK( this, MyWin, SignButtonHdl ) );
284     maSignButton.Show();
285 
286     maVerifyButton.SetPosSizePixel( TEXTFIELDSTARTX+BUTTONWIDTH+BUTTONSPACE, nY, BUTTONWIDTH, BUTTONHEIGHT );
287     maVerifyButton.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Verify" ) ) );
288     maVerifyButton.SetClickHdl( LINK( this, MyWin, VerifyButtonHdl ) );
289     maVerifyButton.Show();
290 
291     nY += EDITHEIGHT*3;
292 
293 #endif // TEST_IMPLEMENTATION_DIRECTLY
294 
295     maTest2Line.SetPosSizePixel( TEXTFIELDSTARTX, nY, aOutputSize.Width()-2*TEXTFIELDSTARTX, FIXEDLINEHEIGHT );
296     maTest2Line.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Test Office Document" ) ) );
297     maTest2Line.Show();
298 
299     nY += EDITHEIGHT*3/2;
300 
301 
302     maFixedTextDOCFileName.SetPosSizePixel( TEXTFIELDSTARTX, nY, TEXTFIELDWIDTH, EDITHEIGHT );
303     maFixedTextDOCFileName.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Office File:" ) ) );
304     maFixedTextDOCFileName.Show();
305 
306     maEditDOCFileName.SetPosSizePixel( TEXTFIELDSTARTX+TEXTFIELDWIDTH, nY, EDITWIDTH, EDITHEIGHT );
307     maEditDOCFileName.Show();
308 
309     nY += EDITHEIGHT*2;
310 
311     maDigitalSignaturesButton.SetPosSizePixel( TEXTFIELDSTARTX, nY, BUTTONWIDTH*2, BUTTONHEIGHT );
312     maDigitalSignaturesButton.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Digital Signatures..." ) ) );
313     maDigitalSignaturesButton.SetClickHdl( LINK( this, MyWin, DigitalSignaturesWithServiceHdl ) );
314     maDigitalSignaturesButton.Show();
315 
316     maVerifyDigitalSignaturesButton.SetPosSizePixel( TEXTFIELDSTARTX+BUTTONWIDTH*2+BUTTONSPACE, nY, BUTTONWIDTH*2, BUTTONHEIGHT );
317     maVerifyDigitalSignaturesButton.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Verify Signatures" ) ) );
318     maVerifyDigitalSignaturesButton.SetClickHdl( LINK( this, MyWin, VerifyDigitalSignaturesHdl ) );
319     maVerifyDigitalSignaturesButton.Show();
320 
321     nY += EDITHEIGHT*2;
322 
323     maHintLine.SetPosSizePixel( TEXTFIELDSTARTX, nY, aOutputSize.Width()-2*TEXTFIELDSTARTX, FIXEDLINEHEIGHT );
324     maHintLine.Show();
325 
326     nY += EDITHEIGHT*2;
327 
328     maHintText.SetPosSizePixel( TEXTFIELDSTARTX, nY, aOutputSize.Width()-2*TEXTFIELDSTARTX, aOutputSize.Height()-nY );
329     maHintText.SetText( String( RTL_CONSTASCII_USTRINGPARAM( "Hint: Copy crypto files from xmlsecurity/tools/cryptoken/nss and sample files from xmlsecurity/tools/examples to <temp>/nss.\nThis location will be used from the demo as the default location." ) ) );
330     maHintText.Show();
331 
332     // Help the user with some default values
333     ::rtl::OUString aTempDirURL;
334     ::osl::File::getTempDirURL( aTempDirURL );
335     INetURLObject aURLObj( aTempDirURL );
336     aURLObj.insertName( String( RTL_CONSTASCII_USTRINGPARAM( "nss" ) ), true );
337     ::rtl::OUString aNSSFolder = aURLObj.getFSysPath( INetURLObject::FSYS_DETECT );
338     String aDefaultXMLFileName( aNSSFolder );
339     maEditXMLFileName.SetText( aNSSFolder + String( RTL_CONSTASCII_USTRINGPARAM( "demo-sample.xml" ) ) );
340     maEditBINFileName.SetText( aNSSFolder + String( RTL_CONSTASCII_USTRINGPARAM( "demo-sample.gif" ) ) );
341     maEditDOCFileName.SetText( aNSSFolder + String( RTL_CONSTASCII_USTRINGPARAM( "demo-sample.sxw" ) ) );
342     maEditSIGFileName.SetText( aNSSFolder + String( RTL_CONSTASCII_USTRINGPARAM( "demo-result.xml" ) ) );
343     maEditTokenName.SetText( aNSSFolder );
344 
345 #ifdef WNT
346     maEditTokenName.SetText( String() );
347     maEditTokenName.Disable();
348     maCryptoCheckBox.Disable();
349 #endif
350 
351 }
352 
353 IMPL_LINK( MyWin, CryptoCheckBoxHdl, CheckBox*, EMPTYARG )
354 {
355     if ( maCryptoCheckBox.IsChecked() )
356     {
357         maEditTokenName.Disable();
358         maFixedTextTokenName.Disable();
359     }
360     else
361     {
362         maEditTokenName.Enable();
363         maFixedTextTokenName.Enable();
364     }
365     return 1;
366 }
367 
368 IMPL_LINK( MyWin, DigitalSignaturesWithServiceHdl, Button*, EMPTYARG )
369 {
370     rtl::OUString aDocFileName = maEditDOCFileName.GetText();
371     uno::Reference < embed::XStorage > xStore = ::comphelper::OStorageHelper::GetStorageFromURL(
372             aDocFileName, embed::ElementModes::READWRITE, comphelper::getProcessServiceFactory() );
373 
374     uno::Reference< security::XDocumentDigitalSignatures > xD(
375         comphelper::getProcessServiceFactory()->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ) ), uno::UNO_QUERY );
376     if ( xD.is() )
377         xD->signDocumentContent( xStore, NULL );
378 
379 
380     return 0;
381 }
382 
383 IMPL_LINK( MyWin, VerifyDigitalSignaturesHdl, Button*, EMPTYARG )
384 {
385     rtl::OUString aDocFileName = maEditDOCFileName.GetText();
386     uno::Reference < embed::XStorage > xStore = ::comphelper::OStorageHelper::GetStorageFromURL(
387             aDocFileName, embed::ElementModes::READWRITE, comphelper::getProcessServiceFactory() );
388 
389     uno::Reference< security::XDocumentDigitalSignatures > xD(
390         comphelper::getProcessServiceFactory()->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.security.DocumentDigitalSignatures" ) ) ), uno::UNO_QUERY );
391     if ( xD.is() )
392     {
393         uno::Sequence< security::DocumentSignatureInformation > aInfos = xD->verifyDocumentContentSignatures( xStore, NULL );
394         int nInfos = aInfos.getLength();
395         for ( int n = 0; n < nInfos; n++ )
396         {
397             security::DocumentSignatureInformation& rInf = aInfos[n];
398             String aText( RTL_CONSTASCII_USTRINGPARAM( "The document is signed by\n\n  " ) );
399             aText += String( rInf.Signer->getSubjectName() );
400             aText += String( RTL_CONSTASCII_USTRINGPARAM( "\n\n The signature is " ) );
401             if ( !rInf.SignatureIsValid )
402                 aText += String( RTL_CONSTASCII_USTRINGPARAM( "NOT " ) );
403             aText += String( RTL_CONSTASCII_USTRINGPARAM( "valid" ) );
404             InfoBox( this, aText ).Execute();
405         }
406 
407     }
408 
409 
410     return 0;
411 }
412 
413 
414 #ifdef TEST_IMPLEMENTATION_DIRECTLY
415 
416 IMPL_LINK( MyWin, DigitalSignaturesWithTokenHdl, Button*, EMPTYARG )
417 {
418     String aDocFileName = maEditDOCFileName.GetText();
419     String aTokenFileName = maEditTokenName.GetText();
420 
421     DigitalSignaturesDialog aSignaturesDialog( this, comphelper::getProcessServiceFactory(), SignatureModeDocumentContent, false );
422 
423     bool bInit = aSignaturesDialog.Init( aTokenFileName );
424     if ( !bInit )
425     {
426         ErrorBox( this, WB_OK, String( RTL_CONSTASCII_USTRINGPARAM( "Error initializing security context!" ) ) ).Execute();
427         return 0;
428     }
429 
430     uno::Reference < embed::XStorage > xStore = ::comphelper::OStorageHelper::GetStorageFromURL(
431             aDocFileName, embed::ElementModes::READWRITE, comphelper::getProcessServiceFactory() );
432 
433     aSignaturesDialog.SetStorage( xStore );
434 
435     aSignaturesDialog.Execute();
436 
437     return 0;
438 }
439 
440 IMPL_LINK( MyWin, SignButtonHdl, Button*, EMPTYARG )
441 {
442     String aXMLFileName = maEditXMLFileName.GetText();
443     String aBINFileName = maEditBINFileName.GetText();
444     String aSIGFileName = maEditSIGFileName.GetText();
445 
446     String aTokenFileName;
447     if ( !maCryptoCheckBox.IsChecked() )
448         aTokenFileName = maEditTokenName.GetText();
449 
450     XMLSignatureHelper aSignatureHelper( comphelper::getProcessServiceFactory() );
451     bool bInit = aSignatureHelper.Init( aTokenFileName );
452 
453     if ( !bInit )
454     {
455         ErrorBox( this, WB_OK, String( RTL_CONSTASCII_USTRINGPARAM( "Error initializing security context!" ) ) ).Execute();
456         return 0;
457     }
458 
459     uno::Reference< ::com::sun::star::security::XCertificate > xCertToUse;
460     CertificateChooser aChooser( this, aSignatureHelper.GetSecurityEnvironment(), SignatureInformations() );
461     if ( aChooser.Execute() )
462         xCertToUse = aChooser.GetSelectedCertificate();
463 
464     if ( !xCertToUse.is() )
465         return 0;
466 
467 
468     aSignatureHelper.StartMission();
469 
470     sal_Int32 nSecurityId = aSignatureHelper.GetNewSecurityId();
471 
472     aSignatureHelper.SetX509Certificate( nSecurityId, xCertToUse->getIssuerName(), bigIntegerToNumericString( xCertToUse->getSerialNumber() ) );
473 
474     aSignatureHelper.AddForSigning( nSecurityId, aXMLFileName, aXMLFileName, sal_False );
475     aSignatureHelper.AddForSigning( nSecurityId, aBINFileName, aBINFileName, sal_True );
476 
477     SvFileStream* pStream = new SvFileStream( aSIGFileName, STREAM_WRITE );
478     SvLockBytesRef xLockBytes = new SvLockBytes( pStream, sal_True );
479     uno::Reference< io::XOutputStream > xOutputStream = new utl::OOutputStreamHelper( xLockBytes );
480     bool bDone = aSignatureHelper.CreateAndWriteSignature( xOutputStream );
481 
482     aSignatureHelper.EndMission();
483 
484     if ( !bDone )
485     {
486         ErrorBox( this, WB_OK, String( RTL_CONSTASCII_USTRINGPARAM( "Error creating Signature!" ) ) ).Execute();
487     }
488     else
489     {
490         rtl::OUString aInfo( String( RTL_CONSTASCII_USTRINGPARAM( "Signature successfully created!\n\n" ) ) );
491         // aInfo += getSignatureInformationmations( aSignatureHelper.getAllSignatureInformation(), aSignatureHelper.GetSecurityEnvironment() );
492 
493 
494         InfoBox( this, aInfo ).Execute();
495     }
496 
497     // Check for more detailed results...
498 
499     return 0;
500 }
501 
502 IMPL_LINK( MyWin, VerifyButtonHdl, Button*, EMPTYARG )
503 {
504     String aXMLFileName = maEditXMLFileName.GetText();
505     String aBINFileName = maEditBINFileName.GetText();
506     String aSIGFileName = maEditSIGFileName.GetText();
507 
508     String aTokenFileName;
509     if ( !maCryptoCheckBox.IsChecked() )
510         aTokenFileName = maEditTokenName.GetText();
511 
512     XMLSignatureHelper aSignatureHelper( comphelper::getProcessServiceFactory() );
513     bool bInit = aSignatureHelper.Init( aTokenFileName );
514 
515     if ( !bInit )
516     {
517         ErrorBox( this, WB_OK, String( RTL_CONSTASCII_USTRINGPARAM( "Error initializing security context!" ) ) ).Execute();
518         return 0;
519     }
520 
521     aSignatureHelper.SetStartVerifySignatureHdl( LINK( this, MyWin, StartVerifySignatureHdl ) );
522 
523     aSignatureHelper.StartMission();
524 
525     SvFileStream* pStream = new SvFileStream( aSIGFileName, STREAM_READ );
526     pStream->Seek( STREAM_SEEK_TO_END );
527     sal_uLong nBytes = pStream->Tell();
528     pStream->Seek( STREAM_SEEK_TO_BEGIN );
529     SvLockBytesRef xLockBytes = new SvLockBytes( pStream, sal_True );
530     uno::Reference< io::XInputStream > xInputStream = new utl::OInputStreamHelper( xLockBytes, nBytes );
531     bool bDone = aSignatureHelper.ReadAndVerifySignature( xInputStream );
532     xInputStream->closeInput();
533 
534     aSignatureHelper.EndMission();
535 
536     if ( !bDone )
537         ErrorBox( this, WB_OK, String( RTL_CONSTASCII_USTRINGPARAM( "Error in Signature!" ) ) ).Execute();
538     else
539         InfoBox( this, String( RTL_CONSTASCII_USTRINGPARAM( "Signatures verified without any problems!" ) ) ).Execute();
540 
541     return 0;
542 }
543 
544 IMPL_LINK( MyWin, StartVerifySignatureHdl, void*, EMPTYARG )
545 {
546     QueryBox aQueryBox( this, WB_YES_NO|WB_DEF_YES, String( RTL_CONSTASCII_USTRINGPARAM( "Found Signature - Verify?" ) ) );
547     return ( aQueryBox.Execute() == RET_YES ) ? 1 : 0;
548 }
549 
550 
551 #endif // #ifdef TEST_IMPLEMENTATION_DIRECTLY
552