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 : * and turn off the additional virtual methods which are part of some interfaces when compiled
22 : * with debug
23 : */
24 : #ifdef DEBUG
25 : #undef DEBUG
26 : #endif
27 :
28 : #include <comphelper/processfactory.hxx>
29 : #include <sal/types.h>
30 : #include <rtl/bootstrap.hxx>
31 : #include <rtl/string.hxx>
32 : #include <rtl/strbuf.hxx>
33 : #include <osl/file.hxx>
34 : #include <osl/thread.h>
35 : #include <rtl/logfile.hxx>
36 : #include <com/sun/star/xml/crypto/SecurityEnvironment.hpp>
37 : #include <com/sun/star/xml/crypto/XMLSecurityContext.hpp>
38 :
39 : #include "seinitializer_nssimpl.hxx"
40 : #include "securityenvironment_nssimpl.hxx"
41 :
42 : #include <nspr.h>
43 : #include <cert.h>
44 : #include <nss.h>
45 : #include <pk11pub.h>
46 : #include <secmod.h>
47 : #include <nssckbi.h>
48 :
49 :
50 : namespace cssl = css::lang;
51 : namespace cssxc = css::xml::crypto;
52 :
53 : using namespace com::sun::star;
54 :
55 : #define SE_SERVICE_NAME "com.sun.star.xml.crypto.SEInitializer"
56 :
57 41 : SEInitializer_NssImpl::SEInitializer_NssImpl( const css::uno::Reference< css::uno::XComponentContext > &rxContext )
58 : {
59 41 : m_xContext = rxContext;
60 41 : }
61 :
62 82 : SEInitializer_NssImpl::~SEInitializer_NssImpl()
63 : {
64 82 : }
65 :
66 : /* XSEInitializer */
67 : uno::Reference< cssxc::XXMLSecurityContext > SAL_CALL
68 0 : SEInitializer_NssImpl::createSecurityContext( const OUString& )
69 : throw (uno::RuntimeException)
70 : {
71 0 : CERTCertDBHandle *pCertHandle = NULL ;
72 :
73 0 : if( !initNSS( m_xContext ) )
74 0 : return NULL;
75 :
76 0 : pCertHandle = CERT_GetDefaultCertDB() ;
77 :
78 : try
79 : {
80 : /* Build XML Security Context */
81 0 : uno::Reference< cssxc::XXMLSecurityContext > xSecCtx = cssxc::XMLSecurityContext::create( m_xContext );
82 :
83 0 : uno::Reference< cssxc::XSecurityEnvironment > xSecEnv = cssxc::SecurityEnvironment::create( m_xContext );
84 0 : uno::Reference< lang::XUnoTunnel > xSecEnvTunnel(xSecEnv, uno::UNO_QUERY_THROW);
85 : SecurityEnvironment_NssImpl* pSecEnv = reinterpret_cast<SecurityEnvironment_NssImpl*>(
86 : sal::static_int_cast<sal_uIntPtr>(
87 0 : xSecEnvTunnel->getSomething(SecurityEnvironment_NssImpl::getUnoTunnelId() ))) ;
88 0 : pSecEnv->setCertDb(pCertHandle);
89 :
90 0 : sal_Int32 n = xSecCtx->addSecurityEnvironment(xSecEnv);
91 : //originally the SecurityEnvironment with the internal slot was set as default
92 0 : xSecCtx->setDefaultSecurityEnvironmentIndex( n );
93 0 : return xSecCtx;
94 : }
95 0 : catch( const uno::Exception& )
96 : {
97 : //PK11_LogoutAll();
98 : //NSS_Shutdown();
99 0 : return NULL;
100 : }
101 : }
102 :
103 0 : void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const uno::Reference< cssxc::XXMLSecurityContext >& )
104 : throw (uno::RuntimeException)
105 : {
106 : /*
107 : * because the security context will free all its content when it
108 : * is destructed, so here no free process for the security context
109 : * is needed.
110 : */
111 : //PK11_LogoutAll();
112 : //NSS_Shutdown();
113 0 : }
114 :
115 2 : OUString SEInitializer_NssImpl_getImplementationName ()
116 : throw (uno::RuntimeException)
117 : {
118 2 : return OUString ("com.sun.star.xml.security.bridge.xmlsec.SEInitializer_NssImpl" );
119 : }
120 :
121 0 : sal_Bool SAL_CALL SEInitializer_NssImpl_supportsService( const OUString& ServiceName )
122 : throw (uno::RuntimeException)
123 : {
124 0 : return ( ServiceName == SE_SERVICE_NAME || ServiceName == NSS_SERVICE_NAME );
125 : }
126 :
127 2 : uno::Sequence< OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames( )
128 : throw (uno::RuntimeException)
129 : {
130 2 : uno::Sequence < OUString > aRet(2);
131 2 : OUString* pArray = aRet.getArray();
132 2 : pArray[0] = OUString ( SE_SERVICE_NAME );
133 2 : pArray[1] = OUString ( NSS_SERVICE_NAME );
134 2 : return aRet;
135 : }
136 :
137 41 : uno::Reference< uno::XInterface > SAL_CALL SEInitializer_NssImpl_createInstance( const uno::Reference< lang::XMultiServiceFactory > & rxMSF)
138 : throw( uno::Exception )
139 : {
140 41 : return (cppu::OWeakObject*) new SEInitializer_NssImpl(comphelper::getComponentContext(rxMSF));
141 : }
142 :
143 : /* XServiceInfo */
144 0 : OUString SAL_CALL SEInitializer_NssImpl::getImplementationName( )
145 : throw (uno::RuntimeException)
146 : {
147 0 : return SEInitializer_NssImpl_getImplementationName();
148 : }
149 0 : sal_Bool SAL_CALL SEInitializer_NssImpl::supportsService( const OUString& rServiceName )
150 : throw (uno::RuntimeException)
151 : {
152 0 : return SEInitializer_NssImpl_supportsService( rServiceName );
153 : }
154 0 : uno::Sequence< OUString > SAL_CALL SEInitializer_NssImpl::getSupportedServiceNames( )
155 : throw (uno::RuntimeException)
156 : {
157 0 : return SEInitializer_NssImpl_getSupportedServiceNames();
158 : }
159 :
160 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|