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