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 "util.hxx"
32 
33 #include <stdio.h>
34 #include <cppuhelper/servicefactory.hxx>
35 
36 #include <xmlsecurity/xmlsignaturehelper.hxx>
37 
38 using namespace ::com::sun::star;
39 
40 long startVerifyHandler( void *, void * )
41 {
42 	return QueryVerifySignature();
43 }
44 
45 int SAL_CALL main( int argc, char **argv )
46 {
47 	if( argc < 2 )
48 	{
49 		fprintf( stderr, "Usage: %s <signature file> [<cryptoken>]\n" , argv[0] ) ;
50 		return -1 ;
51 	}
52 
53 	rtl::OUString aSIGFileName = rtl::OUString::createFromAscii(argv[1]);
54 	rtl::OUString aCryptoToken;
55 	if ( argc >= 3 )
56 	    aCryptoToken = rtl::OUString::createFromAscii(argv[2]);
57 
58 	uno::Reference< lang::XMultiServiceFactory > xMSF = CreateDemoServiceFactory();
59 
60 
61 	/*
62 	 * creates a signature helper
63 	 */
64 	XMLSignatureHelper aSignatureHelper( xMSF );
65 
66 	/*
67 	 * creates a security context.
68 	 */
69 	bool bInit = aSignatureHelper.Init( aCryptoToken );
70 	if ( !bInit )
71 	{
72 		fprintf( stderr, "Error initializing security context!" );
73 		return -1;
74 	}
75 
76 	/*
77 	 * configures the start-verify handler
78 	 */
79 	aSignatureHelper.SetStartVerifySignatureHdl( Link( NULL, startVerifyHandler ) );
80 
81 	aSignatureHelper.StartMission();
82 
83 	/*
84 	 * verifies the signature
85 	 */
86 	uno::Reference< io::XInputStream > xInputStream = OpenInputStream( aSIGFileName );
87 	bool bDone = aSignatureHelper.ReadAndVerifySignature( xInputStream );
88 
89 	/*
90 	 * closes the signature stream
91 	 */
92 	xInputStream->closeInput();
93 
94 	if ( !bDone )
95 	{
96 		fprintf( stderr, "\nSTATUS: Error verifying Signature!\n" );
97 	}
98 	else
99 	{
100 		fprintf( stdout, "\nSTATUS: All choosen Signatures veryfied successfully!\n" );
101 	}
102 
103 	aSignatureHelper.EndMission();
104 
105 	QueryPrintSignatureDetails( aSignatureHelper.GetSignatureInformations(), aSignatureHelper.GetSecurityEnvironment() );
106 
107 	return 0;
108 }
109 
110