2004-07-12 07:15:31 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 18:38:31 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:38:31 -05:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:38:31 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:38:31 -05:00
|
|
|
* $RCSfile: seinitializer_nssimpl.cxx,v $
|
2008-08-18 07:16:11 -05:00
|
|
|
* $Revision: 1.22 $
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:38:31 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:38:31 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:38:31 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
2008-04-10 18:38:31 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2004-07-12 07:15:31 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 08:45:55 -05:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_xmlsecurity.hxx"
|
|
|
|
|
2004-07-12 07:15:31 -05:00
|
|
|
/*
|
|
|
|
* Turn off DEBUG Assertions
|
|
|
|
*/
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#define _DEBUG_WAS_DEFINED _DEBUG
|
|
|
|
#undef _DEBUG
|
|
|
|
#else
|
|
|
|
#undef _DEBUG_WAS_DEFINED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* and turn off the additional virtual methods which are part of some interfaces when compiled
|
|
|
|
* with debug
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define DEBUG_WAS_DEFINED DEBUG
|
|
|
|
#undef DEBUG
|
|
|
|
#else
|
|
|
|
#undef DEBUG_WAS_DEFINED
|
|
|
|
#endif
|
|
|
|
|
2004-07-19 01:36:28 -05:00
|
|
|
|
2004-07-12 07:15:31 -05:00
|
|
|
#include <sal/types.h>
|
2009-08-26 03:22:01 -05:00
|
|
|
#include "rtl/instance.hxx"
|
|
|
|
#include "rtl/bootstrap.hxx"
|
|
|
|
#include "rtl/string.hxx"
|
|
|
|
#include "rtl/strbuf.hxx"
|
|
|
|
#include "osl/file.hxx"
|
|
|
|
#include "osl/thread.h"
|
2004-07-22 22:53:50 -05:00
|
|
|
#include <tools/debug.hxx>
|
2005-05-18 03:58:55 -05:00
|
|
|
#include <rtl/logfile.hxx>
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
#include "seinitializer_nssimpl.hxx"
|
|
|
|
|
|
|
|
#include "securityenvironment_nssimpl.hxx"
|
2005-03-10 11:13:08 -06:00
|
|
|
#include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
|
|
|
|
|
2004-07-12 07:15:31 -05:00
|
|
|
#include "nspr.h"
|
|
|
|
#include "cert.h"
|
|
|
|
#include "nss.h"
|
2009-08-26 03:22:01 -05:00
|
|
|
#include "secmod.h"
|
|
|
|
#include "nssckbi.h"
|
2007-11-07 03:07:25 -06:00
|
|
|
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
namespace cssu = com::sun::star::uno;
|
|
|
|
namespace cssl = com::sun::star::lang;
|
|
|
|
namespace cssxc = com::sun::star::xml::crypto;
|
|
|
|
|
|
|
|
using namespace com::sun::star;
|
2009-08-26 03:22:01 -05:00
|
|
|
using ::rtl::OUString;
|
|
|
|
using ::rtl::OString;
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
#define SERVICE_NAME "com.sun.star.xml.crypto.SEInitializer"
|
|
|
|
#define IMPLEMENTATION_NAME "com.sun.star.xml.security.bridge.xmlsec.SEInitializer_NssImpl"
|
|
|
|
#define SECURITY_ENVIRONMENT "com.sun.star.xml.crypto.SecurityEnvironment"
|
|
|
|
#define SECURITY_CONTEXT "com.sun.star.xml.crypto.XMLSecurityContext"
|
|
|
|
|
2004-08-05 01:13:30 -05:00
|
|
|
|
2009-08-26 03:22:01 -05:00
|
|
|
#define ROOT_CERTS "Root Certs for OpenOffice.org"
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" void nsscrypto_finalize();
|
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2004-08-05 01:13:30 -05:00
|
|
|
|
2009-08-26 03:22:01 -05:00
|
|
|
bool nsscrypto_initialize( const char * sProfile, bool & out_nss_init);
|
|
|
|
|
|
|
|
struct InitNSSInitialize
|
|
|
|
{
|
|
|
|
//path to the database folder
|
|
|
|
const OString m_sProfile;
|
|
|
|
InitNSSInitialize(const OString & sProfile): m_sProfile(sProfile) {};
|
|
|
|
bool * operator()()
|
|
|
|
{
|
|
|
|
static bool bInitialized = false;
|
|
|
|
bool bNSSInit = false;
|
|
|
|
bInitialized = nsscrypto_initialize(m_sProfile.getStr(), bNSSInit);
|
|
|
|
if (bNSSInit)
|
|
|
|
atexit(nsscrypto_finalize );
|
2009-10-29 05:31:59 -05:00
|
|
|
return & bInitialized;
|
2009-08-26 03:22:01 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool * initNSS(const OString & sProfile)
|
|
|
|
{
|
|
|
|
return rtl_Instance< bool, InitNSSInitialize,
|
|
|
|
::osl::MutexGuard, ::osl::GetGlobalMutex >::create(
|
|
|
|
InitNSSInitialize(sProfile), ::osl::GetGlobalMutex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteRootsModule()
|
|
|
|
{
|
|
|
|
SECMODModule *RootsModule = 0;
|
|
|
|
SECMODModuleList *list = SECMOD_GetDefaultModuleList();
|
|
|
|
SECMODListLock *lock = SECMOD_GetDefaultModuleListLock();
|
|
|
|
SECMOD_GetReadLock(lock);
|
|
|
|
|
|
|
|
while (!RootsModule && list)
|
|
|
|
{
|
|
|
|
SECMODModule *module = list->module;
|
|
|
|
|
|
|
|
for (int i=0; i < module->slotCount; i++)
|
|
|
|
{
|
|
|
|
PK11SlotInfo *slot = module->slots[i];
|
|
|
|
if (PK11_IsPresent(slot))
|
|
|
|
{
|
|
|
|
if (PK11_HasRootCerts(slot))
|
2007-11-07 03:07:25 -06:00
|
|
|
{
|
2009-08-26 03:22:01 -05:00
|
|
|
OSL_TRACE("[xmlsecurity] The root certifificates module \"%s"
|
|
|
|
"\" is already loaded: \n%s",
|
|
|
|
module->commonName, module->dllName);
|
2007-11-07 03:07:25 -06:00
|
|
|
|
2009-08-26 03:22:01 -05:00
|
|
|
RootsModule = SECMOD_ReferenceModule(module);
|
|
|
|
break;
|
2007-11-07 03:07:25 -06:00
|
|
|
}
|
2009-08-26 03:22:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
SECMOD_ReleaseReadLock(lock);
|
2008-08-18 07:16:11 -05:00
|
|
|
|
2009-08-26 03:22:01 -05:00
|
|
|
if (RootsModule)
|
|
|
|
{
|
|
|
|
PRInt32 modType;
|
|
|
|
if (SECSuccess == SECMOD_DeleteModule(RootsModule->commonName, &modType))
|
|
|
|
{
|
|
|
|
OSL_TRACE("[xmlsecurity] Deleted module \"%s\".", RootsModule->commonName);
|
|
|
|
}
|
|
|
|
else
|
2008-08-18 07:16:11 -05:00
|
|
|
{
|
2009-08-26 03:22:01 -05:00
|
|
|
OSL_TRACE("[xmlsecurity] Failed to delete \"%s\" : \n%s",
|
|
|
|
RootsModule->commonName, RootsModule->dllName);
|
2008-08-18 07:16:11 -05:00
|
|
|
}
|
2009-08-26 03:22:01 -05:00
|
|
|
SECMOD_DestroyModule(RootsModule);
|
|
|
|
RootsModule = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Older versions of Firefox (FF), for example FF2, and Thunderbird (TB) 2 write
|
|
|
|
//the roots certificate module (libnssckbi.so), which they use, into the
|
|
|
|
//profile. This module will then already be loaded during NSS_Init (and the
|
|
|
|
//other init functions). This fails in two cases. First, FF3 was used to create
|
|
|
|
//the profile, or possibly used that profile before, and second the profile was
|
|
|
|
//used on a different platform.
|
|
|
|
//
|
|
|
|
//Then one needs to add the roots module oneself. This should be done with
|
|
|
|
//SECMOD_LoadUserModule rather then SECMOD_AddNewModule. The latter would write
|
|
|
|
//the location of the roots module to the profile, which makes FF2 and TB2 use
|
|
|
|
//it instead of there own module.
|
|
|
|
//
|
|
|
|
//When using SYSTEM_MOZILLA then the libnss3.so lib is typically found in
|
|
|
|
///usr/lib. This folder may, however, NOT contain the roots certificate
|
|
|
|
//module. That is, just providing the library name in SECMOD_LoadUserModule or
|
|
|
|
//SECMOD_AddNewModule will FAIL to load the mozilla unless the LD_LIBRARY_PATH
|
|
|
|
//contains an FF or TB installation.
|
|
|
|
//ATTENTION: DO NOT call this function directly instead use initNSS
|
|
|
|
//return true - whole initialization was successful
|
|
|
|
//param out_nss_init = true: at least the NSS initialization (NSS_InitReadWrite
|
|
|
|
//was successful and therefor NSS_Shutdown should be called when terminating.
|
|
|
|
bool nsscrypto_initialize( const char* token, bool & out_nss_init )
|
|
|
|
{
|
|
|
|
bool return_value = true;
|
|
|
|
|
|
|
|
OSL_TRACE("[xmlsecurity] Using profile: %s", token);
|
|
|
|
|
|
|
|
PR_Init( PR_USER_THREAD, PR_PRIORITY_NORMAL, 1 ) ;
|
|
|
|
|
|
|
|
if( NSS_InitReadWrite( token ) != SECSuccess )
|
|
|
|
{
|
|
|
|
char * error = NULL;
|
|
|
|
|
|
|
|
PR_GetErrorText(error);
|
|
|
|
if (error)
|
|
|
|
printf("%s",error);
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
out_nss_init = true;
|
|
|
|
|
|
|
|
#if defined SYSTEM_MOZILLA
|
|
|
|
if (!SECMOD_HasRootCerts())
|
|
|
|
{
|
2008-08-18 07:16:11 -05:00
|
|
|
#endif
|
2009-08-26 03:22:01 -05:00
|
|
|
deleteRootsModule();
|
|
|
|
|
|
|
|
#if defined SYSTEM_MOZILLA
|
|
|
|
OUString rootModule(RTL_CONSTASCII_USTRINGPARAM("libnssckbi"SAL_DLLEXTENSION));
|
|
|
|
#else
|
|
|
|
OUString rootModule(RTL_CONSTASCII_USTRINGPARAM("${OOO_BASE_DIR}/program/libnssckbi"SAL_DLLEXTENSION));
|
|
|
|
#endif
|
|
|
|
::rtl::Bootstrap::expandMacros(rootModule);
|
|
|
|
|
|
|
|
OUString rootModulePath;
|
|
|
|
if (::osl::File::E_None == ::osl::File::getSystemPathFromFileURL(rootModule, rootModulePath))
|
|
|
|
{
|
|
|
|
::rtl::OString ospath = ::rtl::OUStringToOString(rootModulePath, osl_getThreadTextEncoding());
|
|
|
|
::rtl::OStringBuffer pkcs11moduleSpec;
|
|
|
|
pkcs11moduleSpec.append("name=\"");
|
|
|
|
pkcs11moduleSpec.append(ROOT_CERTS);
|
|
|
|
pkcs11moduleSpec.append("\" library=\"");
|
|
|
|
pkcs11moduleSpec.append(ospath.getStr());
|
|
|
|
pkcs11moduleSpec.append("\"");
|
|
|
|
|
|
|
|
SECMODModule * RootsModule =
|
|
|
|
SECMOD_LoadUserModule(
|
|
|
|
const_cast<char*>(pkcs11moduleSpec.makeStringAndClear().getStr()),
|
|
|
|
0, // no parent
|
|
|
|
PR_FALSE); // do not recurse
|
|
|
|
|
|
|
|
if (RootsModule)
|
|
|
|
{
|
|
|
|
|
|
|
|
bool found = RootsModule->loaded;
|
|
|
|
|
|
|
|
SECMOD_DestroyModule(RootsModule);
|
|
|
|
RootsModule = 0;
|
|
|
|
if (found)
|
|
|
|
OSL_TRACE("[xmlsecurity] Added new root certificate module "
|
|
|
|
"\""ROOT_CERTS"\" contained in \n%s", ospath.getStr());
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_TRACE("[xmlsecurity] FAILED to load the new root certificate module "
|
|
|
|
"\""ROOT_CERTS"\" contained in \n%s", ospath.getStr());
|
|
|
|
return_value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_TRACE("[xmlsecurity] FAILED to add new root certifice module: "
|
|
|
|
"\""ROOT_CERTS"\" contained in \n%s", ospath.getStr());
|
|
|
|
return_value = false;
|
2008-08-18 07:16:11 -05:00
|
|
|
|
2009-08-26 03:22:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_TRACE("[xmlsecurity] Adding new root certificate module failed.");
|
|
|
|
return_value = false;
|
|
|
|
}
|
|
|
|
#if SYSTEM_MOZILLA
|
2004-08-05 01:13:30 -05:00
|
|
|
}
|
2009-08-26 03:22:01 -05:00
|
|
|
#endif
|
2004-08-05 01:13:30 -05:00
|
|
|
|
2009-08-26 03:22:01 -05:00
|
|
|
return return_value;
|
2004-08-05 01:13:30 -05:00
|
|
|
}
|
|
|
|
|
2009-08-26 03:22:01 -05:00
|
|
|
|
2007-04-17 04:27:46 -05:00
|
|
|
// must be extern "C" because we pass the function pointer to atexit
|
2009-08-26 03:22:01 -05:00
|
|
|
extern "C" void nsscrypto_finalize()
|
|
|
|
{
|
|
|
|
SECMODModule *RootsModule = SECMOD_FindModule(ROOT_CERTS);
|
|
|
|
|
|
|
|
if (RootsModule)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (SECSuccess == SECMOD_UnloadUserModule(RootsModule))
|
|
|
|
{
|
|
|
|
OSL_TRACE("[xmlsecurity] Unloaded module \""ROOT_CERTS"\".");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_TRACE("[xmlsecurity] Failed unloadeding module \""ROOT_CERTS"\".");
|
|
|
|
}
|
|
|
|
SECMOD_DestroyModule(RootsModule);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_TRACE("[xmlsecurity] Unloading module \""ROOT_CERTS
|
|
|
|
"\" failed because it was not found.");
|
|
|
|
}
|
2004-08-05 01:13:30 -05:00
|
|
|
PK11_LogoutAll();
|
|
|
|
NSS_Shutdown();
|
|
|
|
}
|
|
|
|
|
2009-08-26 03:22:01 -05:00
|
|
|
|
2005-03-10 11:13:08 -06:00
|
|
|
bool getMozillaCurrentProfile(
|
|
|
|
const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &rxMSF,
|
2005-05-18 03:58:55 -05:00
|
|
|
rtl::OUString& profilePath)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* first, try to get the profile from "MOZILLA_CERTIFICATE_FOLDER"
|
|
|
|
*/
|
|
|
|
char * env = getenv("MOZILLA_CERTIFICATE_FOLDER");
|
|
|
|
if (env)
|
|
|
|
{
|
|
|
|
profilePath = rtl::OUString::createFromAscii( env );
|
|
|
|
RTL_LOGFILE_PRODUCT_TRACE1( "XMLSEC: Using env MOZILLA_CERTIFICATE_FOLDER: %s", rtl::OUStringToOString( profilePath, RTL_TEXTENCODING_ASCII_US ).getStr() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RTL_LOGFILE_TRACE( "getMozillaCurrentProfile: Using MozillaBootstrap..." );
|
2009-08-26 03:22:01 -05:00
|
|
|
mozilla::MozillaProductType productTypes[4] = {
|
2005-05-18 03:58:55 -05:00
|
|
|
mozilla::MozillaProductType_Thunderbird,
|
|
|
|
mozilla::MozillaProductType_Mozilla,
|
|
|
|
mozilla::MozillaProductType_Firefox,
|
|
|
|
mozilla::MozillaProductType_Default };
|
|
|
|
int nProduct = 4;
|
|
|
|
|
|
|
|
uno::Reference<uno::XInterface> xInstance = rxMSF->createInstance(
|
|
|
|
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap")) );
|
|
|
|
OSL_ENSURE( xInstance.is(), "failed to create instance" );
|
|
|
|
|
|
|
|
uno::Reference<mozilla::XMozillaBootstrap> xMozillaBootstrap
|
|
|
|
= uno::Reference<mozilla::XMozillaBootstrap>(xInstance,uno::UNO_QUERY);
|
|
|
|
OSL_ENSURE( xMozillaBootstrap.is(), "failed to create instance" );
|
|
|
|
|
|
|
|
if (xMozillaBootstrap.is())
|
|
|
|
{
|
|
|
|
for (int i=0; i<nProduct; i++)
|
|
|
|
{
|
|
|
|
::rtl::OUString profile = xMozillaBootstrap->getDefaultProfile(productTypes[i]);
|
|
|
|
|
|
|
|
RTL_LOGFILE_TRACE2( "getMozillaCurrentProfile: getDefaultProfile [%i] returns %s", i, rtl::OUStringToOString( profile, RTL_TEXTENCODING_ASCII_US ).getStr() );
|
|
|
|
|
|
|
|
if (profile != NULL && profile.getLength()>0)
|
|
|
|
{
|
|
|
|
profilePath = xMozillaBootstrap->getProfilePath(productTypes[i],profile);
|
|
|
|
RTL_LOGFILE_PRODUCT_TRACE1( "XMLSEC: Using Mozilla Profile: %s", rtl::OUStringToOString( profilePath, RTL_TEXTENCODING_ASCII_US ).getStr() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-10 11:13:08 -06:00
|
|
|
|
2005-05-18 03:58:55 -05:00
|
|
|
RTL_LOGFILE_PRODUCT_TRACE( "XMLSEC: No Mozilla Profile found!" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2004-07-22 21:00:43 -05:00
|
|
|
|
2009-08-26 03:22:01 -05:00
|
|
|
} // namespace
|
|
|
|
|
2004-07-12 07:15:31 -05:00
|
|
|
SEInitializer_NssImpl::SEInitializer_NssImpl(
|
|
|
|
const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &rxMSF)
|
|
|
|
:mxMSF( rxMSF )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SEInitializer_NssImpl::~SEInitializer_NssImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XSEInitializer */
|
|
|
|
cssu::Reference< cssxc::XXMLSecurityContext > SAL_CALL
|
|
|
|
SEInitializer_NssImpl::createSecurityContext(
|
|
|
|
const rtl::OUString& sCertDB )
|
|
|
|
throw (cssu::RuntimeException)
|
|
|
|
{
|
2005-03-10 11:13:08 -06:00
|
|
|
CERTCertDBHandle *pCertHandle = NULL ;
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
rtl::OString sCertDir;
|
2004-07-23 02:34:25 -05:00
|
|
|
if( sCertDB.getLength() )
|
2004-07-12 07:15:31 -05:00
|
|
|
{
|
|
|
|
sCertDir = rtl::OString(sCertDB, sCertDB.getLength(), RTL_TEXTENCODING_ASCII_US);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-23 02:34:25 -05:00
|
|
|
static rtl::OString* pDefaultCertDir = NULL;
|
|
|
|
if ( !pDefaultCertDir )
|
2004-07-22 21:00:43 -05:00
|
|
|
{
|
2004-07-23 02:34:25 -05:00
|
|
|
pDefaultCertDir = new rtl::OString;
|
|
|
|
rtl::OUString ouCertDir;
|
2005-03-10 11:13:08 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( getMozillaCurrentProfile(mxMSF, ouCertDir) )
|
2004-07-23 02:34:25 -05:00
|
|
|
*pDefaultCertDir = rtl::OString(ouCertDir, ouCertDir.getLength(), RTL_TEXTENCODING_ASCII_US);
|
2004-07-22 21:00:43 -05:00
|
|
|
}
|
2004-07-23 02:34:25 -05:00
|
|
|
sCertDir = *pDefaultCertDir;
|
2004-07-22 21:00:43 -05:00
|
|
|
|
2004-07-23 02:34:25 -05:00
|
|
|
}
|
2004-07-22 21:37:00 -05:00
|
|
|
|
2004-07-23 02:34:25 -05:00
|
|
|
if( !sCertDir.getLength() )
|
2005-05-18 03:58:55 -05:00
|
|
|
{
|
|
|
|
RTL_LOGFILE_TRACE( "XMLSEC: Error - No certificate directory!" );
|
|
|
|
// return NULL;
|
|
|
|
}
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
/* Initialize NSPR and NSS */
|
2004-08-05 01:13:30 -05:00
|
|
|
/* Replaced with new methods by AF. ----
|
|
|
|
//PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1 ) ;
|
|
|
|
PR_Init( PR_USER_THREAD, PR_PRIORITY_NORMAL, 1 ) ;
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
if (NSS_Init(sCertDir.getStr()) != SECSuccess )
|
|
|
|
{
|
|
|
|
PK11_LogoutAll();
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-08-05 01:13:30 -05:00
|
|
|
----*/
|
2009-08-26 03:22:01 -05:00
|
|
|
if( ! *initNSS( sCertDir.getStr() ) )
|
2005-05-18 03:58:55 -05:00
|
|
|
{
|
|
|
|
RTL_LOGFILE_TRACE( "XMLSEC: Error - nsscrypto_initialize() failed." );
|
|
|
|
if ( NSS_NoDB_Init(NULL) != SECSuccess )
|
|
|
|
{
|
|
|
|
RTL_LOGFILE_TRACE( "XMLSEC: NSS_NoDB_Init also failed, NSS Security not available!" );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RTL_LOGFILE_TRACE( "XMLSEC: NSS_NoDB_Init works, enough for verifying signatures..." );
|
|
|
|
}
|
|
|
|
}
|
2004-07-12 07:15:31 -05:00
|
|
|
|
|
|
|
pCertHandle = CERT_GetDefaultCertDB() ;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2005-03-10 11:13:08 -06:00
|
|
|
/* Build XML Security Context */
|
|
|
|
const rtl::OUString sSecyrutyContext ( RTL_CONSTASCII_USTRINGPARAM( SECURITY_CONTEXT ) );
|
|
|
|
cssu::Reference< cssxc::XXMLSecurityContext > xSecCtx( mxMSF->createInstance ( sSecyrutyContext ), cssu::UNO_QUERY );
|
|
|
|
if( !xSecCtx.is() )
|
2004-07-12 07:15:31 -05:00
|
|
|
return NULL;
|
|
|
|
|
2006-07-13 02:10:36 -05:00
|
|
|
const rtl::OUString sSecyrutyEnvironment ( RTL_CONSTASCII_USTRINGPARAM( SECURITY_ENVIRONMENT ) );
|
|
|
|
cssu::Reference< cssxc::XSecurityEnvironment > xSecEnv( mxMSF->createInstance ( sSecyrutyEnvironment ), cssu::UNO_QUERY );
|
|
|
|
cssu::Reference< cssl::XUnoTunnel > xEnvTunnel( xSecEnv , cssu::UNO_QUERY ) ;
|
|
|
|
if( !xEnvTunnel.is() )
|
|
|
|
return NULL;
|
2007-04-17 04:27:46 -05:00
|
|
|
SecurityEnvironment_NssImpl* pSecEnv = reinterpret_cast<SecurityEnvironment_NssImpl*>(
|
|
|
|
sal::static_int_cast<sal_uIntPtr>(
|
|
|
|
xEnvTunnel->getSomething(SecurityEnvironment_NssImpl::getUnoTunnelId() ))) ;
|
2006-07-13 02:10:36 -05:00
|
|
|
pSecEnv->setCertDb(pCertHandle);
|
2004-07-12 07:15:31 -05:00
|
|
|
|
2006-07-13 02:10:36 -05:00
|
|
|
sal_Int32 n = xSecCtx->addSecurityEnvironment(xSecEnv);
|
|
|
|
//originally the SecurityEnvironment with the internal slot was set as default
|
|
|
|
xSecCtx->setDefaultSecurityEnvironmentIndex( n );
|
2004-07-12 07:15:31 -05:00
|
|
|
return xSecCtx;
|
|
|
|
}
|
|
|
|
catch( cssu::Exception& )
|
|
|
|
{
|
2005-03-10 11:13:08 -06:00
|
|
|
//PK11_LogoutAll();
|
|
|
|
//NSS_Shutdown();
|
2004-07-12 07:15:31 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-17 04:27:46 -05:00
|
|
|
void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const cssu::Reference< cssxc::XXMLSecurityContext >& )
|
2004-07-12 07:15:31 -05:00
|
|
|
throw (cssu::RuntimeException)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* because the security context will free all its content when it
|
|
|
|
* is destructed, so here no free process for the security context
|
|
|
|
* is needed.
|
|
|
|
*/
|
2004-08-05 01:13:30 -05:00
|
|
|
//PK11_LogoutAll();
|
|
|
|
//NSS_Shutdown();
|
2004-07-12 07:15:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
rtl::OUString SEInitializer_NssImpl_getImplementationName ()
|
|
|
|
throw (cssu::RuntimeException)
|
|
|
|
{
|
2006-07-13 02:10:36 -05:00
|
|
|
|
2004-07-12 07:15:31 -05:00
|
|
|
return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool SAL_CALL SEInitializer_NssImpl_supportsService( const rtl::OUString& ServiceName )
|
|
|
|
throw (cssu::RuntimeException)
|
|
|
|
{
|
|
|
|
return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
|
|
|
|
}
|
|
|
|
|
|
|
|
cssu::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames( )
|
|
|
|
throw (cssu::RuntimeException)
|
|
|
|
{
|
|
|
|
cssu::Sequence < rtl::OUString > aRet(1);
|
|
|
|
rtl::OUString* pArray = aRet.getArray();
|
|
|
|
pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
|
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
#undef SERVICE_NAME
|
|
|
|
|
|
|
|
cssu::Reference< cssu::XInterface > SAL_CALL SEInitializer_NssImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr)
|
|
|
|
throw( cssu::Exception )
|
|
|
|
{
|
|
|
|
return (cppu::OWeakObject*) new SEInitializer_NssImpl(rSMgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XServiceInfo */
|
|
|
|
rtl::OUString SAL_CALL SEInitializer_NssImpl::getImplementationName( )
|
|
|
|
throw (cssu::RuntimeException)
|
|
|
|
{
|
|
|
|
return SEInitializer_NssImpl_getImplementationName();
|
|
|
|
}
|
|
|
|
sal_Bool SAL_CALL SEInitializer_NssImpl::supportsService( const rtl::OUString& rServiceName )
|
|
|
|
throw (cssu::RuntimeException)
|
|
|
|
{
|
|
|
|
return SEInitializer_NssImpl_supportsService( rServiceName );
|
|
|
|
}
|
|
|
|
cssu::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl::getSupportedServiceNames( )
|
|
|
|
throw (cssu::RuntimeException)
|
|
|
|
{
|
|
|
|
return SEInitializer_NssImpl_getSupportedServiceNames();
|
|
|
|
}
|
|
|
|
|