LCOV - code coverage report
Current view: top level - xmlsecurity/source/xmlsec/nss - nssinitializer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 119 186 64.0 %
Date: 2012-08-25 Functions: 12 21 57.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 86 264 32.6 %

           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                 :            : 
      43                 :            : #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
      44                 :            : #include <com/sun/star/xml/crypto/DigestID.hpp>
      45                 :            : #include <com/sun/star/xml/crypto/CipherID.hpp>
      46                 :            : 
      47                 :            : #include <officecfg/Office/Common.hxx>
      48                 :            : 
      49                 :            : #include <sal/types.h>
      50                 :            : #include <rtl/instance.hxx>
      51                 :            : #include <rtl/bootstrap.hxx>
      52                 :            : #include <rtl/string.hxx>
      53                 :            : #include <rtl/strbuf.hxx>
      54                 :            : #include <osl/file.hxx>
      55                 :            : #include <osl/thread.h>
      56                 :            : #include <rtl/logfile.hxx>
      57                 :            : 
      58                 :            : #include "seinitializer_nssimpl.hxx"
      59                 :            : #include "../diagnose.hxx"
      60                 :            : 
      61                 :            : #include "securityenvironment_nssimpl.hxx"
      62                 :            : #include "digestcontext.hxx"
      63                 :            : #include "ciphercontext.hxx"
      64                 :            : 
      65                 :            : #include <nspr.h>
      66                 :            : #include <cert.h>
      67                 :            : #include <nss.h>
      68                 :            : #include <pk11pub.h>
      69                 :            : #include <secmod.h>
      70                 :            : #include <nssckbi.h>
      71                 :            : 
      72                 :            : namespace css = ::com::sun::star;
      73                 :            : namespace cssu = css::uno;
      74                 :            : namespace cssl = css::lang;
      75                 :            : 
      76                 :            : using namespace xmlsecurity;
      77                 :            : using namespace com::sun::star;
      78                 :            : using ::rtl::OUString;
      79                 :            : using ::rtl::OString;
      80                 :            : 
      81                 :            : #define IMPLEMENTATION_NAME "com.sun.star.xml.security.bridge.xmlsec.NSSInitializer_NssImpl"
      82                 :            : 
      83                 :            : #define ROOT_CERTS "Root Certs for OpenOffice.org"
      84                 :            : 
      85                 :            : extern "C" void nsscrypto_finalize();
      86                 :            : 
      87                 :            : 
      88                 :            : namespace
      89                 :            : {
      90                 :            : 
      91                 :            : bool nsscrypto_initialize( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF, bool & out_nss_init );
      92                 :            : 
      93                 :         42 : struct InitNSSInitialize
      94                 :            : {
      95                 :            :     css::uno::Reference< css::lang::XMultiServiceFactory > mxMSF;
      96                 :            : 
      97                 :         42 :     InitNSSInitialize( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF )
      98                 :         42 :     : mxMSF( xMSF )
      99                 :            :     {
     100                 :         42 :     }
     101                 :            : 
     102                 :          3 :     bool * operator()()
     103                 :            :         {
     104                 :            :             static bool bInitialized = false;
     105                 :          3 :             bool bNSSInit = false;
     106         [ +  - ]:          3 :             bInitialized = nsscrypto_initialize( mxMSF, bNSSInit );
     107         [ +  - ]:          3 :             if (bNSSInit)
     108                 :          3 :                 atexit(nsscrypto_finalize );
     109                 :          3 :              return & bInitialized;
     110                 :            :         }
     111                 :            : };
     112                 :            : 
     113                 :            : struct GetNSSInitStaticMutex
     114                 :            : {
     115                 :          3 :     ::osl::Mutex* operator()()
     116                 :            :     {
     117 [ +  - ][ +  - ]:          3 :         static ::osl::Mutex aNSSInitMutex;
         [ +  - ][ #  # ]
     118                 :          3 :         return &aNSSInitMutex;
     119                 :            :     }
     120                 :            : };
     121                 :            : 
     122                 :          3 : void deleteRootsModule()
     123                 :            : {
     124                 :          3 :     SECMODModule *RootsModule = 0;
     125                 :          3 :     SECMODModuleList *list = SECMOD_GetDefaultModuleList();
     126                 :          3 :     SECMODListLock *lock = SECMOD_GetDefaultModuleListLock();
     127                 :          3 :     SECMOD_GetReadLock(lock);
     128                 :            : 
     129 [ +  - ][ +  + ]:          6 :     while (!RootsModule && list)
                 [ +  + ]
     130                 :            :     {
     131                 :          3 :         SECMODModule *module = list->module;
     132                 :            : 
     133         [ +  + ]:          9 :         for (int i=0; i < module->slotCount; i++)
     134                 :            :         {
     135                 :          6 :             PK11SlotInfo *slot = module->slots[i];
     136         [ +  - ]:          6 :             if (PK11_IsPresent(slot))
     137                 :            :             {
     138         [ -  + ]:          6 :                 if (PK11_HasRootCerts(slot))
     139                 :            :                 {
     140                 :            :                     xmlsec_trace("The root certifificates module \"%s"
     141                 :            :                               "\" is already loaded: \n%s",
     142                 :          0 :                               module->commonName,  module->dllName);
     143                 :            : 
     144                 :          0 :                     RootsModule = SECMOD_ReferenceModule(module);
     145                 :          0 :                     break;
     146                 :            :                 }
     147                 :            :             }
     148                 :            :         }
     149                 :          3 :         list = list->next;
     150                 :            :     }
     151                 :          3 :     SECMOD_ReleaseReadLock(lock);
     152                 :            : 
     153         [ -  + ]:          3 :     if (RootsModule)
     154                 :            :     {
     155                 :            :         PRInt32 modType;
     156 [ #  # ][ #  # ]:          0 :         if (SECSuccess == SECMOD_DeleteModule(RootsModule->commonName, &modType))
     157                 :            :         {
     158         [ #  # ]:          0 :             xmlsec_trace("Deleted module \"%s\".", RootsModule->commonName);
     159                 :            :         }
     160                 :            :         else
     161                 :            :         {
     162                 :            :             xmlsec_trace("Failed to delete \"%s\" : \n%s",
     163         [ #  # ]:          0 :                       RootsModule->commonName, RootsModule->dllName);
     164                 :            :         }
     165         [ #  # ]:          0 :         SECMOD_DestroyModule(RootsModule);
     166                 :          0 :         RootsModule = 0;
     167                 :            :     }
     168                 :          3 : }
     169                 :            : 
     170                 :          3 : ::rtl::OString getMozillaCurrentProfile( const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF )
     171                 :            : {
     172                 :            :     // first, try to get the profile from "MOZILLA_CERTIFICATE_FOLDER"
     173                 :          3 :     const char* pEnv = getenv("MOZILLA_CERTIFICATE_FOLDER");
     174         [ -  + ]:          3 :     if (pEnv)
     175                 :          0 :         return rtl::OString(pEnv);
     176                 :            : 
     177                 :            :     // second, try to get saved user-preference
     178                 :            :     try
     179                 :            :     {
     180                 :            :         rtl::OUString sUserSetCertPath =
     181 [ +  - ][ +  - ]:          3 :             officecfg::Office::Common::Security::Scripting::CertDir::get().get_value_or(rtl::OUString());
         [ +  - ][ +  - ]
     182                 :            : 
     183         [ -  + ]:          3 :         if (!sUserSetCertPath.isEmpty())
     184 [ #  # ][ #  # ]:          3 :             return rtl::OUStringToOString(sUserSetCertPath, osl_getThreadTextEncoding());
         [ +  - ][ #  # ]
     185                 :            :     }
     186         [ #  # ]:          0 :     catch (const uno::Exception &e)
     187                 :            :     {
     188                 :            :         SAL_WARN("xmlsecurity", "getMozillaCurrentProfile: caught exception" << e.Message);
     189                 :            :     }
     190                 :            : 
     191                 :            :     // third, dig around to see if there's one available
     192                 :            :     mozilla::MozillaProductType productTypes[3] = {
     193                 :            :         mozilla::MozillaProductType_Thunderbird,
     194                 :            :         mozilla::MozillaProductType_Firefox,
     195                 :          3 :         mozilla::MozillaProductType_Mozilla };
     196                 :          3 :     int nProduct = SAL_N_ELEMENTS(productTypes);
     197                 :            : 
     198         [ +  - ]:          3 :     uno::Reference<uno::XInterface> xInstance = rxMSF->createInstance(
     199         [ +  - ]:          3 :         "com.sun.star.mozilla.MozillaBootstrap");
     200                 :            :     OSL_ENSURE( xInstance.is(), "failed to create instance" );
     201                 :            : 
     202                 :            :     uno::Reference<mozilla::XMozillaBootstrap> xMozillaBootstrap
     203         [ +  - ]:          3 :         =  uno::Reference<mozilla::XMozillaBootstrap>(xInstance,uno::UNO_QUERY);
     204                 :            :     OSL_ENSURE( xMozillaBootstrap.is(), "failed to create instance" );
     205                 :            : 
     206         [ -  + ]:          3 :     if (xMozillaBootstrap.is())
     207                 :            :     {
     208         [ #  # ]:          0 :         for (int i=0; i<nProduct; ++i)
     209                 :            :         {
     210 [ #  # ][ #  # ]:          0 :             rtl::OUString profile = xMozillaBootstrap->getDefaultProfile(productTypes[i]);
     211                 :            : 
     212         [ #  # ]:          0 :             if (!profile.isEmpty())
     213                 :            :             {
     214 [ #  # ][ #  # ]:          0 :                 rtl::OUString sProfilePath = xMozillaBootstrap->getProfilePath( productTypes[i], profile );
     215 [ #  # ][ #  # ]:          0 :                 return rtl::OUStringToOString(sProfilePath, osl_getThreadTextEncoding());
     216                 :            :             }
     217         [ #  # ]:          0 :         }
     218                 :            :     }
     219                 :            : 
     220         [ +  - ]:          3 :     RTL_LOGFILE_PRODUCT_TRACE( "XMLSEC: No Mozilla Profile found!" );
     221                 :            : 
     222                 :          3 :     return rtl::OString();
     223                 :            : }
     224                 :            : 
     225                 :            : //Older versions of Firefox (FF), for example FF2, and Thunderbird (TB) 2 write
     226                 :            : //the roots certificate module (libnssckbi.so), which they use, into the
     227                 :            : //profile. This module will then already be loaded during NSS_Init (and the
     228                 :            : //other init functions). This fails in two cases. First, FF3 was used to create
     229                 :            : //the profile, or possibly used that profile before, and second the profile was
     230                 :            : //used on a different platform.
     231                 :            : //
     232                 :            : //Then one needs to add the roots module oneself. This should be done with
     233                 :            : //SECMOD_LoadUserModule rather then SECMOD_AddNewModule. The latter would write
     234                 :            : //the location of the roots module to the profile, which makes FF2 and TB2 use
     235                 :            : //it instead of there own module.
     236                 :            : //
     237                 :            : //When using SYSTEM_MOZILLA then the libnss3.so lib is typically found in
     238                 :            : ///usr/lib. This folder may, however, NOT contain the roots certificate
     239                 :            : //module. That is, just providing the library name in SECMOD_LoadUserModule or
     240                 :            : //SECMOD_AddNewModule will FAIL to load the mozilla unless the LD_LIBRARY_PATH
     241                 :            : //contains an FF or TB installation.
     242                 :            : //ATTENTION: DO NOT call this function directly instead use initNSS
     243                 :            : //return true - whole initialization was successful
     244                 :            : //param out_nss_init = true: at least the NSS initialization (NSS_InitReadWrite
     245                 :            : //was successful and therefor NSS_Shutdown should be called when terminating.
     246                 :          3 : bool nsscrypto_initialize( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF, bool & out_nss_init )
     247                 :            : {
     248                 :          3 :     bool return_value = true;
     249                 :            : 
     250                 :            :     // this method must be called only once, no need for additional lock
     251                 :          3 :     rtl::OString sCertDir;
     252                 :            : 
     253                 :            : #ifdef XMLSEC_CRYPTO_NSS
     254         [ +  - ]:          3 :     sCertDir = getMozillaCurrentProfile(xMSF);
     255                 :            : #else
     256                 :            :     (void) xMSF;
     257                 :            : #endif
     258         [ +  - ]:          3 :     xmlsec_trace( "Using profile: %s", sCertDir.getStr() );
     259                 :            : 
     260         [ +  - ]:          3 :     PR_Init( PR_USER_THREAD, PR_PRIORITY_NORMAL, 1 ) ;
     261                 :            : 
     262                 :          3 :     bool bSuccess = true;
     263                 :            :     // there might be no profile
     264         [ -  + ]:          3 :     if ( !sCertDir.isEmpty() )
     265                 :            :     {
     266 [ #  # ][ #  # ]:          0 :         if( NSS_InitReadWrite( sCertDir.getStr() ) != SECSuccess )
     267                 :            :         {
     268         [ #  # ]:          0 :             xmlsec_trace("Initializing NSS with profile failed.");
     269                 :          0 :             char * error = NULL;
     270                 :            : 
     271         [ #  # ]:          0 :             PR_GetErrorText(error);
     272         [ #  # ]:          0 :             if (error)
     273         [ #  # ]:          0 :                 xmlsec_trace("%s",error);
     274                 :          0 :             bSuccess = false;
     275                 :            :         }
     276                 :            :     }
     277                 :            : 
     278 [ -  + ][ #  # ]:          3 :     if( sCertDir.isEmpty() || !bSuccess )
                 [ +  - ]
     279                 :            :     {
     280         [ +  - ]:          3 :         xmlsec_trace("Initializing NSS without profile.");
     281 [ +  - ][ -  + ]:          3 :         if ( NSS_NoDB_Init(NULL) != SECSuccess )
     282                 :            :         {
     283         [ #  # ]:          0 :             xmlsec_trace("Initializing NSS without profile failed.");
     284                 :          0 :             char * error = NULL;
     285         [ #  # ]:          0 :             PR_GetErrorText(error);
     286         [ #  # ]:          0 :             if (error)
     287         [ #  # ]:          0 :                 xmlsec_trace("%s",error);
     288                 :          0 :             return false ;
     289                 :            :         }
     290                 :            :     }
     291                 :          3 :     out_nss_init = true;
     292                 :            : 
     293                 :            : #ifdef XMLSEC_CRYPTO_NSS
     294                 :            : #if defined SYSTEM_MOZILLA
     295 [ +  - ][ +  - ]:          3 :     if (!SECMOD_HasRootCerts())
     296                 :            :     {
     297                 :            : #endif
     298         [ +  - ]:          3 :         deleteRootsModule();
     299                 :            : 
     300                 :            : #if defined SYSTEM_MOZILLA
     301         [ +  - ]:          3 :         OUString rootModule(RTL_CONSTASCII_USTRINGPARAM("libnssckbi" SAL_DLLEXTENSION));
     302                 :            : #else
     303                 :            :         OUString rootModule(RTL_CONSTASCII_USTRINGPARAM("${LO_LIB_DIR}/libnssckbi" SAL_DLLEXTENSION));
     304                 :            : #endif
     305                 :          3 :         ::rtl::Bootstrap::expandMacros(rootModule);
     306                 :            : 
     307                 :          3 :         OUString rootModulePath;
     308 [ +  - ][ +  - ]:          3 :         if (::osl::File::E_None == ::osl::File::getSystemPathFromFileURL(rootModule, rootModulePath))
     309                 :            :         {
     310 [ +  - ][ +  - ]:          3 :             ::rtl::OString ospath = ::rtl::OUStringToOString(rootModulePath, osl_getThreadTextEncoding());
     311                 :          3 :             ::rtl::OStringBuffer pkcs11moduleSpec;
     312         [ +  - ]:          3 :             pkcs11moduleSpec.append("name=\"");
     313         [ +  - ]:          3 :             pkcs11moduleSpec.append(ROOT_CERTS);
     314         [ +  - ]:          3 :             pkcs11moduleSpec.append("\" library=\"");
     315         [ +  - ]:          3 :             pkcs11moduleSpec.append(ospath.getStr());
     316         [ +  - ]:          3 :             pkcs11moduleSpec.append("\"");
     317                 :            : 
     318                 :            :             SECMODModule * RootsModule =
     319                 :            :                 SECMOD_LoadUserModule(
     320                 :          6 :                     const_cast<char*>(pkcs11moduleSpec.makeStringAndClear().getStr()),
     321                 :            :                     0, // no parent
     322         [ +  - ]:          3 :                     PR_FALSE); // do not recurse
     323                 :            : 
     324         [ +  - ]:          3 :             if (RootsModule)
     325                 :            :             {
     326                 :            : 
     327                 :          3 :                 bool found = RootsModule->loaded;
     328                 :            : 
     329         [ +  - ]:          3 :                 SECMOD_DestroyModule(RootsModule);
     330                 :          3 :                 RootsModule = 0;
     331         [ +  - ]:          3 :                 if (found)
     332                 :            :                     xmlsec_trace("Added new root certificate module "
     333         [ +  - ]:          3 :                               "\"" ROOT_CERTS "\" contained in \n%s", ospath.getStr());
     334                 :            :                 else
     335                 :            :                 {
     336                 :            :                     xmlsec_trace("FAILED to load the new root certificate module "
     337         [ #  # ]:          0 :                               "\"" ROOT_CERTS "\" contained in \n%s", ospath.getStr());
     338                 :          0 :                     return_value = false;
     339                 :            :                 }
     340                 :            :             }
     341                 :            :             else
     342                 :            :             {
     343                 :            :                 xmlsec_trace("FAILED to add new root certifice module: "
     344         [ #  # ]:          0 :                           "\"" ROOT_CERTS "\" contained in \n%s", ospath.getStr());
     345                 :          0 :                 return_value = false;
     346                 :            : 
     347                 :          3 :             }
     348                 :            :         }
     349                 :            :         else
     350                 :            :         {
     351         [ #  # ]:          0 :             xmlsec_trace("Adding new root certificate module failed.");
     352                 :          0 :             return_value = false;
     353                 :          3 :         }
     354                 :            : #if SYSTEM_MOZILLA
     355                 :            :     }
     356                 :            : #endif
     357                 :            : #endif
     358                 :            : 
     359                 :          3 :     return return_value;
     360                 :            : }
     361                 :            : 
     362                 :            : 
     363                 :            : // must be extern "C" because we pass the function pointer to atexit
     364                 :          3 : extern "C" void nsscrypto_finalize()
     365                 :            : {
     366                 :          3 :     SECMODModule *RootsModule = SECMOD_FindModule(ROOT_CERTS);
     367                 :            : 
     368         [ +  - ]:          3 :     if (RootsModule)
     369                 :            :     {
     370                 :            : 
     371         [ +  - ]:          3 :         if (SECSuccess == SECMOD_UnloadUserModule(RootsModule))
     372                 :            :         {
     373                 :          3 :             xmlsec_trace("Unloaded module \"" ROOT_CERTS "\".");
     374                 :            :         }
     375                 :            :         else
     376                 :            :         {
     377                 :          0 :             xmlsec_trace("Failed unloading module \"" ROOT_CERTS "\".");
     378                 :            :         }
     379                 :          3 :         SECMOD_DestroyModule(RootsModule);
     380                 :            :     }
     381                 :            :     else
     382                 :            :     {
     383                 :            :         xmlsec_trace("Unloading module \"" ROOT_CERTS
     384                 :          0 :                   "\" failed because it was not found.");
     385                 :            :     }
     386                 :          3 :     PK11_LogoutAll();
     387                 :          3 :     NSS_Shutdown();
     388                 :          3 : }
     389                 :            : } // namespace
     390                 :            : 
     391                 :          0 : ONSSInitializer::ONSSInitializer(
     392                 :            :     const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF)
     393                 :          0 :     :mxMSF( rxMSF )
     394                 :            : {
     395                 :          0 : }
     396                 :            : 
     397                 :         42 : ONSSInitializer::~ONSSInitializer()
     398                 :            : {
     399         [ -  + ]:         42 : }
     400                 :            : 
     401                 :         42 : bool ONSSInitializer::initNSS( const css::uno::Reference< css::lang::XMultiServiceFactory > &xMSF )
     402                 :            : {
     403                 :            :     return *rtl_Instance< bool, InitNSSInitialize, ::osl::MutexGuard, GetNSSInitStaticMutex >
     404 [ +  - ][ +  - ]:         42 :                 ::create( InitNSSInitialize( xMSF ), GetNSSInitStaticMutex() );
                 [ +  - ]
     405                 :            : }
     406                 :            : 
     407                 :         18 : css::uno::Reference< css::xml::crypto::XDigestContext > SAL_CALL ONSSInitializer::getDigestContext( ::sal_Int32 nDigestID, const css::uno::Sequence< css::beans::NamedValue >& aParams )
     408                 :            :     throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
     409                 :            : {
     410                 :         18 :     SECOidTag nNSSDigestID = SEC_OID_UNKNOWN;
     411                 :         18 :     sal_Int32 nDigestLength = 0;
     412                 :         18 :     bool b1KData = false;
     413 [ +  + ][ +  - ]:         18 :     if ( nDigestID == css::xml::crypto::DigestID::SHA256
     414                 :            :       || nDigestID == css::xml::crypto::DigestID::SHA256_1K )
     415                 :            :     {
     416                 :         18 :         nNSSDigestID = SEC_OID_SHA256;
     417                 :         18 :         nDigestLength = 32;
     418                 :         18 :         b1KData = ( nDigestID == css::xml::crypto::DigestID::SHA256_1K );
     419                 :            :     }
     420 [ #  # ][ #  # ]:          0 :     else if ( nDigestID == css::xml::crypto::DigestID::SHA1
     421                 :            :            || nDigestID == css::xml::crypto::DigestID::SHA1_1K )
     422                 :            :     {
     423                 :          0 :         nNSSDigestID = SEC_OID_SHA1;
     424                 :          0 :         nDigestLength = 20;
     425                 :          0 :         b1KData = ( nDigestID == css::xml::crypto::DigestID::SHA1_1K );
     426                 :            :     }
     427                 :            :     else
     428 [ #  # ][ #  # ]:          0 :         throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected digest requested." ) ), css::uno::Reference< css::uno::XInterface >(), 1 );
     429                 :            : 
     430         [ -  + ]:         18 :     if ( aParams.getLength() )
     431 [ #  # ][ #  # ]:          0 :         throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected arguments provided for digest creation." ) ), css::uno::Reference< css::uno::XInterface >(), 2 );
     432                 :            : 
     433                 :         18 :     css::uno::Reference< css::xml::crypto::XDigestContext > xResult;
     434 [ +  - ][ +  - ]:         18 :     if( initNSS( mxMSF ) )
     435                 :            :     {
     436         [ +  - ]:         18 :         PK11Context* pContext = PK11_CreateDigestContext( nNSSDigestID );
     437 [ +  - ][ +  - ]:         18 :         if ( pContext && PK11_DigestBegin( pContext ) == SECSuccess )
         [ +  - ][ +  - ]
     438 [ +  - ][ +  - ]:         18 :             xResult = new ODigestContext( pContext, nDigestLength, b1KData );
                 [ +  - ]
     439                 :            :     }
     440                 :            : 
     441                 :         18 :     return xResult;
     442                 :            : }
     443                 :            : 
     444                 :         24 : css::uno::Reference< css::xml::crypto::XCipherContext > SAL_CALL ONSSInitializer::getCipherContext( ::sal_Int32 nCipherID, const css::uno::Sequence< ::sal_Int8 >& aKey, const css::uno::Sequence< ::sal_Int8 >& aInitializationVector, ::sal_Bool bEncryption, const css::uno::Sequence< css::beans::NamedValue >& aParams )
     445                 :            :     throw (css::lang::IllegalArgumentException, css::uno::RuntimeException)
     446                 :            : {
     447                 :         24 :     CK_MECHANISM_TYPE nNSSCipherID = 0;
     448                 :         24 :     bool bW3CPadding = false;
     449         [ +  - ]:         24 :     if ( nCipherID == css::xml::crypto::CipherID::AES_CBC_W3C_PADDING )
     450                 :            :     {
     451                 :         24 :         nNSSCipherID = CKM_AES_CBC;
     452                 :         24 :         bW3CPadding = true;
     453                 :            : 
     454 [ +  - ][ +  - ]:         24 :         if ( aKey.getLength() != 16 && aKey.getLength() != 24 && aKey.getLength() != 32 )
         [ -  + ][ -  + ]
     455 [ #  # ][ #  # ]:          0 :             throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected key length." ) ), css::uno::Reference< css::uno::XInterface >(), 2 );
     456                 :            : 
     457         [ -  + ]:         24 :         if ( aParams.getLength() )
     458 [ #  # ][ #  # ]:          0 :             throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected arguments provided for cipher creation." ) ), css::uno::Reference< css::uno::XInterface >(), 5 );
     459                 :            :     }
     460                 :            :     else
     461 [ #  # ][ #  # ]:          0 :         throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected cipher requested." ) ), css::uno::Reference< css::uno::XInterface >(), 1 );
     462                 :            : 
     463                 :         24 :     css::uno::Reference< css::xml::crypto::XCipherContext > xResult;
     464 [ +  - ][ +  - ]:         24 :     if( initNSS( mxMSF ) )
     465                 :            :     {
     466 [ +  - ][ -  + ]:         24 :         if ( aInitializationVector.getLength() != PK11_GetIVLength( nNSSCipherID ) )
     467 [ #  # ][ #  # ]:          0 :             throw css::lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected length of initialization vector." ) ), css::uno::Reference< css::uno::XInterface >(), 3 );
     468                 :            : 
     469 [ +  - ][ +  - ]:         24 :         xResult = OCipherContext::Create( nNSSCipherID, aKey, aInitializationVector, bEncryption, bW3CPadding );
     470                 :            :     }
     471                 :            : 
     472                 :         24 :     return xResult;
     473                 :            : }
     474                 :            : 
     475                 :          0 : rtl::OUString ONSSInitializer_getImplementationName ()
     476                 :            :     throw (cssu::RuntimeException)
     477                 :            : {
     478                 :            : 
     479                 :          0 :     return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
     480                 :            : }
     481                 :            : 
     482                 :          0 : sal_Bool SAL_CALL ONSSInitializer_supportsService( const rtl::OUString& ServiceName )
     483                 :            :     throw (cssu::RuntimeException)
     484                 :            : {
     485                 :          0 :     return ServiceName == NSS_SERVICE_NAME;
     486                 :            : }
     487                 :            : 
     488                 :          0 : cssu::Sequence< rtl::OUString > SAL_CALL ONSSInitializer_getSupportedServiceNames(  )
     489                 :            :     throw (cssu::RuntimeException)
     490                 :            : {
     491                 :          0 :     cssu::Sequence < rtl::OUString > aRet(1);
     492         [ #  # ]:          0 :     rtl::OUString* pArray = aRet.getArray();
     493         [ #  # ]:          0 :     pArray[0] =  rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( NSS_SERVICE_NAME ) );
     494                 :          0 :     return aRet;
     495                 :            : }
     496                 :            : 
     497                 :          0 : cssu::Reference< cssu::XInterface > SAL_CALL ONSSInitializer_createInstance( const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr)
     498                 :            :     throw( cssu::Exception )
     499                 :            : {
     500         [ #  # ]:          0 :     return (cppu::OWeakObject*) new ONSSInitializer( rSMgr );
     501                 :            : }
     502                 :            : 
     503                 :            : /* XServiceInfo */
     504                 :          0 : rtl::OUString SAL_CALL ONSSInitializer::getImplementationName()
     505                 :            :     throw (cssu::RuntimeException)
     506                 :            : {
     507                 :          0 :     return ONSSInitializer_getImplementationName();
     508                 :            : }
     509                 :          0 : sal_Bool SAL_CALL ONSSInitializer::supportsService( const rtl::OUString& rServiceName )
     510                 :            :     throw (cssu::RuntimeException)
     511                 :            : {
     512                 :          0 :     return ONSSInitializer_supportsService( rServiceName );
     513                 :            : }
     514                 :          0 : cssu::Sequence< rtl::OUString > SAL_CALL ONSSInitializer::getSupportedServiceNames(  )
     515                 :            :     throw (cssu::RuntimeException)
     516                 :            : {
     517                 :          0 :     return ONSSInitializer_getSupportedServiceNames();
     518                 :            : }
     519                 :            : 
     520                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10