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 <tools/date.hxx>
31 #include <tools/time.hxx>
32 #include <cppuhelper/servicefactory.hxx>
33 
34 #include <xmlsecurity/biginteger.hxx>
35 #include <xmlsecurity/xmlsignaturehelper.hxx>
36 #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
37 
38 using namespace ::com::sun::star;
39 
40 int SAL_CALL main( int argc, char **argv )
41 {
42 	fprintf( stdout, "\nTesting Mozilla Profile Detection...\n\nOpenOffice.org will use the first detected profile.\nResults might be different when started in OOo program folder!\n" ) ;
43 
44 	uno::Reference< lang::XMultiServiceFactory > xMSF = CreateDemoServiceFactory();
45 	if ( !xMSF.is() )
46 	{
47 	    fprintf( stdout, "\n\nERROR: Can't create Service Factory\n" );
48 	    exit (-1);
49 	}
50 
51 	uno::Reference<mozilla::XMozillaBootstrap> xMozillaBootstrap( xMSF->createInstance(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap" ) ) ), uno::UNO_QUERY );
52 	if ( !xMozillaBootstrap.is() )
53 	{
54 	    fprintf( stdout, "\n\nERROR: Can't create Mozilla Bootstrap Service\n" );
55 	    exit (-1);
56 	}
57 
58 	int nProducts = 4;
59 	mozilla::MozillaProductType productTypes[4] = { mozilla::MozillaProductType_Thunderbird, mozilla::MozillaProductType_Mozilla, mozilla::MozillaProductType_Firefox, mozilla::MozillaProductType_Default };
60 	for ( int i = 0; i < nProducts; i++)
61 	{
62 	    if ( i == 0 )
63 	        fprintf( stdout, "\nThunderbird: " );
64 	    else if ( i == 1 )
65 	        fprintf( stdout, "\nMozilla:     " );
66 	    else if ( i == 2 )
67 	        fprintf( stdout, "\nFireFox:     " );
68 	    else
69 	        fprintf( stdout, "\nDefault:     " );
70 
71 		::rtl::OUString profile = xMozillaBootstrap->getDefaultProfile(productTypes[i]);
72 		if ( profile.getLength() )
73 		{
74 			::rtl::OUString profilepath = xMozillaBootstrap->getProfilePath(productTypes[i],profile);
75 	        fprintf( stdout, "Name=%s, Path=%s", rtl::OUStringToOString( profile , RTL_TEXTENCODING_ASCII_US ).getStr(), rtl::OUStringToOString( profilepath , RTL_TEXTENCODING_ASCII_US ).getStr() );
76 		}
77 		else
78 		{
79 		    fprintf( stdout, "NOT FOUND" );
80 		}
81 	}
82 
83 	/*
84 	 * creates a signature helper
85 	 */
86 	XMLSignatureHelper aSignatureHelper( xMSF );
87 
88 	/*
89 	 * creates a security context.
90 	 */
91 	rtl::OUString aCryptoToken;
92 	bool bInit = aSignatureHelper.Init( aCryptoToken );
93 	if ( !bInit )
94 	{
95 		fprintf( stdout, "\n\nERROR: Unable to initialize security environment.\n\n" );
96 	}
97 	else
98 	{
99 		fprintf( stdout, "\n\nSecurity environment can be initialized successfully.\n\n" );
100     }
101 
102 	return 0;
103 }
104 
105