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