1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmlsecurity.hxx"
26
27 #include "util.hxx"
28
29 #include <stdio.h>
30 #include <cppuhelper/servicefactory.hxx>
31
32 #include <xmlsecurity/xmlsignaturehelper.hxx>
33
34 using namespace ::com::sun::star;
35
startVerifyHandler(void *,void *)36 long startVerifyHandler( void *, void * )
37 {
38 return QueryVerifySignature();
39 }
40
main(int argc,char ** argv)41 int SAL_CALL main( int argc, char **argv )
42 {
43 if( argc < 2 )
44 {
45 fprintf( stderr, "Usage: %s <signature file> [<cryptoken>]\n" , argv[0] ) ;
46 return -1 ;
47 }
48
49 rtl::OUString aSIGFileName = rtl::OUString::createFromAscii(argv[1]);
50 rtl::OUString aCryptoToken;
51 if ( argc >= 3 )
52 aCryptoToken = rtl::OUString::createFromAscii(argv[2]);
53
54 uno::Reference< lang::XMultiServiceFactory > xMSF = CreateDemoServiceFactory();
55
56
57 /*
58 * creates a signature helper
59 */
60 XMLSignatureHelper aSignatureHelper( xMSF );
61
62 /*
63 * creates a security context.
64 */
65 bool bInit = aSignatureHelper.Init( aCryptoToken );
66 if ( !bInit )
67 {
68 fprintf( stderr, "Error initializing security context!" );
69 return -1;
70 }
71
72 /*
73 * configures the start-verify handler
74 */
75 aSignatureHelper.SetStartVerifySignatureHdl( Link( NULL, startVerifyHandler ) );
76
77 aSignatureHelper.StartMission();
78
79 /*
80 * verifies the signature
81 */
82 uno::Reference< io::XInputStream > xInputStream = OpenInputStream( aSIGFileName );
83 bool bDone = aSignatureHelper.ReadAndVerifySignature( xInputStream );
84
85 /*
86 * closes the signature stream
87 */
88 xInputStream->closeInput();
89
90 if ( !bDone )
91 {
92 fprintf( stderr, "\nSTATUS: Error verifying Signature!\n" );
93 }
94 else
95 {
96 fprintf( stdout, "\nSTATUS: All choosen Signatures veryfied successfully!\n" );
97 }
98
99 aSignatureHelper.EndMission();
100
101 QueryPrintSignatureDetails( aSignatureHelper.GetSignatureInformations(), aSignatureHelper.GetSecurityEnvironment() );
102
103 return 0;
104 }
105
106