Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : /*
22 : : * Turn off DEBUG Assertions
23 : : */
24 : : #ifdef _DEBUG
25 : : #define _DEBUG_WAS_DEFINED _DEBUG
26 : : #undef _DEBUG
27 : : #else
28 : : #undef _DEBUG_WAS_DEFINED
29 : : #endif
30 : :
31 : : /*
32 : : * and turn off the additional virtual methods which are part of some interfaces when compiled
33 : : * with debug
34 : : */
35 : : #ifdef DEBUG
36 : : #define DEBUG_WAS_DEFINED DEBUG
37 : : #undef DEBUG
38 : : #else
39 : : #undef DEBUG_WAS_DEFINED
40 : : #endif
41 : :
42 : : #include <sal/types.h>
43 : : #include <rtl/bootstrap.hxx>
44 : : #include <rtl/string.hxx>
45 : : #include <rtl/strbuf.hxx>
46 : : #include <osl/file.hxx>
47 : : #include <osl/thread.h>
48 : : #include <rtl/logfile.hxx>
49 : :
50 : : #include "seinitializer_nssimpl.hxx"
51 : : #include "securityenvironment_nssimpl.hxx"
52 : :
53 : : #include <nspr.h>
54 : : #include <cert.h>
55 : : #include <nss.h>
56 : : #include <pk11pub.h>
57 : : #include <secmod.h>
58 : : #include <nssckbi.h>
59 : :
60 : :
61 : : namespace css = ::com::sun::star;
62 : : namespace cssu = css::uno;
63 : : namespace cssl = css::lang;
64 : : namespace cssxc = css::xml::crypto;
65 : :
66 : : using namespace com::sun::star;
67 : : using ::rtl::OUString;
68 : : using ::rtl::OString;
69 : :
70 : : #define SE_SERVICE_NAME "com.sun.star.xml.crypto.SEInitializer"
71 : : #define IMPLEMENTATION_NAME "com.sun.star.xml.security.bridge.xmlsec.SEInitializer_NssImpl"
72 : : #define SECURITY_ENVIRONMENT "com.sun.star.xml.crypto.SecurityEnvironment"
73 : : #define SECURITY_CONTEXT "com.sun.star.xml.crypto.XMLSecurityContext"
74 : :
75 : : int nProduct = 4;
76 : 42 : SEInitializer_NssImpl::SEInitializer_NssImpl(
77 : 42 : const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF )
78 : : {
79 [ + - ]: 42 : mxMSF = rxMSF;
80 : 42 : }
81 : :
82 : 42 : SEInitializer_NssImpl::~SEInitializer_NssImpl()
83 : : {
84 [ - + ]: 84 : }
85 : :
86 : : /* XSEInitializer */
87 : : cssu::Reference< cssxc::XXMLSecurityContext > SAL_CALL
88 : 0 : SEInitializer_NssImpl::createSecurityContext( const ::rtl::OUString& )
89 : : throw (cssu::RuntimeException)
90 : : {
91 : 0 : CERTCertDBHandle *pCertHandle = NULL ;
92 : :
93 [ # # ]: 0 : if( !initNSS( mxMSF ) )
94 : 0 : return NULL;
95 : :
96 : 0 : pCertHandle = CERT_GetDefaultCertDB() ;
97 : :
98 : : try
99 : : {
100 : : /* Build XML Security Context */
101 [ # # ]: 0 : const rtl::OUString sSecyrutyContext ( RTL_CONSTASCII_USTRINGPARAM( SECURITY_CONTEXT ) );
102 [ # # ][ # # ]: 0 : cssu::Reference< cssxc::XXMLSecurityContext > xSecCtx( mxMSF->createInstance ( sSecyrutyContext ), cssu::UNO_QUERY );
[ # # ]
103 [ # # ]: 0 : if( !xSecCtx.is() )
104 [ # # ]: 0 : return NULL;
105 : :
106 [ # # ]: 0 : const rtl::OUString sSecyrutyEnvironment ( RTL_CONSTASCII_USTRINGPARAM( SECURITY_ENVIRONMENT ) );
107 [ # # ][ # # ]: 0 : cssu::Reference< cssxc::XSecurityEnvironment > xSecEnv( mxMSF->createInstance ( sSecyrutyEnvironment ), cssu::UNO_QUERY );
[ # # ]
108 [ # # ]: 0 : cssu::Reference< cssl::XUnoTunnel > xEnvTunnel( xSecEnv , cssu::UNO_QUERY ) ;
109 [ # # ]: 0 : if( !xEnvTunnel.is() )
110 [ # # ]: 0 : return NULL;
111 : : SecurityEnvironment_NssImpl* pSecEnv = reinterpret_cast<SecurityEnvironment_NssImpl*>(
112 : : sal::static_int_cast<sal_uIntPtr>(
113 [ # # ][ # # ]: 0 : xEnvTunnel->getSomething(SecurityEnvironment_NssImpl::getUnoTunnelId() ))) ;
[ # # ]
114 [ # # ]: 0 : pSecEnv->setCertDb(pCertHandle);
115 : :
116 [ # # ][ # # ]: 0 : sal_Int32 n = xSecCtx->addSecurityEnvironment(xSecEnv);
117 : : //originally the SecurityEnvironment with the internal slot was set as default
118 [ # # ][ # # ]: 0 : xSecCtx->setDefaultSecurityEnvironmentIndex( n );
119 : 0 : return xSecCtx;
120 : : }
121 [ # # ]: 0 : catch( cssu::Exception& )
122 : : {
123 : : //PK11_LogoutAll();
124 : : //NSS_Shutdown();
125 [ # # ]: 0 : return NULL;
126 : : }
127 : : }
128 : :
129 : 0 : void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const cssu::Reference< cssxc::XXMLSecurityContext >& )
130 : : throw (cssu::RuntimeException)
131 : : {
132 : : /*
133 : : * because the security context will free all its content when it
134 : : * is destructed, so here no free process for the security context
135 : : * is needed.
136 : : */
137 : : //PK11_LogoutAll();
138 : : //NSS_Shutdown();
139 : 0 : }
140 : :
141 : 3 : rtl::OUString SEInitializer_NssImpl_getImplementationName ()
142 : : throw (cssu::RuntimeException)
143 : : {
144 : :
145 : 3 : return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
146 : : }
147 : :
148 : 0 : sal_Bool SAL_CALL SEInitializer_NssImpl_supportsService( const rtl::OUString& ServiceName )
149 : : throw (cssu::RuntimeException)
150 : : {
151 [ # # ][ # # ]: 0 : return ( ServiceName == SE_SERVICE_NAME || ServiceName == NSS_SERVICE_NAME );
152 : : }
153 : :
154 : 3 : cssu::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames( )
155 : : throw (cssu::RuntimeException)
156 : : {
157 : 3 : cssu::Sequence < rtl::OUString > aRet(2);
158 [ + - ]: 3 : rtl::OUString* pArray = aRet.getArray();
159 [ + - ]: 3 : pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SE_SERVICE_NAME ) );
160 [ + - ]: 3 : pArray[1] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( NSS_SERVICE_NAME ) );
161 : 3 : return aRet;
162 : : }
163 : :
164 : 42 : cssu::Reference< cssu::XInterface > SAL_CALL SEInitializer_NssImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr)
165 : : throw( cssu::Exception )
166 : : {
167 [ + - ]: 42 : return (cppu::OWeakObject*) new SEInitializer_NssImpl(rSMgr);
168 : : }
169 : :
170 : : /* XServiceInfo */
171 : 0 : rtl::OUString SAL_CALL SEInitializer_NssImpl::getImplementationName( )
172 : : throw (cssu::RuntimeException)
173 : : {
174 : 0 : return SEInitializer_NssImpl_getImplementationName();
175 : : }
176 : 0 : sal_Bool SAL_CALL SEInitializer_NssImpl::supportsService( const rtl::OUString& rServiceName )
177 : : throw (cssu::RuntimeException)
178 : : {
179 : 0 : return SEInitializer_NssImpl_supportsService( rServiceName );
180 : : }
181 : 0 : cssu::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl::getSupportedServiceNames( )
182 : : throw (cssu::RuntimeException)
183 : : {
184 : 0 : return SEInitializer_NssImpl_getSupportedServiceNames();
185 : : }
186 : :
187 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|