office-gobmx/xmlsecurity/tools/demo/verifydemo.cxx

112 lines
3.2 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2004-07-12 07:15:31 -05:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2004-07-12 07:15:31 -05:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2004-07-12 07:15:31 -05:00
*
* OpenOffice.org - a multi-platform office productivity suite
2004-07-12 07:15:31 -05:00
*
* This file is part of OpenOffice.org.
2004-07-12 07:15:31 -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
*
* 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
*
* 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
*
************************************************************************/
// 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"
#include <stdio.h>
2004-07-12 07:15:31 -05:00
#include <cppuhelper/servicefactory.hxx>
#include <xmlsecurity/xmlsignaturehelper.hxx>
2004-07-12 07:15:31 -05:00
using namespace ::com::sun::star;
2004-07-12 07:15:31 -05:00
long startVerifyHandler( void *, void * )
{
return QueryVerifySignature();
2004-07-12 07:15:31 -05:00
}
int SAL_CALL main( int argc, char **argv )
{
if( argc < 2 )
2004-07-12 07:15:31 -05:00
{
fprintf( stderr, "Usage: %s <signature file> [<cryptoken>]\n" , argv[0] ) ;
2004-07-12 07:15:31 -05:00
return -1 ;
}
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
*/
XMLSignatureHelper aSignatureHelper( xMSF );
2004-07-12 07:15:31 -05:00
/*
* creates a security context.
*/
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
*/
uno::Reference< io::XInputStream > xInputStream = OpenInputStream( aSIGFileName );
bool bDone = aSignatureHelper.ReadAndVerifySignature( xInputStream );
2004-07-12 07:15:31 -05:00
/*
* closes the signature stream
*/
xInputStream->closeInput();
if ( !bDone )
{
fprintf( stderr, "\nSTATUS: Error verifying Signature!\n" );
2004-07-12 07:15:31 -05:00
}
else
{
fprintf( stdout, "\nSTATUS: All choosen Signatures veryfied successfully!\n" );
2004-07-12 07:15:31 -05:00
}
aSignatureHelper.EndMission();
QueryPrintSignatureDetails( aSignatureHelper.GetSignatureInformations(), aSignatureHelper.GetSecurityEnvironment() );
2004-07-12 07:15:31 -05:00
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */