merged tag ooo/OOO330_m14
[LibreOffice.git] / xmlsecurity / tools / demo / verifydemo.cxx
blob2ea9c8d94a9407c8eb8cd97fe0d8f280afad733d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
31 #include "util.hxx"
33 #include <stdio.h>
34 #include <cppuhelper/servicefactory.hxx>
36 #include <xmlsecurity/xmlsignaturehelper.hxx>
38 using namespace ::com::sun::star;
40 long startVerifyHandler( void *, void * )
42 return QueryVerifySignature();
45 int SAL_CALL main( int argc, char **argv )
47 if( argc < 2 )
49 fprintf( stderr, "Usage: %s <signature file> [<cryptoken>]\n" , argv[0] ) ;
50 return -1 ;
53 rtl::OUString aSIGFileName = rtl::OUString::createFromAscii(argv[1]);
54 rtl::OUString aCryptoToken;
55 if ( argc >= 3 )
56 aCryptoToken = rtl::OUString::createFromAscii(argv[2]);
58 uno::Reference< lang::XMultiServiceFactory > xMSF = CreateDemoServiceFactory();
62 * creates a signature helper
64 XMLSignatureHelper aSignatureHelper( xMSF );
67 * creates a security context.
69 bool bInit = aSignatureHelper.Init( aCryptoToken );
70 if ( !bInit )
72 fprintf( stderr, "Error initializing security context!" );
73 return -1;
77 * configures the start-verify handler
79 aSignatureHelper.SetStartVerifySignatureHdl( Link( NULL, startVerifyHandler ) );
81 aSignatureHelper.StartMission();
84 * verifies the signature
86 uno::Reference< io::XInputStream > xInputStream = OpenInputStream( aSIGFileName );
87 bool bDone = aSignatureHelper.ReadAndVerifySignature( xInputStream );
90 * closes the signature stream
92 xInputStream->closeInput();
94 if ( !bDone )
96 fprintf( stderr, "\nSTATUS: Error verifying Signature!\n" );
98 else
100 fprintf( stdout, "\nSTATUS: All choosen Signatures veryfied successfully!\n" );
103 aSignatureHelper.EndMission();
105 QueryPrintSignatureDetails( aSignatureHelper.GetSignatureInformations(), aSignatureHelper.GetSecurityEnvironment() );
107 return 0;