summaryrefslogtreecommitdiff
path: root/xmlsecurity/source/xmlsec/nss
diff options
context:
space:
mode:
Diffstat (limited to 'xmlsecurity/source/xmlsec/nss')
-rw-r--r--xmlsecurity/source/xmlsec/nss/makefile.mk158
-rw-r--r--xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx832
-rw-r--r--xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx210
-rw-r--r--xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx390
-rw-r--r--xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx152
-rw-r--r--xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx360
-rw-r--r--xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx146
-rw-r--r--xmlsecurity/source/xmlsec/nss/xmlencryption_nssimpl.cxx429
-rw-r--r--xmlsecurity/source/xmlsec/nss/xmlencryption_nssimpl.hxx165
-rw-r--r--xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx290
-rw-r--r--xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.hxx174
-rw-r--r--xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx336
-rw-r--r--xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.hxx165
-rw-r--r--xmlsecurity/source/xmlsec/nss/xsec_nss.cxx199
14 files changed, 4006 insertions, 0 deletions
diff --git a/xmlsecurity/source/xmlsec/nss/makefile.mk b/xmlsecurity/source/xmlsec/nss/makefile.mk
new file mode 100644
index 000000000000..a52e6abf1893
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/makefile.mk
@@ -0,0 +1,158 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1.1.1 $
+#
+# last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+#
+# The Contents of this file are made available subject to the terms of
+# either of the following licenses
+#
+# - GNU Lesser General Public License Version 2.1
+# - Sun Industry Standards Source License Version 1.1
+#
+# Sun Microsystems Inc., October, 2000
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2000 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library 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 for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#
+# Sun Industry Standards Source License Version 1.1
+# =================================================
+# The contents of this file are subject to the Sun Industry Standards
+# Source License Version 1.1 (the "License"); You may not use this file
+# except in compliance with the License. You may obtain a copy of the
+# License at http://www.openoffice.org/license.html.
+#
+# Software provided under this License is provided on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+# See the License for the specific provisions governing your rights and
+# obligations concerning the Software.
+#
+# The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+#
+# Copyright: 2000 by Sun Microsystems, Inc.
+#
+# All Rights Reserved.
+#
+# Contributor(s): _______________________________________
+#
+#
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+
+PRJNAME = xmlsecurity
+TARGET = xs_nss
+
+ENABLE_EXCEPTIONS = TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : svpre.mk
+.INCLUDE : settings.mk
+.INCLUDE : sv.mk
+.INCLUDE : $(PRJ)$/util$/target.pmk
+
+.IF "$(CRYPTO_ENGINE)" != "nss"
+LIBTARGET=NO
+.ENDIF
+
+.IF "$(CRYPTO_ENGINE)" == "nss"
+
+MOZ_INC = $(SOLARVERSION)$/$(INPATH)$/inc$(UPDMINOREXT)$/mozilla
+NSS_INC = $(MOZ_INC)$/nss
+NSPR_INC = $(MOZ_INC)$/nspr
+
+
+.IF "$(GUI)"=="UNX"
+.IF "$(COMNAME)"=="sunpro5"
+CFLAGS += -features=tmplife
+#This flag is needed to build mozilla 1.7 code
+.ENDIF # "$(COMNAME)"=="sunpro5"
+.ENDIF
+
+.IF "$(GUI)" == "WNT"
+.IF "$(DBG_LEVEL)" == "0"
+INCPRE += \
+ -I$(MOZ_INC)$/xpcom \
+-I$(MOZ_INC)$/profile \
+-I$(MOZ_INC)$/string \
+-I$(MOZ_INC)$/embed_base
+CFLAGS += -GR- -W3 -Gy -MD -UDEBUG
+.ELSE
+INCPRE += \
+ -I$(MOZ_INC)$/xpcom \
+-I$(MOZ_INC)$/profile \
+-I$(MOZ_INC)$/string \
+-I$(MOZ_INC)$/embed_base
+CFLAGS += -Zi -GR- -W3 -Gy -MDd -UNDEBUG
+.ENDIF
+.ENDIF
+.IF "$(GUI)" == "UNX"
+INCPOST += \
+$(MOZ_INC)$/xpcom \
+-I$(MOZ_INC)$/profile \
+-I$(MOZ_INC)$/string \
+-I$(MOZ_INC)$/embed_base
+.IF "$(OS)" == "LINUX"
+CFLAGS += -fPIC -g
+CFLAGSCXX += \
+ -fno-rtti -Wall -Wconversion -Wpointer-arith \
+ -Wbad-function-cast -Wcast-align -Woverloaded-virtual -Wsynth \
+ -Wno-long-long -pthread
+CDEFS += -DTRACING
+.ELIF "$(OS)" == "NETBSD"
+CFLAGS += -fPIC
+CFLAGSCXX += \
+ -fno-rtti -Wall -Wconversion -Wpointer-arith \
+ -Wbad-function-cast -Wcast-align -Woverloaded-virtual -Wsynth \
+ -Wno-long-long
+CDEFS += -DTRACING
+.ENDIF
+.ENDIF
+
+CDEFS += -DXMLSEC_CRYPTO_NSS -DXMLSEC_NO_XSLT
+
+# --- Files --------------------------------------------------------
+SOLARINC += \
+ -I$(MOZ_INC) \
+-I$(NSPR_INC) \
+-I$(NSS_INC) \
+-I$(PRJ)$/source$/xmlsec
+
+SLOFILES = \
+ $(SLO)$/securityenvironment_nssimpl.obj \
+ $(SLO)$/xmlencryption_nssimpl.obj \
+ $(SLO)$/xmlsecuritycontext_nssimpl.obj \
+ $(SLO)$/xmlsignature_nssimpl.obj \
+ $(SLO)$/x509certificate_nssimpl.obj \
+ $(SLO)$/seinitializer_nssimpl.obj \
+ $(SLO)$/xsec_nss.obj
+
+
+.ENDIF
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
new file mode 100644
index 000000000000..c59d8b1dd97e
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.cxx
@@ -0,0 +1,832 @@
+/*************************************************************************
+ *
+ * $RCSfile: securityenvironment_nssimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _SAL_CONFIG_H_
+#include <sal/config.h>
+#endif
+
+#ifndef _XSECURITYENVIRONMENT_NSSIMPL_HXX_
+#include "securityenvironment_nssimpl.hxx"
+#endif
+
+#ifndef _X509CERTIFICATE_NSSIMPL_HXX_
+#include "x509certificate_nssimpl.hxx"
+#endif
+
+#ifndef _RTL_UUID_H_
+#include <rtl/uuid.h>
+#endif
+
+#include "nspr.h"
+#include "nss.h"
+#include "secport.h"
+#include "secitem.h"
+#include "secder.h"
+#include "limits.h"
+
+#include "xmlsec/xmlsec.h"
+#include "xmlsec/keysmngr.h"
+#include "xmlsec/crypto.h"
+#include <xmlsec/base64.h>
+#include "xmlsec/strings.h"
+
+#include <tools/string.hxx>
+
+#include <comphelper/processfactory.hxx>
+#include <cppuhelper/servicefactory.hxx>
+#include <svtools/docpasswdrequest.hxx>
+
+#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#endif
+
+// MM : added for password exception
+#include <com/sun/star/security/NoPasswordException.hpp>
+using namespace ::com::sun::star::security;
+
+using namespace com::sun::star;
+using namespace ::com::sun::star::uno ;
+using namespace ::com::sun::star::lang ;
+using ::com::sun::star::lang::XMultiServiceFactory ;
+using ::com::sun::star::lang::XSingleServiceFactory ;
+using ::rtl::OUString ;
+
+using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
+using ::com::sun::star::security::XCertificate ;
+
+extern X509Certificate_NssImpl* NssCertToXCert( CERTCertificate* cert ) ;
+extern X509Certificate_NssImpl* NssPrivKeyToXCert( SECKEYPrivateKey* ) ;
+extern Sequence< sal_Int8 > numericStringToBigInteger( OUString ) ;
+extern OUString bigIntegerToNumericString( Sequence< sal_Int8 > serial ) ;
+
+char* GetPasswordFunction( PK11SlotInfo* pSlot, PRBool bRetry, void* arg )
+{
+ char* pPassword = NULL;
+
+ uno::Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
+ if ( xMSF.is() )
+ {
+ uno::Reference < task::XInteractionHandler > xInteractionHandler(
+ xMSF->createInstance( rtl::OUString::createFromAscii("com.sun.star.task.InteractionHandler") ), uno::UNO_QUERY );
+
+ if ( xInteractionHandler.is() )
+ {
+ task::PasswordRequestMode eMode = bRetry ? task::PasswordRequestMode_PASSWORD_REENTER : task::PasswordRequestMode_PASSWORD_ENTER;
+ RequestDocumentPassword* pPasswordRequest = new RequestDocumentPassword( eMode, ::rtl::OUString() );
+
+ uno::Reference< task::XInteractionRequest > xRequest( pPasswordRequest );
+ xInteractionHandler->handle( xRequest );
+
+ if ( pPasswordRequest->isPassword() )
+ {
+ // We need TOOLS anyway, because of class RequestDocumentPassword.
+ // If this changes, use rtl String functions for this...
+ ByteString aPassword = ByteString( String( pPasswordRequest->getPassword() ), gsl_getSystemTextEncoding() );
+ USHORT nLen = aPassword.Len();
+ pPassword = (char*) PORT_Alloc( nLen+1 ) ;
+ pPassword[nLen] = 0;
+ memcpy( pPassword, aPassword.GetBuffer(), nLen );
+ }
+ }
+ }
+#ifdef DEBUG
+ else
+ {
+ // TEST Password is 'sceri'
+ pPassword = ( char* )PORT_Alloc( 20 ) ;
+ pPassword[0]='s';
+ pPassword[1]='c';
+ pPassword[2]='e';
+ pPassword[3]='r';
+ pPassword[4]='i';
+ pPassword[5]=0x0;
+ }
+#endif
+
+ return pPassword;
+}
+
+SecurityEnvironment_NssImpl :: SecurityEnvironment_NssImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_pSlot( NULL ) , m_pHandler( NULL ) , m_tSymKeyList() , m_tPubKeyList() , m_tPriKeyList() {
+
+ PK11_SetPasswordFunc( GetPasswordFunction ) ;
+}
+
+SecurityEnvironment_NssImpl :: ~SecurityEnvironment_NssImpl() {
+
+ PK11_SetPasswordFunc( NULL ) ;
+
+ if( m_pSlot != NULL ) {
+ PK11_FreeSlot( m_pSlot ) ;
+ m_pSlot = NULL ;
+ }
+
+ if( !m_tSymKeyList.empty() ) {
+ std::list< PK11SymKey* >::iterator symKeyIt ;
+
+ for( symKeyIt = m_tSymKeyList.begin() ; symKeyIt != m_tSymKeyList.end() ; symKeyIt ++ )
+ PK11_FreeSymKey( *symKeyIt ) ;
+ }
+
+ if( !m_tPubKeyList.empty() ) {
+ std::list< SECKEYPublicKey* >::iterator pubKeyIt ;
+
+ for( pubKeyIt = m_tPubKeyList.begin() ; pubKeyIt != m_tPubKeyList.end() ; pubKeyIt ++ )
+ SECKEY_DestroyPublicKey( *pubKeyIt ) ;
+ }
+
+ if( !m_tPriKeyList.empty() ) {
+ std::list< SECKEYPrivateKey* >::iterator priKeyIt ;
+
+ for( priKeyIt = m_tPriKeyList.begin() ; priKeyIt != m_tPriKeyList.end() ; priKeyIt ++ )
+ SECKEY_DestroyPrivateKey( *priKeyIt ) ;
+ }
+}
+
+/* XInitialization */
+void SAL_CALL SecurityEnvironment_NssImpl :: initialize( const Sequence< Any >& aArguments ) throw( Exception, RuntimeException ) {
+ // TBD
+} ;
+
+/* XServiceInfo */
+OUString SAL_CALL SecurityEnvironment_NssImpl :: getImplementationName() throw( RuntimeException ) {
+ return impl_getImplementationName() ;
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL SecurityEnvironment_NssImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) {
+ Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
+ const OUString* pArray = seqServiceNames.getConstArray() ;
+ for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
+ if( *( pArray + i ) == serviceName )
+ return sal_True ;
+ }
+ return sal_False ;
+}
+
+/* XServiceInfo */
+Sequence< OUString > SAL_CALL SecurityEnvironment_NssImpl :: getSupportedServiceNames() throw( RuntimeException ) {
+ return impl_getSupportedServiceNames() ;
+}
+
+//Helper for XServiceInfo
+Sequence< OUString > SecurityEnvironment_NssImpl :: impl_getSupportedServiceNames() {
+ ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+ Sequence< OUString > seqServiceNames( 1 ) ;
+ seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.SecurityEnvironment" ) ;
+ return seqServiceNames ;
+}
+
+OUString SecurityEnvironment_NssImpl :: impl_getImplementationName() throw( RuntimeException ) {
+ return OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.SecurityEnvironment_NssImpl" ) ;
+}
+
+//Helper for registry
+Reference< XInterface > SAL_CALL SecurityEnvironment_NssImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
+ return Reference< XInterface >( *new SecurityEnvironment_NssImpl( aServiceManager ) ) ;
+}
+
+Reference< XSingleServiceFactory > SecurityEnvironment_NssImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
+ //Reference< XSingleServiceFactory > xFactory ;
+ //xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
+ //return xFactory ;
+ return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
+}
+
+/* XUnoTunnel */
+sal_Int64 SAL_CALL SecurityEnvironment_NssImpl :: getSomething( const Sequence< sal_Int8 >& aIdentifier )
+ throw( RuntimeException )
+{
+ if( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) {
+ return ( sal_Int64 )this ;
+ }
+ return 0 ;
+}
+
+/* XUnoTunnel extension */
+const Sequence< sal_Int8>& SecurityEnvironment_NssImpl :: getUnoTunnelId() {
+ static Sequence< sal_Int8 >* pSeq = 0 ;
+ if( !pSeq ) {
+ ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+ if( !pSeq ) {
+ static Sequence< sal_Int8> aSeq( 16 ) ;
+ rtl_createUuid( ( sal_uInt8* )aSeq.getArray() , 0 , sal_True ) ;
+ pSeq = &aSeq ;
+ }
+ }
+ return *pSeq ;
+}
+
+/* XUnoTunnel extension */
+SecurityEnvironment_NssImpl* SecurityEnvironment_NssImpl :: getImplementation( const Reference< XInterface > xObj ) {
+ Reference< XUnoTunnel > xUT( xObj , UNO_QUERY ) ;
+ if( xUT.is() ) {
+ return ( SecurityEnvironment_NssImpl* )xUT->getSomething( getUnoTunnelId() ) ;
+ } else
+ return NULL ;
+}
+
+/* Native methods */
+PK11SlotInfo* SecurityEnvironment_NssImpl :: getCryptoSlot() throw( Exception , RuntimeException ) {
+ return m_pSlot ;
+}
+
+void SecurityEnvironment_NssImpl :: setCryptoSlot( PK11SlotInfo* aSlot) throw( Exception , RuntimeException ) {
+ if( m_pSlot != NULL ) {
+ PK11_FreeSlot( m_pSlot ) ;
+ m_pSlot = NULL ;
+ }
+
+ if( aSlot != NULL ) {
+ m_pSlot = PK11_ReferenceSlot( aSlot ) ;
+ }
+}
+
+CERTCertDBHandle* SecurityEnvironment_NssImpl :: getCertDb() throw( Exception , RuntimeException ) {
+ return m_pHandler ;
+}
+
+void SecurityEnvironment_NssImpl :: setCertDb( CERTCertDBHandle* aCertDb ) throw( Exception , RuntimeException ) {
+ m_pHandler = aCertDb ;
+}
+
+void SecurityEnvironment_NssImpl :: adoptSymKey( PK11SymKey* aSymKey ) throw( Exception , RuntimeException ) {
+ PK11SymKey* symkey ;
+ std::list< PK11SymKey* >::iterator keyIt ;
+
+ if( aSymKey != NULL ) {
+ //First try to find the key in the list
+ for( keyIt = m_tSymKeyList.begin() ; keyIt != m_tSymKeyList.end() ; keyIt ++ ) {
+ if( *keyIt == aSymKey )
+ return ;
+ }
+
+ //If we do not find the key in the list, add a new node
+ symkey = PK11_ReferenceSymKey( aSymKey ) ;
+ if( symkey == NULL )
+ throw RuntimeException() ;
+
+ try {
+ m_tSymKeyList.push_back( symkey ) ;
+ } catch ( Exception& ) {
+ PK11_FreeSymKey( symkey ) ;
+ }
+ }
+}
+
+void SecurityEnvironment_NssImpl :: rejectSymKey( PK11SymKey* aSymKey ) throw( Exception , RuntimeException ) {
+ PK11SymKey* symkey ;
+ std::list< PK11SymKey* >::iterator keyIt ;
+
+ if( aSymKey != NULL ) {
+ for( keyIt = m_tSymKeyList.begin() ; keyIt != m_tSymKeyList.end() ; keyIt ++ ) {
+ if( *keyIt == aSymKey ) {
+ symkey = *keyIt ;
+ PK11_FreeSymKey( symkey ) ;
+ m_tSymKeyList.erase( keyIt ) ;
+ break ;
+ }
+ }
+ }
+}
+
+PK11SymKey* SecurityEnvironment_NssImpl :: getSymKey( unsigned int position ) throw( Exception , RuntimeException ) {
+ PK11SymKey* symkey ;
+ std::list< PK11SymKey* >::iterator keyIt ;
+ unsigned int pos ;
+
+ symkey = NULL ;
+ for( pos = 0, keyIt = m_tSymKeyList.begin() ; pos < position && keyIt != m_tSymKeyList.end() ; pos ++ , keyIt ++ ) ;
+
+ if( pos == position && keyIt != m_tSymKeyList.end() )
+ symkey = *keyIt ;
+
+ return symkey ;
+}
+
+void SecurityEnvironment_NssImpl :: adoptPubKey( SECKEYPublicKey* aPubKey ) throw( Exception , RuntimeException ) {
+ SECKEYPublicKey* pubkey ;
+ std::list< SECKEYPublicKey* >::iterator keyIt ;
+
+ if( aPubKey != NULL ) {
+ //First try to find the key in the list
+ for( keyIt = m_tPubKeyList.begin() ; keyIt != m_tPubKeyList.end() ; keyIt ++ ) {
+ if( *keyIt == aPubKey )
+ return ;
+ }
+
+ //If we do not find the key in the list, add a new node
+ pubkey = SECKEY_CopyPublicKey( aPubKey ) ;
+ if( pubkey == NULL )
+ throw RuntimeException() ;
+
+ try {
+ m_tPubKeyList.push_back( pubkey ) ;
+ } catch ( Exception& ) {
+ SECKEY_DestroyPublicKey( pubkey ) ;
+ }
+ }
+}
+
+void SecurityEnvironment_NssImpl :: rejectPubKey( SECKEYPublicKey* aPubKey ) throw( Exception , RuntimeException ) {
+ SECKEYPublicKey* pubkey ;
+ std::list< SECKEYPublicKey* >::iterator keyIt ;
+
+ if( aPubKey != NULL ) {
+ for( keyIt = m_tPubKeyList.begin() ; keyIt != m_tPubKeyList.end() ; keyIt ++ ) {
+ if( *keyIt == aPubKey ) {
+ pubkey = *keyIt ;
+ SECKEY_DestroyPublicKey( pubkey ) ;
+ m_tPubKeyList.erase( keyIt ) ;
+ break ;
+ }
+ }
+ }
+}
+
+SECKEYPublicKey* SecurityEnvironment_NssImpl :: getPubKey( unsigned int position ) throw( Exception , RuntimeException ) {
+ SECKEYPublicKey* pubkey ;
+ std::list< SECKEYPublicKey* >::iterator keyIt ;
+ unsigned int pos ;
+
+ pubkey = NULL ;
+ for( pos = 0, keyIt = m_tPubKeyList.begin() ; pos < position && keyIt != m_tPubKeyList.end() ; pos ++ , keyIt ++ ) ;
+
+ if( pos == position && keyIt != m_tPubKeyList.end() )
+ pubkey = *keyIt ;
+
+ return pubkey ;
+}
+
+void SecurityEnvironment_NssImpl :: adoptPriKey( SECKEYPrivateKey* aPriKey ) throw( Exception , RuntimeException ) {
+ SECKEYPrivateKey* prikey ;
+ std::list< SECKEYPrivateKey* >::iterator keyIt ;
+
+ if( aPriKey != NULL ) {
+ //First try to find the key in the list
+ for( keyIt = m_tPriKeyList.begin() ; keyIt != m_tPriKeyList.end() ; keyIt ++ ) {
+ if( *keyIt == aPriKey )
+ return ;
+ }
+
+ //If we do not find the key in the list, add a new node
+ prikey = SECKEY_CopyPrivateKey( aPriKey ) ;
+ if( prikey == NULL )
+ throw RuntimeException() ;
+
+ try {
+ m_tPriKeyList.push_back( prikey ) ;
+ } catch ( Exception& ) {
+ SECKEY_DestroyPrivateKey( prikey ) ;
+ }
+ }
+}
+
+void SecurityEnvironment_NssImpl :: rejectPriKey( SECKEYPrivateKey* aPriKey ) throw( Exception , RuntimeException ) {
+ SECKEYPrivateKey* prikey ;
+ std::list< SECKEYPrivateKey* >::iterator keyIt ;
+
+ if( aPriKey != NULL ) {
+ for( keyIt = m_tPriKeyList.begin() ; keyIt != m_tPriKeyList.end() ; keyIt ++ ) {
+ if( *keyIt == aPriKey ) {
+ prikey = *keyIt ;
+ SECKEY_DestroyPrivateKey( prikey ) ;
+ m_tPriKeyList.erase( keyIt ) ;
+ break ;
+ }
+ }
+ }
+}
+
+SECKEYPrivateKey* SecurityEnvironment_NssImpl :: getPriKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) {
+ SECKEYPrivateKey* prikey ;
+ std::list< SECKEYPrivateKey* >::iterator keyIt ;
+ unsigned int pos ;
+
+ prikey = NULL ;
+ for( pos = 0, keyIt = m_tPriKeyList.begin() ; pos < position && keyIt != m_tPriKeyList.end() ; pos ++ , keyIt ++ ) ;
+
+ if( pos == position && keyIt != m_tPriKeyList.end() )
+ prikey = *keyIt ;
+
+ return prikey ;
+}
+
+Sequence< Reference < XCertificate > > SecurityEnvironment_NssImpl :: getPersonalCertificates() throw( SecurityException , RuntimeException ) {
+ sal_Int32 length ;
+ X509Certificate_NssImpl* xcert ;
+ std::list< X509Certificate_NssImpl* > certsList ;
+
+ //firstly, we try to find private keys in slot
+ if( m_pSlot != NULL ) {
+ SECKEYPrivateKeyList* priKeyList ;
+ SECKEYPrivateKeyListNode* curPri ;
+
+ if( PK11_NeedLogin( m_pSlot ) ) {
+ SECStatus nRet = PK11_Authenticate( m_pSlot, PR_TRUE, NULL );
+ if( nRet != SECSuccess ) {
+ throw NoPasswordException();
+ }
+ }
+
+ priKeyList = PK11_ListPrivateKeysInSlot( m_pSlot ) ;
+ if( priKeyList != NULL ) {
+ for( curPri = PRIVKEY_LIST_HEAD( priKeyList ); !PRIVKEY_LIST_END( curPri, priKeyList ) && curPri != NULL ; curPri = PRIVKEY_LIST_NEXT( curPri ) ) {
+ xcert = NssPrivKeyToXCert( curPri->key ) ;
+ if( xcert != NULL )
+ certsList.push_back( xcert ) ;
+ }
+ }
+
+ SECKEY_DestroyPrivateKeyList( priKeyList ) ;
+ }
+
+ //Deprecated
+ /*-------
+ {
+ PK11SlotList* soltList ;
+ PK11SlotListElement* soltEle ;
+
+ SECKEYPrivateKeyList* priKeyList ;
+ SECKEYPrivateKeyListNode* curPri ;
+
+ soltList = PK11_GetAllTokens( CKM_INVALID_MECHANISM, PR_FALSE, PR_FALSE, NULL ) ;
+ if( soltList != NULL ) {
+ for( soltEle = soltList->head; soltEle != NULL; soltEle = soltEle->next ) {
+ if( PK11_NeedLogin( soltEle->slot ) ) {
+ if( PK11_Authenticate( soltEle->slot, PR_TRUE, NULL ) != SECSuccess ) {
+ return NULL ;
+ }
+ }
+
+ priKeyList = PK11_ListPrivateKeysInSlot( soltEle->slot ) ;
+ if( priKeyList != NULL ) {
+ for( curPri = PRIVKEY_LIST_HEAD( priKeyList ); !PRIVKEY_LIST_END( curPri, priKeyList ) && curPri != NULL ; curPri = PRIVKEY_LIST_NEXT( curPri ) ) {
+ xcert = NssPrivKeyToXCert( curPri->key ) ;
+ if( xcert != NULL )
+ certsList.push_back( xcert ) ;
+ }
+ }
+
+ SECKEY_DestroyPrivateKeyList( priKeyList ) ;
+ }
+ }
+ }
+ ----------*/
+
+ //secondly, we try to find certificate from registered private keys.
+ if( !m_tPriKeyList.empty() ) {
+ std::list< SECKEYPrivateKey* >::iterator priKeyIt ;
+
+ for( priKeyIt = m_tPriKeyList.begin() ; priKeyIt != m_tPriKeyList.end() ; priKeyIt ++ ) {
+ xcert = NssPrivKeyToXCert( *priKeyIt ) ;
+ if( xcert != NULL )
+ certsList.push_back( xcert ) ;
+ }
+ }
+
+ length = certsList.size() ;
+ if( length != 0 ) {
+ int i ;
+ std::list< X509Certificate_NssImpl* >::iterator xcertIt ;
+ Sequence< Reference< XCertificate > > certSeq( length ) ;
+
+ for( i = 0, xcertIt = certsList.begin(); xcertIt != certsList.end(); xcertIt ++, i++ ) {
+ certSeq[i] = *xcertIt ;
+ }
+
+ return certSeq ;
+ }
+
+ return NULL ;
+}
+
+Reference< XCertificate > SecurityEnvironment_NssImpl :: getCertificate( const OUString& issuerName, const Sequence< sal_Int8 >& serialNumber ) throw( SecurityException , RuntimeException ) {
+ X509Certificate_NssImpl* xcert ;
+
+ if( m_pHandler != NULL ) {
+ CERTIssuerAndSN issuerAndSN ;
+ CERTCertificate* cert ;
+ CERTName* nmIssuer ;
+ char* chIssuer ;
+ SECItem* derIssuer ;
+ PRArenaPool* arena ;
+
+ arena = PORT_NewArena( DER_DEFAULT_CHUNKSIZE ) ;
+ if( arena == NULL )
+ throw RuntimeException() ;
+
+ rtl::OString ostr = rtl::OUStringToOString( issuerName , RTL_TEXTENCODING_ASCII_US ) ;
+ chIssuer = PL_strndup( ( char* )ostr.getStr(), ( int )ostr.getLength() ) ;
+ nmIssuer = CERT_AsciiToName( chIssuer ) ;
+ if( nmIssuer == NULL ) {
+ PL_strfree( chIssuer ) ;
+ PORT_FreeArena( arena, PR_FALSE ) ;
+ throw RuntimeException() ;
+ }
+
+ derIssuer = SEC_ASN1EncodeItem( arena, NULL, ( void* )nmIssuer, SEC_ASN1_GET( CERT_NameTemplate ) ) ;
+ if( derIssuer == NULL ) {
+ PL_strfree( chIssuer ) ;
+ CERT_DestroyName( nmIssuer ) ;
+ PORT_FreeArena( arena, PR_FALSE ) ;
+ throw RuntimeException() ;
+ }
+
+ memset( &issuerAndSN, 0, sizeof( issuerAndSN ) ) ;
+
+ issuerAndSN.derIssuer.data = derIssuer->data ;
+ issuerAndSN.derIssuer.len = derIssuer->len ;
+
+ issuerAndSN.serialNumber.data = ( unsigned char* )&serialNumber[0] ;
+ issuerAndSN.serialNumber.len = serialNumber.getLength() ;
+
+ cert = CERT_FindCertByIssuerAndSN( m_pHandler, &issuerAndSN ) ;
+ if( cert != NULL ) {
+ xcert = NssCertToXCert( cert ) ;
+ } else {
+ xcert = NULL ;
+ }
+
+ PL_strfree( chIssuer ) ;
+ CERT_DestroyName( nmIssuer ) ;
+ //SECITEM_FreeItem( derIssuer, PR_FALSE ) ;
+ CERT_DestroyCertificate( cert ) ;
+ PORT_FreeArena( arena, PR_FALSE ) ;
+ } else {
+ xcert = NULL ;
+ }
+
+ return xcert ;
+}
+
+Reference< XCertificate > SecurityEnvironment_NssImpl :: getCertificate( const OUString& issuerName, const OUString& serialNumber ) throw( SecurityException , RuntimeException ) {
+ Sequence< sal_Int8 > serial = numericStringToBigInteger( serialNumber ) ;
+ return getCertificate( issuerName, serial ) ;
+}
+
+Sequence< Reference < XCertificate > > SecurityEnvironment_NssImpl :: buildCertificatePath( const Reference< XCertificate >& begin ) throw( SecurityException , RuntimeException ) {
+ const X509Certificate_NssImpl* xcert ;
+ const CERTCertificate* cert ;
+ CERTCertList* certChain ;
+
+ Reference< XUnoTunnel > xCertTunnel( begin, UNO_QUERY ) ;
+ if( !xCertTunnel.is() ) {
+ throw RuntimeException() ;
+ }
+
+ xcert = ( X509Certificate_NssImpl* )xCertTunnel->getSomething( X509Certificate_NssImpl::getUnoTunnelId() ) ;
+ if( xcert == NULL ) {
+ throw RuntimeException() ;
+ }
+
+ cert = xcert->getNssCert() ;
+ if( cert != NULL ) {
+ int64 timeboundary ;
+
+ //Get the system clock time
+ timeboundary = PR_Now() ;
+
+ certChain = CERT_GetCertChainFromCert( ( CERTCertificate* )cert, timeboundary, certUsageAnyCA ) ;
+ } else {
+ certChain = NULL ;
+ }
+
+ if( certChain != NULL ) {
+ X509Certificate_NssImpl* pCert ;
+ CERTCertListNode* node ;
+ int len ;
+
+ for( len = 0, node = CERT_LIST_HEAD( certChain ); !CERT_LIST_END( node, certChain ); node = CERT_LIST_NEXT( node ), len ++ ) ;
+ Sequence< Reference< XCertificate > > xCertChain( len ) ;
+
+ for( len = 0, node = CERT_LIST_HEAD( certChain ); !CERT_LIST_END( node, certChain ); node = CERT_LIST_NEXT( node ), len ++ ) {
+ pCert = new X509Certificate_NssImpl() ;
+ if( pCert == NULL ) {
+ CERT_DestroyCertList( certChain ) ;
+ throw RuntimeException() ;
+ }
+
+ pCert->setCert( node->cert ) ;
+
+ xCertChain[len] = pCert ;
+ }
+
+ CERT_DestroyCertList( certChain ) ;
+
+ return xCertChain ;
+ }
+
+ return NULL ;
+}
+
+Reference< XCertificate > SecurityEnvironment_NssImpl :: createCertificateFromRaw( const Sequence< sal_Int8 >& rawCertificate ) throw( SecurityException , RuntimeException ) {
+ X509Certificate_NssImpl* xcert ;
+
+ if( rawCertificate.getLength() > 0 ) {
+ xcert = new X509Certificate_NssImpl() ;
+ if( xcert == NULL )
+ throw RuntimeException() ;
+
+ xcert->setRawCert( rawCertificate ) ;
+ } else {
+ xcert = NULL ;
+ }
+
+ return xcert ;
+}
+
+Reference< XCertificate > SecurityEnvironment_NssImpl :: createCertificateFromAscii( const OUString& asciiCertificate ) throw( SecurityException , RuntimeException ) {
+ xmlChar* chCert ;
+ xmlSecSize certSize ;
+
+ rtl::OString oscert = rtl::OUStringToOString( asciiCertificate , RTL_TEXTENCODING_ASCII_US ) ;
+
+ chCert = xmlStrndup( ( const xmlChar* )oscert.getStr(), ( int )oscert.getLength() ) ;
+
+ certSize = xmlSecBase64Decode( chCert, ( xmlSecByte* )chCert, xmlStrlen( chCert ) ) ;
+
+ Sequence< sal_Int8 > rawCert( certSize ) ;
+ for( unsigned int i = 0 ; i < certSize ; i ++ )
+ rawCert[i] = *( chCert + i ) ;
+
+ xmlFree( chCert ) ;
+
+ return createCertificateFromRaw( rawCert ) ;
+}
+
+X509Certificate_NssImpl* NssCertToXCert( CERTCertificate* cert )
+{
+ X509Certificate_NssImpl* xcert ;
+
+ if( cert != NULL ) {
+ xcert = new X509Certificate_NssImpl() ;
+ if( xcert == NULL ) {
+ xcert = NULL ;
+ } else {
+ xcert->setCert( cert ) ;
+ }
+ } else {
+ xcert = NULL ;
+ }
+
+ return xcert ;
+}
+
+X509Certificate_NssImpl* NssPrivKeyToXCert( SECKEYPrivateKey* priKey )
+{
+ CERTCertificate* cert ;
+ X509Certificate_NssImpl* xcert ;
+
+ if( priKey != NULL ) {
+ cert = PK11_GetCertFromPrivateKey( priKey ) ;
+
+ if( cert != NULL ) {
+ xcert = NssCertToXCert( cert ) ;
+ } else {
+ xcert = NULL ;
+ }
+
+ CERT_DestroyCertificate( cert ) ;
+ } else {
+ xcert = NULL ;
+ }
+
+ return xcert ;
+}
+
+/*-
+ * This is just one temporary conversion
+ */
+Sequence< sal_Int8 > numericStringToBigInteger (
+ OUString serialNumber
+) {
+ char* chSerial ;
+ unsigned long ui ;
+ unsigned char bb[5] ;
+ int len ;
+
+ rtl::OString oseri = rtl::OUStringToOString( serialNumber , RTL_TEXTENCODING_ASCII_US ) ;
+
+ chSerial = PL_strndup( ( char* )oseri.getStr(), ( int )oseri.getLength() ) ;
+ ui = PORT_Atoi( chSerial ) ;
+ PL_strfree( chSerial ) ;
+
+ bb[0] = 0;
+ bb[1] = (unsigned char) (ui >> 24);
+ bb[2] = (unsigned char) (ui >> 16);
+ bb[3] = (unsigned char) (ui >> 8);
+ bb[4] = (unsigned char) (ui);
+
+ /*
+ ** Small integers are encoded in a single byte. Larger integers
+ ** require progressively more space.
+ */
+ if (ui > 0x7f) {
+ if (ui > 0x7fff) {
+ if (ui > 0x7fffffL) {
+ if (ui >= 0x80000000L) {
+ len = 5;
+ } else {
+ len = 4;
+ }
+ } else {
+ len = 3;
+ }
+ } else {
+ len = 2;
+ }
+ } else {
+ len = 1;
+ }
+
+ Sequence< sal_Int8 > serial( len ) ;
+ for( int i = 0 ; i < len ; i ++ )
+ serial[i] = *( bb + sizeof( bb ) - len + i ) ;
+
+ return serial ;
+}
+
+/*-
+ * This is just one temporary conversion
+ */
+OUString bigIntegerToNumericString ( Sequence< sal_Int8 > serial)
+{
+ OUString aRet;
+
+ if ( serial.getLength() )
+ {
+ SECItem snItem ;
+ long sn ;
+
+ snItem.data = ( unsigned char* )&serial[0] ;
+ snItem.len = serial.getLength() ;
+
+ sn = DER_GetInteger( &snItem ) ;
+ if( sn != ULONG_MAX )
+ {
+ char str[10] ;
+ int len ;
+ len = sprintf( str, "%d", sn ) ;
+ aRet = OUString::createFromAscii( str ) ;
+ }
+ }
+ return aRet;
+}
diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx
new file mode 100644
index 000000000000..54d771544075
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx
@@ -0,0 +1,210 @@
+/*************************************************************************
+ *
+ * $RCSfile: securityenvironment_nssimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _XSECURITYENVIRONMENT_NSSIMPL_HXX_
+#define _XSECURITYENVIRONMENT_NSSIMPL_HXX_
+
+#ifndef _SAL_CONFIG_H_
+#include <sal/config.h>
+#endif
+
+#ifndef _RTL_USTRING_HXX_
+#include <rtl/ustring.hxx>
+#endif
+
+#ifndef _CPPUHELPER_FACTORY_HXX_
+#include <cppuhelper/factory.hxx>
+#endif
+
+#ifndef _CPPUHELPER_IMPLBASE4_HXX_
+#include <cppuhelper/implbase4.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP_
+#include <com/sun/star/uno/Exception.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
+#include <com/sun/star/uno/Reference.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
+#include <com/sun/star/lang/XInitialization.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XSECURITYENVIRONMENT_HPP_
+#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_SECURITY_XCERTIFICATE_HPP_
+#include <com/sun/star/security/XCertificate.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#endif
+
+#include "pk11func.h"
+#include "keyhi.h"
+#include "certdb.h"
+#include "list"
+
+class SecurityEnvironment_NssImpl : public ::cppu::WeakImplHelper4<
+ ::com::sun::star::xml::crypto::XSecurityEnvironment ,
+ ::com::sun::star::lang::XInitialization ,
+ ::com::sun::star::lang::XServiceInfo ,
+ ::com::sun::star::lang::XUnoTunnel >
+{
+ private :
+ PK11SlotInfo* m_pSlot ;
+ CERTCertDBHandle* m_pHandler ;
+ std::list< PK11SymKey* > m_tSymKeyList ;
+ std::list< SECKEYPublicKey* > m_tPubKeyList ;
+ std::list< SECKEYPrivateKey* > m_tPriKeyList ;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;
+
+ public :
+ SecurityEnvironment_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
+ virtual ~SecurityEnvironment_NssImpl() ;
+
+ //Methods from XSecurityEnvironment
+
+ //Methods from XInitialization
+ virtual void SAL_CALL initialize(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments
+ ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ //Methods from XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual sal_Bool SAL_CALL supportsService(
+ const ::rtl::OUString& ServiceName
+ ) throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ //Helper for XServiceInfo
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ;
+
+ static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ //Helper for registry
+ static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL impl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > impl_createFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) ;
+
+ //Methods from XUnoTunnel
+ virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
+ throw (::com::sun::star::uno::RuntimeException);
+
+ static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId() ;
+ static SecurityEnvironment_NssImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ;
+
+ //Native mehtods
+ virtual PK11SlotInfo* getCryptoSlot() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void setCryptoSlot( PK11SlotInfo* aSlot ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual CERTCertDBHandle* getCertDb() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void setCertDb( CERTCertDBHandle* aCertDb ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void adoptSymKey( PK11SymKey* aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void rejectSymKey( PK11SymKey* aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual PK11SymKey* getSymKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void adoptPubKey( SECKEYPublicKey* aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void rejectPubKey( SECKEYPublicKey* aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual SECKEYPublicKey* getPubKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void adoptPriKey( SECKEYPrivateKey* aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void rejectPriKey( SECKEYPrivateKey* aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual SECKEYPrivateKey* getPriKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > > SAL_CALL getPersonalCertificates() throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL getCertificate( const ::rtl::OUString& issuerName, const ::com::sun::star::uno::Sequence< sal_Int8 >& serialNumber ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL getCertificate( const ::rtl::OUString& issuerName, const ::rtl::OUString& serialNumber ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > > SAL_CALL buildCertificatePath( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& beginCert ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL createCertificateFromRaw( const ::com::sun::star::uno::Sequence< sal_Int8 >& rawCertificate ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL createCertificateFromAscii( const ::rtl::OUString& asciiCertificate ) throw( ::com::sun::star::uno::SecurityException , ::com::sun::star::uno::RuntimeException ) ;
+} ;
+
+#endif // _XSECURITYENVIRONMENT_NSSIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx
new file mode 100644
index 000000000000..a9bea86e4d85
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx
@@ -0,0 +1,390 @@
+/*************************************************************************
+ *
+ * $RCSfile: seinitializer_nssimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+/*
+ * 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
+
+/*
+ * header files needed for getCurrentProfilePath
+ */
+#include "nsIServiceManager.h"
+#include "nsIProfileInternal.h"
+#include "nsString.h"
+#include "nsEmbedAPI.h"
+#include <sal/types.h>
+
+
+#include "seinitializer_nssimpl.hxx"
+
+#include "securityenvironment_nssimpl.hxx"
+
+#include "nspr.h"
+#include "prtypes.h"
+#include "pk11func.h"
+#include "cert.h"
+#include "cryptohi.h"
+#include "certdb.h"
+#include "nss.h"
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+
+using namespace com::sun::star;
+
+#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"
+
+/*
+ * MM : get the current user profile
+ */
+
+// MM : By now, the XPCOM is initialized only once in the current thread, and it will
+// not be shutdown until StarOffice exits.
+// This is a bug, because any other component who will initialize the XPCOM afterward
+// will always fail.
+// This bug will be fixed when there is solution.
+static nsIServiceManager *sServiceManager = nsnull;
+static nsIDirectoryServiceProvider *appFileLocProvider = nsnull;
+static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
+
+char* getCurrentProfilePath( )
+{
+ nsCOMPtr<nsILocalFile> binDir;
+
+ if (sServiceManager == nsnull)
+ {
+ NS_InitXPCOM2(&sServiceManager, binDir, appFileLocProvider);
+ }
+
+ if (!sServiceManager)
+ return NULL;
+
+ nsresult rv;
+ nsCOMPtr< nsIProfile > theProfile = do_GetService( kProfileCID, &rv );
+ if (NS_SUCCEEDED(rv))
+ {
+ nsXPIDLString profileName;
+ rv = theProfile->GetCurrentProfile(getter_Copies(profileName));
+ if (NS_SUCCEEDED(rv))
+ {
+ nsCOMPtr<nsIFile> curProfileDir;
+ PRBool exists = PR_FALSE;
+ nsCOMPtr<nsIProfileInternal> profileInternal=do_QueryInterface(theProfile);
+ if (NS_SUCCEEDED(rv))
+ {
+ rv = profileInternal->GetProfileDir(profileName, getter_AddRefs(curProfileDir));
+ if (NS_SUCCEEDED(rv))
+ {
+ nsCOMPtr<nsILocalFile> localFile(do_QueryInterface(curProfileDir));
+
+ nsAutoString path;
+ rv = localFile->GetPath(path);
+ if (NS_SUCCEEDED(rv))
+ {
+ char cs[1024];
+ path.ToCString(cs, 1024);
+
+ // MM : I can't shutdown, because the XPCom can't be initialized twice in
+ // one program
+ //NS_RELEASE(sServiceManager);
+ //NS_ShutdownXPCOM(sServiceManager);
+
+ return (strdup(cs));
+ }
+ }
+ }
+ }
+ }
+
+
+ // MM : I can't shutdown, because the XPCom can't be initialized twice in
+ // one program
+ //NS_RELEASE(sServiceManager);
+ //NS_ShutdownXPCOM(sServiceManager);
+
+ return NULL;
+}
+
+/*
+ * get the current user profile (end)
+ */
+
+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)
+{
+ CERTCertDBHandle* pCertHandle = NULL ;
+ PK11SlotInfo* pSlot = NULL ;
+
+ rtl::OString sCertDir;
+ if( sCertDB.getLength() > 0 )
+ {
+ sCertDir = rtl::OString(sCertDB, sCertDB.getLength(), RTL_TEXTENCODING_ASCII_US);
+ }
+ else
+ {
+ char *pCurrentProfilePath = getCurrentProfilePath();
+
+ if (pCurrentProfilePath == NULL)
+ {
+ return NULL;
+ }
+ else
+ {
+ sCertDir = rtl::OString(pCurrentProfilePath);
+ free(pCurrentProfilePath);
+ }
+ }
+
+ /* Initialize NSPR and NSS */
+ PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1 ) ;
+
+ if (NSS_Init(sCertDir.getStr()) != SECSuccess )
+ {
+ PK11_LogoutAll();
+ return NULL;
+ }
+
+ pCertHandle = CERT_GetDefaultCertDB() ;
+ pSlot = PK11_GetInternalKeySlot() ;
+
+ if (pSlot == NULL)
+ {
+ PK11_LogoutAll();
+ NSS_Shutdown();
+ return NULL;
+ }
+
+ PK11SymKey* pSymKey = PK11_KeyGen( pSlot , CKM_DES3_CBC, NULL, 128, NULL ) ;
+ if( pSymKey == NULL )
+ {
+ PK11_FreeSlot( pSlot ) ;
+ PK11_LogoutAll();
+ NSS_Shutdown();
+ return NULL;
+ }
+
+ try
+ {
+ /* Build Security Environment */
+ const rtl::OUString sSecyrutyEnvironment ( RTL_CONSTASCII_USTRINGPARAM( SECURITY_ENVIRONMENT ) );
+ cssu::Reference< cssxc::XSecurityEnvironment > xSecEnv( mxMSF->createInstance ( sSecyrutyEnvironment ), cssu::UNO_QUERY );
+ if( !xSecEnv.is() )
+ {
+ PK11_FreeSymKey( pSymKey ) ;
+ PK11_FreeSlot( pSlot ) ;
+ PK11_LogoutAll();
+ NSS_Shutdown();
+ return NULL;
+ }
+
+ /* Setup key slot and certDb */
+ cssu::Reference< cssl::XUnoTunnel > xEnvTunnel( xSecEnv , cssu::UNO_QUERY ) ;
+ if( !xEnvTunnel.is() )
+ {
+ PK11_FreeSymKey( pSymKey ) ;
+ PK11_FreeSlot( pSlot ) ;
+ PK11_LogoutAll();
+ NSS_Shutdown();
+ return NULL;
+ }
+
+ SecurityEnvironment_NssImpl* pSecEnv = ( SecurityEnvironment_NssImpl* )xEnvTunnel->getSomething( SecurityEnvironment_NssImpl::getUnoTunnelId() ) ;
+ if( pSecEnv == NULL )
+ {
+ PK11_FreeSymKey( pSymKey ) ;
+ PK11_FreeSlot( pSlot ) ;
+ PK11_LogoutAll();
+ NSS_Shutdown();
+ return NULL;
+ }
+
+ pSecEnv->setCryptoSlot( pSlot ) ;
+ PK11_FreeSlot( pSlot ) ;
+ pSlot = NULL;
+
+ pSecEnv->setCertDb( pCertHandle ) ;
+
+ pSecEnv->adoptSymKey( pSymKey ) ;
+ PK11_FreeSymKey( pSymKey ) ;
+ pSymKey = NULL;
+
+ /* 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() )
+ {
+ PK11_LogoutAll();
+ NSS_Shutdown();
+ return NULL;
+ }
+
+ xSecCtx->setSecurityEnvironment( xSecEnv ) ;
+ return xSecCtx;
+ }
+ catch( cssu::Exception& )
+ {
+ if (pSymKey != NULL)
+ {
+ PK11_FreeSymKey( pSymKey ) ;
+ }
+
+ if (pSlot != NULL)
+ {
+ PK11_FreeSlot( pSlot ) ;
+ }
+
+ PK11_LogoutAll();
+ NSS_Shutdown();
+ return NULL;
+ }
+}
+
+void SAL_CALL SEInitializer_NssImpl::freeSecurityContext( const cssu::Reference< cssxc::XXMLSecurityContext >& securityContext )
+ 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.
+ */
+ PK11_LogoutAll();
+ NSS_Shutdown();
+}
+
+rtl::OUString SEInitializer_NssImpl_getImplementationName ()
+ throw (cssu::RuntimeException)
+{
+ 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();
+}
+
diff --git a/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx
new file mode 100644
index 000000000000..dcca7207b05b
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx
@@ -0,0 +1,152 @@
+/*************************************************************************
+ *
+ * $RCSfile: seinitializer_nssimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _SEINITIALIZERIMPL_HXX
+#define _SEINITIALIZERIMPL_HXX
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLSECURITYCONTEXT_HPP_
+#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SEINITIALIZER_HPP_
+#include <com/sun/star/xml/crypto/XSEInitializer.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+#ifndef _CPPUHELPER_IMPLBASE2_HXX_
+#include <cppuhelper/implbase2.hxx>
+#endif
+
+#include <libxml/tree.h>
+
+class SEInitializer_NssImpl : public cppu::WeakImplHelper2
+<
+ com::sun::star::xml::crypto::XSEInitializer,
+ com::sun::star::lang::XServiceInfo
+>
+/****** SEInitializer_NssImpl.hxx/CLASS SEInitializer_NssImpl ***********
+ *
+ * NAME
+ * SEInitializer_NssImpl -- Class to initialize a Security Context
+ * instance
+ *
+ * FUNCTION
+ * Use this class to initialize a XmlSec based Security Context
+ * instance. After this instance is used up, use this class to free this
+ * instance.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XSEInitializer, XSEInitializer
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+private:
+ com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF;
+
+public:
+ SEInitializer_NssImpl(const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &rxMSF);
+ virtual ~SEInitializer_NssImpl();
+
+ /* XSEInitializer */
+ virtual com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLSecurityContext >
+ SAL_CALL createSecurityContext( const rtl::OUString& certDB )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL freeSecurityContext( const com::sun::star::uno::Reference<
+ com::sun::star::xml::crypto::XXMLSecurityContext >& securityContext )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /* XServiceInfo */
+ virtual rtl::OUString SAL_CALL getImplementationName( )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& ServiceName )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames( )
+ throw (com::sun::star::uno::RuntimeException);
+};
+
+rtl::OUString SEInitializer_NssImpl_getImplementationName()
+ throw ( com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL SEInitializer_NssImpl_supportsService( const rtl::OUString& ServiceName )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL SEInitializer_NssImpl_getSupportedServiceNames( )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
+SAL_CALL SEInitializer_NssImpl_createInstance( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rSMgr)
+ throw ( com::sun::star::uno::Exception );
+
+#endif
+
diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
new file mode 100644
index 000000000000..13a1be861811
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
@@ -0,0 +1,360 @@
+/*************************************************************************
+ *
+ * $RCSfile: x509certificate_nssimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _SAL_CONFIG_H_
+#include <sal/config.h>
+#endif
+
+#ifndef _RTL_UUID_H_
+#include <rtl/uuid.h>
+#endif
+
+#ifndef _X509CERTIFICATE_NSSIMPL_HXX_
+#include "x509certificate_nssimpl.hxx"
+#endif
+
+#ifndef _CERTIFICATEEXTENSION_NSSIMPL_HXX_
+#include "certificateextension_xmlsecimpl.hxx"
+#endif
+
+#include "nspr.h"
+#include "nss.h"
+#include "secder.h"
+
+using namespace ::com::sun::star::uno ;
+using namespace ::com::sun::star::security ;
+using ::rtl::OUString ;
+
+using ::com::sun::star::security::XCertificate ;
+using ::com::sun::star::util::DateTime ;
+
+X509Certificate_NssImpl :: X509Certificate_NssImpl() :
+ m_pCert( NULL )
+{
+}
+
+X509Certificate_NssImpl :: ~X509Certificate_NssImpl() {
+ if( m_pCert != NULL ) {
+ CERT_DestroyCertificate( m_pCert ) ;
+ }
+}
+
+//Methods from XCertificate
+sal_Int16 SAL_CALL X509Certificate_NssImpl :: getVersion() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL ) {
+ if( m_pCert->version.len > 0 ) {
+ return ( char )*( m_pCert->version.data ) ;
+ } else
+ return 0 ;
+ } else {
+ return -1 ;
+ }
+}
+
+::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl :: getSerialNumber() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL && m_pCert->serialNumber.len > 0 ) {
+ Sequence< sal_Int8 > serial( m_pCert->serialNumber.len ) ;
+ for( unsigned int i = 0 ; i < m_pCert->serialNumber.len ; i ++ )
+ serial[i] = *( m_pCert->serialNumber.data + i ) ;
+
+ return serial ;
+ } else {
+ return NULL ;
+ }
+}
+
+::rtl::OUString SAL_CALL X509Certificate_NssImpl :: getIssuerName() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL ) {
+ return OUString::createFromAscii( m_pCert->issuerName ) ;
+ } else {
+ return OUString() ;
+ }
+}
+
+::rtl::OUString SAL_CALL X509Certificate_NssImpl :: getSubjectName() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL ) {
+ return OUString::createFromAscii( m_pCert->subjectName ) ;
+ } else {
+ return OUString() ;
+ }
+}
+
+::com::sun::star::util::DateTime SAL_CALL X509Certificate_NssImpl :: getNotBefore() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL ) {
+ SECStatus rv ;
+ PRTime notBefore ;
+ PRExplodedTime explTime ;
+ DateTime dateTime ;
+
+ rv = DER_DecodeTimeChoice( &notBefore, &m_pCert->validity.notBefore ) ;
+ if( rv ) {
+ return DateTime() ;
+ }
+
+ //Convert the time to readable local time
+ PR_ExplodeTime( notBefore, PR_LocalTimeParameters, &explTime ) ;
+
+ dateTime.HundredthSeconds = explTime.tm_usec / 1000 ;
+ dateTime.Seconds = explTime.tm_sec ;
+ dateTime.Minutes = explTime.tm_min ;
+ dateTime.Hours = explTime.tm_hour ;
+ dateTime.Day = explTime.tm_mday ;
+ dateTime.Month = explTime.tm_month ;
+ dateTime.Year = explTime.tm_year ;
+
+ return dateTime ;
+ } else {
+ return DateTime() ;
+ }
+}
+
+::com::sun::star::util::DateTime SAL_CALL X509Certificate_NssImpl :: getNotAfter() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL ) {
+ SECStatus rv ;
+ PRTime notAfter ;
+ PRExplodedTime explTime ;
+ DateTime dateTime ;
+
+ rv = DER_DecodeTimeChoice( &notAfter, &m_pCert->validity.notAfter ) ;
+ if( rv ) {
+ return DateTime() ;
+ }
+
+ //Convert the time to readable local time
+ PR_ExplodeTime( notAfter, PR_LocalTimeParameters, &explTime ) ;
+
+ dateTime.HundredthSeconds = explTime.tm_usec / 1000 ;
+ dateTime.Seconds = explTime.tm_sec ;
+ dateTime.Minutes = explTime.tm_min ;
+ dateTime.Hours = explTime.tm_hour ;
+ dateTime.Day = explTime.tm_mday ;
+ dateTime.Month = explTime.tm_month ;
+ dateTime.Year = explTime.tm_year ;
+
+ return dateTime ;
+ } else {
+ return DateTime() ;
+ }
+}
+
+::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl :: getIssuerUniqueID() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL && m_pCert->issuerID.len > 0 ) {
+ Sequence< sal_Int8 > issuerUid( m_pCert->issuerID.len ) ;
+ for( unsigned int i = 0 ; i < m_pCert->issuerID.len ; i ++ )
+ issuerUid[i] = *( m_pCert->issuerID.data + i ) ;
+
+ return issuerUid ;
+ } else {
+ return NULL ;
+ }
+}
+
+::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl :: getSubjectUniqueID() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL && m_pCert->subjectID.len > 0 ) {
+ Sequence< sal_Int8 > subjectUid( m_pCert->subjectID.len ) ;
+ for( unsigned int i = 0 ; i < m_pCert->subjectID.len ; i ++ )
+ subjectUid[i] = *( m_pCert->subjectID.data + i ) ;
+
+ return subjectUid ;
+ } else {
+ return NULL ;
+ }
+}
+
+::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificateExtension > > SAL_CALL X509Certificate_NssImpl :: getExtensions() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL && m_pCert->extensions != NULL ) {
+ CERTCertExtension** extns ;
+ CertificateExtension_XmlSecImpl* pExtn ;
+ sal_Bool crit ;
+ int len ;
+
+ for( len = 0, extns = m_pCert->extensions; *extns != NULL; len ++, extns ++ ) ;
+ Sequence< Reference< XCertificateExtension > > xExtns( len ) ;
+
+ for( extns = m_pCert->extensions, len = 0; *extns != NULL; extns ++, len ++ ) {
+ pExtn = new CertificateExtension_XmlSecImpl() ;
+ if( (*extns)->critical.data == NULL )
+ crit = sal_False ;
+ else
+ crit = ( (*extns)->critical.data[0] == 0xFF ) ? sal_True : sal_False ;
+ pExtn->setCertExtn( (*extns)->value.data, (*extns)->value.len, (*extns)->id.data, (*extns)->id.len, crit ) ;
+
+ xExtns[len] = pExtn ;
+ }
+
+ return xExtns ;
+ } else {
+ return NULL ;
+ }
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificateExtension > SAL_CALL X509Certificate_NssImpl :: findCertExtension( const ::com::sun::star::uno::Sequence< sal_Int8 >& oid ) throw (::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL && m_pCert->extensions != NULL ) {
+ CertificateExtension_XmlSecImpl* pExtn ;
+ CERTCertExtension** extns ;
+ SECItem idItem ;
+ sal_Bool crit ;
+
+ idItem.data = ( unsigned char* )&oid[0] ;
+ idItem.len = oid.getLength() ;
+
+ pExtn = NULL ;
+ for( extns = m_pCert->extensions; *extns != NULL; extns ++ ) {
+ if( SECITEM_CompareItem( &idItem, &(*extns)->id ) == SECEqual ) {
+ pExtn = new CertificateExtension_XmlSecImpl() ;
+ if( (*extns)->critical.data == NULL )
+ crit = sal_False ;
+ else
+ crit = ( (*extns)->critical.data[0] == 0xFF ) ? sal_True : sal_False ;
+ pExtn->setCertExtn( (*extns)->value.data, (*extns)->value.len, (*extns)->id.data, (*extns)->id.len, crit ) ;
+ }
+ }
+
+ return pExtn ;
+ } else {
+ return NULL ;
+ }
+}
+
+
+::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl :: getEncoded() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCert != NULL && m_pCert->derCert.len > 0 ) {
+ Sequence< sal_Int8 > rawCert( m_pCert->derCert.len ) ;
+
+ for( unsigned int i = 0 ; i < m_pCert->derCert.len ; i ++ )
+ rawCert[i] = *( m_pCert->derCert.data + i ) ;
+
+ return rawCert ;
+ } else {
+ return NULL ;
+ }
+}
+
+//Helper methods
+void X509Certificate_NssImpl :: setCert( CERTCertificate* cert ) {
+ if( m_pCert != NULL ) {
+ CERT_DestroyCertificate( m_pCert ) ;
+ m_pCert = NULL ;
+ }
+
+ if( cert != NULL ) {
+ m_pCert = CERT_DupCertificate( cert ) ;
+ }
+}
+
+const CERTCertificate* X509Certificate_NssImpl :: getNssCert() const {
+ if( m_pCert != NULL ) {
+ return m_pCert ;
+ } else {
+ return NULL ;
+ }
+}
+
+void X509Certificate_NssImpl :: setRawCert( Sequence< sal_Int8 > rawCert ) throw ( ::com::sun::star::uno::RuntimeException) {
+ CERTCertificate* cert ;
+ SECItem certItem ;
+
+ certItem.data = ( unsigned char* )&rawCert[0] ;
+ certItem.len = rawCert.getLength() ;
+
+ cert = CERT_DecodeDERCertificate( &certItem, PR_TRUE, NULL ) ;
+ if( cert == NULL )
+ throw RuntimeException() ;
+
+ if( m_pCert != NULL ) {
+ CERT_DestroyCertificate( m_pCert ) ;
+ m_pCert = NULL ;
+ }
+
+ m_pCert = cert ;
+}
+
+/* XUnoTunnel */
+sal_Int64 SAL_CALL X509Certificate_NssImpl :: getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw( RuntimeException ) {
+ if( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) {
+ return ( sal_Int64 )this ;
+ }
+ return 0 ;
+}
+
+/* XUnoTunnel extension */
+const Sequence< sal_Int8>& X509Certificate_NssImpl :: getUnoTunnelId() {
+ static Sequence< sal_Int8 >* pSeq = 0 ;
+ if( !pSeq ) {
+ ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+ if( !pSeq ) {
+ static Sequence< sal_Int8> aSeq( 16 ) ;
+ rtl_createUuid( ( sal_uInt8* )aSeq.getArray() , 0 , sal_True ) ;
+ pSeq = &aSeq ;
+ }
+ }
+ return *pSeq ;
+}
+
+/* XUnoTunnel extension */
+X509Certificate_NssImpl* X509Certificate_NssImpl :: getImplementation( const Reference< XInterface > xObj ) {
+ Reference< XUnoTunnel > xUT( xObj , UNO_QUERY ) ;
+ if( xUT.is() ) {
+ return ( X509Certificate_NssImpl* )xUT->getSomething( getUnoTunnelId() ) ;
+ } else
+ return NULL ;
+}
+
diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx
new file mode 100644
index 000000000000..3078ad16c64c
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx
@@ -0,0 +1,146 @@
+/*************************************************************************
+ *
+ * $RCSfile: x509certificate_nssimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _X509CERTIFICATE_NSSIMPL_HXX_
+#define _X509CERTIFICATE_NSSIMPL_HXX_
+
+#ifndef _SAL_CONFIG_H_
+#include <sal/config.h>
+#endif
+
+#ifndef _RTL_USTRING_HXX_
+#include <rtl/ustring.hxx>
+#endif
+
+#ifndef _CPPUHELPER_FACTORY_HXX_
+#include <cppuhelper/factory.hxx>
+#endif
+
+#ifndef _CPPUHELPER_IMPLBASE2_HXX_
+#include <cppuhelper/implbase2.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP_
+#include <com/sun/star/uno/Exception.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_SECURITYEXCEPTION_HPP_
+#include "com/sun/star/uno/SecurityException.hpp"
+#endif
+
+#ifndef _COM_SUN_STAR_SECURITY_XCERTIFICATE_HPP_
+#include <com/sun/star/security/XCertificate.hpp>
+#endif
+
+#include "cert.h"
+
+class X509Certificate_NssImpl : public ::cppu::WeakImplHelper2<
+ ::com::sun::star::security::XCertificate ,
+ ::com::sun::star::lang::XUnoTunnel >
+{
+ private :
+ CERTCertificate* m_pCert ;
+
+ public :
+ X509Certificate_NssImpl() ;
+ virtual ~X509Certificate_NssImpl() ;
+
+ //Methods from XCertificate
+ virtual sal_Int16 SAL_CALL getVersion( ) throw ( ::com::sun::star::uno::RuntimeException) ;
+
+ virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getSerialNumber( ) throw ( ::com::sun::star::uno::RuntimeException) ;
+
+ virtual ::rtl::OUString SAL_CALL getIssuerName( ) throw ( ::com::sun::star::uno::RuntimeException) ;
+
+ virtual ::rtl::OUString SAL_CALL getSubjectName( ) throw ( ::com::sun::star::uno::RuntimeException) ;
+
+ virtual ::com::sun::star::util::DateTime SAL_CALL getNotBefore( ) throw ( ::com::sun::star::uno::RuntimeException) ;
+
+ virtual ::com::sun::star::util::DateTime SAL_CALL getNotAfter( ) throw ( ::com::sun::star::uno::RuntimeException) ;
+
+ virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getIssuerUniqueID( ) throw ( ::com::sun::star::uno::RuntimeException) ;
+
+ virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getSubjectUniqueID( ) throw ( ::com::sun::star::uno::RuntimeException) ;
+
+ virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificateExtension > > SAL_CALL getExtensions( ) throw ( ::com::sun::star::uno::RuntimeException) ;
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificateExtension > SAL_CALL findCertExtension( const ::com::sun::star::uno::Sequence< sal_Int8 >& oid ) throw (::com::sun::star::uno::RuntimeException) ;
+
+ virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getEncoded( ) throw ( ::com::sun::star::uno::RuntimeException) ;
+
+ //Methods from XUnoTunnel
+ virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw (com::sun::star::uno::RuntimeException);
+
+ static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId() ;
+ static X509Certificate_NssImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ;
+
+ //Helper methods
+ void setCert( CERTCertificate* cert ) ;
+ const CERTCertificate* getNssCert() const ;
+ void setRawCert( ::com::sun::star::uno::Sequence< sal_Int8 > rawCert ) throw ( ::com::sun::star::uno::RuntimeException) ;
+} ;
+
+#endif // _X509CERTIFICATE_NSSIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/nss/xmlencryption_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/xmlencryption_nssimpl.cxx
new file mode 100644
index 000000000000..79d11247ebf5
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/xmlencryption_nssimpl.cxx
@@ -0,0 +1,429 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlencryption_nssimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _SAL_CONFIG_H_
+#include <sal/config.h>
+#endif
+
+#ifndef _RTL_UUID_H_
+#include <rtl/uuid.h>
+#endif
+
+#ifndef _XMLENCRYPTION_NSSIMPL_HXX_
+#include "xmlencryption_nssimpl.hxx"
+#endif
+
+#ifndef _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX_
+#include "xmldocumentwrapper_xmlsecimpl.hxx"
+#endif
+
+#ifndef _XMLELEMENTWRAPPER_XMLSECIMPL_HXX_
+#include "xmlelementwrapper_xmlsecimpl.hxx"
+#endif
+
+#ifndef _XMLSECURITYCONTEXT_NSSIMPL_HXX_
+#include "xmlsecuritycontext_nssimpl.hxx"
+#endif
+
+#include "xmlsec/xmlsec.h"
+#include "xmlsec/xmltree.h"
+#include "xmlsec/xmlenc.h"
+#include "xmlsec/crypto.h"
+
+#ifdef UNX
+#define stricmp strcasecmp
+#endif
+
+using namespace ::com::sun::star::uno ;
+using namespace ::com::sun::star::lang ;
+using ::com::sun::star::lang::XMultiServiceFactory ;
+using ::com::sun::star::lang::XSingleServiceFactory ;
+using ::rtl::OUString ;
+
+using ::com::sun::star::xml::wrapper::XXMLElementWrapper ;
+using ::com::sun::star::xml::wrapper::XXMLDocumentWrapper ;
+using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
+using ::com::sun::star::xml::crypto::XXMLEncryption ;
+using ::com::sun::star::xml::crypto::XXMLEncryptionTemplate ;
+using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
+
+XMLEncryption_NssImpl :: XMLEncryption_NssImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_xServiceManager( aFactory ) {
+}
+
+XMLEncryption_NssImpl :: ~XMLEncryption_NssImpl() {
+}
+
+/* XXMLEncryption */
+Reference< XXMLEncryptionTemplate >
+SAL_CALL XMLEncryption_NssImpl :: encrypt(
+ const Reference< XXMLEncryptionTemplate >& aTemplate ,
+ const Reference< XXMLSecurityContext >& aSecurityCtx
+) throw( com::sun::star::xml::crypto::XMLEncryptionException,
+ com::sun::star::uno::SecurityException )
+{
+ xmlSecKeysMngrPtr pMngr = NULL ;
+ xmlSecEncCtxPtr pEncCtx = NULL ;
+ xmlNodePtr pEncryptedData = NULL ;
+ xmlNodePtr pEncryptedKey = NULL ;
+ xmlNodePtr pContent = NULL ;
+
+ if( !aTemplate.is() )
+ throw RuntimeException() ;
+
+ if( !aSecurityCtx.is() )
+ throw RuntimeException() ;
+
+ //Get Keys Manager
+ Reference< XUnoTunnel > xSecTunnel( aSecurityCtx , UNO_QUERY ) ;
+ if( !xSecTunnel.is() ) {
+ throw RuntimeException() ;
+ }
+
+ XMLSecurityContext_NssImpl* pSecCtxt = ( XMLSecurityContext_NssImpl* )xSecTunnel->getSomething( XMLSecurityContext_NssImpl::getUnoTunnelId() ) ;
+ if( pSecCtxt == NULL )
+ throw RuntimeException() ;
+
+ pMngr = pSecCtxt->keysManager() ;
+
+
+ //Create Encryption context
+ pEncCtx = xmlSecEncCtxCreate( pMngr ) ;
+ if( pEncCtx == NULL )
+ throw RuntimeException() ;
+
+
+ //Get the encryption template
+ Reference< XXMLElementWrapper > xTemplate = aTemplate->getTemplate() ;
+ if( !xTemplate.is() ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ Reference< XUnoTunnel > xTplTunnel( xTemplate , UNO_QUERY ) ;
+ if( !xTplTunnel.is() ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ XMLElementWrapper_XmlSecImpl* pTemplate = ( XMLElementWrapper_XmlSecImpl* )xTplTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
+ if( pTemplate == NULL ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ pEncryptedData = pTemplate->getNativeElement() ;
+
+ //Find the element to be encrypted.
+ /* MM : remove the old method to get the target element
+ //This element is wrapped in the CipherValue sub-element.
+ xmlNodePtr pCipherData = pEncryptedData->children;
+ while (pCipherData != NULL && stricmp((const char *)(pCipherData->name), "CipherData"))
+ {
+ pCipherData = pCipherData->next;
+ }
+
+ if( pCipherData == NULL ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ xmlNodePtr pCipherValue = pCipherData->children;
+ while (pCipherValue != NULL && stricmp((const char *)(pCipherValue->name), "CipherValue"))
+ {
+ pCipherValue = pCipherValue->next;
+ }
+
+ if( pCipherValue == NULL ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ pContent = pCipherValue->children;
+ */
+
+ //MM : Get the element to be encrypted
+ Reference< XXMLElementWrapper > xTarget = aTemplate->getTarget() ;
+ if( !xTarget.is() ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ Reference< XUnoTunnel > xTgtTunnel( xTarget , UNO_QUERY ) ;
+ if( !xTgtTunnel.is() ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ XMLElementWrapper_XmlSecImpl* pTarget = ( XMLElementWrapper_XmlSecImpl* )xTgtTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
+ if( pTarget == NULL ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ pContent = pTarget->getNativeElement() ;
+ //MM : end
+
+ if( pContent == NULL ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ /* MM : remove the following 2 lines
+ xmlUnlinkNode(pContent);
+ xmlAddNextSibling(pEncryptedData, pContent);
+ */
+
+ //remember the position of the element to be signed
+ sal_Bool isParentRef = sal_True;
+ xmlNodePtr pParent = pEncryptedData->parent;
+ xmlNodePtr referenceNode;
+
+ if (pEncryptedData == pParent->children)
+ {
+ referenceNode = pParent;
+ }
+ else
+ {
+ referenceNode = pEncryptedData->prev;
+ isParentRef = sal_False;
+ }
+
+ //Encrypt the template
+ if( xmlSecEncCtxXmlEncrypt( pEncCtx , pEncryptedData , pContent ) < 0 ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+
+ //get the new EncryptedData element
+ if (isParentRef)
+ {
+ pTemplate->setNativeElement(referenceNode->children) ;
+ }
+ else
+ {
+ pTemplate->setNativeElement(referenceNode->next);
+ }
+
+ return aTemplate ;
+}
+
+/* XXMLEncryption */
+Reference< XXMLElementWrapper > SAL_CALL
+XMLEncryption_NssImpl :: decrypt(
+ const Reference< XXMLEncryptionTemplate >& aTemplate ,
+ const Reference< XXMLSecurityContext >& aSecurityCtx
+) throw( com::sun::star::xml::crypto::XMLEncryptionException ,
+ com::sun::star::uno::SecurityException) {
+ xmlSecKeysMngrPtr pMngr = NULL ;
+ xmlSecEncCtxPtr pEncCtx = NULL ;
+ xmlNodePtr pEncryptedData = NULL ;
+ xmlNodePtr pContent = NULL ;
+
+ if( !aTemplate.is() )
+ throw RuntimeException() ;
+
+ if( !aSecurityCtx.is() )
+ throw RuntimeException() ;
+
+ //Get Keys Manager
+ Reference< XUnoTunnel > xSecTunnel( aSecurityCtx , UNO_QUERY ) ;
+ if( !xSecTunnel.is() ) {
+ throw RuntimeException() ;
+ }
+
+ XMLSecurityContext_NssImpl* pSecCtxt = ( XMLSecurityContext_NssImpl* )xSecTunnel->getSomething( XMLSecurityContext_NssImpl::getUnoTunnelId() ) ;
+ if( pSecCtxt == NULL )
+ throw RuntimeException() ;
+
+ pMngr = pSecCtxt->keysManager() ;
+
+
+ //Create Encryption context
+ pEncCtx = xmlSecEncCtxCreate( pMngr ) ;
+ if( pEncCtx == NULL )
+ throw RuntimeException() ;
+
+
+ //Get the encryption template
+ Reference< XXMLElementWrapper > xTemplate = aTemplate->getTemplate() ;
+ if( !xTemplate.is() ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ Reference< XUnoTunnel > xTplTunnel( xTemplate , UNO_QUERY ) ;
+ if( !xTplTunnel.is() ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ XMLElementWrapper_XmlSecImpl* pTemplate = ( XMLElementWrapper_XmlSecImpl* )xTplTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
+ if( pTemplate == NULL ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ pEncryptedData = pTemplate->getNativeElement() ;
+
+ //remember the position of the element to be signed
+ sal_Bool isParentRef = sal_True;
+ xmlNodePtr pParent = pEncryptedData->parent;
+ xmlNodePtr referenceNode;
+
+ if (pEncryptedData == pParent->children)
+ {
+ referenceNode = pParent;
+ }
+ else
+ {
+ referenceNode = pEncryptedData->prev;
+ isParentRef = sal_False;
+ }
+
+ //Decrypt the template
+ if( xmlSecEncCtxDecrypt( pEncCtx , pEncryptedData ) < 0 || pEncCtx->result == NULL ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+ /*----------------------------------------
+ if( pEncCtx->resultReplaced != 0 ) {
+ pContent = pEncryptedData ;
+
+ Reference< XUnoTunnel > xTunnel( ret , UNO_QUERY ) ;
+ if( !xTunnel.is() ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+ XMLElementWrapper_XmlSecImpl* pNode = ( XMLElementWrapper_XmlSecImpl* )xTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
+ if( pNode == NULL ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ pNode->setNativeElement( pContent ) ;
+ } else {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+ ----------------------------------------*/
+
+ //Destroy the encryption context
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+
+ //get the decrypted element
+ XMLElementWrapper_XmlSecImpl * ret = new XMLElementWrapper_XmlSecImpl(isParentRef?
+ (referenceNode->children):(referenceNode->next));
+
+ return ret;
+}
+
+/* XInitialization */
+void SAL_CALL XMLEncryption_NssImpl :: initialize( const Sequence< Any >& aArguments ) throw( Exception, RuntimeException ) {
+ // TBD
+} ;
+
+/* XServiceInfo */
+OUString SAL_CALL XMLEncryption_NssImpl :: getImplementationName() throw( RuntimeException ) {
+ return impl_getImplementationName() ;
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL XMLEncryption_NssImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) {
+ Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
+ const OUString* pArray = seqServiceNames.getConstArray() ;
+ for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
+ if( *( pArray + i ) == serviceName )
+ return sal_True ;
+ }
+ return sal_False ;
+}
+
+/* XServiceInfo */
+Sequence< OUString > SAL_CALL XMLEncryption_NssImpl :: getSupportedServiceNames() throw( RuntimeException ) {
+ return impl_getSupportedServiceNames() ;
+}
+
+//Helper for XServiceInfo
+Sequence< OUString > XMLEncryption_NssImpl :: impl_getSupportedServiceNames() {
+ ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+ Sequence< OUString > seqServiceNames( 1 ) ;
+ seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.XMLEncryption" ) ;
+ return seqServiceNames ;
+}
+
+OUString XMLEncryption_NssImpl :: impl_getImplementationName() throw( RuntimeException ) {
+ return OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLEncryption_NssImpl" ) ;
+}
+
+//Helper for registry
+Reference< XInterface > SAL_CALL XMLEncryption_NssImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
+ return Reference< XInterface >( *new XMLEncryption_NssImpl( aServiceManager ) ) ;
+}
+
+Reference< XSingleServiceFactory > XMLEncryption_NssImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
+ //Reference< XSingleServiceFactory > xFactory ;
+ //xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
+ //return xFactory ;
+ return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
+}
+
diff --git a/xmlsecurity/source/xmlsec/nss/xmlencryption_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/xmlencryption_nssimpl.hxx
new file mode 100644
index 000000000000..92e20f99f0ad
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/xmlencryption_nssimpl.hxx
@@ -0,0 +1,165 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlencryption_nssimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _XMLENCRYPTION_NSSIMPL_HXX_
+#define _XMLENCRYPTION_NSSIMPL_HXX_
+
+#ifndef _SAL_CONFIG_H_
+#include <sal/config.h>
+#endif
+
+#ifndef _RTL_USTRING_HXX_
+#include <rtl/ustring.hxx>
+#endif
+
+#ifndef _CPPUHELPER_FACTORY_HXX_
+#include <cppuhelper/factory.hxx>
+#endif
+
+#ifndef _CPPUHELPER_IMPLBASE3_HXX_
+#include <cppuhelper/implbase3.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP_
+#include <com/sun/star/uno/Exception.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
+#include <com/sun/star/uno/Reference.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
+#include <com/sun/star/lang/XInitialization.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLENCRYPTION_HPP_
+#include <com/sun/star/xml/crypto/XXMLEncryption.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLENCRYPTIONTEMPLATE_HPP_
+#include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLSECURITYCONTEXT_HPP_
+#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
+#endif
+
+class XMLEncryption_NssImpl : public ::cppu::WeakImplHelper3<
+ ::com::sun::star::xml::crypto::XXMLEncryption ,
+ ::com::sun::star::lang::XInitialization ,
+ ::com::sun::star::lang::XServiceInfo >
+{
+ private :
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;
+
+ public :
+ XMLEncryption_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
+ virtual ~XMLEncryption_NssImpl() ;
+
+ //Methods from XXMLEncryption
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLEncryptionTemplate > SAL_CALL encrypt(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLEncryptionTemplate >& aTemplate ,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSecurityContext >& aContext)
+ // ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+ throw ( com::sun::star::xml::crypto::XMLEncryptionException ,
+ com::sun::star::uno::SecurityException);
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL decrypt(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLEncryptionTemplate >& aTemplate ,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSecurityContext >& aContext
+ ) throw( com::sun::star::xml::crypto::XMLEncryptionException ,
+ com::sun::star::uno::SecurityException) ;
+
+ //Methods from XInitialization
+ virtual void SAL_CALL initialize(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments
+ ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ //Methods from XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual sal_Bool SAL_CALL supportsService(
+ const ::rtl::OUString& ServiceName
+ ) throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ //Helper for XServiceInfo
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ;
+
+ static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ //Helper for registry
+ static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL impl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > impl_createFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) ;
+} ;
+
+#endif // _XMLENCRYPTION_NSSIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx
new file mode 100644
index 000000000000..5bf5ae59a2e8
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.cxx
@@ -0,0 +1,290 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsecuritycontext_nssimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _SAL_CONFIG_H_
+#include <sal/config.h>
+#endif
+
+#ifndef _RTL_UUID_H_
+#include <rtl/uuid.h>
+#endif
+
+#ifndef _XSECURITYENVIRONMENT_NSSIMPL_HXX_
+#include "securityenvironment_nssimpl.hxx"
+#endif
+
+#ifndef _XMLSECURITYCONTEXT_NSSIMPL_HXX_
+#include "xmlsecuritycontext_nssimpl.hxx"
+#endif
+
+#ifndef _XMLSTREAMIO_XMLSECIMPL_HXX_
+#include "xmlstreamio.hxx"
+#endif
+
+#include "xmlsec/xmlsec.h"
+#include "xmlsec/keysmngr.h"
+#include "xmlsec/crypto.h"
+
+using namespace ::com::sun::star::uno ;
+using namespace ::com::sun::star::lang ;
+using ::com::sun::star::lang::XMultiServiceFactory ;
+using ::com::sun::star::lang::XSingleServiceFactory ;
+using ::rtl::OUString ;
+
+using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
+using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
+
+XMLSecurityContext_NssImpl :: XMLSecurityContext_NssImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_pKeysMngr( NULL ) , m_xServiceManager( aFactory ) , m_xSecurityEnvironment( NULL ) {
+ //Init xmlsec library
+ if( xmlSecInit() < 0 ) {
+ throw RuntimeException() ;
+ }
+
+ //Init xmlsec crypto engine library
+ if( xmlSecCryptoInit() < 0 ) {
+ xmlSecShutdown() ;
+ throw RuntimeException() ;
+ }
+
+ //Enable external stream handlers
+ if( xmlEnableStreamInputCallbacks() < 0 ) {
+ xmlSecCryptoShutdown() ;
+ xmlSecShutdown() ;
+ throw RuntimeException() ;
+ }
+}
+
+XMLSecurityContext_NssImpl :: ~XMLSecurityContext_NssImpl() {
+ if( m_pKeysMngr != NULL ) {
+ xmlSecKeysMngrDestroy( m_pKeysMngr ) ;
+ }
+
+ xmlDisableStreamInputCallbacks() ;
+ xmlSecCryptoShutdown() ;
+ xmlSecShutdown() ;
+}
+
+/* XXMLSecurityContext */
+void SAL_CALL XMLSecurityContext_NssImpl :: setSecurityEnvironment( const Reference< XSecurityEnvironment >& aSecurityEnvironment ) throw( com::sun::star::security::SecurityInfrastructureException ) {
+ PK11SlotInfo* slot ;
+ CERTCertDBHandle* handler ;
+ //xmlSecKeyPtr key ;
+ //xmlSecKeyDataPtr keyData ;
+ PK11SymKey* symKey ;
+ SECKEYPublicKey* pubKey ;
+ SECKEYPrivateKey* priKey ;
+ unsigned int i ;
+
+ if( !aSecurityEnvironment.is() )
+ throw RuntimeException() ;
+
+ m_xSecurityEnvironment = aSecurityEnvironment ;
+
+ //Clear key manager
+ if( m_pKeysMngr != NULL ) {
+ xmlSecKeysMngrDestroy( m_pKeysMngr ) ;
+ m_pKeysMngr = NULL ;
+ }
+
+ //Create key manager
+ Reference< XUnoTunnel > xEnvTunnel( m_xSecurityEnvironment , UNO_QUERY ) ;
+ if( !xEnvTunnel.is() ) {
+ throw RuntimeException() ;
+ }
+
+ SecurityEnvironment_NssImpl* pSecEnv = ( SecurityEnvironment_NssImpl* )xEnvTunnel->getSomething( SecurityEnvironment_NssImpl::getUnoTunnelId() ) ;
+ if( pSecEnv == NULL )
+ throw RuntimeException() ;
+
+ slot = pSecEnv->getCryptoSlot() ;
+ handler = pSecEnv->getCertDb() ;
+
+ /*-
+ * The following lines is based on the private version of xmlSec-NSS
+ * crypto engine
+ */
+ m_pKeysMngr = xmlSecNssAppliedKeysMngrCreate( slot , handler ) ;
+ if( m_pKeysMngr == NULL )
+ throw RuntimeException() ;
+
+ /*-
+ * Adopt symmetric key into keys manager
+ */
+ for( i = 0 ; ( symKey = pSecEnv->getSymKey( i ) ) != NULL ; i ++ ) {
+ if( xmlSecNssAppliedKeysMngrSymKeyLoad( m_pKeysMngr, symKey ) < 0 ) {
+ throw RuntimeException() ;
+ }
+ }
+
+ /*-
+ * Adopt asymmetric public key into keys manager
+ */
+ for( i = 0 ; ( pubKey = pSecEnv->getPubKey( i ) ) != NULL ; i ++ ) {
+ if( xmlSecNssAppliedKeysMngrPubKeyLoad( m_pKeysMngr, pubKey ) < 0 ) {
+ throw RuntimeException() ;
+ }
+ }
+
+ /*-
+ * Adopt asymmetric private key into keys manager
+ */
+ for( i = 0 ; ( priKey = pSecEnv->getPriKey( i ) ) != NULL ; i ++ ) {
+ if( xmlSecNssAppliedKeysMngrPriKeyLoad( m_pKeysMngr, priKey ) < 0 ) {
+ throw RuntimeException() ;
+ }
+ }
+}
+
+/* XXMLSecurityContext */
+Reference< XSecurityEnvironment > SAL_CALL XMLSecurityContext_NssImpl :: getSecurityEnvironment()
+ throw (RuntimeException)
+{
+ return m_xSecurityEnvironment ;
+}
+
+/* XInitialization */
+void SAL_CALL XMLSecurityContext_NssImpl :: initialize( const Sequence< Any >& aArguments ) throw( Exception, RuntimeException ) {
+ // TBD
+} ;
+
+/* XServiceInfo */
+OUString SAL_CALL XMLSecurityContext_NssImpl :: getImplementationName() throw( RuntimeException ) {
+ return impl_getImplementationName() ;
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL XMLSecurityContext_NssImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) {
+ Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
+ const OUString* pArray = seqServiceNames.getConstArray() ;
+ for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
+ if( *( pArray + i ) == serviceName )
+ return sal_True ;
+ }
+ return sal_False ;
+}
+
+/* XServiceInfo */
+Sequence< OUString > SAL_CALL XMLSecurityContext_NssImpl :: getSupportedServiceNames() throw( RuntimeException ) {
+ return impl_getSupportedServiceNames() ;
+}
+
+//Helper for XServiceInfo
+Sequence< OUString > XMLSecurityContext_NssImpl :: impl_getSupportedServiceNames() {
+ ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+ Sequence< OUString > seqServiceNames( 1 ) ;
+ seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.XMLSecurityContext" ) ;
+ return seqServiceNames ;
+}
+
+OUString XMLSecurityContext_NssImpl :: impl_getImplementationName() throw( RuntimeException ) {
+ return OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_NssImpl" ) ;
+}
+
+//Helper for registry
+Reference< XInterface > SAL_CALL XMLSecurityContext_NssImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
+ return Reference< XInterface >( *new XMLSecurityContext_NssImpl( aServiceManager ) ) ;
+}
+
+Reference< XSingleServiceFactory > XMLSecurityContext_NssImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
+ //Reference< XSingleServiceFactory > xFactory ;
+ //xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
+ //return xFactory ;
+ return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
+}
+
+/* XUnoTunnel */
+sal_Int64 SAL_CALL XMLSecurityContext_NssImpl :: getSomething( const Sequence< sal_Int8 >& aIdentifier )
+throw (RuntimeException)
+{
+ if( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), aIdentifier.getConstArray(), 16 ) ) {
+ return ( sal_Int64 )this ;
+ }
+ return 0 ;
+}
+
+/* XUnoTunnel extension */
+const Sequence< sal_Int8>& XMLSecurityContext_NssImpl :: getUnoTunnelId() {
+ static Sequence< sal_Int8 >* pSeq = 0 ;
+ if( !pSeq ) {
+ ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+ if( !pSeq ) {
+ static Sequence< sal_Int8> aSeq( 16 ) ;
+ rtl_createUuid( ( sal_uInt8* )aSeq.getArray() , 0 , sal_True ) ;
+ pSeq = &aSeq ;
+ }
+ }
+ return *pSeq ;
+}
+
+/* XUnoTunnel extension */
+XMLSecurityContext_NssImpl* XMLSecurityContext_NssImpl :: getImplementation( const Reference< XInterface > xObj ) {
+ Reference< XUnoTunnel > xUT( xObj , UNO_QUERY ) ;
+ if( xUT.is() ) {
+ return ( XMLSecurityContext_NssImpl* )xUT->getSomething( getUnoTunnelId() ) ;
+ } else
+ return NULL ;
+}
+
+/* Native methods */
+xmlSecKeysMngrPtr XMLSecurityContext_NssImpl :: keysManager() throw( Exception, RuntimeException ) {
+ return m_pKeysMngr ;
+}
+
diff --git a/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.hxx
new file mode 100644
index 000000000000..a5b33a720f27
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/xmlsecuritycontext_nssimpl.hxx
@@ -0,0 +1,174 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsecuritycontext_nssimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _XMLSIGNATURECONTEXT_NSSIMPL_HXX_
+#define _XMLSIGNATURECONTEXT_NSSIMPL_HXX_
+
+#ifndef _SAL_CONFIG_H_
+#include <sal/config.h>
+#endif
+
+#ifndef _RTL_USTRING_HXX_
+#include <rtl/ustring.hxx>
+#endif
+
+#ifndef _CPPUHELPER_FACTORY_HXX_
+#include <cppuhelper/factory.hxx>
+#endif
+
+#ifndef _CPPUHELPER_IMPLBASE4_HXX_
+#include <cppuhelper/implbase4.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP_
+#include <com/sun/star/uno/Exception.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
+#include <com/sun/star/uno/Reference.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
+#include <com/sun/star/lang/XInitialization.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XSECURITYENVIRONMENT_HPP_
+#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLSECURITYCONTEXT_HPP_
+#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
+#endif
+
+#include "xmlsec/xmlsec.h"
+
+class XMLSecurityContext_NssImpl : public ::cppu::WeakImplHelper4<
+ ::com::sun::star::xml::crypto::XXMLSecurityContext ,
+ ::com::sun::star::lang::XInitialization ,
+ ::com::sun::star::lang::XServiceInfo ,
+ ::com::sun::star::lang::XUnoTunnel >
+{
+ private :
+ xmlSecKeysMngrPtr m_pKeysMngr ;
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > m_xSecurityEnvironment ;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;
+
+ public :
+ XMLSecurityContext_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
+ virtual ~XMLSecurityContext_NssImpl() ;
+
+ //Methods from XXMLSecurityContext
+ virtual void SAL_CALL setSecurityEnvironment(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment >& aSecurityEnvironment
+ ) throw( com::sun::star::security::SecurityInfrastructureException) ;
+
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > SAL_CALL getSecurityEnvironment()
+ throw(::com::sun::star::uno::RuntimeException);
+
+ //Methods from XInitialization
+ virtual void SAL_CALL initialize(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments
+ ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ //Methods from XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual sal_Bool SAL_CALL supportsService(
+ const ::rtl::OUString& ServiceName
+ ) throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ //Helper for XServiceInfo
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ;
+
+ static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ //Helper for registry
+ static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL impl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > impl_createFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) ;
+
+ //Methods from XUnoTunnel
+ virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
+ throw (com::sun::star::uno::RuntimeException);
+
+ static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId() ;
+ static XMLSecurityContext_NssImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ;
+
+ //Native mehtods
+ virtual xmlSecKeysMngrPtr keysManager() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+} ;
+
+#endif // _XMLSIGNATURECONTEXT_NSSIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx
new file mode 100644
index 000000000000..1f9ad4115265
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.cxx
@@ -0,0 +1,336 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsignature_nssimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _SAL_CONFIG_H_
+#include <sal/config.h>
+#endif
+
+#ifndef _RTL_UUID_H_
+#include <rtl/uuid.h>
+#endif
+
+#ifndef _XMLSIGNATURE_NSSIMPL_HXX_
+#include "xmlsignature_nssimpl.hxx"
+#endif
+
+#ifndef _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX_
+#include "xmldocumentwrapper_xmlsecimpl.hxx"
+#endif
+
+#ifndef _XMLELEMENTWRAPPER_XMLSECIMPL_HXX_
+#include "xmlelementwrapper_xmlsecimpl.hxx"
+#endif
+
+#ifndef _XMLSECURITYCONTEXT_NSSIMPL_HXX_
+#include "xmlsecuritycontext_nssimpl.hxx"
+#endif
+
+#ifndef _XMLSTREAMIO_XMLSECIMPL_HXX_
+#include "xmlstreamio.hxx"
+#endif
+
+#include "xmlsec/xmlsec.h"
+#include "xmlsec/xmldsig.h"
+#include "xmlsec/crypto.h"
+
+using namespace ::com::sun::star::uno ;
+using namespace ::com::sun::star::lang ;
+using ::com::sun::star::lang::XMultiServiceFactory ;
+using ::com::sun::star::lang::XSingleServiceFactory ;
+using ::rtl::OUString ;
+
+using ::com::sun::star::xml::wrapper::XXMLElementWrapper ;
+using ::com::sun::star::xml::wrapper::XXMLDocumentWrapper ;
+using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
+using ::com::sun::star::xml::crypto::XXMLSignature ;
+using ::com::sun::star::xml::crypto::XXMLSignatureTemplate ;
+using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
+using ::com::sun::star::xml::crypto::XUriBinding ;
+
+XMLSignature_NssImpl :: XMLSignature_NssImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_xServiceManager( aFactory ) {
+}
+
+XMLSignature_NssImpl :: ~XMLSignature_NssImpl() {
+}
+
+/* XXMLSignature */
+Reference< XXMLSignatureTemplate >
+SAL_CALL XMLSignature_NssImpl :: generate(
+ const Reference< XXMLSignatureTemplate >& aTemplate ,
+ const Reference< XXMLSecurityContext >& aSecurityCtx
+) throw( com::sun::star::xml::crypto::XMLSignatureException,
+ com::sun::star::uno::SecurityException )
+{
+ xmlSecKeysMngrPtr pMngr = NULL ;
+ xmlSecDSigCtxPtr pDsigCtx = NULL ;
+ xmlNodePtr pNode = NULL ;
+
+ if( !aTemplate.is() )
+ throw RuntimeException() ;
+
+ if( !aSecurityCtx.is() )
+ throw RuntimeException() ;
+
+ //Get the xml node
+ Reference< XXMLElementWrapper > xElement = aTemplate->getTemplate() ;
+ if( !xElement.is() ) {
+ throw RuntimeException() ;
+ }
+
+ Reference< XUnoTunnel > xNodTunnel( xElement , UNO_QUERY ) ;
+ if( !xNodTunnel.is() ) {
+ throw RuntimeException() ;
+ }
+
+ XMLElementWrapper_XmlSecImpl* pElement = ( XMLElementWrapper_XmlSecImpl* )xNodTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
+ if( pElement == NULL ) {
+ throw RuntimeException() ;
+ }
+
+ pNode = pElement->getNativeElement() ;
+
+ //Get the stream/URI binding
+ Reference< XUriBinding > xUriBinding = aTemplate->getBinding() ;
+ if( xUriBinding.is() ) {
+ //Register the stream input callbacks into libxml2
+ if( xmlRegisterStreamInputCallbacks( xUriBinding ) < 0 )
+ throw RuntimeException() ;
+ }
+
+ //Get Keys Manager
+ Reference< XUnoTunnel > xSecTunnel( aSecurityCtx , UNO_QUERY ) ;
+ if( !xSecTunnel.is() ) {
+ throw RuntimeException() ;
+ }
+
+ XMLSecurityContext_NssImpl* pSecCtxt = ( XMLSecurityContext_NssImpl* )xSecTunnel->getSomething( XMLSecurityContext_NssImpl::getUnoTunnelId() ) ;
+ if( pSecCtxt == NULL )
+ throw RuntimeException() ;
+
+ pMngr = pSecCtxt->keysManager() ;
+
+ //Create Signature context
+ pDsigCtx = xmlSecDSigCtxCreate( pMngr ) ;
+ if( pDsigCtx == NULL )
+ throw RuntimeException() ;
+
+ //Sign the template
+ if( xmlSecDSigCtxSign( pDsigCtx , pNode ) < 0 ) {
+ xmlSecDSigCtxDestroy( pDsigCtx ) ;
+
+ //Unregistered the stream/URI binding
+ if( xUriBinding.is() )
+ xmlUnregisterStreamInputCallbacks() ;
+
+ throw RuntimeException() ;
+ }
+
+ xmlSecDSigCtxDestroy( pDsigCtx ) ;
+
+ //Unregistered the stream/URI binding
+ if( xUriBinding.is() )
+ xmlUnregisterStreamInputCallbacks() ;
+
+ return aTemplate ;
+}
+
+/* XXMLSignature */
+sal_Bool SAL_CALL
+XMLSignature_NssImpl :: validate(
+ const Reference< XXMLSignatureTemplate >& aTemplate ,
+ const Reference< XXMLSecurityContext >& aSecurityCtx
+) throw( com::sun::star::uno::RuntimeException,
+ com::sun::star::uno::SecurityException,
+ com::sun::star::xml::crypto::XMLSignatureException ) {
+ xmlSecKeysMngrPtr pMngr = NULL ;
+ xmlSecDSigCtxPtr pDsigCtx = NULL ;
+ xmlNodePtr pNode = NULL ;
+ sal_Bool valid ;
+
+ if( !aTemplate.is() )
+ throw RuntimeException() ;
+
+ if( !aSecurityCtx.is() )
+ throw RuntimeException() ;
+
+ //Get the xml node
+ Reference< XXMLElementWrapper > xElement = aTemplate->getTemplate() ;
+ if( !xElement.is() )
+ throw RuntimeException() ;
+
+ Reference< XUnoTunnel > xNodTunnel( xElement , UNO_QUERY ) ;
+ if( !xNodTunnel.is() ) {
+ throw RuntimeException() ;
+ }
+
+ XMLElementWrapper_XmlSecImpl* pElement = ( XMLElementWrapper_XmlSecImpl* )xNodTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
+ if( pElement == NULL )
+ throw RuntimeException() ;
+
+ pNode = pElement->getNativeElement() ;
+
+ //Get the stream/URI binding
+ Reference< XUriBinding > xUriBinding = aTemplate->getBinding() ;
+ if( xUriBinding.is() ) {
+ //Register the stream input callbacks into libxml2
+ if( xmlRegisterStreamInputCallbacks( xUriBinding ) < 0 )
+ throw RuntimeException() ;
+ }
+
+ //added for test: save the result
+ /*
+ {
+ FILE *dstFile = fopen( "c:\\1.txt", "w" ) ;
+ xmlDocDump( dstFile, pNode->doc) ;
+ fclose( dstFile ) ;
+ }
+ */
+
+ //Get Keys Manager
+ Reference< XUnoTunnel > xSecTunnel( aSecurityCtx , UNO_QUERY ) ;
+ if( !xSecTunnel.is() ) {
+ throw RuntimeException() ;
+ }
+
+ XMLSecurityContext_NssImpl* pSecCtxt = ( XMLSecurityContext_NssImpl* )xSecTunnel->getSomething( XMLSecurityContext_NssImpl::getUnoTunnelId() ) ;
+ if( pSecCtxt == NULL )
+ throw RuntimeException() ;
+
+ pMngr = pSecCtxt->keysManager() ;
+
+ //Create Signature context
+ pDsigCtx = xmlSecDSigCtxCreate( pMngr ) ;
+ if( pDsigCtx == NULL )
+ throw RuntimeException() ;
+
+
+ //Verify signature
+ if( xmlSecDSigCtxVerify( pDsigCtx , pNode ) < 0 ) {
+ xmlSecDSigCtxDestroy( pDsigCtx ) ;
+
+ //Unregistered the stream/URI binding
+ if( xUriBinding.is() )
+ xmlUnregisterStreamInputCallbacks() ;
+
+ throw RuntimeException() ;
+ }
+
+ valid = ( pDsigCtx->status == xmlSecDSigStatusSucceeded ) ;
+
+ xmlSecDSigCtxDestroy( pDsigCtx ) ;
+
+ //Unregistered the stream/URI binding
+ if( xUriBinding.is() )
+ xmlUnregisterStreamInputCallbacks() ;
+
+ return valid ;
+}
+
+/* XInitialization */
+void SAL_CALL XMLSignature_NssImpl :: initialize( const Sequence< Any >& aArguments ) throw( Exception, RuntimeException ) {
+ // TBD
+} ;
+
+/* XServiceInfo */
+OUString SAL_CALL XMLSignature_NssImpl :: getImplementationName() throw( RuntimeException ) {
+ return impl_getImplementationName() ;
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL XMLSignature_NssImpl :: supportsService( const OUString& serviceName) throw( RuntimeException ) {
+ Sequence< OUString > seqServiceNames = getSupportedServiceNames() ;
+ const OUString* pArray = seqServiceNames.getConstArray() ;
+ for( sal_Int32 i = 0 ; i < seqServiceNames.getLength() ; i ++ ) {
+ if( *( pArray + i ) == serviceName )
+ return sal_True ;
+ }
+ return sal_False ;
+}
+
+/* XServiceInfo */
+Sequence< OUString > SAL_CALL XMLSignature_NssImpl :: getSupportedServiceNames() throw( RuntimeException ) {
+ return impl_getSupportedServiceNames() ;
+}
+
+//Helper for XServiceInfo
+Sequence< OUString > XMLSignature_NssImpl :: impl_getSupportedServiceNames() {
+ ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ) ;
+ Sequence< OUString > seqServiceNames( 1 ) ;
+ seqServiceNames.getArray()[0] = OUString::createFromAscii( "com.sun.star.xml.crypto.XMLSignature" ) ;
+ return seqServiceNames ;
+}
+
+OUString XMLSignature_NssImpl :: impl_getImplementationName() throw( RuntimeException ) {
+ return OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLSignature_NssImpl" ) ;
+}
+
+//Helper for registry
+Reference< XInterface > SAL_CALL XMLSignature_NssImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
+ return Reference< XInterface >( *new XMLSignature_NssImpl( aServiceManager ) ) ;
+}
+
+Reference< XSingleServiceFactory > XMLSignature_NssImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
+ //Reference< XSingleServiceFactory > xFactory ;
+ //xFactory = ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName , impl_createInstance , impl_getSupportedServiceNames ) ;
+ //return xFactory ;
+ return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
+}
+
diff --git a/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.hxx
new file mode 100644
index 000000000000..644813bdcc2c
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/xmlsignature_nssimpl.hxx
@@ -0,0 +1,165 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsignature_nssimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _XMLSIGNATURE_NSSIMPL_HXX_
+#define _XMLSIGNATURE_NSSIMPL_HXX_
+
+#ifndef _SAL_CONFIG_H_
+#include <sal/config.h>
+#endif
+
+#ifndef _RTL_USTRING_HXX_
+#include <rtl/ustring.hxx>
+#endif
+
+#ifndef _CPPUHELPER_FACTORY_HXX_
+#include <cppuhelper/factory.hxx>
+#endif
+
+#ifndef _CPPUHELPER_IMPLBASE3_HXX_
+#include <cppuhelper/implbase3.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP_
+#include <com/sun/star/uno/Exception.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
+#include <com/sun/star/uno/Reference.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XSECVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
+#include <com/sun/star/lang/XInitialization.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLSIGNATURE_HPP_
+#include <com/sun/star/xml/crypto/XXMLSignature.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLSIGNATURETEMPLATE_HPP_
+#include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XXMLSECURITYCONTEXT_HPP_
+#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
+#endif
+
+class XMLSignature_NssImpl : public ::cppu::WeakImplHelper3<
+ ::com::sun::star::xml::crypto::XXMLSignature ,
+ ::com::sun::star::lang::XInitialization ,
+ ::com::sun::star::lang::XServiceInfo >
+{
+ private :
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;
+
+ public :
+ XMLSignature_NssImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
+ virtual ~XMLSignature_NssImpl() ;
+
+ //Methods from XXMLSignature
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSignatureTemplate > SAL_CALL generate(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSignatureTemplate >& aTemplate ,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSecurityContext >& aContext
+ ) throw( com::sun::star::xml::crypto::XMLSignatureException,
+ com::sun::star::uno::SecurityException) ;
+
+ virtual sal_Bool SAL_CALL validate(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSignatureTemplate >& aTemplate ,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSecurityContext >& aContext
+ ) throw( com::sun::star::uno::RuntimeException,
+ com::sun::star::uno::SecurityException,
+ com::sun::star::xml::crypto::XMLSignatureException);
+
+ //Methods from XInitialization
+ virtual void SAL_CALL initialize(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments
+ ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ //Methods from XServiceInfo
+ virtual ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual sal_Bool SAL_CALL supportsService(
+ const ::rtl::OUString& ServiceName
+ ) throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ //Helper for XServiceInfo
+ static ::com::sun::star::uno::Sequence< ::rtl::OUString > impl_getSupportedServiceNames() ;
+
+ static ::rtl::OUString impl_getImplementationName() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ //Helper for registry
+ static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL impl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > impl_createFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aServiceManager ) ;
+} ;
+
+#endif // _XMLSIGNATURE_NSSIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx b/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx
new file mode 100644
index 000000000000..002f17b17935
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/nss/xsec_nss.cxx
@@ -0,0 +1,199 @@
+/*************************************************************************
+ *
+ * $RCSfile: xsec_nss.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:21 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#include <sal/config.h>
+#include <stdio.h>
+
+#include <osl/mutex.hxx>
+#include <osl/thread.h>
+#include <cppuhelper/factory.hxx>
+
+#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#endif
+
+#include "seinitializer_nssimpl.hxx"
+#include "xmlsignature_nssimpl.hxx"
+#include "xmlencryption_nssimpl.hxx"
+#include "xmlsecuritycontext_nssimpl.hxx"
+#include "securityenvironment_nssimpl.hxx"
+
+using namespace ::rtl;
+using namespace ::cppu;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+
+extern "C"
+{
+
+sal_Bool SAL_CALL nss_component_writeInfo( void* pServiceManager , void* pRegistryKey )
+{
+ sal_Bool result = sal_False;
+ sal_Int32 i ;
+ OUString sKeyName ;
+ Reference< XRegistryKey > xNewKey ;
+ Sequence< OUString > seqServices ;
+ Reference< XRegistryKey > xKey( reinterpret_cast< XRegistryKey* >( pRegistryKey ) ) ;
+
+ if( xKey.is() ) {
+ // try {
+ // XMLSignature_NssImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += XMLSignature_NssImpl::impl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = XMLSignature_NssImpl::impl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+ // XMLEncryption_NssImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += XMLEncryption_NssImpl::impl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = XMLEncryption_NssImpl::impl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+ // XMLSecurityContext_NssImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += XMLSecurityContext_NssImpl::impl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = XMLSecurityContext_NssImpl::impl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+ // SecurityEnvironment_NssImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += SecurityEnvironment_NssImpl::impl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = SecurityEnvironment_NssImpl::impl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+ // SEInitializer_NssImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += SEInitializer_NssImpl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = SEInitializer_NssImpl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+ return sal_True;
+ //} catch( InvalidRegistryException & ) {
+ // //we should not ignore exceptions
+ // return sal_False ;
+ //}
+ }
+ return result;
+}
+
+void* SAL_CALL nss_component_getFactory( const sal_Char* pImplName , void* pServiceManager , void* pRegistryKey )
+{
+ void* pRet = 0;
+ Reference< XSingleServiceFactory > xFactory ;
+
+ if( pImplName != NULL && pServiceManager != NULL ) {
+ if( XMLSignature_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
+ xFactory = XMLSignature_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+ } else if( XMLSecurityContext_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
+ xFactory = XMLSecurityContext_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+ } else if( SecurityEnvironment_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
+ xFactory = SecurityEnvironment_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+ } else if( XMLEncryption_NssImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
+ xFactory = XMLEncryption_NssImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+ } else if( SEInitializer_NssImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
+ xFactory = Reference< XSingleServiceFactory >( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ SEInitializer_NssImpl_createInstance, SEInitializer_NssImpl_getSupportedServiceNames() ) );
+ }
+ }
+
+ if( xFactory.is() ) {
+ xFactory->acquire() ;
+ pRet = xFactory.get() ;
+ }
+
+ return pRet ;
+}
+
+}
+