summaryrefslogtreecommitdiff
path: root/xmlsecurity/source/xmlsec
diff options
context:
space:
mode:
authorMalte Timmermann <mt@openoffice.org>2004-07-12 12:15:31 +0000
committerMalte Timmermann <mt@openoffice.org>2004-07-12 12:15:31 +0000
commit9f34fde7a8750b856570b5e855d2ecb226bf0c23 (patch)
tree994a2faf203d884d79fe9e1f1e055f041e5703d0 /xmlsecurity/source/xmlsec
parent8c7c9465b6a35c829294a829cfc3152e5dc9ce6e (diff)
libxmlsec
Diffstat (limited to 'xmlsecurity/source/xmlsec')
-rw-r--r--xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.cxx134
-rw-r--r--xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.hxx119
-rw-r--r--xmlsecurity/source/xmlsec/makefile.mk94
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/makefile.mk102
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx1028
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.hxx235
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.cxx269
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.hxx152
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx392
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx147
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/xmlencryption_mscryptimpl.cxx403
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/xmlencryption_mscryptimpl.hxx165
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/xmlsecuritycontext_mscryptimpl.cxx331
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/xmlsecuritycontext_mscryptimpl.hxx174
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.cxx336
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.hxx165
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/xsec_mscrypt.cxx198
-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
-rw-r--r--xmlsecurity/source/xmlsec/saxhelper.cxx465
-rw-r--r--xmlsecurity/source/xmlsec/saxhelper.hxx123
-rw-r--r--xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx1187
-rw-r--r--xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.hxx328
-rw-r--r--xmlsecurity/source/xmlsec/xmlelementwrapper_xmlsecimpl.cxx221
-rw-r--r--xmlsecurity/source/xmlsec/xmlelementwrapper_xmlsecimpl.hxx152
-rw-r--r--xmlsecurity/source/xmlsec/xmlstreamio.cxx244
-rw-r--r--xmlsecurity/source/xmlsec/xmlstreamio.hxx83
-rw-r--r--xmlsecurity/source/xmlsec/xsec_xmlsec.cxx201
40 files changed, 11454 insertions, 0 deletions
diff --git a/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.cxx b/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.cxx
new file mode 100644
index 000000000000..f9c7f9f78fb6
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.cxx
@@ -0,0 +1,134 @@
+/*************************************************************************
+ *
+ * $RCSfile: certificateextension_xmlsecimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:20 $
+ *
+ * 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 _certificateextension_nssimpl_hxx_
+#include "certificateextension_xmlsecimpl.hxx"
+#endif
+
+using namespace ::com::sun::star::uno ;
+using ::rtl::OUString ;
+
+using ::com::sun::star::security::XCertificateExtension ;
+
+CertificateExtension_XmlSecImpl :: CertificateExtension_XmlSecImpl() :
+ m_critical( sal_False ) ,
+ m_xExtnId() ,
+ m_xExtnValue()
+{
+}
+
+CertificateExtension_XmlSecImpl :: ~CertificateExtension_XmlSecImpl() {
+}
+
+
+//Methods from XCertificateExtension
+sal_Bool SAL_CALL CertificateExtension_XmlSecImpl :: isCritical() throw( ::com::sun::star::uno::RuntimeException ) {
+ return m_critical ;
+}
+
+::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL CertificateExtension_XmlSecImpl :: getExtnId() throw( ::com::sun::star::uno::RuntimeException ) {
+ return m_xExtnId ;
+}
+
+::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL CertificateExtension_XmlSecImpl :: getExtnValue() throw( ::com::sun::star::uno::RuntimeException ) {
+ return m_xExtnValue ;
+}
+
+//Helper method
+void CertificateExtension_XmlSecImpl :: setCertExtn( ::com::sun::star::uno::Sequence< sal_Int8 > extnId, ::com::sun::star::uno::Sequence< sal_Int8 > extnValue, sal_Bool critical ) {
+ m_critical = critical ;
+ m_xExtnId = extnId ;
+ m_xExtnValue = extnValue ;
+}
+
+void CertificateExtension_XmlSecImpl :: setCertExtn( unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, sal_Bool critical ) {
+ unsigned int i ;
+ if( value != NULL && vlen != 0 ) {
+ Sequence< sal_Int8 > extnv( vlen ) ;
+ for( i = 0; i < vlen ; i ++ )
+ extnv[i] = *( value + i ) ;
+
+ m_xExtnValue = extnv ;
+ } else {
+ m_xExtnValue = NULL ;
+ }
+
+ if( id != NULL && idlen != 0 ) {
+ Sequence< sal_Int8 > extnId( idlen ) ;
+ for( i = 0; i < idlen ; i ++ )
+ extnId[i] = *( id + i ) ;
+
+ m_xExtnId = extnId ;
+ } else {
+ m_xExtnId = NULL ;
+ }
+
+ m_critical = critical ;
+}
+
diff --git a/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.hxx b/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.hxx
new file mode 100644
index 000000000000..f71d9831e6c1
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.hxx
@@ -0,0 +1,119 @@
+/*************************************************************************
+ *
+ * $RCSfile: certificateextension_xmlsecimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:20 $
+ *
+ * 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 _CERTIFICATEEXTENSION_XMLSECIMPL_HXX_
+#define _CERTIFICATEEXTENSION_XMLSECIMPL_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_IMPLBASE1_HXX_
+#include <cppuhelper/implbase1.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP_
+#include <com/sun/star/uno/Exception.hpp>
+#endif
+
+#ifndef _COM_SUN_STAR_UNO_SECURITYEXCEPTION_HPP_
+#include "com/sun/star/uno/SecurityException.hpp"
+#endif
+
+#ifndef _COM_SUN_STAR_SECURITY_XCERTIFICATEEXTENSION_HPP_
+#include <com/sun/star/security/XCertificateExtension.hpp>
+#endif
+
+class CertificateExtension_XmlSecImpl : public ::cppu::WeakImplHelper1<
+ ::com::sun::star::security::XCertificateExtension >
+{
+ private :
+ sal_Bool m_critical ;
+ ::com::sun::star::uno::Sequence< sal_Int8 > m_xExtnId ;
+ ::com::sun::star::uno::Sequence< sal_Int8 > m_xExtnValue ;
+
+ public :
+ CertificateExtension_XmlSecImpl() ;
+ virtual ~CertificateExtension_XmlSecImpl() ;
+
+ //Methods from XCertificateExtension
+ virtual sal_Bool SAL_CALL isCritical() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getExtnId() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getExtnValue() throw( ::com::sun::star::uno::RuntimeException ) ;
+
+ //Helper method
+ void setCertExtn( ::com::sun::star::uno::Sequence< sal_Int8 > extnId, ::com::sun::star::uno::Sequence< sal_Int8 > extnValue, sal_Bool critical ) ;
+
+ void setCertExtn( unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, sal_Bool critical ) ;
+} ;
+
+#endif // _CERTIFICATEEXTENSION_XMLSECIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/makefile.mk b/xmlsecurity/source/xmlsec/makefile.mk
new file mode 100644
index 000000000000..0f563a39b288
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/makefile.mk
@@ -0,0 +1,94 @@
+#*************************************************************************
+#
+# $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_comm
+
+ENABLE_EXCEPTIONS = TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : svpre.mk
+.INCLUDE : settings.mk
+.INCLUDE : sv.mk
+.INCLUDE : $(PRJ)$/util$/target.pmk
+
+.IF "$(CRYPTO_ENGINE)" == "mscrypto"
+CDEFS += -DXMLSEC_CRYPTO_MSCRYPTO -DXMLSEC_NO_XSLT
+.ELSE
+CDEFS += -DXMLSEC_CRYPTO_NSS -DXMLSEC_NO_XSLT
+.ENDIF
+
+# --- Files --------------------------------------------------------
+SLOFILES = \
+ $(SLO)$/saxhelper.obj \
+ $(SLO)$/xmldocumentwrapper_xmlsecimpl.obj \
+ $(SLO)$/xmlelementwrapper_xmlsecimpl.obj \
+ $(SLO)$/certificateextension_xmlsecimpl.obj \
+ $(SLO)$/xmlstreamio.obj \
+ $(SLO)$/xsec_xmlsec.obj
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
diff --git a/xmlsecurity/source/xmlsec/mscrypt/makefile.mk b/xmlsecurity/source/xmlsec/mscrypt/makefile.mk
new file mode 100644
index 000000000000..22a9437bbceb
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/makefile.mk
@@ -0,0 +1,102 @@
+#*************************************************************************
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.1.1.1 $
+#
+# last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+#
+# 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_mscrypt
+
+ENABLE_EXCEPTIONS = TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : svpre.mk
+.INCLUDE : settings.mk
+.INCLUDE : sv.mk
+.INCLUDE : $(PRJ)$/util$/target.pmk
+
+.IF "$(CRYPTO_ENGINE)" != "mscrypto"
+LIBTARGET=NO
+.ENDIF
+
+.IF "$(CRYPTO_ENGINE)" == "mscrypto"
+
+CDEFS += -DXMLSEC_CRYPTO_MSCRYPTO -DXMLSEC_NO_XSLT
+
+# --- Files --------------------------------------------------------
+INCLOCAL = \
+ ..
+
+SLOFILES = \
+ $(SLO)$/securityenvironment_mscryptimpl.obj \
+ $(SLO)$/xmlencryption_mscryptimpl.obj \
+ $(SLO)$/xmlsecuritycontext_mscryptimpl.obj \
+ $(SLO)$/xmlsignature_mscryptimpl.obj \
+ $(SLO)$/x509certificate_mscryptimpl.obj \
+ $(SLO)$/seinitializer_mscryptimpl.obj \
+ $(SLO)$/xsec_mscrypt.obj
+
+.ENDIF
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
diff --git a/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx
new file mode 100644
index 000000000000..61647496a20d
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx
@@ -0,0 +1,1028 @@
+/*************************************************************************
+ *
+ * $RCSfile: securityenvironment_mscryptimpl.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_MSCRYPTIMPL_HXX_
+#include "securityenvironment_mscryptimpl.hxx"
+#endif
+
+#ifndef _X509CERTIFICATE_NSSIMPL_HXX_
+#include "x509certificate_mscryptimpl.hxx"
+#endif
+
+#ifndef _RTL_UUID_H_
+#include <rtl/uuid.h>
+#endif
+
+#include "Windows.h"
+#include "WinCrypt.h"
+
+#include "xmlsec/xmlsec.h"
+#include "xmlsec/keysmngr.h"
+#include "xmlsec/crypto.h"
+#include <xmlsec/base64.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::security::XCertificate ;
+
+extern Sequence< sal_Int8 > numericStringToBigInteger( OUString ) ;
+extern OUString bigIntegerToNumericString( Sequence< sal_Int8 > serial ) ;
+
+extern X509Certificate_MSCryptImpl* MswcryCertContextToXCert( PCCERT_CONTEXT cert ) ;
+
+SecurityEnvironment_MSCryptImpl :: SecurityEnvironment_MSCryptImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_hProv( NULL ) , m_pszContainer( NULL ) , m_hKeyStore( NULL ), m_hCertStore( NULL ), m_tSymKeyList() , m_tPubKeyList() , m_tPriKeyList(), m_xServiceManager( aFactory ), m_bEnableDefault( sal_False ) {
+}
+
+SecurityEnvironment_MSCryptImpl :: ~SecurityEnvironment_MSCryptImpl() {
+ if( m_hProv != NULL ) {
+ CryptReleaseContext( m_hProv, 0 ) ;
+ m_hProv = NULL ;
+ }
+
+ if( m_pszContainer != NULL ) {
+ //TODO: Don't know whether or not it should be released now.
+ m_pszContainer = NULL ;
+ }
+
+ if( m_hCertStore != NULL ) {
+ CertCloseStore( m_hCertStore, CERT_CLOSE_STORE_FORCE_FLAG ) ;
+ m_hCertStore = NULL ;
+ }
+
+ if( m_hKeyStore != NULL ) {
+ CertCloseStore( m_hKeyStore, CERT_CLOSE_STORE_FORCE_FLAG ) ;
+ m_hKeyStore = NULL ;
+ }
+
+ if( !m_tSymKeyList.empty() ) {
+ std::list< HCRYPTKEY >::iterator symKeyIt ;
+
+ for( symKeyIt = m_tSymKeyList.begin() ; symKeyIt != m_tSymKeyList.end() ; symKeyIt ++ )
+ CryptDestroyKey( *symKeyIt ) ;
+ }
+
+ if( !m_tPubKeyList.empty() ) {
+ std::list< HCRYPTKEY >::iterator pubKeyIt ;
+
+ for( pubKeyIt = m_tPubKeyList.begin() ; pubKeyIt != m_tPubKeyList.end() ; pubKeyIt ++ )
+ CryptDestroyKey( *pubKeyIt ) ;
+ }
+
+ if( !m_tPriKeyList.empty() ) {
+ std::list< HCRYPTKEY >::iterator priKeyIt ;
+
+ for( priKeyIt = m_tPriKeyList.begin() ; priKeyIt != m_tPriKeyList.end() ; priKeyIt ++ )
+ CryptDestroyKey( *priKeyIt ) ;
+ }
+}
+
+/* XInitialization */
+void SAL_CALL SecurityEnvironment_MSCryptImpl :: initialize( const Sequence< Any >& aArguments ) throw( Exception, RuntimeException ) {
+ //TODO
+} ;
+
+/* XServiceInfo */
+OUString SAL_CALL SecurityEnvironment_MSCryptImpl :: getImplementationName() throw( RuntimeException ) {
+ return impl_getImplementationName() ;
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL SecurityEnvironment_MSCryptImpl :: 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_MSCryptImpl :: getSupportedServiceNames() throw( RuntimeException ) {
+ return impl_getSupportedServiceNames() ;
+}
+
+//Helper for XServiceInfo
+Sequence< OUString > SecurityEnvironment_MSCryptImpl :: 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_MSCryptImpl :: impl_getImplementationName() throw( RuntimeException ) {
+ return OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.SecurityEnvironment_MSCryptImpl" ) ;
+}
+
+//Helper for registry
+Reference< XInterface > SAL_CALL SecurityEnvironment_MSCryptImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
+ return Reference< XInterface >( *new SecurityEnvironment_MSCryptImpl( aServiceManager ) ) ;
+}
+
+Reference< XSingleServiceFactory > SecurityEnvironment_MSCryptImpl :: impl_createFactory( const Reference< XMultiServiceFactory >& aServiceManager ) {
+ return ::cppu::createSingleFactory( aServiceManager , impl_getImplementationName() , impl_createInstance , impl_getSupportedServiceNames() ) ;
+}
+
+/* XUnoTunnel */
+sal_Int64 SAL_CALL SecurityEnvironment_MSCryptImpl :: 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_MSCryptImpl :: 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_MSCryptImpl* SecurityEnvironment_MSCryptImpl :: getImplementation( const Reference< XInterface > xObj ) {
+ Reference< XUnoTunnel > xUT( xObj , UNO_QUERY ) ;
+ if( xUT.is() ) {
+ return ( SecurityEnvironment_MSCryptImpl* )xUT->getSomething( getUnoTunnelId() ) ;
+ } else
+ return NULL ;
+}
+
+/* Native methods */
+HCRYPTPROV SecurityEnvironment_MSCryptImpl :: getCryptoProvider() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) {
+ return m_hProv ;
+}
+
+void SecurityEnvironment_MSCryptImpl :: setCryptoProvider( HCRYPTPROV aProv ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) {
+ if( m_hProv != NULL ) {
+ CryptReleaseContext( m_hProv, 0 ) ;
+ m_hProv = NULL ;
+ }
+
+ if( aProv != NULL ) {
+ if( !CryptContextAddRef( aProv, NULL, NULL ) )
+ throw Exception() ;
+ else
+ m_hProv = aProv ;
+ }
+}
+
+LPCTSTR SecurityEnvironment_MSCryptImpl :: getKeyContainer() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) {
+ return m_pszContainer ;
+}
+
+void SecurityEnvironment_MSCryptImpl :: setKeyContainer( LPCTSTR aKeyContainer ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) {
+ //TODO: Don't know whether or not it should be copied.
+ m_pszContainer = aKeyContainer ;
+}
+
+
+HCERTSTORE SecurityEnvironment_MSCryptImpl :: getCryptoSlot() throw( Exception , RuntimeException ) {
+ return m_hKeyStore ;
+}
+
+void SecurityEnvironment_MSCryptImpl :: setCryptoSlot( HCERTSTORE aSlot) throw( Exception , RuntimeException ) {
+ if( m_hKeyStore != NULL ) {
+ CertCloseStore( m_hKeyStore, CERT_CLOSE_STORE_FORCE_FLAG ) ;
+ m_hKeyStore = NULL ;
+ }
+
+ if( aSlot != NULL ) {
+ m_hKeyStore = CertDuplicateStore( aSlot ) ;
+ }
+}
+
+HCERTSTORE SecurityEnvironment_MSCryptImpl :: getCertDb() throw( Exception , RuntimeException ) {
+ return m_hCertStore ;
+}
+
+void SecurityEnvironment_MSCryptImpl :: setCertDb( HCERTSTORE aCertDb ) throw( Exception , RuntimeException ) {
+ if( m_hCertStore != NULL ) {
+ CertCloseStore( m_hCertStore, CERT_CLOSE_STORE_FORCE_FLAG ) ;
+ m_hCertStore = NULL ;
+ }
+
+ if( aCertDb != NULL ) {
+ m_hCertStore = CertDuplicateStore( aCertDb ) ;
+ }
+}
+
+void SecurityEnvironment_MSCryptImpl :: adoptSymKey( HCRYPTKEY aSymKey ) throw( Exception , RuntimeException ) {
+ HCRYPTKEY symkey ;
+ std::list< HCRYPTKEY >::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
+ if( !CryptDuplicateKey( aSymKey, NULL, 0, &symkey ) )
+ throw RuntimeException() ;
+
+ try {
+ m_tSymKeyList.push_back( symkey ) ;
+ } catch ( Exception& ) {
+ CryptDestroyKey( symkey ) ;
+ }
+ }
+}
+
+void SecurityEnvironment_MSCryptImpl :: rejectSymKey( HCRYPTKEY aSymKey ) throw( Exception , RuntimeException ) {
+ HCRYPTKEY symkey ;
+ std::list< HCRYPTKEY >::iterator keyIt ;
+
+ if( aSymKey != NULL ) {
+ for( keyIt = m_tSymKeyList.begin() ; keyIt != m_tSymKeyList.end() ; keyIt ++ ) {
+ if( *keyIt == aSymKey ) {
+ symkey = *keyIt ;
+ CryptDestroyKey( symkey ) ;
+ m_tSymKeyList.erase( keyIt ) ;
+ break ;
+ }
+ }
+ }
+}
+
+HCRYPTKEY SecurityEnvironment_MSCryptImpl :: getSymKey( unsigned int position ) throw( Exception , RuntimeException ) {
+ HCRYPTKEY symkey ;
+ std::list< HCRYPTKEY >::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_MSCryptImpl :: adoptPubKey( HCRYPTKEY aPubKey ) throw( Exception , RuntimeException ) {
+ HCRYPTKEY pubkey ;
+ std::list< HCRYPTKEY >::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
+ if( !CryptDuplicateKey( aPubKey, NULL, 0, &pubkey ) )
+ throw RuntimeException() ;
+
+ try {
+ m_tPubKeyList.push_back( pubkey ) ;
+ } catch ( Exception& ) {
+ CryptDestroyKey( pubkey ) ;
+ }
+ }
+}
+
+void SecurityEnvironment_MSCryptImpl :: rejectPubKey( HCRYPTKEY aPubKey ) throw( Exception , RuntimeException ) {
+ HCRYPTKEY pubkey ;
+ std::list< HCRYPTKEY >::iterator keyIt ;
+
+ if( aPubKey != NULL ) {
+ for( keyIt = m_tPubKeyList.begin() ; keyIt != m_tPubKeyList.end() ; keyIt ++ ) {
+ if( *keyIt == aPubKey ) {
+ pubkey = *keyIt ;
+ CryptDestroyKey( pubkey ) ;
+ m_tPubKeyList.erase( keyIt ) ;
+ break ;
+ }
+ }
+ }
+}
+
+HCRYPTKEY SecurityEnvironment_MSCryptImpl :: getPubKey( unsigned int position ) throw( Exception , RuntimeException ) {
+ HCRYPTKEY pubkey ;
+ std::list< HCRYPTKEY >::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_MSCryptImpl :: adoptPriKey( HCRYPTKEY aPriKey ) throw( Exception , RuntimeException ) {
+ HCRYPTKEY prikey ;
+ std::list< HCRYPTKEY >::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
+ if( !CryptDuplicateKey( aPriKey, NULL, 0, &prikey ) )
+ throw RuntimeException() ;
+
+ try {
+ m_tPriKeyList.push_back( prikey ) ;
+ } catch ( Exception& ) {
+ CryptDestroyKey( prikey ) ;
+ }
+ }
+}
+
+void SecurityEnvironment_MSCryptImpl :: rejectPriKey( HCRYPTKEY aPriKey ) throw( Exception , RuntimeException ) {
+ HCRYPTKEY prikey ;
+ std::list< HCRYPTKEY >::iterator keyIt ;
+
+ if( aPriKey != NULL ) {
+ for( keyIt = m_tPriKeyList.begin() ; keyIt != m_tPriKeyList.end() ; keyIt ++ ) {
+ if( *keyIt == aPriKey ) {
+ prikey = *keyIt ;
+ CryptDestroyKey( prikey ) ;
+ m_tPriKeyList.erase( keyIt ) ;
+ break ;
+ }
+ }
+ }
+}
+
+HCRYPTKEY SecurityEnvironment_MSCryptImpl :: getPriKey( unsigned int position ) throw( SecurityException , RuntimeException ) {
+ HCRYPTKEY prikey ;
+ std::list< HCRYPTKEY >::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 ;
+}
+
+//Methods from XSecurityEnvironment
+Sequence< Reference < XCertificate > > SecurityEnvironment_MSCryptImpl :: getPersonalCertificates() throw( SecurityException , RuntimeException ) {
+ sal_Int32 length ;
+ X509Certificate_MSCryptImpl* xcert ;
+ std::list< X509Certificate_MSCryptImpl* > certsList ;
+ PCCERT_CONTEXT pCertContext ;
+
+ //firstly, we try to find private keys in given key store.
+ if( m_hKeyStore != NULL ) {
+ pCertContext = NULL ;
+ while( pCertContext = CertEnumCertificatesInStore( m_hKeyStore, pCertContext ) ) {
+ xcert = MswcryCertContextToXCert( pCertContext ) ;
+ if( xcert != NULL )
+ certsList.push_back( xcert ) ;
+ }
+ }
+
+ //secondly, we try to find certificate from registered private keys.
+ if( !m_tPriKeyList.empty() ) {
+ //TODO: Don't know whether or not it is necessary ans possible.
+ }
+
+ //Thirdly, we try to find certificate from system default key store.
+ if( m_bEnableDefault ) {
+ HCERTSTORE hSystemKeyStore ;
+
+ /*
+ hSystemKeyStore = CertOpenStore(
+ CERT_STORE_PROV_SYSTEM ,
+ 0 ,
+ NULL ,
+ CERT_SYSTEM_STORE_CURRENT_USER | CERT_STORE_READONLY_FLAG | CERT_STORE_OPEN_EXISTING_FLAG ,
+ L"MY"
+ ) ;
+ */
+ hSystemKeyStore = CertOpenSystemStore( 0, "MY" ) ;
+ if( hSystemKeyStore != NULL ) {
+ pCertContext = NULL ;
+ while( pCertContext = CertEnumCertificatesInStore( hSystemKeyStore, pCertContext ) ) {
+ xcert = MswcryCertContextToXCert( pCertContext ) ;
+ if( xcert != NULL )
+ certsList.push_back( xcert ) ;
+ }
+ }
+
+ CertCloseStore( hSystemKeyStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ }
+
+ length = certsList.size() ;
+ if( length != 0 ) {
+ int i ;
+ std::list< X509Certificate_MSCryptImpl* >::iterator xcertIt ;
+ Sequence< Reference< XCertificate > > certSeq( length ) ;
+
+ for( i = 0, xcertIt = certsList.begin(); xcertIt != certsList.end(); xcertIt ++, i++ ) {
+ certSeq[i] = *xcertIt ;
+ }
+
+ return certSeq ;
+ }
+
+ return Sequence< Reference< XCertificate > >() ;
+}
+
+Reference< XCertificate > SecurityEnvironment_MSCryptImpl :: getCertificate( const OUString& issuerName, const Sequence< sal_Int8 >& serialNumber ) throw( SecurityException , RuntimeException ) {
+ X509Certificate_MSCryptImpl* xcert ;
+ PCCERT_CONTEXT pCertContext ;
+ LPSTR pszName ;
+ CERT_INFO certInfo ;
+
+ //Create cert info from issue and serial
+ rtl::OString oissuer = rtl::OUStringToOString( issuerName , RTL_TEXTENCODING_ASCII_US ) ;
+ pszName = ( char* )oissuer.getStr() ;
+
+ if( ! ( CertStrToName(
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
+ pszName ,
+ CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG ,
+ NULL ,
+ NULL ,
+ &certInfo.Issuer.cbData, NULL ) )
+ ) {
+ throw SecurityException() ;
+ }
+
+ if( !( certInfo.Issuer.pbData = ( BYTE* )malloc( certInfo.Issuer.cbData ) ) ) {
+ throw RuntimeException() ;
+ }
+
+ if( ! ( CertStrToName(
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
+ pszName ,
+ CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG ,
+ NULL ,
+ ( BYTE* )certInfo.Issuer.pbData ,
+ &certInfo.Issuer.cbData, NULL ) )
+ ) {
+ free( certInfo.Issuer.pbData ) ;
+ throw SecurityException() ;
+ }
+
+ certInfo.SerialNumber.cbData = serialNumber.getLength() ;
+ if( !( certInfo.SerialNumber.pbData = ( BYTE* )malloc( certInfo.SerialNumber.cbData ) ) ) {
+ free( certInfo.Issuer.pbData ) ;
+ throw SecurityException() ;
+ }
+
+ for( unsigned int i = 0; i < certInfo.SerialNumber.cbData; i ++ )
+ certInfo.SerialNumber.pbData[i] = serialNumber[ certInfo.SerialNumber.cbData - i - 1 ] ;
+
+ pCertContext = NULL ;
+
+ //Above all, we try to find the certificate in the given key store.
+ if( m_hKeyStore != NULL ) {
+ //Find the certificate from the store.
+ pCertContext = CertFindCertificateInStore(
+ m_hKeyStore,
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
+ 0,
+ CERT_FIND_SUBJECT_CERT,
+ &certInfo,
+ NULL
+ ) ;
+ }
+
+ //firstly, we try to find the certificate in the given cert store.
+ if( m_hCertStore != NULL ) {
+ //Find the certificate from the store.
+ pCertContext = CertFindCertificateInStore(
+ m_hCertStore,
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
+ 0,
+ CERT_FIND_SUBJECT_CERT,
+ &certInfo,
+ NULL
+ ) ;
+ }
+
+ //Secondly, we try to find certificate from system default key store.
+ if( pCertContext == NULL && m_bEnableDefault ) {
+ HCERTSTORE hSystemKeyStore ;
+
+ hSystemKeyStore = CertOpenSystemStore( 0, "MY" ) ;
+ if( hSystemKeyStore != NULL ) {
+ pCertContext = CertFindCertificateInStore(
+ hSystemKeyStore,
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
+ 0,
+ CERT_FIND_SUBJECT_CERT,
+ &certInfo,
+ NULL
+ ) ;
+ }
+
+ CertCloseStore( hSystemKeyStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ }
+
+ //Thirdly, we try to find certificate from system default root cert store.
+ if( pCertContext == NULL && m_bEnableDefault ) {
+ HCERTSTORE hSystemRootStore ;
+
+ hSystemRootStore = CertOpenSystemStore( 0, "Root" ) ;
+ if( hSystemRootStore != NULL ) {
+ pCertContext = CertFindCertificateInStore(
+ hSystemRootStore,
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
+ 0,
+ CERT_FIND_SUBJECT_CERT,
+ &certInfo,
+ NULL
+ ) ;
+ }
+
+ CertCloseStore( hSystemRootStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ }
+
+ //Fourthly, we try to find certificate from system default trust cert store.
+ if( pCertContext == NULL && m_bEnableDefault ) {
+ HCERTSTORE hSystemTrustStore ;
+
+ hSystemTrustStore = CertOpenSystemStore( 0, "Trust" ) ;
+ if( hSystemTrustStore != NULL ) {
+ pCertContext = CertFindCertificateInStore(
+ hSystemTrustStore,
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
+ 0,
+ CERT_FIND_SUBJECT_CERT,
+ &certInfo,
+ NULL
+ ) ;
+ }
+
+ CertCloseStore( hSystemTrustStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ }
+
+ //Fifthly, we try to find certificate from system default CA cert store.
+ if( pCertContext == NULL && m_bEnableDefault ) {
+ HCERTSTORE hSystemCAStore ;
+
+ hSystemCAStore = CertOpenSystemStore( 0, "CA" ) ;
+ if( hSystemCAStore != NULL ) {
+ pCertContext = CertFindCertificateInStore(
+ hSystemCAStore,
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
+ 0,
+ CERT_FIND_SUBJECT_CERT,
+ &certInfo,
+ NULL
+ ) ;
+ }
+
+ CertCloseStore( hSystemCAStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ }
+
+
+ free( certInfo.Issuer.pbData ) ;
+ free( certInfo.SerialNumber.pbData ) ;
+
+ if( pCertContext != NULL ) {
+ xcert = MswcryCertContextToXCert( pCertContext ) ;
+ } else {
+ xcert = NULL ;
+ }
+
+ return xcert ;
+}
+
+Reference< XCertificate > SecurityEnvironment_MSCryptImpl :: getCertificate( const OUString& issuerName, const OUString& serialNumber ) throw( SecurityException , RuntimeException ) {
+ Sequence< sal_Int8 > serial = numericStringToBigInteger( serialNumber ) ;
+ return getCertificate( issuerName, serial ) ;
+}
+
+Sequence< Reference < XCertificate > > SecurityEnvironment_MSCryptImpl :: buildCertificatePath( const Reference< XCertificate >& begin ) throw( SecurityException , RuntimeException ) {
+ PCCERT_CHAIN_CONTEXT pChainContext ;
+ PCCERT_CONTEXT pCertContext ;
+ const X509Certificate_MSCryptImpl* xcert ;
+
+ CERT_ENHKEY_USAGE enhKeyUsage ;
+ CERT_USAGE_MATCH certUsage ;
+ CERT_CHAIN_PARA chainPara ;
+
+ enhKeyUsage.cUsageIdentifier = 0 ;
+ enhKeyUsage.rgpszUsageIdentifier = NULL ;
+ certUsage.dwType = USAGE_MATCH_TYPE_AND ;
+ certUsage.Usage = enhKeyUsage ;
+ chainPara.cbSize = sizeof( CERT_CHAIN_PARA ) ;
+ chainPara.RequestedUsage = certUsage ;
+
+ Reference< XUnoTunnel > xCertTunnel( begin, UNO_QUERY ) ;
+ if( !xCertTunnel.is() ) {
+ throw RuntimeException() ;
+ }
+
+ xcert = ( X509Certificate_MSCryptImpl* )xCertTunnel->getSomething( X509Certificate_MSCryptImpl::getUnoTunnelId() ) ;
+ if( xcert == NULL ) {
+ throw RuntimeException() ;
+ }
+
+ pCertContext = xcert->getMswcryCert() ;
+
+ pChainContext = NULL ;
+
+ //Above all, we try to find the certificate in the given key store.
+ if( pCertContext != NULL ) {
+ if( !CertGetCertificateChain(
+ NULL ,
+ pCertContext ,
+ NULL ,
+ m_hKeyStore ,
+ &chainPara ,
+ 0 ,
+ NULL ,
+ &pChainContext
+ )
+ ) {
+ pChainContext = NULL ;
+ }
+ }
+
+ //firstly, we try to find the certificate in the given cert store.
+ if( pCertContext != NULL && pChainContext != NULL ) {
+ if( !CertGetCertificateChain(
+ NULL ,
+ pCertContext ,
+ NULL ,
+ m_hCertStore ,
+ &chainPara ,
+ 0 ,
+ NULL ,
+ &pChainContext
+ )
+ ) {
+ pChainContext = NULL ;
+ }
+ }
+
+ //Secondly, we try to find certificate from system default system store.
+ if( pCertContext != NULL && pChainContext != NULL ) {
+ HCERTSTORE hCollectionStore ;
+
+ hCollectionStore = CertOpenStore(
+ CERT_STORE_PROV_COLLECTION ,
+ 0 ,
+ NULL ,
+ 0 ,
+ NULL
+ ) ;
+
+ if( hCollectionStore != NULL ) {
+ HCERTSTORE hSystemStore ;
+
+ //Add system key store to the collection.
+ hSystemStore = CertOpenSystemStore( 0, "MY" ) ;
+ if( hSystemStore != NULL ) {
+ CertAddStoreToCollection (
+ hCollectionStore ,
+ hSystemStore ,
+ CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG ,
+ 1
+ ) ;
+ CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ }
+
+ //Add system root store to the collection.
+ hSystemStore = CertOpenSystemStore( 0, "Root" ) ;
+ if( hSystemStore != NULL ) {
+ CertAddStoreToCollection (
+ hCollectionStore ,
+ hSystemStore ,
+ CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG ,
+ 2
+ ) ;
+ CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ }
+
+ //Add system trust store to the collection.
+ hSystemStore = CertOpenSystemStore( 0, "Trust" ) ;
+ if( hSystemStore != NULL ) {
+ CertAddStoreToCollection (
+ hCollectionStore ,
+ hSystemStore ,
+ CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG ,
+ 3
+ ) ;
+ CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ }
+
+ //Add system CA store to the collection.
+ hSystemStore = CertOpenSystemStore( 0, "CA" ) ;
+ if( hSystemStore != NULL ) {
+ CertAddStoreToCollection (
+ hCollectionStore ,
+ hSystemStore ,
+ CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG ,
+ 4
+ ) ;
+ CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ }
+
+ //Get the chain from the collection store.
+ if( !CertGetCertificateChain(
+ NULL ,
+ pCertContext ,
+ NULL ,
+ hCollectionStore ,
+ &chainPara ,
+ 0 ,
+ NULL ,
+ &pChainContext
+ )
+ ) {
+ pChainContext = NULL ;
+ }
+
+ CertCloseStore( hCollectionStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ }
+ }
+
+ if( pChainContext != NULL && pChainContext->cChain > 0 ) {
+ PCCERT_CONTEXT pCertInChain ;
+ PCERT_SIMPLE_CHAIN pCertChain ;
+ X509Certificate_MSCryptImpl* pCert ;
+
+ pCertChain = pChainContext->rgpChain[0] ;
+ if( pCertChain->cElement ) {
+ Sequence< Reference< XCertificate > > xCertChain( pCertChain->cElement ) ;
+
+ for( unsigned int i = 0 ; i < pCertChain->cElement ; i ++ ) {
+ if( pCertChain->rgpElement[i] )
+ pCertInChain = pCertChain->rgpElement[i]->pCertContext ;
+ else
+ pCertInChain = NULL ;
+
+ if( pCertInChain != NULL ) {
+ pCert = MswcryCertContextToXCert( pCertInChain ) ;
+ if( pCert != NULL )
+ xCertChain[i] = pCert ;
+ }
+ }
+
+ CertFreeCertificateChain( pChainContext ) ;
+ pChainContext = NULL ;
+
+ return xCertChain ;
+ }
+ }
+
+ return NULL ;
+}
+
+Reference< XCertificate > SecurityEnvironment_MSCryptImpl :: createCertificateFromRaw( const Sequence< sal_Int8 >& rawCertificate ) throw( SecurityException , RuntimeException ) {
+ X509Certificate_MSCryptImpl* xcert ;
+
+ if( rawCertificate.getLength() > 0 ) {
+ xcert = new X509Certificate_MSCryptImpl() ;
+ if( xcert == NULL )
+ throw RuntimeException() ;
+
+ xcert->setRawCert( rawCertificate ) ;
+ } else {
+ xcert = NULL ;
+ }
+
+ return xcert ;
+}
+
+Reference< XCertificate > SecurityEnvironment_MSCryptImpl :: 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 ) ;
+}
+
+void SecurityEnvironment_MSCryptImpl :: enableDefaultCrypt( sal_Bool enable ) throw( Exception, RuntimeException ) {
+ m_bEnableDefault = enable ;
+}
+
+sal_Bool SecurityEnvironment_MSCryptImpl :: defaultEnabled() throw( Exception, RuntimeException ) {
+ return m_bEnableDefault ;
+}
+
+X509Certificate_MSCryptImpl* MswcryCertContextToXCert( PCCERT_CONTEXT cert )
+{
+ X509Certificate_MSCryptImpl* xcert ;
+
+ if( cert != NULL ) {
+ xcert = new X509Certificate_MSCryptImpl() ;
+ if( xcert != NULL ) {
+ xcert->setMswcryCert( cert ) ;
+ }
+ } else {
+ xcert = NULL ;
+ }
+
+ return xcert ;
+}
+
+/*-
+ * This is just one temporary conversion
+ */
+Sequence< sal_Int8 > numericStringToBigInteger (
+ OUString serialNumber
+) {
+ xmlChar* chSerial ;
+ unsigned long ui ;
+ unsigned char bb[5] ;
+ int len ;
+
+ rtl::OString oseri = rtl::OUStringToOString( serialNumber , RTL_TEXTENCODING_ASCII_US ) ;
+
+ chSerial = xmlStrndup( ( const xmlChar* )oseri.getStr(), ( int )oseri.getLength() ) ;
+ ui = atoi( ( const char* )chSerial ) ;
+ xmlFree( 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() )
+ {
+ long ival = 0;
+
+ {
+ unsigned len = serial.getLength() ;
+ unsigned char *cp = ( unsigned char* )&serial[0] ;
+ unsigned long overflow = 0x1ffUL << (((sizeof(ival) - 1) * 8) - 1);
+ unsigned long ofloinit;
+
+ if (*cp & 0x80)
+ ival = -1L;
+ ofloinit = ival & overflow;
+
+ while (len) {
+ if ((ival & overflow) != ofloinit) {
+ return aRet;
+ }
+ ival = ival << 8;
+ ival |= *cp++;
+ --len;
+ }
+ }
+
+ /*----------------------
+ {
+ unsigned len = serial.getLength() ;
+ unsigned char *cp = ( unsigned char* )&serial[len-1] ;
+ unsigned long overflow = 0x1ffUL << (((sizeof(ival) - 1) * 8) - 1);
+ unsigned long ofloinit;
+
+ if (*cp & 0x80)
+ ival = -1L;
+ ofloinit = ival & overflow;
+
+ while (len) {
+ if ((ival & overflow) != ofloinit) {
+ return aRet;
+ }
+ ival = ival << 8;
+ ival |= *cp--;
+ --len;
+ }
+ }
+ ----------------------*/
+
+ {
+ char str[10] ;
+ int len ;
+ len = sprintf( str, "%d", ival ) ;
+ aRet = OUString::createFromAscii( str ) ;
+ }
+ }
+
+ return aRet;
+}
+
diff --git a/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.hxx b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.hxx
new file mode 100644
index 000000000000..bd80f566a248
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.hxx
@@ -0,0 +1,235 @@
+/*************************************************************************
+ *
+ * $RCSfile: securityenvironment_mscryptimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+ *
+ * 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_MSCRYPTIMPL_HXX_
+#define _XSECURITYENVIRONMENT_MSCRYPTIMPL_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 <list>
+
+#include <windows.h>
+#include <wincrypt.h>
+
+class SecurityEnvironment_MSCryptImpl : 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 :
+ //cyrpto provider and key container
+ HCRYPTPROV m_hProv ;
+ LPCTSTR m_pszContainer ;
+
+ //Key store
+ HCERTSTORE m_hKeyStore ;
+
+ //Certiticate store
+ HCERTSTORE m_hCertStore ;
+
+ //Enable default system cryptography setting
+ sal_Bool m_bEnableDefault ;
+
+ //External keys
+ std::list< HCRYPTKEY > m_tSymKeyList ;
+ std::list< HCRYPTKEY > m_tPubKeyList ;
+ std::list< HCRYPTKEY > m_tPriKeyList ;
+
+ //Service manager
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager ;
+
+ public :
+ SecurityEnvironment_MSCryptImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
+ virtual ~SecurityEnvironment_MSCryptImpl() ;
+
+ //Methods from XSecurityEnvironment
+ 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 ) ;
+
+ //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_MSCryptImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ;
+
+ //Native mehtods
+ virtual HCRYPTPROV getCryptoProvider() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void setCryptoProvider( HCRYPTPROV aProv ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual LPCTSTR getKeyContainer() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void setKeyContainer( LPCTSTR aKeyContainer ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual HCERTSTORE getCryptoSlot() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void setCryptoSlot( HCERTSTORE aKeyStore ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual HCERTSTORE getCertDb() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void setCertDb( HCERTSTORE aCertDb ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void adoptSymKey( HCRYPTKEY aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void rejectSymKey( HCRYPTKEY aSymKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual HCRYPTKEY getSymKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void adoptPubKey( HCRYPTKEY aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void rejectPubKey( HCRYPTKEY aPubKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual HCRYPTKEY getPubKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void adoptPriKey( HCRYPTKEY aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void rejectPriKey( HCRYPTKEY aPriKey ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual HCRYPTKEY getPriKey( unsigned int position ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual void enableDefaultCrypt( sal_Bool enable ) throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+
+ virtual sal_Bool defaultEnabled() throw( ::com::sun::star::uno::Exception , ::com::sun::star::uno::RuntimeException ) ;
+} ;
+
+#endif // _XSECURITYENVIRONMENT_MSCRYPTIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.cxx
new file mode 100644
index 000000000000..a526634c6e0a
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.cxx
@@ -0,0 +1,269 @@
+/*************************************************************************
+ *
+ * $RCSfile: seinitializer_mscryptimpl.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 "seinitializer_mscryptimpl.hxx"
+
+#include "securityenvironment_mscryptimpl.hxx"
+
+#include "xmlsec/strings.h"
+#include "xmlsec/mscrypto/app.h"
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+
+#define SERVICE_NAME "com.sun.star.xml.crypto.SEInitializer"
+#define IMPLEMENTATION_NAME "com.sun.star.xml.security.bridge.xmlsec.SEInitializer_MSCryptImpl"
+#define SECURITY_ENVIRONMENT "com.sun.star.xml.crypto.SecurityEnvironment"
+#define SECURITY_CONTEXT "com.sun.star.xml.crypto.XMLSecurityContext"
+
+SEInitializer_MSCryptImpl::SEInitializer_MSCryptImpl(
+ const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &rxMSF)
+ :mxMSF( rxMSF )
+{
+}
+
+SEInitializer_MSCryptImpl::~SEInitializer_MSCryptImpl()
+{
+}
+
+/* XSEInitializer */
+cssu::Reference< cssxc::XXMLSecurityContext > SAL_CALL
+ SEInitializer_MSCryptImpl::createSecurityContext(
+ const rtl::OUString& sCertDB )
+ throw (cssu::RuntimeException)
+{
+ const char* n_pCertStore ;
+ HCERTSTORE n_hStoreHandle ;
+
+ //Initialize the crypto engine
+ if( sCertDB.getLength() > 0 )
+ {
+ rtl::OString sCertDir(sCertDB, sCertDB.getLength(), RTL_TEXTENCODING_ASCII_US);
+ n_pCertStore = sCertDir.getStr();
+ n_hStoreHandle = CertOpenSystemStore( NULL, n_pCertStore ) ;
+ if( n_hStoreHandle == NULL )
+ {
+ return NULL;
+ }
+ }
+ else
+ {
+ n_pCertStore = NULL ;
+ n_hStoreHandle = NULL ;
+ }
+
+ xmlSecMSCryptoAppInit( n_pCertStore ) ;
+
+ 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() )
+ {
+ if( n_hStoreHandle != NULL )
+ {
+ CertCloseStore( n_hStoreHandle, CERT_CLOSE_STORE_FORCE_FLAG ) ;
+ }
+
+ xmlSecMSCryptoAppShutdown() ;
+ return NULL;
+ }
+
+ /* Setup key slot and certDb */
+ cssu::Reference< cssl::XUnoTunnel > xEnvTunnel( xSecEnv , cssu::UNO_QUERY ) ;
+ if( !xEnvTunnel.is() )
+ {
+ if( n_hStoreHandle != NULL )
+ {
+ CertCloseStore( n_hStoreHandle, CERT_CLOSE_STORE_FORCE_FLAG ) ;
+ }
+
+ xmlSecMSCryptoAppShutdown() ;
+ return NULL;
+ }
+
+ SecurityEnvironment_MSCryptImpl* pSecEnv = ( SecurityEnvironment_MSCryptImpl* )xEnvTunnel->getSomething( SecurityEnvironment_MSCryptImpl::getUnoTunnelId() ) ;
+ if( pSecEnv == NULL )
+ {
+ if( n_hStoreHandle != NULL )
+ {
+ CertCloseStore( n_hStoreHandle, CERT_CLOSE_STORE_FORCE_FLAG ) ;
+ }
+
+ xmlSecMSCryptoAppShutdown() ;
+ return NULL;
+ }
+
+ if( n_hStoreHandle != NULL )
+ {
+ pSecEnv->setCryptoSlot( n_hStoreHandle ) ;
+ pSecEnv->setCertDb( n_hStoreHandle ) ;
+ }
+ else
+ {
+ pSecEnv->enableDefaultCrypt( sal_True ) ;
+ }
+
+ /* 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() )
+ {
+ if( n_hStoreHandle != NULL )
+ {
+ CertCloseStore( n_hStoreHandle, CERT_CLOSE_STORE_FORCE_FLAG ) ;
+ }
+
+ xmlSecMSCryptoAppShutdown() ;
+ return NULL;
+ }
+
+ xSecCtx->setSecurityEnvironment( xSecEnv ) ;
+ return xSecCtx;
+ }
+ catch( cssu::Exception& )
+ {
+ if( n_hStoreHandle != NULL )
+ {
+ CertCloseStore( n_hStoreHandle, CERT_CLOSE_STORE_FORCE_FLAG ) ;
+ }
+
+ xmlSecMSCryptoAppShutdown() ;
+ return NULL;
+ }
+}
+
+void SAL_CALL SEInitializer_MSCryptImpl::freeSecurityContext( const cssu::Reference< cssxc::XXMLSecurityContext >& securityContext )
+ throw (cssu::RuntimeException)
+{
+ /*
+ cssu::Reference< cssxc::XSecurityEnvironment > xSecEnv
+ = securityContext->getSecurityEnvironment();
+
+ if( xSecEnv.is() )
+ {
+ cssu::Reference< cssl::XUnoTunnel > xEnvTunnel( xSecEnv , cssu::UNO_QUERY ) ;
+ if( xEnvTunnel.is() )
+ {
+ SecurityEnvironment_MSCryptImpl* pSecEnv = ( SecurityEnvironment_MSCryptImpl* )xEnvTunnel->getSomething( SecurityEnvironment_MSCryptImpl::getUnoTunnelId() ) ;
+ HCERTSTORE n_hStoreHandle = pSecEnv->getCryptoSlot();
+
+ if( n_hStoreHandle != NULL )
+ {
+ CertCloseStore( n_hStoreHandle, CERT_CLOSE_STORE_FORCE_FLAG ) ;
+ pSecEnv->setCryptoSlot( NULL ) ;
+ pSecEnv->setCertDb( NULL ) ;
+ }
+
+ xmlSecMSCryptoAppShutdown() ;
+ }
+ }
+ */
+
+ xmlSecMSCryptoAppShutdown() ;
+}
+
+rtl::OUString SEInitializer_MSCryptImpl_getImplementationName ()
+ throw (cssu::RuntimeException)
+{
+ return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
+}
+
+sal_Bool SAL_CALL SEInitializer_MSCryptImpl_supportsService( const rtl::OUString& ServiceName )
+ throw (cssu::RuntimeException)
+{
+ return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
+}
+
+cssu::Sequence< rtl::OUString > SAL_CALL SEInitializer_MSCryptImpl_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_MSCryptImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr)
+ throw( cssu::Exception )
+{
+ return (cppu::OWeakObject*) new SEInitializer_MSCryptImpl(rSMgr);
+}
+
+/* XServiceInfo */
+rtl::OUString SAL_CALL SEInitializer_MSCryptImpl::getImplementationName( )
+ throw (cssu::RuntimeException)
+{
+ return SEInitializer_MSCryptImpl_getImplementationName();
+}
+sal_Bool SAL_CALL SEInitializer_MSCryptImpl::supportsService( const rtl::OUString& rServiceName )
+ throw (cssu::RuntimeException)
+{
+ return SEInitializer_MSCryptImpl_supportsService( rServiceName );
+}
+cssu::Sequence< rtl::OUString > SAL_CALL SEInitializer_MSCryptImpl::getSupportedServiceNames( )
+ throw (cssu::RuntimeException)
+{
+ return SEInitializer_MSCryptImpl_getSupportedServiceNames();
+}
+
diff --git a/xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.hxx b/xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.hxx
new file mode 100644
index 000000000000..1726e79533ad
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.hxx
@@ -0,0 +1,152 @@
+/*************************************************************************
+ *
+ * $RCSfile: seinitializer_mscryptimpl.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_MSCryptImpl : public cppu::WeakImplHelper2
+<
+ com::sun::star::xml::crypto::XSEInitializer,
+ com::sun::star::lang::XServiceInfo
+>
+/****** SEInitializer_MSCryptImpl.hxx/CLASS SEInitializer_MSCryptImpl ***********
+ *
+ * NAME
+ * SEInitializer_MSCryptImpl -- 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_MSCryptImpl(const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &rxMSF);
+ virtual ~SEInitializer_MSCryptImpl();
+
+ /* 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_MSCryptImpl_getImplementationName()
+ throw ( com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL SEInitializer_MSCryptImpl_supportsService( const rtl::OUString& ServiceName )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL SEInitializer_MSCryptImpl_getSupportedServiceNames( )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
+SAL_CALL SEInitializer_MSCryptImpl_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/mscrypt/x509certificate_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx
new file mode 100644
index 000000000000..b24779740a95
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx
@@ -0,0 +1,392 @@
+/*************************************************************************
+ *
+ * $RCSfile: x509certificate_mscryptimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+ *
+ * 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_MSCRYPTIMPL_HXX_
+#include "x509certificate_mscryptimpl.hxx"
+#endif
+
+#ifndef _CERTIFICATEEXTENSION_XMLSECIMPL_HXX_
+#include "certificateextension_xmlsecimpl.hxx"
+#endif
+
+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_MSCryptImpl :: X509Certificate_MSCryptImpl() :
+ m_pCertContext( NULL )
+{
+}
+
+X509Certificate_MSCryptImpl :: ~X509Certificate_MSCryptImpl() {
+ if( m_pCertContext != NULL ) {
+ CertFreeCertificateContext( m_pCertContext ) ;
+ }
+}
+
+//Methods from XCertificate
+sal_Int16 SAL_CALL X509Certificate_MSCryptImpl :: getVersion() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL ) {
+ return ( char )m_pCertContext->pCertInfo->dwVersion ;
+ } else {
+ return -1 ;
+ }
+}
+
+::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_MSCryptImpl :: getSerialNumber() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL ) {
+ Sequence< sal_Int8 > serial( m_pCertContext->pCertInfo->SerialNumber.cbData ) ;
+ for( unsigned int i = 0 ; i < m_pCertContext->pCertInfo->SerialNumber.cbData ; i ++ )
+ serial[i] = *( m_pCertContext->pCertInfo->SerialNumber.pbData + m_pCertContext->pCertInfo->SerialNumber.cbData - i - 1 ) ;
+
+ return serial ;
+ } else {
+ return NULL ;
+ }
+}
+
+::rtl::OUString SAL_CALL X509Certificate_MSCryptImpl :: getIssuerName() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL ) {
+ char* issuer ;
+ DWORD cbIssuer ;
+
+ cbIssuer = CertNameToStr(
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
+ &( m_pCertContext->pCertInfo->Issuer ),
+ CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG ,
+ NULL, 0
+ ) ;
+
+ if( cbIssuer != 0 ) {
+ issuer = new char[ cbIssuer ] ;
+ if( issuer == NULL )
+ throw RuntimeException() ;
+
+ cbIssuer = CertNameToStr(
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
+ &( m_pCertContext->pCertInfo->Issuer ),
+ CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG ,
+ issuer, cbIssuer
+ ) ;
+
+ if( cbIssuer <= 0 ) {
+ delete issuer ;
+ throw RuntimeException() ;
+ }
+
+ OUString xIssuer = OUString::createFromAscii( issuer ) ;
+ delete issuer ;
+
+ return xIssuer ;
+ } else {
+ return OUString() ;
+ }
+ } else {
+ return OUString() ;
+ }
+}
+
+::rtl::OUString SAL_CALL X509Certificate_MSCryptImpl :: getSubjectName() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL ) {
+ char* subject ;
+ DWORD cbSubject ;
+
+ cbSubject = CertNameToStr(
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
+ &( m_pCertContext->pCertInfo->Subject ),
+ CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG ,
+ NULL, 0
+ ) ;
+
+ if( cbSubject != 0 ) {
+ subject = new char[ cbSubject ] ;
+ if( subject == NULL )
+ throw RuntimeException() ;
+
+ cbSubject = CertNameToStr(
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
+ &( m_pCertContext->pCertInfo->Subject ),
+ CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG ,
+ subject, cbSubject
+ ) ;
+
+ if( cbSubject <= 0 ) {
+ delete subject ;
+ throw RuntimeException() ;
+ }
+
+ OUString xSubject = OUString::createFromAscii( subject ) ;
+ delete subject ;
+
+ return xSubject ;
+ } else {
+ return OUString() ;
+ }
+ } else {
+ return OUString() ;
+ }
+}
+
+::com::sun::star::util::DateTime SAL_CALL X509Certificate_MSCryptImpl :: getNotBefore() throw ( ::com::sun::star::uno::RuntimeException ) {
+ if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL ) {
+ SYSTEMTIME explTime ;
+ DateTime dateTime ;
+
+ if( FileTimeToSystemTime( &( m_pCertContext->pCertInfo->NotBefore ), &explTime ) ) {
+ //Convert the time to readable local time
+ dateTime.HundredthSeconds = explTime.wMilliseconds / 100 ;
+ dateTime.Seconds = explTime.wSecond ;
+ dateTime.Minutes = explTime.wMinute ;
+ dateTime.Hours = explTime.wHour ;
+ dateTime.Day = explTime.wDay ;
+ dateTime.Month = explTime.wMonth ;
+ dateTime.Year = explTime.wYear ;
+ }
+
+ return dateTime ;
+ } else {
+ return DateTime() ;
+ }
+}
+
+::com::sun::star::util::DateTime SAL_CALL X509Certificate_MSCryptImpl :: getNotAfter() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL ) {
+ SYSTEMTIME explTime ;
+ DateTime dateTime ;
+
+ if( FileTimeToSystemTime( &( m_pCertContext->pCertInfo->NotAfter ), &explTime ) ) {
+ //Convert the time to readable local time
+ dateTime.HundredthSeconds = explTime.wMilliseconds / 100 ;
+ dateTime.Seconds = explTime.wSecond ;
+ dateTime.Minutes = explTime.wMinute ;
+ dateTime.Hours = explTime.wHour ;
+ dateTime.Day = explTime.wDay ;
+ dateTime.Month = explTime.wMonth ;
+ dateTime.Year = explTime.wYear ;
+ }
+
+ return dateTime ;
+ } else {
+ return DateTime() ;
+ }
+}
+
+::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_MSCryptImpl :: getIssuerUniqueID() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL ) {
+ Sequence< sal_Int8 > issuerUid( m_pCertContext->pCertInfo->IssuerUniqueId.cbData ) ;
+ for( unsigned int i = 0 ; i < m_pCertContext->pCertInfo->IssuerUniqueId.cbData; i ++ )
+ issuerUid[i] = *( m_pCertContext->pCertInfo->IssuerUniqueId.pbData + i ) ;
+
+ return issuerUid ;
+ } else {
+ return NULL ;
+ }
+}
+
+::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_MSCryptImpl :: getSubjectUniqueID() throw ( ::com::sun::star::uno::RuntimeException ) {
+ if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL ) {
+ Sequence< sal_Int8 > subjectUid( m_pCertContext->pCertInfo->SubjectUniqueId.cbData ) ;
+ for( unsigned int i = 0 ; i < m_pCertContext->pCertInfo->SubjectUniqueId.cbData; i ++ )
+ subjectUid[i] = *( m_pCertContext->pCertInfo->SubjectUniqueId.pbData + i ) ;
+
+ return subjectUid ;
+ } else {
+ return NULL ;
+ }
+}
+
+::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificateExtension > > SAL_CALL X509Certificate_MSCryptImpl :: getExtensions() throw ( ::com::sun::star::uno::RuntimeException ) {
+ if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL && m_pCertContext->pCertInfo->cExtension != 0 ) {
+ CertificateExtension_XmlSecImpl* xExtn ;
+ CERT_EXTENSION* pExtn ;
+ Sequence< Reference< XCertificateExtension > > xExtns( m_pCertContext->pCertInfo->cExtension ) ;
+
+ for( unsigned int i = 0; i < m_pCertContext->pCertInfo->cExtension; i++ ) {
+ pExtn = &(m_pCertContext->pCertInfo->rgExtension[i]) ;
+
+ xExtn = new CertificateExtension_XmlSecImpl() ;
+ if( xExtn == NULL )
+ throw RuntimeException() ;
+
+ xExtn->setCertExtn( pExtn->Value.pbData, pExtn->Value.cbData, ( unsigned char* )pExtn->pszObjId, strlen( pExtn->pszObjId ), pExtn->fCritical ) ;
+
+ xExtns[i] = xExtn ;
+ }
+
+ return xExtns ;
+ } else {
+ return NULL ;
+ }
+}
+
+::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificateExtension > SAL_CALL X509Certificate_MSCryptImpl :: findCertExtension( const ::com::sun::star::uno::Sequence< sal_Int8 >& oid ) throw (::com::sun::star::uno::RuntimeException) {
+ if( m_pCertContext != NULL && m_pCertContext->pCertInfo != NULL && m_pCertContext->pCertInfo->cExtension != 0 ) {
+ CertificateExtension_XmlSecImpl* xExtn ;
+ CERT_EXTENSION* pExtn ;
+ Sequence< Reference< XCertificateExtension > > xExtns( m_pCertContext->pCertInfo->cExtension ) ;
+
+ xExtn = NULL ;
+ for( unsigned int i = 0; i < m_pCertContext->pCertInfo->cExtension; i++ ) {
+ pExtn = &( m_pCertContext->pCertInfo->rgExtension[i] ) ;
+
+ //TODO: Compare the oid
+ if( 0 ) {
+ xExtn = new CertificateExtension_XmlSecImpl() ;
+ if( xExtn == NULL )
+ throw RuntimeException() ;
+
+ xExtn->setCertExtn( pExtn->Value.pbData, pExtn->Value.cbData, ( unsigned char* )pExtn->pszObjId, strlen( pExtn->pszObjId ), pExtn->fCritical ) ;
+ }
+ }
+
+ return xExtn ;
+ } else {
+ return NULL ;
+ }
+}
+
+
+::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_MSCryptImpl :: getEncoded() throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCertContext != NULL && m_pCertContext->cbCertEncoded > 0 ) {
+ Sequence< sal_Int8 > rawCert( m_pCertContext->cbCertEncoded ) ;
+
+ for( unsigned int i = 0 ; i < m_pCertContext->cbCertEncoded ; i ++ )
+ rawCert[i] = *( m_pCertContext->pbCertEncoded + i ) ;
+
+ return rawCert ;
+ } else {
+ return NULL ;
+ }
+}
+
+//Helper methods
+void X509Certificate_MSCryptImpl :: setMswcryCert( const CERT_CONTEXT* cert ) {
+ if( m_pCertContext != NULL ) {
+ CertFreeCertificateContext( m_pCertContext ) ;
+ m_pCertContext = NULL ;
+ }
+
+ if( cert != NULL ) {
+ m_pCertContext = CertDuplicateCertificateContext( cert ) ;
+ }
+}
+
+const CERT_CONTEXT* X509Certificate_MSCryptImpl :: getMswcryCert() const {
+ if( m_pCertContext != NULL ) {
+ return m_pCertContext ;
+ } else {
+ return NULL ;
+ }
+}
+
+void X509Certificate_MSCryptImpl :: setRawCert( Sequence< sal_Int8 > rawCert ) throw ( ::com::sun::star::uno::RuntimeException) {
+ if( m_pCertContext != NULL ) {
+ CertFreeCertificateContext( m_pCertContext ) ;
+ m_pCertContext = NULL ;
+ }
+
+ if( rawCert.getLength() != 0 ) {
+ m_pCertContext = CertCreateCertificateContext( X509_ASN_ENCODING, ( const BYTE* )&rawCert[0], rawCert.getLength() ) ;
+ }
+}
+
+/* XUnoTunnel */
+sal_Int64 SAL_CALL X509Certificate_MSCryptImpl :: 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_MSCryptImpl :: 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_MSCryptImpl* X509Certificate_MSCryptImpl :: getImplementation( const Reference< XInterface > xObj ) {
+ Reference< XUnoTunnel > xUT( xObj , UNO_QUERY ) ;
+ if( xUT.is() ) {
+ return ( X509Certificate_MSCryptImpl* )xUT->getSomething( getUnoTunnelId() ) ;
+ } else
+ return NULL ;
+}
+
diff --git a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx
new file mode 100644
index 000000000000..ac184938cf35
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx
@@ -0,0 +1,147 @@
+/*************************************************************************
+ *
+ * $RCSfile: x509certificate_mscryptimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+ *
+ * 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_MSCRYPTIMPL_HXX_
+#define _X509CERTIFICATE_MSCRYPTIMPL_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 "Windows.h"
+#include "WinCrypt.h"
+
+class X509Certificate_MSCryptImpl : public ::cppu::WeakImplHelper2<
+ ::com::sun::star::security::XCertificate ,
+ ::com::sun::star::lang::XUnoTunnel >
+{
+ private :
+ const CERT_CONTEXT* m_pCertContext ;
+
+ public :
+ X509Certificate_MSCryptImpl() ;
+ virtual ~X509Certificate_MSCryptImpl() ;
+
+ //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_MSCryptImpl* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xObj ) ;
+
+ //Helper methods
+ void setMswcryCert( const CERT_CONTEXT* cert ) ;
+ const CERT_CONTEXT* getMswcryCert() const ;
+ void setRawCert( ::com::sun::star::uno::Sequence< sal_Int8 > rawCert ) throw ( ::com::sun::star::uno::RuntimeException) ;
+} ;
+
+#endif // _X509CERTIFICATE_MSCRYPTIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/mscrypt/xmlencryption_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/xmlencryption_mscryptimpl.cxx
new file mode 100644
index 000000000000..9a4f0a0e6cc7
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/xmlencryption_mscryptimpl.cxx
@@ -0,0 +1,403 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlencryption_mscryptimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+ *
+ * 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_MSCRYPTIMPL_HXX_
+#include "xmlencryption_mscryptimpl.hxx"
+#endif
+
+#ifndef _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX_
+#include "xmldocumentwrapper_xmlsecimpl.hxx"
+#endif
+
+#ifndef _XMLELEMENTWRAPPER_XMLSECIMPL_HXX_
+#include "xmlelementwrapper_xmlsecimpl.hxx"
+#endif
+
+#ifndef _XMLSECURITYCONTEXT_MSCRYPTIMPL_HXX_
+#include "xmlsecuritycontext_mscryptimpl.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_MSCryptImpl :: XMLEncryption_MSCryptImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_xServiceManager( aFactory ) {
+}
+
+XMLEncryption_MSCryptImpl :: ~XMLEncryption_MSCryptImpl() {
+}
+
+/* XXMLEncryption */
+Reference< XXMLEncryptionTemplate >
+SAL_CALL XMLEncryption_MSCryptImpl :: 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_MSCryptImpl* pSecCtxt = ( XMLSecurityContext_MSCryptImpl* )xSecTunnel->getSomething( XMLSecurityContext_MSCryptImpl::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.
+ //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;
+
+ if( pContent == NULL ) {
+ xmlSecEncCtxDestroy( pEncCtx ) ;
+ throw RuntimeException() ;
+ }
+
+ 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_MSCryptImpl :: 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_MSCryptImpl* pSecCtxt = ( XMLSecurityContext_MSCryptImpl* )xSecTunnel->getSomething( XMLSecurityContext_MSCryptImpl::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_MSCryptImpl :: initialize( const Sequence< Any >& aArguments ) throw( Exception, RuntimeException ) {
+ // TBD
+} ;
+
+/* XServiceInfo */
+OUString SAL_CALL XMLEncryption_MSCryptImpl :: getImplementationName() throw( RuntimeException ) {
+ return impl_getImplementationName() ;
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL XMLEncryption_MSCryptImpl :: 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_MSCryptImpl :: getSupportedServiceNames() throw( RuntimeException ) {
+ return impl_getSupportedServiceNames() ;
+}
+
+//Helper for XServiceInfo
+Sequence< OUString > XMLEncryption_MSCryptImpl :: 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_MSCryptImpl :: impl_getImplementationName() throw( RuntimeException ) {
+ return OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLEncryption_MSCryptImpl" ) ;
+}
+
+//Helper for registry
+Reference< XInterface > SAL_CALL XMLEncryption_MSCryptImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
+ return Reference< XInterface >( *new XMLEncryption_MSCryptImpl( aServiceManager ) ) ;
+}
+
+Reference< XSingleServiceFactory > XMLEncryption_MSCryptImpl :: 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/mscrypt/xmlencryption_mscryptimpl.hxx b/xmlsecurity/source/xmlsec/mscrypt/xmlencryption_mscryptimpl.hxx
new file mode 100644
index 000000000000..a65fa54cefd7
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/xmlencryption_mscryptimpl.hxx
@@ -0,0 +1,165 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlencryption_mscryptimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+ *
+ * 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_MSCRYPTIMPL_HXX_
+#define _XMLENCRYPTION_MSCRYPTIMPL_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_MSCryptImpl : 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_MSCryptImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
+ virtual ~XMLEncryption_MSCryptImpl() ;
+
+ //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_MSCRYPTIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/mscrypt/xmlsecuritycontext_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/xmlsecuritycontext_mscryptimpl.cxx
new file mode 100644
index 000000000000..41119ad96eab
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/xmlsecuritycontext_mscryptimpl.cxx
@@ -0,0 +1,331 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsecuritycontext_mscryptimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+ *
+ * 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_MSCRYPTIMPL_HXX_
+#include "securityenvironment_mscryptimpl.hxx"
+#endif
+
+#ifndef _XMLSECURITYCONTEXT_MSCRYPTIMPL_HXX_
+#include "xmlsecuritycontext_mscryptimpl.hxx"
+#endif
+
+#ifndef _XMLSTREAMIO_XMLSECIMPL_HXX_
+#include "xmlstreamio.hxx"
+#endif
+
+#include "xmlsec/xmlsec.h"
+#include "xmlsec/keysmngr.h"
+#include "xmlsec/crypto.h"
+#include "xmlsec/mscrypto/akmngr.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_MSCryptImpl :: XMLSecurityContext_MSCryptImpl( 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_MSCryptImpl :: ~XMLSecurityContext_MSCryptImpl() {
+ if( m_pKeysMngr != NULL ) {
+ xmlSecKeysMngrDestroy( m_pKeysMngr ) ;
+ }
+
+ xmlDisableStreamInputCallbacks() ;
+ xmlSecCryptoShutdown() ;
+ xmlSecShutdown() ;
+}
+
+/* XXMLSecurityContext */
+void SAL_CALL XMLSecurityContext_MSCryptImpl :: setSecurityEnvironment( const Reference< XSecurityEnvironment >& aSecurityEnvironment ) throw( com::sun::star::security::SecurityInfrastructureException ) {
+ HCERTSTORE hkeyStore ;
+ HCERTSTORE hCertStore ;
+ HCRYPTKEY symKey ;
+ HCRYPTKEY pubKey ;
+ HCRYPTKEY 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_MSCryptImpl* pSecEnv = ( SecurityEnvironment_MSCryptImpl* )xEnvTunnel->getSomething( SecurityEnvironment_MSCryptImpl::getUnoTunnelId() ) ;
+ if( pSecEnv == NULL )
+ throw RuntimeException() ;
+
+ hkeyStore = pSecEnv->getCryptoSlot() ;
+ hCertStore = pSecEnv->getCertDb() ;
+
+ /*-
+ * The following lines is based on the of xmlsec-mscrypto crypto engine
+ */
+ m_pKeysMngr = xmlSecMSCryptoAppliedKeysMngrCreate( hkeyStore , hCertStore ) ;
+ if( m_pKeysMngr == NULL )
+ throw RuntimeException() ;
+
+ /*-
+ * Adopt symmetric key into keys manager
+ */
+ for( i = 0 ; ( symKey = pSecEnv->getSymKey( i ) ) != NULL ; i ++ ) {
+ if( xmlSecMSCryptoAppliedKeysMngrSymKeyLoad( m_pKeysMngr, symKey ) < 0 ) {
+ throw RuntimeException() ;
+ }
+ }
+
+ /*-
+ * Adopt asymmetric public key into keys manager
+ */
+ for( i = 0 ; ( pubKey = pSecEnv->getPubKey( i ) ) != NULL ; i ++ ) {
+ if( xmlSecMSCryptoAppliedKeysMngrPubKeyLoad( m_pKeysMngr, pubKey ) < 0 ) {
+ throw RuntimeException() ;
+ }
+ }
+
+ /*-
+ * Adopt asymmetric private key into keys manager
+ */
+ for( i = 0 ; ( priKey = pSecEnv->getPriKey( i ) ) != NULL ; i ++ ) {
+ if( xmlSecMSCryptoAppliedKeysMngrPriKeyLoad( m_pKeysMngr, priKey ) < 0 ) {
+ throw RuntimeException() ;
+ }
+ }
+
+ /*-
+ * Adopt system default certificate store.
+ */
+ if( pSecEnv->defaultEnabled() ) {
+ HCERTSTORE hSystemStore ;
+
+ //Add system key store into the keys manager.
+ hSystemStore = CertOpenSystemStore( 0, "MY" ) ;
+ if( hSystemStore != NULL ) {
+ if( xmlSecMSCryptoAppliedKeysMngrAdoptKeyStore( m_pKeysMngr, hSystemStore ) < 0 ) {
+ CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ throw RuntimeException() ;
+ }
+ }
+
+ //Add system root store into the keys manager.
+ hSystemStore = CertOpenSystemStore( 0, "Root" ) ;
+ if( hSystemStore != NULL ) {
+ if( xmlSecMSCryptoAppliedKeysMngrAdoptTrustedStore( m_pKeysMngr, hSystemStore ) < 0 ) {
+ CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ throw RuntimeException() ;
+ }
+ }
+
+ //Add system trusted store into the keys manager.
+ hSystemStore = CertOpenSystemStore( 0, "Trust" ) ;
+ if( hSystemStore != NULL ) {
+ if( xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore( m_pKeysMngr, hSystemStore ) < 0 ) {
+ CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ throw RuntimeException() ;
+ }
+ }
+
+ //Add system CA store into the keys manager.
+ hSystemStore = CertOpenSystemStore( 0, "CA" ) ;
+ if( hSystemStore != NULL ) {
+ if( xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore( m_pKeysMngr, hSystemStore ) < 0 ) {
+ CertCloseStore( hSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
+ throw RuntimeException() ;
+ }
+ }
+ }
+}
+
+/* XXMLSecurityContext */
+Reference< XSecurityEnvironment > SAL_CALL XMLSecurityContext_MSCryptImpl :: getSecurityEnvironment()
+ throw (RuntimeException)
+{
+ return m_xSecurityEnvironment ;
+}
+
+/* XInitialization */
+void SAL_CALL XMLSecurityContext_MSCryptImpl :: initialize( const Sequence< Any >& aArguments ) throw( Exception, RuntimeException ) {
+ // TBD
+} ;
+
+/* XServiceInfo */
+OUString SAL_CALL XMLSecurityContext_MSCryptImpl :: getImplementationName() throw( RuntimeException ) {
+ return impl_getImplementationName() ;
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL XMLSecurityContext_MSCryptImpl :: 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_MSCryptImpl :: getSupportedServiceNames() throw( RuntimeException ) {
+ return impl_getSupportedServiceNames() ;
+}
+
+//Helper for XServiceInfo
+Sequence< OUString > XMLSecurityContext_MSCryptImpl :: 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_MSCryptImpl :: impl_getImplementationName() throw( RuntimeException ) {
+ return OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_MSCryptImpl" ) ;
+}
+
+//Helper for registry
+Reference< XInterface > SAL_CALL XMLSecurityContext_MSCryptImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
+ return Reference< XInterface >( *new XMLSecurityContext_MSCryptImpl( aServiceManager ) ) ;
+}
+
+Reference< XSingleServiceFactory > XMLSecurityContext_MSCryptImpl :: 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_MSCryptImpl :: 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_MSCryptImpl :: 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_MSCryptImpl* XMLSecurityContext_MSCryptImpl :: getImplementation( const Reference< XInterface > xObj ) {
+ Reference< XUnoTunnel > xUT( xObj , UNO_QUERY ) ;
+ if( xUT.is() ) {
+ return ( XMLSecurityContext_MSCryptImpl* )xUT->getSomething( getUnoTunnelId() ) ;
+ } else
+ return NULL ;
+}
+
+/* Native methods */
+xmlSecKeysMngrPtr XMLSecurityContext_MSCryptImpl :: keysManager() throw( Exception, RuntimeException ) {
+ return m_pKeysMngr ;
+}
+
diff --git a/xmlsecurity/source/xmlsec/mscrypt/xmlsecuritycontext_mscryptimpl.hxx b/xmlsecurity/source/xmlsec/mscrypt/xmlsecuritycontext_mscryptimpl.hxx
new file mode 100644
index 000000000000..bc8143350c27
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/xmlsecuritycontext_mscryptimpl.hxx
@@ -0,0 +1,174 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsecuritycontext_mscryptimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+ *
+ * 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_MSCRYPTIMPL_HXX_
+#define _XMLSIGNATURECONTEXT_MSCRYPTIMPL_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_MSCryptImpl : 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_MSCryptImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
+ virtual ~XMLSecurityContext_MSCryptImpl() ;
+
+ //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_MSCryptImpl* 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_MSCRYPTIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.cxx
new file mode 100644
index 000000000000..8e027e1a0022
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.cxx
@@ -0,0 +1,336 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsignature_mscryptimpl.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+ *
+ * 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_MSCRYPTIMPL_HXX_
+#include "xmlsignature_mscryptimpl.hxx"
+#endif
+
+#ifndef _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX_
+#include "xmldocumentwrapper_xmlsecimpl.hxx"
+#endif
+
+#ifndef _XMLELEMENTWRAPPER_XMLSECIMPL_HXX_
+#include "xmlelementwrapper_xmlsecimpl.hxx"
+#endif
+
+#ifndef _XMLSECURITYCONTEXT_MSCRYPTIMPL_HXX_
+#include "xmlsecuritycontext_mscryptimpl.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_MSCryptImpl :: XMLSignature_MSCryptImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_xServiceManager( aFactory ) {
+}
+
+XMLSignature_MSCryptImpl :: ~XMLSignature_MSCryptImpl() {
+}
+
+/* XXMLSignature */
+Reference< XXMLSignatureTemplate >
+SAL_CALL XMLSignature_MSCryptImpl :: 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_MSCryptImpl* pSecCtxt = ( XMLSecurityContext_MSCryptImpl* )xSecTunnel->getSomething( XMLSecurityContext_MSCryptImpl::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_MSCryptImpl :: 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_MSCryptImpl* pSecCtxt = ( XMLSecurityContext_MSCryptImpl* )xSecTunnel->getSomething( XMLSecurityContext_MSCryptImpl::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_MSCryptImpl :: initialize( const Sequence< Any >& aArguments ) throw( Exception, RuntimeException ) {
+ // TBD
+} ;
+
+/* XServiceInfo */
+OUString SAL_CALL XMLSignature_MSCryptImpl :: getImplementationName() throw( RuntimeException ) {
+ return impl_getImplementationName() ;
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL XMLSignature_MSCryptImpl :: 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_MSCryptImpl :: getSupportedServiceNames() throw( RuntimeException ) {
+ return impl_getSupportedServiceNames() ;
+}
+
+//Helper for XServiceInfo
+Sequence< OUString > XMLSignature_MSCryptImpl :: 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_MSCryptImpl :: impl_getImplementationName() throw( RuntimeException ) {
+ return OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLSignature_MSCryptImpl" ) ;
+}
+
+//Helper for registry
+Reference< XInterface > SAL_CALL XMLSignature_MSCryptImpl :: impl_createInstance( const Reference< XMultiServiceFactory >& aServiceManager ) throw( RuntimeException ) {
+ return Reference< XInterface >( *new XMLSignature_MSCryptImpl( aServiceManager ) ) ;
+}
+
+Reference< XSingleServiceFactory > XMLSignature_MSCryptImpl :: 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/mscrypt/xmlsignature_mscryptimpl.hxx b/xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.hxx
new file mode 100644
index 000000000000..8f401a86c824
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/xmlsignature_mscryptimpl.hxx
@@ -0,0 +1,165 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlsignature_mscryptimpl.hxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+ *
+ * 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_MSCRYPTIMPL_HXX_
+#define _XMLSIGNATURE_MSCRYPTIMPL_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_MSCryptImpl : 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_MSCryptImpl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& aFactory ) ;
+ virtual ~XMLSignature_MSCryptImpl() ;
+
+ //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_MSCRYPTIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/mscrypt/xsec_mscrypt.cxx b/xmlsecurity/source/xmlsec/mscrypt/xsec_mscrypt.cxx
new file mode 100644
index 000000000000..59e93dccde14
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/mscrypt/xsec_mscrypt.cxx
@@ -0,0 +1,198 @@
+/*************************************************************************
+ *
+ * $RCSfile: xsec_mscrypt.cxx,v $
+ *
+ * $Revision: 1.1.1.1 $
+ *
+ * last change: $Author: mt $ $Date: 2004-07-12 13:15:22 $
+ *
+ * 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_mscryptimpl.hxx"
+#include "xmlsignature_mscryptimpl.hxx"
+#include "xmlencryption_mscryptimpl.hxx"
+#include "xmlsecuritycontext_mscryptimpl.hxx"
+#include "securityenvironment_mscryptimpl.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 mscrypt_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_MSCryptImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += XMLSignature_MSCryptImpl::impl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = XMLSignature_MSCryptImpl::impl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+ // XMLEncryption_MSCryptImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += XMLEncryption_MSCryptImpl::impl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = XMLEncryption_MSCryptImpl::impl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+ // XMLSecurityContext_MSCryptImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += XMLSecurityContext_MSCryptImpl::impl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = XMLSecurityContext_MSCryptImpl::impl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+ // SecurityEnvironment_MSCryptImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += SecurityEnvironment_MSCryptImpl::impl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = SecurityEnvironment_MSCryptImpl::impl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+ // SEInitializer_MSCryptImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += SEInitializer_MSCryptImpl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = SEInitializer_MSCryptImpl_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 mscrypt_component_getFactory( const sal_Char* pImplName , void* pServiceManager , void* pRegistryKey )
+{
+ void* pRet = 0;
+ Reference< XSingleServiceFactory > xFactory ;
+
+ if( pImplName != NULL && pServiceManager != NULL ) {
+ if( XMLSignature_MSCryptImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
+ xFactory = XMLSignature_MSCryptImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+ } else if( XMLSecurityContext_MSCryptImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
+ xFactory = XMLSecurityContext_MSCryptImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+ } else if( SecurityEnvironment_MSCryptImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
+ xFactory = SecurityEnvironment_MSCryptImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+ } else if( XMLEncryption_MSCryptImpl::impl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
+ xFactory = XMLEncryption_MSCryptImpl::impl_createFactory( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ;
+ } else if( SEInitializer_MSCryptImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) ) {
+ xFactory = Reference< XSingleServiceFactory >( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ SEInitializer_MSCryptImpl_createInstance, SEInitializer_MSCryptImpl_getSupportedServiceNames() ) );
+ }
+ }
+
+ if( xFactory.is() ) {
+ xFactory->acquire() ;
+ pRet = xFactory.get() ;
+ }
+
+ return pRet ;
+}
+
+}
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 ;
+}
+
+}
+
diff --git a/xmlsecurity/source/xmlsec/saxhelper.cxx b/xmlsecurity/source/xmlsec/saxhelper.cxx
new file mode 100644
index 000000000000..b95c5baacce8
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/saxhelper.cxx
@@ -0,0 +1,465 @@
+/*************************************************************************
+ *
+ * $RCSfile: saxhelper.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 <rtl/ustring.hxx>
+
+#include "saxhelper.hxx"
+#include "libxml/parserInternals.h"
+
+#ifndef XMLSEC_NO_XSLT
+#include "libxslt/xslt.h"
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssxs = com::sun::star::xml::sax;
+namespace cssxcsax = com::sun::star::xml::csax;
+
+/**
+ * The return value is NULL terminated. The application has the responsibilty to
+ * deallocte the return value.
+ */
+xmlChar* ous_to_xmlstr( const rtl::OUString& oustr )
+{
+ rtl::OString ostr = rtl::OUStringToOString( oustr , RTL_TEXTENCODING_UTF8 ) ;
+ return xmlStrndup( ( xmlChar* )ostr.getStr(), ( int )ostr.getLength() ) ;
+}
+
+/**
+ * The return value is NULL terminated. The application has the responsibilty to
+ * deallocte the return value.
+ */
+xmlChar* ous_to_nxmlstr( const rtl::OUString& oustr, int& length )
+{
+ rtl::OString ostr = rtl::OUStringToOString( oustr , RTL_TEXTENCODING_UTF8 ) ;
+ length = ostr.getLength();
+
+ return xmlStrndup( ( xmlChar* )ostr.getStr(), length ) ;
+}
+
+/**
+ * The input parameter isn't necessaryly NULL terminated.
+ */
+rtl::OUString xmlchar_to_ous( const xmlChar* pChar, int length )
+{
+ if( pChar != NULL )
+ {
+ return rtl::OUString( ( sal_Char* )pChar , length , RTL_TEXTENCODING_UTF8 ) ;
+ }
+ else
+ {
+ return rtl::OUString() ;
+ }
+}
+
+/**
+ * The input parameter is NULL terminated
+ */
+rtl::OUString xmlstr_to_ous( const xmlChar* pStr )
+{
+ if( pStr != NULL )
+ {
+ return xmlchar_to_ous( pStr , xmlStrlen( pStr ) ) ;
+ }
+ else
+ {
+ return rtl::OUString() ;
+ }
+}
+
+/**
+ * The return value and the referenced value must be NULL terminated.
+ * The application has the responsibilty to deallocte the return value.
+ */
+const xmlChar** attrlist_to_nxmlstr( const cssu::Sequence< cssxcsax::XMLAttribute >& aAttributes )
+{
+ xmlChar* attname = NULL ;
+ xmlChar* attvalue = NULL ;
+ const xmlChar** attrs = NULL ;
+ rtl::OUString oustr ;
+
+ sal_Int32 nLength = aAttributes.getLength();;
+
+ if( nLength != 0 )
+ {
+ attrs = ( const xmlChar** )xmlMalloc( ( nLength * 2 + 2 ) * sizeof( xmlChar* ) ) ;
+ }
+ else
+ {
+ return NULL ;
+ }
+
+ for( int i = 0 , j = 0 ; j < nLength ; ++j )
+ {
+ attname = ous_to_xmlstr( aAttributes[j].sName ) ;
+ attvalue = ous_to_xmlstr( aAttributes[j].sValue ) ;
+
+ if( attname != NULL && attvalue != NULL )
+ {
+ attrs[i++] = attname ;
+ attrs[i++] = attvalue ;
+ attrs[i] = NULL ;
+ attrs[i+1] = NULL ;
+ }
+ else
+ {
+ if( attname != NULL )
+ xmlFree( attname ) ;
+ if( attvalue != NULL )
+ xmlFree( attvalue ) ;
+ }
+ }
+
+ return attrs ;
+}
+
+/**
+ * Constructor
+ *
+ * In this constructor, a libxml sax parser context is initialized. a libxml
+ * default sax handler is initialized with the context.
+ */
+SAXHelper::SAXHelper( )
+ : m_pParserCtxt( NULL ),
+ m_pSaxHandler( NULL )
+{
+ xmlInitParser() ;
+ LIBXML_TEST_VERSION ;
+
+ /*
+ * compile error:
+ * xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS ;
+ */
+ xmlSubstituteEntitiesDefault( 1 ) ;
+
+#ifndef XMLSEC_NO_XSLT
+ xmlIndentTreeOutput = 1 ;
+#endif /* XMLSEC_NO_XSLT */
+
+ m_pParserCtxt = xmlNewParserCtxt() ;
+ if( m_pParserCtxt->inputTab[0] != NULL )
+ {
+ m_pParserCtxt->inputTab[0] = NULL ;
+ }
+
+ if( m_pParserCtxt == NULL )
+ {
+#ifndef XMLSEC_NO_XSLT
+ xsltCleanupGlobals() ;
+#endif
+ xmlCleanupParser() ;
+ throw cssu::RuntimeException() ;
+ }
+ else if( m_pParserCtxt->sax == NULL )
+ {
+ xmlFreeParserCtxt( m_pParserCtxt ) ;
+
+#ifndef XMLSEC_NO_XSLT
+ xsltCleanupGlobals() ;
+#endif
+ xmlCleanupParser() ;
+ m_pParserCtxt = NULL ;
+ throw cssu::RuntimeException() ;
+ }
+ else
+ {
+ m_pSaxHandler = m_pParserCtxt->sax ;
+
+ //Adjust the context
+ m_pParserCtxt->recovery = 1 ;
+ }
+}
+
+/**
+ * Destructor
+ *
+ * In this destructor, a libxml sax parser context is desturcted. The XML tree
+ * in the context is not deallocated because the tree is bind with a document
+ * model by the setTargetDocument method, which delegate the target document to
+ * destruct the xml tree.
+ */
+SAXHelper::~SAXHelper() {
+ if( m_pParserCtxt != NULL )
+ {
+ /*
+ * In the situation that no object refer the Document, this destructor
+ * must deallocate the Document memory
+ */
+ if( m_pSaxHandler == m_pParserCtxt->sax )
+ {
+ m_pSaxHandler = NULL ;
+ }
+
+ xmlFreeParserCtxt( m_pParserCtxt ) ;
+ m_pParserCtxt = NULL ;
+ }
+
+ if( m_pSaxHandler != NULL )
+ {
+ xmlFree( m_pSaxHandler ) ;
+ m_pSaxHandler = NULL ;
+ }
+
+ xmlCleanupParser() ;
+}
+
+xmlNodePtr SAXHelper::getCurrentNode()
+{
+ return m_pParserCtxt->node;
+}
+
+void SAXHelper::setCurrentNode(const xmlNodePtr pNode)
+{
+ /*
+ * This is really a black trick.
+ * When the current node is replaced, the nodeTab
+ * stack's top has to been replaced with the same
+ * node, in order to make compatibility.
+ */
+ m_pParserCtxt->nodeTab[m_pParserCtxt->nodeNr - 1]
+ = m_pParserCtxt->node
+ = pNode;
+}
+
+xmlDocPtr SAXHelper::getDocument()
+{
+ return m_pParserCtxt->myDoc;
+}
+
+/**
+ * XDocumentHandler -- start an xml document
+ */
+void SAXHelper::startDocument( void )
+ throw( cssxs::SAXException , cssu::RuntimeException )
+{
+ /*
+ * Adjust inputTab
+ */
+ xmlParserInputPtr pInput = xmlNewInputStream( m_pParserCtxt ) ;
+
+ if( m_pParserCtxt->inputTab != NULL && m_pParserCtxt->inputMax != 0 )
+ {
+ m_pParserCtxt->inputTab[0] = pInput ;
+ m_pParserCtxt->input = pInput ;
+ }
+
+ m_pSaxHandler->startDocument( m_pParserCtxt ) ;
+
+ if( m_pParserCtxt == NULL || m_pParserCtxt->myDoc == NULL )
+ {
+ throw cssu::RuntimeException() ;
+ }
+}
+
+/**
+ * XDocumentHandler -- end an xml document
+ */
+void SAXHelper::endDocument( void )
+ throw( cssxs::SAXException , cssu::RuntimeException )
+{
+ m_pSaxHandler->endDocument( m_pParserCtxt ) ;
+}
+
+/**
+ * XDocumentHandler -- start an xml element
+ */
+void SAXHelper::startElement(
+ const rtl::OUString& aName,
+ const cssu::Sequence< cssxcsax::XMLAttribute >& aAttributes )
+ throw( cssxs::SAXException , cssu::RuntimeException )
+{
+ const xmlChar* fullName = NULL ;
+ const xmlChar** attrs = NULL ;
+
+ fullName = ous_to_xmlstr( aName ) ;
+ attrs = attrlist_to_nxmlstr( aAttributes ) ;
+
+ if( fullName != NULL || attrs != NULL )
+ {
+ m_pSaxHandler->startElement( m_pParserCtxt , fullName , attrs ) ;
+ }
+
+ if( fullName != NULL )
+ {
+ xmlFree( ( xmlChar* )fullName ) ;
+ fullName = NULL ;
+ }
+
+ if( attrs != NULL )
+ {
+ for( int i = 0 ; attrs[i] != NULL ; ++i )
+ {
+ xmlFree( ( xmlChar* )attrs[i] ) ;
+ attrs[i] = NULL ;
+ }
+
+ xmlFree( ( void* ) attrs ) ;
+ attrs = NULL ;
+ }
+}
+
+/**
+ * XDocumentHandler -- end an xml element
+ */
+void SAXHelper::endElement( const rtl::OUString& aName )
+ throw( cssxs::SAXException , cssu::RuntimeException )
+{
+ xmlChar* fullname = NULL ;
+
+ fullname = ous_to_xmlstr( aName ) ;
+ m_pSaxHandler->endElement( m_pParserCtxt , fullname ) ;
+
+ if( fullname != NULL )
+ {
+ xmlFree( ( xmlChar* )fullname ) ;
+ fullname = NULL ;
+ }
+}
+
+/**
+ * XDocumentHandler -- an xml element or cdata characters
+ */
+void SAXHelper::characters( const rtl::OUString& aChars )
+ throw( cssxs::SAXException , cssu::RuntimeException )
+{
+ const xmlChar* chars = NULL ;
+ int length = 0 ;
+
+ chars = ous_to_nxmlstr( aChars, length ) ;
+ m_pSaxHandler->characters( m_pParserCtxt , chars , length ) ;
+
+ if( chars != NULL )
+ {
+ xmlFree( ( xmlChar* )chars ) ;
+ }
+}
+
+/**
+ * XDocumentHandler -- ignorable xml white space
+ */
+void SAXHelper::ignorableWhitespace( const rtl::OUString& aWhitespaces )
+ throw( cssxs::SAXException , cssu::RuntimeException )
+{
+ const xmlChar* chars = NULL ;
+ int length = 0 ;
+
+ chars = ous_to_nxmlstr( aWhitespaces, length ) ;
+ m_pSaxHandler->ignorableWhitespace( m_pParserCtxt , chars , length ) ;
+
+ if( chars != NULL )
+ {
+ xmlFree( ( xmlChar* )chars ) ;
+ }
+}
+
+/**
+ * XDocumentHandler -- preaorocessing instruction
+ */
+void SAXHelper::processingInstruction(
+ const rtl::OUString& aTarget,
+ const rtl::OUString& aData )
+ throw( cssxs::SAXException , cssu::RuntimeException )
+{
+ xmlChar* target = NULL ;
+ xmlChar* data = NULL ;
+
+ target = ous_to_xmlstr( aTarget ) ;
+ data = ous_to_xmlstr( aData ) ;
+
+ m_pSaxHandler->processingInstruction( m_pParserCtxt , target , data ) ;
+
+ if( target != NULL )
+ {
+ xmlFree( ( xmlChar* )target ) ;
+ target = NULL ;
+ }
+
+ if( data != NULL )
+ {
+ xmlFree( ( xmlChar* )data ) ;
+ data = NULL ;
+ }
+}
+
+/**
+ * XDocumentHandler -- set document locator
+ * In this case, locator is useless.
+ */
+void SAXHelper::setDocumentLocator(
+ const cssu::Reference< cssxs::XLocator > & xLocator )
+ throw( cssxs::SAXException , cssu::RuntimeException )
+{
+ //--Pseudo code if necessary
+ //--m_pSaxLocator is a member defined as xmlSAXHabdlerPtr
+ //--m_pSaxLocatorHdl is a member defined as Sax_Locator
+
+ //if( m_pSaxLocator != NULL ) {
+ // //Deallocate the memory
+ //}
+ //if( m_pSaxLocatorHdl != NULL ) {
+ // //Deallocate the memory
+ //}
+
+ //m_pSaxLocatorHdl = new Sax_Locator( xLocator ) ;
+ //m_pSaxLocator = { m_pSaxLocatorHdl->getPublicId , m_pSaxLocatorHdl->getSystemId , m_pSaxLocatorHdl->getLineNumber , m_pSaxLocatorHdl->getColumnNumber } ;
+
+ //m_pSaxHandler->setDocumentLocator( m_pParserCtxt , m_pSaxLocator ) ;
+}
+
diff --git a/xmlsecurity/source/xmlsec/saxhelper.hxx b/xmlsecurity/source/xmlsec/saxhelper.hxx
new file mode 100644
index 000000000000..2642c05177c5
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/saxhelper.hxx
@@ -0,0 +1,123 @@
+/*************************************************************************
+ *
+ * $RCSfile: saxhelper.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 _SAXHELPER_HXX
+#define _SAXHELPER_HXX
+
+#include "libxml/tree.h"
+
+#include <com/sun/star/xml/sax/SAXException.hpp>
+#include <com/sun/star/xml/sax/XAttributeList.hpp>
+#include <com/sun/star/xml/sax/XLocator.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+
+#ifndef _COM_SUN_STAR_XML_CSAX_XMLATTRIBUTE_HPP_
+#include <com/sun/star/xml/csax/XMLAttribute.hpp>
+#endif
+
+
+class SAXHelper
+{
+ private :
+ xmlParserCtxtPtr m_pParserCtxt ;
+ xmlSAXHandlerPtr m_pSaxHandler ;
+
+ public:
+ SAXHelper( ) ;
+ virtual ~SAXHelper() ;
+
+ xmlNodePtr getCurrentNode();
+ void setCurrentNode(const xmlNodePtr pNode);
+ xmlDocPtr getDocument();
+
+ void startDocument( void )
+ throw( ::com::sun::star::xml::sax::SAXException , ::com::sun::star::uno::RuntimeException ) ;
+
+ void endDocument( void )
+ throw( ::com::sun::star::xml::sax::SAXException , ::com::sun::star::uno::RuntimeException ) ;
+
+ void startElement(
+ const ::rtl::OUString& aName ,
+ const com::sun::star::uno::Sequence<
+ com::sun::star::xml::csax::XMLAttribute >& aAttributes )
+ throw( ::com::sun::star::xml::sax::SAXException , ::com::sun::star::uno::RuntimeException ) ;
+
+ void endElement( const ::rtl::OUString& aName )
+ throw( ::com::sun::star::xml::sax::SAXException , ::com::sun::star::uno::RuntimeException ) ;
+
+ void characters( const ::rtl::OUString& aChars )
+ throw( ::com::sun::star::xml::sax::SAXException , ::com::sun::star::uno::RuntimeException ) ;
+
+ void ignorableWhitespace( const ::rtl::OUString& aWhitespaces )
+ throw( ::com::sun::star::xml::sax::SAXException , ::com::sun::star::uno::RuntimeException ) ;
+
+ void processingInstruction(
+ const ::rtl::OUString& aTarget ,
+ const ::rtl::OUString& aData )
+ throw( ::com::sun::star::xml::sax::SAXException , ::com::sun::star::uno::RuntimeException ) ;
+
+ void setDocumentLocator( const ::com::sun::star::uno::Reference<
+ ::com::sun::star::xml::sax::XLocator > & xLocator )
+ throw( ::com::sun::star::xml::sax::SAXException , ::com::sun::star::uno::RuntimeException ) ;
+} ;
+
+#endif
+
diff --git a/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx b/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx
new file mode 100644
index 000000000000..795ac4a8d225
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.cxx
@@ -0,0 +1,1187 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmldocumentwrapper_xmlsecimpl.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 "xmldocumentwrapper_xmlsecimpl.hxx"
+
+#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#endif
+
+#include <xmloff/attrlist.hxx>
+#include "xmlelementwrapper_xmlsecimpl.hxx"
+
+#include <malloc.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * Deleted by AF
+#include <memory.h>
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifndef INCLUDED_VECTOR
+#include <vector>
+#define INCLUDED_VECTOR
+#endif
+
+#ifdef UNX
+#define stricmp strcasecmp
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+namespace cssxc = com::sun::star::xml::crypto;
+namespace cssxcsax = com::sun::star::xml::csax;
+namespace cssxs = com::sun::star::xml::sax;
+namespace cssxw = com::sun::star::xml::wrapper;
+
+#define SERVICE_NAME "com.sun.star.xml.wrapper.XMLDocumentWrapper"
+#define IMPLEMENTATION_NAME "com.sun.star.xml.security.bridge.xmlsec.XMLDocumentWrapper_XmlSecImpl"
+
+#define STRXMLNS "xmlns"
+
+#define RTL_ASCII_USTRINGPARAM( asciiStr ) asciiStr, strlen( asciiStr ), RTL_TEXTENCODING_ASCII_US
+#define RTL_UTF8_USTRINGPARAM( asciiStr ) asciiStr, strlen( asciiStr ), RTL_TEXTENCODING_UTF8
+
+/* used by the recursiveDelete method */
+#define NODE_REMOVED 0
+#define NODE_NOTREMOVED 1
+#define NODE_STOPED 2
+
+XMLDocumentWrapper_XmlSecImpl::XMLDocumentWrapper_XmlSecImpl( )
+{
+ saxHelper.startDocument();
+ m_pDocument = saxHelper.getDocument();
+
+ /*
+ * creates the virtual root element
+ */
+ saxHelper.startElement(rtl::OUString(RTL_UTF8_USTRINGPARAM( "root" )), NULL);
+
+ m_pRootElement = saxHelper.getCurrentNode();
+ m_pCurrentElement = m_pRootElement;
+}
+
+XMLDocumentWrapper_XmlSecImpl::~XMLDocumentWrapper_XmlSecImpl()
+{
+ saxHelper.endDocument();
+ xmlFreeDoc(m_pDocument);
+}
+
+void XMLDocumentWrapper_XmlSecImpl::getNextSAXEvent()
+/****** XMLDocumentWrapper_XmlSecImpl/getNextSAXEvent *************************
+ *
+ * NAME
+ * getNextSAXEvent -- Prepares the next SAX event to be manipulate
+ *
+ * SYNOPSIS
+ * getNextSAXEvent();
+ *
+ * FUNCTION
+ * When converting the document into SAX events, this method is used to
+ * decide the next SAX event to be generated.
+ * Two member variables are checked to make the decision, the
+ * m_pCurrentElement and the m_nCurrentPosition.
+ * The m_pCurrentElement represents the node which have been covered, and
+ * the m_nCurrentPosition represents the event which have been sent.
+ * For example, suppose that the m_pCurrentElement
+ * points to element A, and the m_nCurrentPosition equals to
+ * NODEPOSITION_STARTELEMENT, then the next SAX event should be the
+ * endElement for element A if A has no child, or startElement for the
+ * first child element of element A otherwise.
+ * The m_nCurrentPosition can be one of following values:
+ * NODEPOSITION_STARTELEMENT for startElement;
+ * NODEPOSITION_ENDELEMENT for endElement;
+ * NODEPOSITION_NORMAL for other SAX events;
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ OSL_ASSERT( m_pCurrentElement != NULL );
+
+ /*
+ * Get the next event through tree order.
+ *
+ * if the current event is a startElement, then the next
+ * event depends on whether or not the current node has
+ * children.
+ */
+ if (m_nCurrentPosition == NODEPOSITION_STARTELEMENT)
+ {
+ /*
+ * If the current node has children, then its first child
+ * should be next current node, and the next event will be
+ * startElement or charaters(PI) based on that child's node
+ * type. Otherwise, the endElement of current node is the
+ * next event.
+ */
+ if (m_pCurrentElement->children != NULL)
+ {
+ m_pCurrentElement = m_pCurrentElement->children;
+ m_nCurrentPosition
+ = (m_pCurrentElement->type == XML_ELEMENT_NODE)?
+ NODEPOSITION_STARTELEMENT:NODEPOSITION_NORMAL;
+ }
+ else
+ {
+ m_nCurrentPosition = NODEPOSITION_ENDELEMENT;
+ }
+ }
+ /*
+ * if the current event is a not startElement, then the next
+ * event depends on whether or not the current node has
+ * following sibling.
+ */
+ else if (m_nCurrentPosition == NODEPOSITION_ENDELEMENT || m_nCurrentPosition == NODEPOSITION_NORMAL)
+ {
+ xmlNodePtr pNextSibling = m_pCurrentElement->next;
+
+ /*
+ * If the current node has following sibling, that sibling
+ * should be next current node, and the next event will be
+ * startElement or charaters(PI) based on that sibling's node
+ * type. Otherwise, the endElement of current node's parent
+ * becomes the next event.
+ */
+ if (pNextSibling != NULL)
+ {
+ m_pCurrentElement = pNextSibling;
+ m_nCurrentPosition
+ = (m_pCurrentElement->type == XML_ELEMENT_NODE)?
+ NODEPOSITION_STARTELEMENT:NODEPOSITION_NORMAL;
+ }
+ else
+ {
+ m_pCurrentElement = m_pCurrentElement->parent;
+ m_nCurrentPosition = NODEPOSITION_ENDELEMENT;
+ }
+ }
+}
+
+void XMLDocumentWrapper_XmlSecImpl::sendStartElement(
+ const cssu::Reference< cssxs::XDocumentHandler >& xHandler,
+ const cssu::Reference< cssxs::XDocumentHandler >& xHandler2,
+ const xmlNodePtr pNode) const
+ throw (cssxs::SAXException)
+/****** XMLDocumentWrapper_XmlSecImpl/sendStartElement ************************
+ *
+ * NAME
+ * sendStartElement -- Constructs a startElement SAX event
+ *
+ * SYNOPSIS
+ * sendStartElement(xHandler, xHandler2, pNode);
+ *
+ * FUNCTION
+ * Used when converting the document into SAX event stream.
+ * This method constructs a startElement SAX event for a particular
+ * element, then calls the startElement methods of the XDocumentHandlers.
+ *
+ * INPUTS
+ * xHandler - the first XDocumentHandler interface to receive the
+ * startElement SAX event. It can be NULL.
+ * xHandler2 - the second XDocumentHandler interface to receive the
+ * startElement SAX event. It can't be NULL.
+ * pNode - the node on which the startElement should be generated.
+ * This node must be a element type.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ SvXMLAttributeList* pAttributeList = new SvXMLAttributeList();
+ cssu::Reference < cssxs::XAttributeList > xAttrList = cssu::Reference< cssxs::XAttributeList > (pAttributeList);
+
+ xmlNsPtr pNsDef = pNode->nsDef;
+
+ while (pNsDef != NULL)
+ {
+ const xmlChar* pNsPrefix = pNsDef->prefix;
+ const xmlChar* pNsHref = pNsDef->href;
+
+ if (pNsDef->prefix == NULL)
+ {
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_UTF8_USTRINGPARAM( STRXMLNS )),
+ rtl::OUString(RTL_UTF8_USTRINGPARAM( (sal_Char*)pNsHref )));
+ }
+ else
+ {
+ pAttributeList->AddAttribute(
+ rtl::OUString(RTL_UTF8_USTRINGPARAM( STRXMLNS ))
+ +rtl::OUString(RTL_UTF8_USTRINGPARAM( ":" ))
+ +rtl::OUString(RTL_UTF8_USTRINGPARAM( (sal_Char*)pNsPrefix )),
+ rtl::OUString(RTL_UTF8_USTRINGPARAM( (sal_Char*)pNsHref )));
+ }
+
+ pNsDef = pNsDef->next;
+ }
+
+ xmlAttrPtr pAttr = pNode->properties;
+
+ while (pAttr != NULL)
+ {
+ const xmlChar* pAttrName = pAttr->name;
+ xmlNsPtr pAttrNs = pAttr->ns;
+
+ rtl::OUString ouAttrName;
+ if (pAttrNs == NULL)
+ {
+ ouAttrName = rtl::OUString(RTL_UTF8_USTRINGPARAM( (sal_Char*)pAttrName ));
+ }
+ else
+ {
+ ouAttrName = rtl::OUString(RTL_UTF8_USTRINGPARAM( (sal_Char*)pAttrNs->prefix))
+ +rtl::OUString(RTL_UTF8_USTRINGPARAM( (sal_Char*)":" ))
+ +rtl::OUString(RTL_UTF8_USTRINGPARAM( (sal_Char*)pAttrName ));
+ }
+
+ pAttributeList->AddAttribute(
+ ouAttrName,
+ rtl::OUString(RTL_UTF8_USTRINGPARAM( (sal_Char*)(pAttr->children->content))));
+ pAttr = pAttr->next;
+ }
+
+ rtl::OString sNodeName = getNodeQName(pNode);
+
+ if (xHandler.is())
+ {
+ xHandler->startElement(
+ rtl::OUString(RTL_UTF8_USTRINGPARAM ( ((sal_Char*)(sNodeName.getStr())) )),
+ xAttrList);
+ }
+
+ xHandler2->startElement(
+ rtl::OUString(RTL_UTF8_USTRINGPARAM ( ((sal_Char*)(sNodeName.getStr())) )),
+ xAttrList);
+}
+
+void XMLDocumentWrapper_XmlSecImpl::sendEndElement(
+ const cssu::Reference< cssxs::XDocumentHandler >& xHandler,
+ const cssu::Reference< cssxs::XDocumentHandler >& xHandler2,
+ const xmlNodePtr pNode) const
+ throw (cssxs::SAXException)
+/****** XMLDocumentWrapper_XmlSecImpl/sendEndElement **************************
+ *
+ * NAME
+ * sendEndElement -- Constructs a endElement SAX event
+ *
+ * SYNOPSIS
+ * sendEndElement(xHandler, xHandler2, pNode);
+ *
+ * FUNCTION
+ * Used when converting the document into SAX event stream.
+ * This method constructs a endElement SAX event for a particular
+ * element, then calls the endElement methods of the XDocumentHandlers.
+ *
+ * INPUTS
+ * xHandler - the first XDocumentHandler interface to receive the
+ * endElement SAX event. It can be NULL.
+ * xHandler2 - the second XDocumentHandler interface to receive the
+ * endElement SAX event. It can't be NULL.
+ * pNode - the node on which the endElement should be generated.
+ * This node must be a element type.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ rtl::OString sNodeName = getNodeQName(pNode);
+
+ if (xHandler.is())
+ {
+ xHandler->endElement(rtl::OUString(RTL_UTF8_USTRINGPARAM ( ((sal_Char*)(sNodeName.getStr())) )));
+ }
+
+ xHandler2->endElement(rtl::OUString(RTL_UTF8_USTRINGPARAM ( ((sal_Char*)(sNodeName.getStr())) )));
+}
+
+void XMLDocumentWrapper_XmlSecImpl::sendNode(
+ const cssu::Reference< cssxs::XDocumentHandler >& xHandler,
+ const cssu::Reference< cssxs::XDocumentHandler >& xHandler2,
+ const xmlNodePtr pNode) const
+ throw (cssxs::SAXException)
+/****** XMLDocumentWrapper_XmlSecImpl/sendNode ********************************
+ *
+ * NAME
+ * sendNode -- Constructs a characters SAX event or a
+ * processingInstruction SAX event
+ *
+ * SYNOPSIS
+ * sendNode(xHandler, xHandler2, pNode);
+ *
+ * FUNCTION
+ * Used when converting the document into SAX event stream.
+ * This method constructs a characters SAX event or a
+ * processingInstructionfor SAX event based on the type of a particular
+ * element, then calls the corresponding methods of the XDocumentHandlers.
+ *
+ * INPUTS
+ * xHandler - the first XDocumentHandler interface to receive the
+ * SAX event. It can be NULL.
+ * xHandler2 - the second XDocumentHandler interface to receive the
+ * SAX event. It can't be NULL.
+ * pNode - the node on which the endElement should be generated.
+ * If it is a text node, then a characters SAX event is
+ * generated; if it is a PI node, then a
+ * processingInstructionfor SAX event is generated.
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ xmlElementType type = pNode->type;
+
+ if (type == XML_TEXT_NODE)
+ {
+ if (xHandler.is())
+ {
+ xHandler->characters(rtl::OUString(RTL_UTF8_USTRINGPARAM ( ((sal_Char*)(pNode->content)) )));
+ }
+
+ xHandler2->characters(rtl::OUString(RTL_UTF8_USTRINGPARAM ( ((sal_Char*)(pNode->content)) )));
+ }
+ else if (type == XML_PI_NODE)
+ {
+ if (xHandler.is())
+ {
+ xHandler->processingInstruction(
+ rtl::OUString(RTL_UTF8_USTRINGPARAM ( ((sal_Char*)(pNode->name)) )),
+ rtl::OUString(RTL_UTF8_USTRINGPARAM ( ((sal_Char*)(pNode->content)) )));
+ }
+
+ xHandler2->processingInstruction(
+ rtl::OUString(RTL_UTF8_USTRINGPARAM ( ((sal_Char*)(pNode->name)) )),
+ rtl::OUString(RTL_UTF8_USTRINGPARAM ( ((sal_Char*)(pNode->content)) )));
+ }
+}
+
+rtl::OString XMLDocumentWrapper_XmlSecImpl::getNodeQName(const xmlNodePtr pNode) const
+/****** XMLDocumentWrapper_XmlSecImpl/getNodeQName ****************************
+ *
+ * NAME
+ * getNodeQName -- Retrives the qualified name of a node
+ *
+ * SYNOPSIS
+ * name = getNodeQName(pNode);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pNode - the node whose name will be retrived
+ *
+ * RESULT
+ * name - the node's qualified name
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ rtl::OString sNodeName((const sal_Char*)pNode->name);
+ if (pNode->ns != NULL)
+ {
+ xmlNsPtr pNs = pNode->ns;
+
+ if (pNs->prefix != NULL)
+ {
+ rtl::OString sPrefix((const sal_Char*)pNs->prefix);
+ sNodeName = sPrefix+rtl::OString(":")+sNodeName;
+ }
+ }
+
+ return sNodeName;
+}
+
+xmlNodePtr XMLDocumentWrapper_XmlSecImpl::checkElement( const cssu::Reference< cssxw::XXMLElementWrapper >& xXMLElement) const
+/****** XMLDocumentWrapper_XmlSecImpl/checkElement ****************************
+ *
+ * NAME
+ * checkElement -- Retrives the node wrapped by an XXMLElementWrapper
+ * interface
+ *
+ * SYNOPSIS
+ * node = checkElement(xXMLElement);
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * xXMLElement - the XXMLElementWrapper interface wraping a node
+ *
+ * RESULT
+ * node - the node wrapped in the XXMLElementWrapper interface
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ xmlNodePtr rc = NULL;
+
+ if (xXMLElement.is())
+ {
+ cssu::Reference< cssl::XUnoTunnel > xNodTunnel( xXMLElement, cssu::UNO_QUERY ) ;
+ if( !xNodTunnel.is() )
+ {
+ throw cssu::RuntimeException() ;
+ }
+
+ XMLElementWrapper_XmlSecImpl* pElement
+ = ( XMLElementWrapper_XmlSecImpl* )xNodTunnel->getSomething(
+ XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
+
+ if( pElement == NULL ) {
+ throw cssu::RuntimeException() ;
+ }
+
+ rc = pElement->getNativeElement();
+ }
+
+ return rc;
+}
+
+sal_Int32 XMLDocumentWrapper_XmlSecImpl::recursiveDelete(
+ const xmlNodePtr pNode)
+/****** XMLDocumentWrapper_XmlSecImpl/recursiveDelete *************************
+ *
+ * NAME
+ * recursiveDelete -- Deletes a paticular node with its branch.
+ *
+ * SYNOPSIS
+ * result = recursiveDelete(pNode);
+ *
+ * FUNCTION
+ * Deletes a paticular node with its branch, while reserving the nodes
+ * (and their brance) listed in the m_aReservedNodes.
+ * The deletion process is preformed in the tree order, that is, a node
+ * is deleted after its previous sibling node is deleted, a parent node
+ * is deleted after its branch is deleted.
+ * During the deletion process when the m_pStopAtNode is reached, the
+ * progress is interrupted at once.
+ *
+ * INPUTS
+ * pNode - the node to be deleted
+ *
+ * RESULT
+ * result - the result of the deletion process, can be one of following
+ * values:
+ * NODE_STOPED - the process is interrupted by meeting the
+ * m_pStopAtNode
+ * NODE_NOTREMOVED - the pNode is not completely removed
+ * because there is its descendant in the
+ * m_aReservedNodes list
+ * NODE_REMOVED - the pNode and its branch are completely
+ * removed
+ *
+ * NOTES
+ * The node in the m_aReservedNodes list must be in the tree order, otherwise
+ * the result is unpredictable.
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (pNode == m_pStopAtNode)
+ {
+ return NODE_STOPED;
+ }
+
+ if (pNode != m_pCurrentReservedNode)
+ {
+ xmlNodePtr pChild = pNode->children;
+
+ xmlNodePtr pNextSibling;
+ bool bIsRemoved = true;
+ sal_Int32 nResult;
+
+ while( pChild != NULL )
+ {
+ pNextSibling = pChild->next;
+ nResult = recursiveDelete(pChild);
+
+ switch (nResult)
+ {
+ case NODE_STOPED:
+ return NODE_STOPED;
+ case NODE_NOTREMOVED:
+ bIsRemoved = false;
+ break;
+ case NODE_REMOVED:
+ removeNode(pChild);
+ break;
+ default:
+ throw cssu::RuntimeException();
+ break;
+ }
+
+ pChild = pNextSibling;
+ }
+
+ if (pNode == m_pCurrentElement)
+ {
+ bIsRemoved = false;
+ }
+
+ return bIsRemoved?NODE_REMOVED:NODE_NOTREMOVED;
+ }
+ else
+ {
+ getNextReservedNode();
+ return NODE_NOTREMOVED;
+ }
+}
+
+void XMLDocumentWrapper_XmlSecImpl::getNextReservedNode()
+/****** XMLDocumentWrapper_XmlSecImpl/getNextReservedNode *********************
+ *
+ * NAME
+ * getNextReservedNode -- Highlights the next reserved node in the
+ * reserved node list
+ *
+ * SYNOPSIS
+ * getNextReservedNode();
+ *
+ * FUNCTION
+ * The m_aReservedNodes array holds a node list, while the
+ * m_pCurrentReservedNode points to the one currently highlighted.
+ * This method is used to highlight the next node in the node list.
+ * This method is called at the time when the current highlighted node
+ * has been already processed, and the next node should be ready.
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (m_nReservedNodeIndex < m_aReservedNodes.getLength())
+ {
+ m_pCurrentReservedNode = checkElement( m_aReservedNodes[m_nReservedNodeIndex] );
+ m_nReservedNodeIndex ++;
+ }
+ else
+ {
+ m_pCurrentReservedNode = NULL;
+ }
+}
+
+void XMLDocumentWrapper_XmlSecImpl::removeNode(const xmlNodePtr pNode) const
+/****** XMLDocumentWrapper_XmlSecImpl/removeNode ******************************
+ *
+ * NAME
+ * removeNode -- Deletes a node with its branch unconditionaly
+ *
+ * SYNOPSIS
+ * removeNode( pNode );
+ *
+ * FUNCTION
+ * Delete the node along with its branch from the document.
+ *
+ * INPUTS
+ * pNode - the node to be deleted
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ /* you can't remove the current node */
+ OSL_ASSERT( m_pCurrentElement != pNode );
+
+ xmlAttrPtr pAttr = pNode->properties;
+
+ while (pAttr != NULL)
+ {
+ if (!stricmp((sal_Char*)pAttr->name,"id"))
+ {
+ xmlRemoveID(m_pDocument, pAttr);
+ }
+
+ pAttr = pAttr->next;
+ }
+
+ xmlUnlinkNode(pNode);
+ xmlFreeNode(pNode);
+}
+
+void XMLDocumentWrapper_XmlSecImpl::buildIDAttr(xmlNodePtr pNode) const
+/****** XMLDocumentWrapper_XmlSecImpl/buildIDAttr *****************************
+ *
+ * NAME
+ * buildIDAttr -- build the ID attribute of a node
+ *
+ * SYNOPSIS
+ * buildIDAttr( pNode );
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pNode - the node whose id attribute will be built
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 14.06.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ xmlAttrPtr idAttr = xmlHasProp( pNode, (const unsigned char *)"id" );
+ if (idAttr == NULL)
+ {
+ idAttr = xmlHasProp( pNode, (const unsigned char *)"Id" );
+ }
+
+ if (idAttr != NULL)
+ {
+ xmlChar* idValue = xmlNodeListGetString( m_pDocument, idAttr->children, 1 ) ;
+ xmlAddID( NULL, m_pDocument, idValue, idAttr );
+ }
+}
+
+void XMLDocumentWrapper_XmlSecImpl::rebuildIDLink(xmlNodePtr pNode) const
+/****** XMLDocumentWrapper_XmlSecImpl/rebuildIDLink ***************************
+ *
+ * NAME
+ * rebuildIDLink -- rebuild the ID link for the branch
+ *
+ * SYNOPSIS
+ * rebuildIDLink( pNode );
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pNode - the node, from which the branch will be rebuilt
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 14.06.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ if (pNode != NULL && pNode->type == XML_ELEMENT_NODE)
+ {
+ buildIDAttr( pNode );
+
+ xmlNodePtr child = pNode->children;
+ while (child != NULL)
+ {
+ rebuildIDLink(child);
+ child = child->next;
+ }
+ }
+}
+
+/* XXMLDocumentWrapper */
+cssu::Reference< cssxw::XXMLElementWrapper > SAL_CALL XMLDocumentWrapper_XmlSecImpl::getCurrentElement( )
+ throw (cssu::RuntimeException)
+{
+ XMLElementWrapper_XmlSecImpl* pElement = new XMLElementWrapper_XmlSecImpl(m_pCurrentElement);
+ return (cssu::Reference< cssxw::XXMLElementWrapper >)pElement;
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::setCurrentElement( const cssu::Reference< cssxw::XXMLElementWrapper >& element )
+ throw (cssu::RuntimeException)
+{
+ m_pCurrentElement = checkElement( element );
+ saxHelper.setCurrentNode( m_pCurrentElement );
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::removeCurrentElement( )
+ throw (cssu::RuntimeException)
+{
+ OSL_ASSERT( m_pCurrentElement != NULL );
+
+ xmlNodePtr pOldCurrentElement = m_pCurrentElement;
+
+ /*
+ * pop the top node in the parser context's
+ * nodeTab stack, then the parent of that node will
+ * automatically become the new stack top, and
+ * the current node as well.
+ */
+ saxHelper.endElement(
+ rtl::OUString(
+ RTL_UTF8_USTRINGPARAM (
+ (sal_Char*)(pOldCurrentElement->name)
+ )));
+ m_pCurrentElement = saxHelper.getCurrentNode();
+
+ /*
+ * remove the node
+ */
+ removeNode(pOldCurrentElement);
+}
+
+sal_Bool SAL_CALL XMLDocumentWrapper_XmlSecImpl::isCurrent( const cssu::Reference< cssxw::XXMLElementWrapper >& node )
+ throw (cssu::RuntimeException)
+{
+ xmlNodePtr pNode = checkElement(node);
+ return (pNode == m_pCurrentElement);
+}
+
+sal_Bool SAL_CALL XMLDocumentWrapper_XmlSecImpl::isCurrentElementEmpty( )
+ throw (cssu::RuntimeException)
+{
+ sal_Bool rc = sal_False;
+
+ if (m_pCurrentElement->children == NULL)
+ {
+ rc = sal_True;
+ }
+
+ return rc;
+}
+
+rtl::OUString SAL_CALL XMLDocumentWrapper_XmlSecImpl::getNodeName( const cssu::Reference< cssxw::XXMLElementWrapper >& node )
+ throw (cssu::RuntimeException)
+{
+ xmlNodePtr pNode = checkElement(node);
+ return rtl::OUString(RTL_UTF8_USTRINGPARAM ( (sal_Char*)pNode->name ));
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::clearUselessData(
+ const cssu::Reference< cssxw::XXMLElementWrapper >& node,
+ const cssu::Sequence< cssu::Reference< cssxw::XXMLElementWrapper > >& reservedDescendants,
+ const cssu::Reference< cssxw::XXMLElementWrapper >& stopAtNode )
+ throw (cssu::RuntimeException)
+{
+ xmlNodePtr pTargetNode = checkElement(node);
+
+ m_pStopAtNode = checkElement(stopAtNode);
+ m_aReservedNodes = reservedDescendants;
+ m_nReservedNodeIndex = 0;
+
+ getNextReservedNode();
+
+ recursiveDelete(pTargetNode);
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::collapse( const cssu::Reference< cssxw::XXMLElementWrapper >& node )
+ throw (cssu::RuntimeException)
+{
+ xmlNodePtr pTargetNode = checkElement(node);
+ xmlNodePtr pParent;
+
+ while (pTargetNode != NULL)
+ {
+ if (pTargetNode->children != NULL || pTargetNode == m_pCurrentElement)
+ {
+ break;
+ }
+
+ pParent = pTargetNode->parent;
+ removeNode(pTargetNode);
+ pTargetNode = pParent;
+ }
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::getTree( const cssu::Reference< cssxs::XDocumentHandler >& handler )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ if (m_pRootElement != NULL)
+ {
+ xmlNodePtr pTempCurrentElement = m_pCurrentElement;
+ sal_Int32 nTempCurrentPosition = m_nCurrentPosition;
+
+ m_pCurrentElement = m_pRootElement;
+
+ m_nCurrentPosition = NODEPOSITION_STARTELEMENT;
+ cssu::Reference< cssxs::XDocumentHandler > xHandler = handler;
+
+ while(true)
+ {
+ switch (m_nCurrentPosition)
+ {
+ case NODEPOSITION_STARTELEMENT:
+ sendStartElement(NULL, xHandler, m_pCurrentElement);
+ break;
+ case NODEPOSITION_ENDELEMENT:
+ sendEndElement(NULL, xHandler, m_pCurrentElement);
+ break;
+ case NODEPOSITION_NORMAL:
+ sendNode(NULL, xHandler, m_pCurrentElement);
+ break;
+ }
+
+ if ( (m_pCurrentElement == m_pRootElement) && (m_nCurrentPosition == NODEPOSITION_ENDELEMENT ))
+ {
+ break;
+ }
+
+ getNextSAXEvent();
+ }
+
+ m_pCurrentElement = pTempCurrentElement;
+ m_nCurrentPosition = nTempCurrentPosition;
+ }
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::generateSAXEvents(
+ const cssu::Reference< cssxs::XDocumentHandler >& handler,
+ const cssu::Reference< cssxs::XDocumentHandler >& xEventKeeperHandler,
+ const cssu::Reference< cssxw::XXMLElementWrapper >& startNode,
+ const cssu::Reference< cssxw::XXMLElementWrapper >& endNode )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ /*
+ * The first SAX event is the startElement of the startNode
+ * element.
+ */
+ bool bHasCurrentElementChild = (m_pCurrentElement->children != NULL);
+
+ xmlNodePtr pTempCurrentElement = m_pCurrentElement;
+
+ m_pCurrentElement = checkElement(startNode);
+
+ if (m_pCurrentElement->type == XML_ELEMENT_NODE)
+ {
+ m_nCurrentPosition = NODEPOSITION_STARTELEMENT;
+ }
+ else
+ {
+ m_nCurrentPosition = NODEPOSITION_NORMAL;
+ }
+
+ xmlNodePtr pEndNode = checkElement(endNode);
+
+ cssu::Reference < cssxc::sax::XSAXEventKeeper > xSAXEventKeeper( xEventKeeperHandler, cssu::UNO_QUERY );
+
+ cssu::Reference< cssxs::XDocumentHandler > xHandler = handler;
+
+ while(true)
+ {
+ switch (m_nCurrentPosition)
+ {
+ case NODEPOSITION_STARTELEMENT:
+ sendStartElement(xHandler, xEventKeeperHandler, m_pCurrentElement);
+ break;
+ case NODEPOSITION_ENDELEMENT:
+ sendEndElement(xHandler, xEventKeeperHandler, m_pCurrentElement);
+ break;
+ case NODEPOSITION_NORMAL:
+ sendNode(xHandler, xEventKeeperHandler, m_pCurrentElement);
+ break;
+ default:
+ throw cssu::RuntimeException();
+ break;
+ }
+
+ if (xSAXEventKeeper->isBlocking())
+ {
+ xHandler = NULL;
+ }
+
+ if (pEndNode == NULL &&
+ ((bHasCurrentElementChild && m_pCurrentElement == xmlGetLastChild(pTempCurrentElement) && m_nCurrentPosition != NODEPOSITION_STARTELEMENT) ||
+ (!bHasCurrentElementChild && m_pCurrentElement == pTempCurrentElement && m_nCurrentPosition == NODEPOSITION_STARTELEMENT)))
+ {
+ break;
+ }
+
+ getNextSAXEvent();
+
+ /*
+ * If there is an end point specified, then check whether
+ * the current node equals to the end point. If so, stop
+ * generating.
+ */
+ if (pEndNode != NULL && m_pCurrentElement == pEndNode)
+ {
+ break;
+ }
+ }
+
+ m_pCurrentElement = pTempCurrentElement;
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::rebuildIDLink(
+ const com::sun::star::uno::Reference< com::sun::star::xml::wrapper::XXMLElementWrapper >& node )
+ throw (com::sun::star::uno::RuntimeException)
+{
+ xmlNodePtr pNode = checkElement( node );
+ rebuildIDLink(pNode);
+}
+
+
+/* cssxs::XDocumentHandler */
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::startDocument( )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::endDocument( )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::startElement( const rtl::OUString& aName, const cssu::Reference< cssxs::XAttributeList >& xAttribs )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ sal_Int32 nLength = xAttribs->getLength();
+ cssu::Sequence< cssxcsax::XMLAttribute > aAttributes (nLength);
+
+ for (int i = 0; i < nLength; ++i)
+ {
+ aAttributes[i].sName = xAttribs->getNameByIndex((short)i);
+ aAttributes[i].sValue =xAttribs->getValueByIndex((short)i);
+ }
+
+ _startElement(aName, aAttributes);
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::endElement( const rtl::OUString& aName )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ saxHelper.endElement(aName);
+ m_pCurrentElement = saxHelper.getCurrentNode();
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::characters( const rtl::OUString& aChars )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ saxHelper.characters(aChars);
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::ignorableWhitespace( const rtl::OUString& aWhitespaces )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ saxHelper.ignorableWhitespace(aWhitespaces);
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ saxHelper.processingInstruction(aTarget, aData);
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::setDocumentLocator( const cssu::Reference< cssxs::XLocator >& xLocator )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ saxHelper.setDocumentLocator(xLocator);
+}
+
+/* XCompressedDocumentHandler */
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::_startDocument( )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::_endDocument( )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::_startElement( const rtl::OUString& aName, const cssu::Sequence< cssxcsax::XMLAttribute >& aAttributes )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ saxHelper.startElement(aName, aAttributes);
+ m_pCurrentElement = saxHelper.getCurrentNode();
+
+ buildIDAttr( m_pCurrentElement );
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::_endElement( const rtl::OUString& aName )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ endElement( aName );
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::_characters( const rtl::OUString& aChars )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ characters( aChars );
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::_ignorableWhitespace( const rtl::OUString& aWhitespaces )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ ignorableWhitespace( aWhitespaces );
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::_processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+ processingInstruction( aTarget, aData );
+}
+
+void SAL_CALL XMLDocumentWrapper_XmlSecImpl::_setDocumentLocator( sal_Int32 columnNumber, sal_Int32 lineNumber, const rtl::OUString& publicId, const rtl::OUString& systemId )
+ throw (cssxs::SAXException, cssu::RuntimeException)
+{
+}
+
+rtl::OUString XMLDocumentWrapper_XmlSecImpl_getImplementationName ()
+ throw (cssu::RuntimeException)
+{
+ return rtl::OUString ( RTL_ASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
+}
+
+sal_Bool SAL_CALL XMLDocumentWrapper_XmlSecImpl_supportsService( const rtl::OUString& ServiceName )
+ throw (cssu::RuntimeException)
+{
+ return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
+}
+
+cssu::Sequence< rtl::OUString > SAL_CALL XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames( )
+ throw (cssu::RuntimeException)
+{
+ cssu::Sequence < rtl::OUString > aRet(1);
+ rtl::OUString* pArray = aRet.getArray();
+ pArray[0] = rtl::OUString ( RTL_ASCII_USTRINGPARAM ( SERVICE_NAME ) );
+ return aRet;
+}
+#undef SERVICE_NAME
+
+cssu::Reference< cssu::XInterface > SAL_CALL XMLDocumentWrapper_XmlSecImpl_createInstance(
+ const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr)
+ throw( cssu::Exception )
+{
+ return (cppu::OWeakObject*) new XMLDocumentWrapper_XmlSecImpl( );
+}
+
+/* XServiceInfo */
+rtl::OUString SAL_CALL XMLDocumentWrapper_XmlSecImpl::getImplementationName( )
+ throw (cssu::RuntimeException)
+{
+ return XMLDocumentWrapper_XmlSecImpl_getImplementationName();
+}
+sal_Bool SAL_CALL XMLDocumentWrapper_XmlSecImpl::supportsService( const rtl::OUString& rServiceName )
+ throw (cssu::RuntimeException)
+{
+ return XMLDocumentWrapper_XmlSecImpl_supportsService( rServiceName );
+}
+cssu::Sequence< rtl::OUString > SAL_CALL XMLDocumentWrapper_XmlSecImpl::getSupportedServiceNames( )
+ throw (cssu::RuntimeException)
+{
+ return XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames();
+}
+
diff --git a/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.hxx b/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.hxx
new file mode 100644
index 000000000000..8cdbfd1fcdc0
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/xmldocumentwrapper_xmlsecimpl.hxx
@@ -0,0 +1,328 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmldocumentwrapper_xmlsecimpl.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 _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX
+#define _XMLDOCUMENTWRAPPER_XMLSECIMPL_HXX
+
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLDOCUMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CSAX_XCOMPRESSEDDOCUMENTHANDLER_HPP_
+#include <com/sun/star/xml/csax/XCompressedDocumentHandler.hpp>
+#endif
+#ifndef _COM_SUN_STAR_XML_CRYPTO_SAX_XSAXEVENTKEEPER_HPP_
+#include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+#ifndef _CPPUHELPER_IMPLBASE4_HXX_
+#include <cppuhelper/implbase4.hxx>
+#endif
+
+#include "saxhelper.hxx"
+//#include "libxml/parserInternals.h"
+//#include "libxslt/xslt.h"
+
+#define NODEPOSITION_NORMAL 1
+#define NODEPOSITION_STARTELEMENT 2
+#define NODEPOSITION_ENDELEMENT 3
+
+#include <libxml/tree.h>
+
+class XMLDocumentWrapper_XmlSecImpl : public cppu::WeakImplHelper4
+<
+ com::sun::star::xml::wrapper::XXMLDocumentWrapper,
+ com::sun::star::xml::sax::XDocumentHandler,
+ com::sun::star::xml::csax::XCompressedDocumentHandler,
+ com::sun::star::lang::XServiceInfo
+>
+/****** XMLDocumentWrapper_XmlSecImpl.hxx/CLASS XMLDocumentWrapper_XmlSecImpl *
+ *
+ * NAME
+ * XMLDocumentWrapper_XmlSecImpl -- Class to manipulate a libxml2
+ * document
+ *
+ * FUNCTION
+ * Converts SAX events into a libxml2 document, converts the document back
+ * into SAX event stream, and manipulate nodes in the document.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XXMLDocumentWrapper,
+ * XDocumentHandler, XCompressedDocumentHandler,
+ * XServiceInfo
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+private:
+ /* the sax helper */
+ SAXHelper saxHelper;
+
+ /* the document used to convert SAX events to */
+ xmlDocPtr m_pDocument;
+
+ /* the root element */
+ xmlNodePtr m_pRootElement;
+
+ /*
+ * the current active element. The next incoming SAX event will be
+ * appended to this element
+ */
+ xmlNodePtr m_pCurrentElement;
+
+ /*
+ * This variable is used when converting the document or part of it into
+ * SAX events. See getNextSAXEvent method.
+ */
+ sal_Int32 m_nCurrentPosition;
+
+ /*
+ * used for recursive deletion. See recursiveDelete method
+ */
+ xmlNodePtr m_pStopAtNode;
+ xmlNodePtr m_pCurrentReservedNode;
+ com::sun::star::uno::Sequence< com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper > > m_aReservedNodes;
+ sal_Int32 m_nReservedNodeIndex;
+
+private:
+ void getNextSAXEvent();
+
+ void sendStartElement(
+ const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler,
+ const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2,
+ const xmlNodePtr pNode) const
+ throw (com::sun::star::xml::sax::SAXException);
+
+ void sendEndElement(
+ const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler,
+ const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2,
+ const xmlNodePtr pNode) const
+ throw (com::sun::star::xml::sax::SAXException);
+
+ void sendNode(
+ const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler,
+ const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xHandler2,
+ const xmlNodePtr pNode) const
+ throw (com::sun::star::xml::sax::SAXException);
+
+ rtl::OString getNodeQName(const xmlNodePtr pNode) const;
+
+ sal_Int32 recursiveDelete( const xmlNodePtr pNode);
+
+ void getNextReservedNode();
+
+ void removeNode( const xmlNodePtr pNode) const;
+
+ xmlNodePtr checkElement(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& xXMLElement) const;
+
+ void buildIDAttr( xmlNodePtr pNode ) const;
+ void rebuildIDLink( xmlNodePtr pNode ) const;
+
+public:
+ XMLDocumentWrapper_XmlSecImpl();
+ virtual ~XMLDocumentWrapper_XmlSecImpl();
+
+ /* com::sun::star::xml::wrapper::XXMLDocumentWrapper */
+ virtual com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper > SAL_CALL getCurrentElement( )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL setCurrentElement( const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& element )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL removeCurrentElement( )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL isCurrent( const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& node )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL isCurrentElementEmpty( )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual rtl::OUString SAL_CALL getNodeName( const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& node )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL clearUselessData(
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& node,
+ const com::sun::star::uno::Sequence< com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper > >& reservedDescendants,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& stopAtNode )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL collapse( const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& node )
+ throw (com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL generateSAXEvents(
+ const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& handler,
+ const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xEventKeeperHandler,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& startNode,
+ const com::sun::star::uno::Reference<
+ com::sun::star::xml::wrapper::XXMLElementWrapper >& endNode )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL getTree(
+ const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& handler )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL rebuildIDLink(
+ const com::sun::star::uno::Reference< com::sun::star::xml::wrapper::XXMLElementWrapper >& node )
+ throw (com::sun::star::uno::RuntimeException);
+
+ /* com::sun::star::xml::sax::XDocumentHandler */
+ virtual void SAL_CALL startDocument( )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL endDocument( )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL startElement(
+ const rtl::OUString& aName,
+ const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL endElement( const rtl::OUString& aName )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL characters( const rtl::OUString& aChars )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL ignorableWhitespace( const rtl::OUString& aWhitespaces )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL setDocumentLocator( const com::sun::star::uno::Reference< com::sun::star::xml::sax::XLocator >& xLocator )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ /* com::sun::star::xml::csax::XCompressedDocumentHandler */
+ virtual void SAL_CALL _startDocument( )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL _endDocument( )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL _startElement(
+ const rtl::OUString& aName,
+ const com::sun::star::uno::Sequence<
+ com::sun::star::xml::csax::XMLAttribute >& aAttributes )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL _endElement( const rtl::OUString& aName )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL _characters( const rtl::OUString& aChars )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL _ignorableWhitespace( const rtl::OUString& aWhitespaces )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL _processingInstruction( const rtl::OUString& aTarget, const rtl::OUString& aData )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ virtual void SAL_CALL _setDocumentLocator(
+ sal_Int32 columnNumber,
+ sal_Int32 lineNumber,
+ const rtl::OUString& publicId,
+ const rtl::OUString& systemId )
+ throw (com::sun::star::xml::sax::SAXException, com::sun::star::uno::RuntimeException);
+
+ /* com::sun::star::lang::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 XMLDocumentWrapper_XmlSecImpl_getImplementationName()
+ throw ( com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL XMLDocumentWrapper_XmlSecImpl_supportsService( const rtl::OUString& ServiceName )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
+ XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames( )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
+SAL_CALL XMLDocumentWrapper_XmlSecImpl_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/xmlelementwrapper_xmlsecimpl.cxx b/xmlsecurity/source/xmlsec/xmlelementwrapper_xmlsecimpl.cxx
new file mode 100644
index 000000000000..9b396fed8615
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/xmlelementwrapper_xmlsecimpl.cxx
@@ -0,0 +1,221 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlelementwrapper_xmlsecimpl.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 "xmlelementwrapper_xmlsecimpl.hxx"
+
+#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
+#include <cppuhelper/typeprovider.hxx>
+#endif
+
+namespace cssu = com::sun::star::uno;
+namespace cssl = com::sun::star::lang;
+
+#define SERVICE_NAME "com.sun.star.xml.wrapper.XMLElementWrapper"
+#define IMPLEMENTATION_NAME "com.sun.star.xml.security.bridge.xmlsec.XMLElementWrapper_XmlSecImpl"
+
+XMLElementWrapper_XmlSecImpl::XMLElementWrapper_XmlSecImpl(const xmlNodePtr pNode)
+ : m_pElement( pNode )
+{
+}
+
+/* XXMLElementWrapper */
+
+
+/* XUnoTunnel */
+cssu::Sequence< sal_Int8 > XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId( void )
+ throw (cssu::RuntimeException)
+{
+ static ::cppu::OImplementationId* pId = 0;
+ if (! pId)
+ {
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
+ if (! pId)
+ {
+ static ::cppu::OImplementationId aId;
+ pId = &aId;
+ }
+ }
+ return pId->getImplementationId();
+}
+
+sal_Int64 SAL_CALL XMLElementWrapper_XmlSecImpl::getSomething( const cssu::Sequence< sal_Int8 >& aIdentifier )
+ throw (cssu::RuntimeException)
+{
+ if (aIdentifier.getLength() == 16 &&
+ 0 == rtl_compareMemory(
+ getUnoTunnelImplementationId().getConstArray(),
+ aIdentifier.getConstArray(),
+ 16 ))
+ {
+ return reinterpret_cast < sal_Int64 > ( this );
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+
+rtl::OUString XMLElementWrapper_XmlSecImpl_getImplementationName ()
+ throw (cssu::RuntimeException)
+{
+ return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
+}
+
+sal_Bool SAL_CALL XMLElementWrapper_XmlSecImpl_supportsService( const rtl::OUString& ServiceName )
+ throw (cssu::RuntimeException)
+{
+ return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
+}
+
+cssu::Sequence< rtl::OUString > SAL_CALL XMLElementWrapper_XmlSecImpl_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
+ XMLElementWrapper_XmlSecImpl_createInstance(
+ const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr)
+ throw( cssu::Exception )
+{
+ return (cppu::OWeakObject*) new XMLElementWrapper_XmlSecImpl(NULL);
+}
+
+/* XServiceInfo */
+rtl::OUString SAL_CALL XMLElementWrapper_XmlSecImpl::getImplementationName( )
+ throw (cssu::RuntimeException)
+{
+ return XMLElementWrapper_XmlSecImpl_getImplementationName();
+}
+sal_Bool SAL_CALL XMLElementWrapper_XmlSecImpl::supportsService( const rtl::OUString& rServiceName )
+ throw (cssu::RuntimeException)
+{
+ return XMLElementWrapper_XmlSecImpl_supportsService( rServiceName );
+}
+cssu::Sequence< rtl::OUString > SAL_CALL XMLElementWrapper_XmlSecImpl::getSupportedServiceNames( )
+ throw (cssu::RuntimeException)
+{
+ return XMLElementWrapper_XmlSecImpl_getSupportedServiceNames();
+}
+
+xmlNodePtr XMLElementWrapper_XmlSecImpl::getNativeElement( ) const
+/****** XMLElementWrapper_XmlSecImpl/getNativeElement *************************
+ *
+ * NAME
+ * getNativeElement -- Retrieves the libxml2 node wrapped by this object
+ *
+ * SYNOPSIS
+ * pNode = getNativeElement();
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * empty
+ *
+ * RESULT
+ * pNode - the libxml2 node wrapped by this object
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ return m_pElement;
+}
+
+void XMLElementWrapper_XmlSecImpl::setNativeElement(const xmlNodePtr pNode)
+/****** XMLElementWrapper_XmlSecImpl/setNativeElement *************************
+ *
+ * NAME
+ * setNativeElement -- Configures the libxml2 node wrapped by this object
+ *
+ * SYNOPSIS
+ * setNativeElement( pNode );
+ *
+ * FUNCTION
+ * see NAME
+ *
+ * INPUTS
+ * pNode - the new libxml2 node to be wrapped by this object
+ *
+ * RESULT
+ * empty
+ *
+ * HISTORY
+ * 05.01.2004 - implemented
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+ m_pElement = pNode;
+}
+
diff --git a/xmlsecurity/source/xmlsec/xmlelementwrapper_xmlsecimpl.hxx b/xmlsecurity/source/xmlsec/xmlelementwrapper_xmlsecimpl.hxx
new file mode 100644
index 000000000000..d9d614d07136
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/xmlelementwrapper_xmlsecimpl.hxx
@@ -0,0 +1,152 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlelementwrapper_xmlsecimpl.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 _XMLELEMENTWRAPPER_XMLSECIMPL_HXX
+#define _XMLELEMENTWRAPPER_XMLSECIMPL_HXX
+
+#ifndef _COM_SUN_STAR_XML_WRAPPER_XXMLELEMENTWRAPPER_HPP_
+#include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_
+#include <com/sun/star/lang/XInitialization.hpp>
+#endif
+#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#endif
+#ifndef _CPPUHELPER_IMPLBASE3_HXX_
+#include <cppuhelper/implbase3.hxx>
+#endif
+
+#include <libxml/tree.h>
+
+class XMLElementWrapper_XmlSecImpl : public cppu::WeakImplHelper3
+<
+ com::sun::star::xml::wrapper::XXMLElementWrapper,
+ com::sun::star::lang::XUnoTunnel,
+ com::sun::star::lang::XServiceInfo
+>
+/****** XMLElementWrapper_XmlSecImpl.hxx/CLASS XMLElementWrapper_XmlSecImpl ***
+ *
+ * NAME
+ * XMLElementWrapper_XmlSecImpl -- Class to wrap a libxml2 node
+ *
+ * FUNCTION
+ * Used as a wrapper class to transfer a libxml2 node structure
+ * between different UNO components.
+ *
+ * HISTORY
+ * 05.01.2004 - Interface supported: XXMLElementWrapper, XUnoTunnel
+ * XServiceInfo
+ *
+ * AUTHOR
+ * Michael Mi
+ * Email: michael.mi@sun.com
+ ******************************************************************************/
+{
+private:
+ /* the libxml2 node wrapped by this object */
+ xmlNodePtr m_pElement;
+
+public:
+ explicit XMLElementWrapper_XmlSecImpl(const xmlNodePtr pNode);
+ virtual ~XMLElementWrapper_XmlSecImpl() {};
+
+ /* XXMLElementWrapper */
+
+ /* com::sun::star::lang::XUnoTunnel */
+ virtual sal_Int64 SAL_CALL getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
+ throw (com::sun::star::uno::RuntimeException);
+ static com::sun::star::uno::Sequence < sal_Int8 > getUnoTunnelImplementationId( void )
+ throw(com::sun::star::uno::RuntimeException);
+
+ /* com::sun::star::lang::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);
+
+public:
+ xmlNodePtr getNativeElement( ) const;
+ void setNativeElement(const xmlNodePtr pNode);
+};
+
+rtl::OUString XMLElementWrapper_XmlSecImpl_getImplementationName()
+ throw ( com::sun::star::uno::RuntimeException );
+
+sal_Bool SAL_CALL XMLElementWrapper_XmlSecImpl_supportsService( const rtl::OUString& ServiceName )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL XMLElementWrapper_XmlSecImpl_getSupportedServiceNames( )
+ throw ( com::sun::star::uno::RuntimeException );
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
+SAL_CALL XMLElementWrapper_XmlSecImpl_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/xmlstreamio.cxx b/xmlsecurity/source/xmlsec/xmlstreamio.cxx
new file mode 100644
index 000000000000..e11355f6103e
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/xmlstreamio.cxx
@@ -0,0 +1,244 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlstreamio.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): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+/*
+ * Implementation of the I/O interfaces based on stream and URI binding
+ */
+#ifndef _XMLSTREAMIO_XMLSECIMPL_HXX_
+#include "xmlstreamio.hxx"
+#endif
+
+#ifndef _RTL_USTRING_HXX_
+#include <rtl/ustring.hxx>
+#endif
+
+#include <libxml/uri.h>
+#include <xmlsec/io.h>
+
+#define XMLSTREAMIO_INITIALIZED 0x01
+#define XMLSTREAMIO_REGISTERED 0x02
+
+/* Global variables */
+/*-
+ * Enable stream I/O or not.
+ */
+static char enableXmlStreamIO = 0x00 ;
+
+::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XUriBinding > m_xUriBinding ;
+
+int xmlStreamMatch( const char* uri )
+{
+ ::com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInputStream ;
+
+ if( ( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) &&
+ ( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) {
+ if( uri == NULL || !m_xUriBinding.is() )
+ return 0 ;
+
+ xInputStream = m_xUriBinding->getUriBinding( ::rtl::OUString::createFromAscii( uri ) ) ;
+ if( xInputStream.is() )
+ return 1 ;
+ }
+
+ return 0 ;
+}
+
+void* xmlStreamOpen( const char* uri )
+{
+ ::com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInputStream ;
+ ::com::sun::star::io::XInputStream* pInputStream ;
+
+ if( ( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) &&
+ ( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) {
+ if( uri == NULL || !m_xUriBinding.is() )
+ return NULL ;
+
+ xInputStream = m_xUriBinding->getUriBinding( ::rtl::OUString::createFromAscii( uri ) ) ;
+ if( xInputStream.is() ) {
+ pInputStream = xInputStream.get() ;
+ pInputStream->acquire() ;
+ return ( void* )pInputStream ;
+ }
+ }
+
+ return NULL ;
+}
+
+int xmlStreamRead( void* context, char* buffer, int len )
+{
+ int numbers ;
+ ::com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInputStream ;
+ ::com::sun::star::uno::Sequence< sal_Int8 > outSeqs( len ) ;
+
+ numbers = 0 ;
+ if( ( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) &&
+ ( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) {
+ if( context != NULL ) {
+ xInputStream = ( com::sun::star::io::XInputStream* )context ;
+ if( !xInputStream.is() )
+ return 0 ;
+
+ numbers = xInputStream->readBytes( outSeqs, len ) ;
+ const sal_Int8* readBytes = ( const sal_Int8* )outSeqs.getArray() ;
+ for( int i = 0 ; i < numbers ; i ++ )
+ *( buffer + i ) = *( readBytes + i ) ;
+ }
+ }
+
+ return numbers ;
+}
+
+int xmlStreamClose( void * context )
+{
+ ::com::sun::star::io::XInputStream* pInputStream ;
+
+ if( ( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) &&
+ ( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) {
+ if( context != NULL ) {
+ pInputStream = ( ::com::sun::star::io::XInputStream* )context ;
+ pInputStream->release() ;
+ }
+ }
+
+ return 0 ;
+}
+
+int xmlEnableStreamInputCallbacks()
+{
+ int cbs = 0 ;
+
+ if( !( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) ) {
+ //Register the callbacks into libxml2
+ //cbs = xmlRegisterInputCallbacks(
+ // xmlStreamMatch,
+ // xmlStreamOpen,
+ // xmlStreamRead,
+ // xmlStreamClose ) ;
+ //if( cbs < 0 ) {
+ // return -1 ;
+ //}
+
+ //Register the callbacks into xmlSec
+ //In order to make the xmlsec io finding the callbacks firstly,
+ //I put the callbacks at the very begining.
+
+ //Cleanup the older callbacks.
+ //Notes: all none default callbacks will lose.
+ xmlSecIOCleanupCallbacks() ;
+
+ //Register my classbacks.
+ cbs = xmlSecIORegisterCallbacks(
+ xmlStreamMatch,
+ xmlStreamOpen,
+ xmlStreamRead,
+ xmlStreamClose ) ;
+ if( cbs < 0 ) {
+ return -1 ;
+ }
+
+ //Register the default callbacks.
+ //Notes: the error will cause xmlsec working problems.
+ cbs = xmlSecIORegisterDefaultCallbacks() ;
+ if( cbs < 0 ) {
+ return -1 ;
+ }
+
+ enableXmlStreamIO |= XMLSTREAMIO_INITIALIZED ;
+ }
+
+ return 0 ;
+}
+
+int xmlRegisterStreamInputCallbacks(
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XUriBinding >& aUriBinding
+) {
+ if( !( enableXmlStreamIO & XMLSTREAMIO_INITIALIZED ) ) {
+ if( xmlEnableStreamInputCallbacks() < 0 )
+ return -1 ;
+ }
+
+ if( !( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) {
+ enableXmlStreamIO |= XMLSTREAMIO_REGISTERED ;
+ }
+
+ m_xUriBinding = aUriBinding ;
+
+ return 0 ;
+}
+
+int xmlUnregisterStreamInputCallbacks( void )
+{
+ if( ( enableXmlStreamIO & XMLSTREAMIO_REGISTERED ) ) {
+ //Clear the uir-stream binding
+ m_xUriBinding.clear() ;
+
+ //disable the registered flag
+ enableXmlStreamIO &= ~XMLSTREAMIO_REGISTERED ;
+ }
+
+ return 0 ;
+}
+
+void xmlDisableStreamInputCallbacks() {
+ xmlUnregisterStreamInputCallbacks() ;
+ enableXmlStreamIO &= ~XMLSTREAMIO_INITIALIZED ;
+}
+
diff --git a/xmlsecurity/source/xmlsec/xmlstreamio.hxx b/xmlsecurity/source/xmlsec/xmlstreamio.hxx
new file mode 100644
index 000000000000..bad8162a5b01
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/xmlstreamio.hxx
@@ -0,0 +1,83 @@
+/*************************************************************************
+ *
+ * $RCSfile: xmlstreamio.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 _XMLSTREAMIO_XMLSECIMPL_HXX_
+#define _XMLSTREAMIO_XMLSECIMPL_HXX_
+
+#ifndef _COM_SUN_STAR_UNO_REFERENCE_HPP_
+#include <com/sun/star/uno/Reference.hxx>
+#endif
+
+#ifndef _COM_SUN_STAR_XML_CRYPTO_XURIBINDING_HPP_
+#include <com/sun/star/xml/crypto/XUriBinding.hpp>
+#endif
+
+int xmlEnableStreamInputCallbacks( void ) ;
+void xmlDisableStreamInputCallbacks( void ) ;
+
+int xmlRegisterStreamInputCallbacks(
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XUriBinding >& aUriBinding
+) ;
+
+int xmlUnregisterStreamInputCallbacks( void ) ;
+
+#endif //_XMLSTREAMIO_XMLSECIMPL_HXX_
+
diff --git a/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx b/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx
new file mode 100644
index 000000000000..1b96d54ae962
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx
@@ -0,0 +1,201 @@
+/*************************************************************************
+ *
+ * $RCSfile: xsec_xmlsec.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 "xmlelementwrapper_xmlsecimpl.hxx"
+#include "xmldocumentwrapper_xmlsecimpl.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"
+{
+
+#if defined( XMLSEC_CRYPTO_NSS )
+extern sal_Bool nss_component_writeInfo( void*, void* );
+extern void* nss_component_getFactory( const sal_Char*, void*, void* );
+#endif
+
+#if defined( XMLSEC_CRYPTO_MSCRYPTO )
+extern sal_Bool mscrypt_component_writeInfo( void*, void* );
+extern void* mscrypt_component_getFactory( const sal_Char*, void*, void* );
+#endif
+
+void SAL_CALL component_getImplementationEnvironment(
+ const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv )
+{
+ *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+
+
+sal_Bool SAL_CALL 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 {
+ // XMLElementWrapper_XmlSecImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += XMLElementWrapper_XmlSecImpl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = XMLElementWrapper_XmlSecImpl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+ // XMLDocumentWrapper_XmlSecImpl
+ sKeyName = OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ;
+ sKeyName += XMLDocumentWrapper_XmlSecImpl_getImplementationName() ;
+ sKeyName += OUString::createFromAscii( "/UNO/SERVICES" ) ;
+
+ xNewKey = xKey->createKey( sKeyName ) ;
+ if( xNewKey.is() ) {
+ seqServices = XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames() ;
+ for( i = seqServices.getLength() ; i -- ; )
+ xNewKey->createKey( seqServices.getConstArray()[i] ) ;
+ }
+
+#if defined( XMLSEC_CRYPTO_NSS )
+ result = nss_component_writeInfo( pServiceManager, pRegistryKey ) ;
+ if( !result )
+ return sal_False ;
+#endif
+
+#if defined( XMLSEC_CRYPTO_MSCRYPTO )
+ result = mscrypt_component_writeInfo( pServiceManager, pRegistryKey ) ;
+ if( !result )
+ return sal_False ;
+#endif
+
+ //} catch( InvalidRegistryException & ) {
+ // //we should not ignore exceptions
+ // return sal_False ;
+ //}
+ }
+
+ return result;
+}
+
+void* SAL_CALL component_getFactory( const sal_Char* pImplName , void* pServiceManager , void* pRegistryKey )
+{
+ void* pRet = 0;
+ Reference< XSingleServiceFactory > xFactory ;
+
+ if( pImplName != NULL && pServiceManager != NULL ) {
+ if( XMLElementWrapper_XmlSecImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) )
+ {
+ xFactory = Reference< XSingleServiceFactory >( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ XMLElementWrapper_XmlSecImpl_createInstance, XMLElementWrapper_XmlSecImpl_getSupportedServiceNames() ) );
+ }
+ else if( XMLDocumentWrapper_XmlSecImpl_getImplementationName().equals( OUString::createFromAscii( pImplName ) ) )
+ {
+ xFactory = Reference< XSingleServiceFactory >( createSingleFactory(
+ reinterpret_cast< XMultiServiceFactory * >( pServiceManager ),
+ OUString::createFromAscii( pImplName ),
+ XMLDocumentWrapper_XmlSecImpl_createInstance, XMLDocumentWrapper_XmlSecImpl_getSupportedServiceNames() ) );
+ }
+ }
+
+ if( xFactory.is() ) {
+ xFactory->acquire() ;
+ pRet = xFactory.get() ;
+ } else {
+#if defined( XMLSEC_CRYPTO_NSS )
+ pRet = nss_component_getFactory( pImplName, pServiceManager, pRegistryKey ) ;
+ if( pRet != NULL )
+ return pRet ;
+#endif
+
+#if defined( XMLSEC_CRYPTO_MSCRYPTO )
+ pRet = mscrypt_component_getFactory( pImplName, pServiceManager, pRegistryKey ) ;
+ if( pRet != NULL )
+ return pRet ;
+#endif
+ }
+
+ return pRet ;
+}
+
+}
+