2004-07-12 07:15:31 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 18:44:10 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:44:10 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:44:10 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:44:10 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:44:10 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:44:10 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 08:48:56 -05:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_xmlsecurity.hxx"
|
|
|
|
|
2004-07-12 07:15:31 -05:00
|
|
|
#include "util.hxx"
|
|
|
|
|
2005-05-18 04:03:28 -05:00
|
|
|
#include <stdio.h>
|
2004-07-12 07:15:31 -05:00
|
|
|
#include <cppuhelper/servicefactory.hxx>
|
2005-03-10 11:15:58 -06:00
|
|
|
|
2005-05-18 04:03:28 -05:00
|
|
|
#include <xmlsecurity/xmlsignaturehelper.hxx>
|
2004-07-12 07:15:31 -05:00
|
|
|
|
2005-05-18 04:03:28 -05:00
|
|
|
using namespace ::com::sun::star;
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
long startVerifyHandler( void *, void * )
|
|
|
|
{
|
2005-05-18 04:03:28 -05:00
|
|
|
return QueryVerifySignature();
|
2004-07-12 07:15:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int SAL_CALL main( int argc, char **argv )
|
|
|
|
{
|
2005-05-18 04:03:28 -05:00
|
|
|
if( argc < 2 )
|
2004-07-12 07:15:31 -05:00
|
|
|
{
|
2005-05-18 04:03:28 -05:00
|
|
|
fprintf( stderr, "Usage: %s <signature file> [<cryptoken>]\n" , argv[0] ) ;
|
2004-07-12 07:15:31 -05:00
|
|
|
return -1 ;
|
|
|
|
}
|
|
|
|
|
2005-05-18 04:03:28 -05:00
|
|
|
rtl::OUString aSIGFileName = rtl::OUString::createFromAscii(argv[1]);
|
|
|
|
rtl::OUString aCryptoToken;
|
|
|
|
if ( argc >= 3 )
|
|
|
|
aCryptoToken = rtl::OUString::createFromAscii(argv[2]);
|
|
|
|
|
|
|
|
uno::Reference< lang::XMultiServiceFactory > xMSF = CreateDemoServiceFactory();
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* creates a signature helper
|
|
|
|
*/
|
2005-05-18 04:03:28 -05:00
|
|
|
XMLSignatureHelper aSignatureHelper( xMSF );
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* creates a security context.
|
|
|
|
*/
|
2005-05-18 04:03:28 -05:00
|
|
|
bool bInit = aSignatureHelper.Init( aCryptoToken );
|
2004-07-12 07:15:31 -05:00
|
|
|
if ( !bInit )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Error initializing security context!" );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* configures the start-verify handler
|
|
|
|
*/
|
|
|
|
aSignatureHelper.SetStartVerifySignatureHdl( Link( NULL, startVerifyHandler ) );
|
|
|
|
|
|
|
|
aSignatureHelper.StartMission();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* verifies the signature
|
|
|
|
*/
|
2005-05-18 04:03:28 -05:00
|
|
|
uno::Reference< io::XInputStream > xInputStream = OpenInputStream( aSIGFileName );
|
2004-07-15 02:12:10 -05:00
|
|
|
bool bDone = aSignatureHelper.ReadAndVerifySignature( xInputStream );
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* closes the signature stream
|
|
|
|
*/
|
|
|
|
xInputStream->closeInput();
|
|
|
|
|
|
|
|
if ( !bDone )
|
|
|
|
{
|
2005-05-18 04:03:28 -05:00
|
|
|
fprintf( stderr, "\nSTATUS: Error verifying Signature!\n" );
|
2004-07-12 07:15:31 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-05-18 04:03:28 -05:00
|
|
|
fprintf( stdout, "\nSTATUS: All choosen Signatures veryfied successfully!\n" );
|
2004-07-12 07:15:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
aSignatureHelper.EndMission();
|
|
|
|
|
2005-05-18 04:03:28 -05:00
|
|
|
QueryPrintSignatureDetails( aSignatureHelper.GetSignatureInformations(), aSignatureHelper.GetSecurityEnvironment() );
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|