LCOV - code coverage report
Current view: top level - xmlsecurity/source/xmlsec/nss - seinitializer_nssimpl.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 38 0.0 %
Date: 2014-04-14 Functions: 0 11 0.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             :  * 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           0 : SEInitializer_NssImpl::SEInitializer_NssImpl( const css::uno::Reference< css::uno::XComponentContext > &rxContext )
      57             : {
      58           0 :     m_xContext = rxContext;
      59           0 : }
      60             : 
      61           0 : SEInitializer_NssImpl::~SEInitializer_NssImpl()
      62             : {
      63           0 : }
      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           0 : OUString SEInitializer_NssImpl_getImplementationName ()
     115             :     throw (uno::RuntimeException)
     116             : {
     117           0 :     return OUString ("com.sun.star.xml.security.bridge.xmlsec.SEInitializer_NssImpl" );
     118             : }
     119             : 
     120           0 : uno::Sequence< OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames(  )
     121             :     throw (uno::RuntimeException)
     122             : {
     123           0 :     uno::Sequence < OUString > aRet(2);
     124           0 :     OUString* pArray = aRet.getArray();
     125           0 :     pArray[0] =  "com.sun.star.xml.crypto.SEInitializer";
     126           0 :     pArray[1] =  OUString ( NSS_SERVICE_NAME );
     127           0 :     return aRet;
     128             : }
     129             : 
     130           0 : uno::Reference< uno::XInterface > SAL_CALL SEInitializer_NssImpl_createInstance( const uno::Reference< lang::XMultiServiceFactory > & rxMSF)
     131             :     throw( uno::Exception )
     132             : {
     133           0 :     return (cppu::OWeakObject*) new SEInitializer_NssImpl(comphelper::getComponentContext(rxMSF));
     134             : }
     135             : 
     136             : /* XServiceInfo */
     137           0 : OUString SAL_CALL SEInitializer_NssImpl::getImplementationName(  )
     138             :     throw (uno::RuntimeException, std::exception)
     139             : {
     140           0 :     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           0 : uno::Sequence< OUString > SAL_CALL SEInitializer_NssImpl::getSupportedServiceNames(  )
     148             :     throw (uno::RuntimeException, std::exception)
     149             : {
     150           0 :     return SEInitializer_NssImpl_getSupportedServiceNames();
     151             : }
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10