LCOV - code coverage report
Current view: top level - libreoffice/xmlsecurity/source/xmlsec/nss - seinitializer_nssimpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 15 46 32.6 %
Date: 2012-12-27 Functions: 6 12 50.0 %
Legend: Lines: hit not hit

          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 <comphelper/processfactory.hxx>
      43             : #include <sal/types.h>
      44             : #include <rtl/bootstrap.hxx>
      45             : #include <rtl/string.hxx>
      46             : #include <rtl/strbuf.hxx>
      47             : #include <osl/file.hxx>
      48             : #include <osl/thread.h>
      49             : #include <rtl/logfile.hxx>
      50             : 
      51             : #include "seinitializer_nssimpl.hxx"
      52             : #include "securityenvironment_nssimpl.hxx"
      53             : 
      54             : #include <nspr.h>
      55             : #include <cert.h>
      56             : #include <nss.h>
      57             : #include <pk11pub.h>
      58             : #include <secmod.h>
      59             : #include <nssckbi.h>
      60             : 
      61             : 
      62             : namespace cssl = css::lang;
      63             : namespace cssxc = css::xml::crypto;
      64             : 
      65             : using namespace com::sun::star;
      66             : using ::rtl::OUString;
      67             : using ::rtl::OString;
      68             : 
      69             : #define SE_SERVICE_NAME "com.sun.star.xml.crypto.SEInitializer"
      70             : #define IMPLEMENTATION_NAME "com.sun.star.xml.security.bridge.xmlsec.SEInitializer_NssImpl"
      71             : #define SECURITY_ENVIRONMENT "com.sun.star.xml.crypto.SecurityEnvironment"
      72             : #define SECURITY_CONTEXT "com.sun.star.xml.crypto.XMLSecurityContext"
      73             : 
      74          36 : SEInitializer_NssImpl::SEInitializer_NssImpl( const css::uno::Reference< css::uno::XComponentContext > &rxContext )
      75             : {
      76          36 :     m_xContext = rxContext;
      77          36 : }
      78             : 
      79          72 : SEInitializer_NssImpl::~SEInitializer_NssImpl()
      80             : {
      81          72 : }
      82             : 
      83             : /* XSEInitializer */
      84             : uno::Reference< cssxc::XXMLSecurityContext > SAL_CALL
      85           0 :     SEInitializer_NssImpl::createSecurityContext( const ::rtl::OUString& )
      86             :     throw (uno::RuntimeException)
      87             : {
      88           0 :     CERTCertDBHandle    *pCertHandle = NULL ;
      89             : 
      90           0 :     if( !initNSS( m_xContext ) )
      91           0 :         return NULL;
      92             : 
      93           0 :     pCertHandle = CERT_GetDefaultCertDB() ;
      94             : 
      95             :     try
      96             :     {
      97             :         /* Build XML Security Context */
      98           0 :         const rtl::OUString sSecyrutyContext ( RTL_CONSTASCII_USTRINGPARAM( SECURITY_CONTEXT ) );
      99           0 :         uno::Reference< cssxc::XXMLSecurityContext > xSecCtx( m_xContext->getServiceManager()->createInstanceWithContext(sSecyrutyContext, m_xContext), uno::UNO_QUERY );
     100           0 :         if( !xSecCtx.is() )
     101           0 :             return NULL;
     102             : 
     103           0 :         const rtl::OUString sSecyrutyEnvironment ( RTL_CONSTASCII_USTRINGPARAM( SECURITY_ENVIRONMENT ) );
     104           0 :         uno::Reference< cssxc::XSecurityEnvironment > xSecEnv( m_xContext->getServiceManager()->createInstanceWithContext(sSecyrutyEnvironment, m_xContext), uno::UNO_QUERY );
     105           0 :         uno::Reference< cssl::XUnoTunnel > xEnvTunnel( xSecEnv , uno::UNO_QUERY ) ;
     106           0 :         if( !xEnvTunnel.is() )
     107           0 :             return NULL;
     108             :         SecurityEnvironment_NssImpl* pSecEnv = reinterpret_cast<SecurityEnvironment_NssImpl*>(
     109             :             sal::static_int_cast<sal_uIntPtr>(
     110           0 :                 xEnvTunnel->getSomething(SecurityEnvironment_NssImpl::getUnoTunnelId() ))) ;
     111           0 :         pSecEnv->setCertDb(pCertHandle);
     112             : 
     113           0 :         sal_Int32 n = xSecCtx->addSecurityEnvironment(xSecEnv);
     114             :         //originally the SecurityEnvironment with the internal slot was set as default
     115           0 :         xSecCtx->setDefaultSecurityEnvironmentIndex( n );
     116           0 :         return xSecCtx;
     117             :     }
     118           0 :     catch( const uno::Exception& )
     119             :     {
     120             :         //PK11_LogoutAll();
     121             :         //NSS_Shutdown();
     122           0 :         return NULL;
     123             :     }
     124             : }
     125             : 
     126           0 : void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const uno::Reference< cssxc::XXMLSecurityContext >& )
     127             :     throw (uno::RuntimeException)
     128             : {
     129             :     /*
     130             :      * because the security context will free all its content when it
     131             :      * is destructed, so here no free process for the security context
     132             :      * is needed.
     133             :      */
     134             :     //PK11_LogoutAll();
     135             :     //NSS_Shutdown();
     136           0 : }
     137             : 
     138           2 : rtl::OUString SEInitializer_NssImpl_getImplementationName ()
     139             :     throw (uno::RuntimeException)
     140             : {
     141             : 
     142           2 :     return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
     143             : }
     144             : 
     145           0 : sal_Bool SAL_CALL SEInitializer_NssImpl_supportsService( const rtl::OUString& ServiceName )
     146             :     throw (uno::RuntimeException)
     147             : {
     148           0 :     return ( ServiceName == SE_SERVICE_NAME || ServiceName == NSS_SERVICE_NAME );
     149             : }
     150             : 
     151           2 : uno::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames(  )
     152             :     throw (uno::RuntimeException)
     153             : {
     154           2 :     uno::Sequence < rtl::OUString > aRet(2);
     155           2 :     rtl::OUString* pArray = aRet.getArray();
     156           2 :     pArray[0] =  rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SE_SERVICE_NAME ) );
     157           2 :     pArray[1] =  rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( NSS_SERVICE_NAME ) );
     158           2 :     return aRet;
     159             : }
     160             : 
     161          36 : uno::Reference< uno::XInterface > SAL_CALL SEInitializer_NssImpl_createInstance( const uno::Reference< lang::XMultiServiceFactory > & rxMSF)
     162             :     throw( uno::Exception )
     163             : {
     164          36 :     return (cppu::OWeakObject*) new SEInitializer_NssImpl(comphelper::getComponentContext(rxMSF));
     165             : }
     166             : 
     167             : /* XServiceInfo */
     168           0 : rtl::OUString SAL_CALL SEInitializer_NssImpl::getImplementationName(  )
     169             :     throw (uno::RuntimeException)
     170             : {
     171           0 :     return SEInitializer_NssImpl_getImplementationName();
     172             : }
     173           0 : sal_Bool SAL_CALL SEInitializer_NssImpl::supportsService( const rtl::OUString& rServiceName )
     174             :     throw (uno::RuntimeException)
     175             : {
     176           0 :     return SEInitializer_NssImpl_supportsService( rServiceName );
     177             : }
     178           0 : uno::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl::getSupportedServiceNames(  )
     179             :     throw (uno::RuntimeException)
     180             : {
     181           0 :     return SEInitializer_NssImpl_getSupportedServiceNames();
     182             : }
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10