Kaydet (Commit) 6e65df9a authored tarafından Rüdiger Timm's avatar Rüdiger Timm

INTEGRATION: CWS xmlsec12 (1.4.6); FILE MERGED

2005/04/13 10:14:49 mt 1.4.6.1: Clean-Ups...
üst e1956188
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: verifydemo.cxx,v $ * $RCSfile: verifydemo.cxx,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change: $Author: rt $ $Date: 2005-03-29 13:28:31 $ * last change: $Author: rt $ $Date: 2005-05-18 10:03:28 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -59,77 +59,45 @@ ...@@ -59,77 +59,45 @@
* *
************************************************************************/ ************************************************************************/
#include <stdio.h>
#include "util.hxx" #include "util.hxx"
#include <rtl/ustring.hxx> #include <stdio.h>
#include <cppuhelper/servicefactory.hxx> #include <cppuhelper/servicefactory.hxx>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <unotools/streamhelper.hxx>
//CP : added by CP
#include <rtl/locale.h>
#include <osl/nlsupport.h>
#ifndef _OSL_PROCESS_H_
#include <osl/process.h>
#endif
//CP : end #include <xmlsecurity/xmlsignaturehelper.hxx>
namespace cssu = com::sun::star::uno; using namespace ::com::sun::star;
namespace cssl = com::sun::star::lang;
namespace cssxc = com::sun::star::xml::crypto;
namespace cssi = com::sun::star::io;
long startVerifyHandler( void *, void * ) long startVerifyHandler( void *, void * )
{ {
char answer; return QueryVerifySignature();
fprintf( stdout,
"A signature is found, whether to verify it(y/n)?[y]:" );
fscanf( stdin, "%c", &answer);
return (answer == 'n')?0:1;
} }
int SAL_CALL main( int argc, char **argv ) int SAL_CALL main( int argc, char **argv )
{ {
if( argc != 4 ) if( argc < 2 )
{ {
fprintf( stderr, "Usage: %s <rdb file> <signature file> <cryptoken>\n" , argv[0] ) ; fprintf( stderr, "Usage: %s <signature file> [<cryptoken>]\n" , argv[0] ) ;
return -1 ; return -1 ;
} }
/* rtl::OUString aSIGFileName = rtl::OUString::createFromAscii(argv[1]);
* creates a component factory from local rdb file. rtl::OUString aCryptoToken;
*/ if ( argc >= 3 )
cssu::Reference< cssl::XMultiServiceFactory > xManager = NULL ; aCryptoToken = rtl::OUString::createFromAscii(argv[2]);
cssu::Reference< cssu::XComponentContext > xContext = NULL ;
try uno::Reference< lang::XMultiServiceFactory > xMSF = CreateDemoServiceFactory();
{
xManager = serviceManager( xContext , rtl::OUString::createFromAscii( "local" ), rtl::OUString::createFromAscii( argv[1] ) ) ;
OSL_ENSURE( xManager.is() ,
"ServicesManager - "
"Cannot get service manager" );
fprintf( stdout , "xManager created.\n" ) ;
}
catch( cssu::Exception& e )
{
fprintf( stderr , "Error Message: %s\n" , rtl::OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() ) ;
return -1;
}
/* /*
* creates a signature helper * creates a signature helper
*/ */
XMLSignatureHelper aSignatureHelper( xManager ); XMLSignatureHelper aSignatureHelper( xMSF );
/* /*
* creates a security context. * creates a security context.
*/ */
bool bInit = aSignatureHelper.Init( rtl::OUString::createFromAscii(argv[3]) ); bool bInit = aSignatureHelper.Init( aCryptoToken );
if ( !bInit ) if ( !bInit )
{ {
fprintf( stderr, "Error initializing security context!" ); fprintf( stderr, "Error initializing security context!" );
...@@ -143,24 +111,10 @@ int SAL_CALL main( int argc, char **argv ) ...@@ -143,24 +111,10 @@ int SAL_CALL main( int argc, char **argv )
aSignatureHelper.StartMission(); aSignatureHelper.StartMission();
/*
* prepares the signature stream.
*/
rtl::OUString aSIGFileName = rtl::OUString::createFromAscii(argv[2]);
SvFileStream* pStream = new SvFileStream( aSIGFileName, STREAM_READ );
pStream->Seek( STREAM_SEEK_TO_END );
ULONG nBytes = pStream->Tell();
pStream->Seek( STREAM_SEEK_TO_BEGIN );
SvLockBytesRef xLockBytes = new SvLockBytes( pStream, TRUE );
/*
* creates the signature stream.
*/
cssu::Reference< cssi::XInputStream > xInputStream = new utl::OInputStreamHelper( xLockBytes, nBytes );
/* /*
* verifies the signature * verifies the signature
*/ */
uno::Reference< io::XInputStream > xInputStream = OpenInputStream( aSIGFileName );
bool bDone = aSignatureHelper.ReadAndVerifySignature( xInputStream ); bool bDone = aSignatureHelper.ReadAndVerifySignature( xInputStream );
/* /*
...@@ -170,27 +124,16 @@ int SAL_CALL main( int argc, char **argv ) ...@@ -170,27 +124,16 @@ int SAL_CALL main( int argc, char **argv )
if ( !bDone ) if ( !bDone )
{ {
fprintf( stderr, "Error in Signature!\n" ); fprintf( stderr, "\nSTATUS: Error verifying Signature!\n" );
} }
else else
{ {
fprintf( stdout, "Signatures verified without any problems!\n" ); fprintf( stdout, "\nSTATUS: All choosen Signatures veryfied successfully!\n" );
} }
aSignatureHelper.EndMission(); aSignatureHelper.EndMission();
// By CP , for correct encoding QueryPrintSignatureDetails( aSignatureHelper.GetSignatureInformations(), aSignatureHelper.GetSecurityEnvironment() );
sal_uInt16 encoding ;
rtl_Locale *pLocale = NULL ;
osl_getProcessLocale( &pLocale ) ;
encoding = osl_getTextEncodingFromLocale( pLocale ) ;
// CP end
fprintf( stdout, "------------- Signature details -------------\n" );
fprintf( stdout, "%s",
rtl::OUStringToOString(
getSignatureInformations(aSignatureHelper.GetSignatureInformations(), aSignatureHelper.GetSecurityEnvironment()),
encoding).getStr());
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment