LCOV - code coverage report
Current view: top level - xmlsecurity/source/xmlsec/nss - seinitializer_nssimpl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 19 38 50.0 %
Date: 2015-06-13 12:38:46 Functions: 8 11 72.7 %
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             :  * 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 <com/sun/star/xml/crypto/SecurityEnvironment.hpp>
      36             : #include <com/sun/star/xml/crypto/XMLSecurityContext.hpp>
      37             : #include <cppuhelper/supportsservice.hxx>
      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             : 
      56          67 : SEInitializer_NssImpl::SEInitializer_NssImpl( const css::uno::Reference< css::uno::XComponentContext > &rxContext )
      57             : {
      58          67 :     m_xContext = rxContext;
      59          67 : }
      60             : 
      61         134 : SEInitializer_NssImpl::~SEInitializer_NssImpl()
      62             : {
      63         134 : }
      64             : 
      65             : /* XSEInitializer */
      66             : uno::Reference< cssxc::XXMLSecurityContext > SAL_CALL
      67           0 :     SEInitializer_NssImpl::createSecurityContext( const OUString& )
      68             :     throw (uno::RuntimeException, std::exception)
      69             : {
      70           0 :     CERTCertDBHandle    *pCertHandle = NULL ;
      71             : 
      72           0 :     if( !initNSS( m_xContext ) )
      73           0 :         return NULL;
      74             : 
      75           0 :     pCertHandle = CERT_GetDefaultCertDB() ;
      76             : 
      77             :     try
      78             :     {
      79             :         /* Build XML Security Context */
      80           0 :         uno::Reference< cssxc::XXMLSecurityContext > xSecCtx = cssxc::XMLSecurityContext::create( m_xContext );
      81             : 
      82           0 :         uno::Reference< cssxc::XSecurityEnvironment > xSecEnv = cssxc::SecurityEnvironment::create( m_xContext );
      83           0 :         uno::Reference< lang::XUnoTunnel > xSecEnvTunnel(xSecEnv, uno::UNO_QUERY_THROW);
      84             :         SecurityEnvironment_NssImpl* pSecEnv = reinterpret_cast<SecurityEnvironment_NssImpl*>(
      85             :             sal::static_int_cast<sal_uIntPtr>(
      86           0 :                 xSecEnvTunnel->getSomething(SecurityEnvironment_NssImpl::getUnoTunnelId() ))) ;
      87           0 :         pSecEnv->setCertDb(pCertHandle);
      88             : 
      89           0 :         sal_Int32 n = xSecCtx->addSecurityEnvironment(xSecEnv);
      90             :         //originally the SecurityEnvironment with the internal slot was set as default
      91           0 :         xSecCtx->setDefaultSecurityEnvironmentIndex( n );
      92           0 :         return xSecCtx;
      93             :     }
      94           0 :     catch( const uno::Exception& )
      95             :     {
      96             :         //PK11_LogoutAll();
      97             :         //NSS_Shutdown();
      98           0 :         return NULL;
      99             :     }
     100             : }
     101             : 
     102           0 : void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const uno::Reference< cssxc::XXMLSecurityContext >& )
     103             :     throw (uno::RuntimeException, std::exception)
     104             : {
     105             :     /*
     106             :      * because the security context will free all its content when it
     107             :      * is destructed, so here no free process for the security context
     108             :      * is needed.
     109             :      */
     110             :     //PK11_LogoutAll();
     111             :     //NSS_Shutdown();
     112           0 : }
     113             : 
     114          10 : OUString SEInitializer_NssImpl_getImplementationName ()
     115             :     throw (uno::RuntimeException)
     116             : {
     117          10 :     return OUString ("com.sun.star.xml.security.bridge.xmlsec.SEInitializer_NssImpl" );
     118             : }
     119             : 
     120           6 : uno::Sequence< OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames(  )
     121             :     throw (uno::RuntimeException)
     122             : {
     123           6 :     uno::Sequence < OUString > aRet(2);
     124           6 :     OUString* pArray = aRet.getArray();
     125           6 :     pArray[0] =  "com.sun.star.xml.crypto.SEInitializer";
     126           6 :     pArray[1] =  NSS_SERVICE_NAME;
     127           6 :     return aRet;
     128             : }
     129             : 
     130          67 : uno::Reference< uno::XInterface > SAL_CALL SEInitializer_NssImpl_createInstance( const uno::Reference< lang::XMultiServiceFactory > & rxMSF)
     131             :     throw( uno::Exception )
     132             : {
     133          67 :     return static_cast<cppu::OWeakObject*>(new SEInitializer_NssImpl(comphelper::getComponentContext(rxMSF)));
     134             : }
     135             : 
     136             : /* XServiceInfo */
     137           2 : OUString SAL_CALL SEInitializer_NssImpl::getImplementationName(  )
     138             :     throw (uno::RuntimeException, std::exception)
     139             : {
     140           2 :     return SEInitializer_NssImpl_getImplementationName();
     141             : }
     142           0 : sal_Bool SAL_CALL SEInitializer_NssImpl::supportsService( const OUString& rServiceName )
     143             :     throw (uno::RuntimeException, std::exception)
     144             : {
     145           0 :     return cppu::supportsService( this, rServiceName );
     146             : }
     147           2 : uno::Sequence< OUString > SAL_CALL SEInitializer_NssImpl::getSupportedServiceNames(  )
     148             :     throw (uno::RuntimeException, std::exception)
     149             : {
     150           2 :     return SEInitializer_NssImpl_getSupportedServiceNames();
     151             : }
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11